# CIDRMATCH.RC # # File created 7/12/2005 -GE # CIDR (Classless Inter-Domain Routing) # Generate partial regexp patterns for every possible IPv4 NETWORK/CIDR # pattern from /8 to /32 related to the IPv4 address we are looking at. # # This file is written entirely in procmail. Yes, I know it's re-inventing the wheel # however this may be the only way to ensure maximum backward compatability with # the various older operating systems using the SpamBouncer. -GE :0 * ! LOCALIP ?? ^000\.000\.000\.000$ { Q1A=${QUAD2} # Bit7 :0 * 1^0 * $ ${Q1A}^0 * -128^0 { BIT7=128 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT7=0 } # Bit6 :0 * 1^0 * $ ${Q1A}^0 * -64^0 { BIT6=64 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT6=0 } # Bit5 :0 * 1^0 * $ ${Q1A}^0 * -32^0 { BIT5=32 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT5=0 } # Bit4 :0 * 1^0 * $ ${Q1A}^0 * -16^0 { BIT4=16 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT4=0 } # Bit3 :0 * 1^0 * $ ${Q1A}^0 * -8^0 { BIT3=8 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT3=0 } # Bit2 :0 * 1^0 * $ ${Q1A}^0 * -4^0 { BIT2=4 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT2=0 } # Bit1 :0 * 1^0 * $ ${Q1A}^0 * -2^0 { BIT1=2 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT1=0 } # Bit0 is implied # CIDR8 CIDR8="${QUAD1}\.0\.0\.0/8" # CIDR9 :0 * $ ${BIT7}^0 { CIDRT=$= CIDR9="${QUAD1}\.${CIDRT}\.0\.0/9" } :0 E { CIDR9="${QUAD1}\.0\.0\.0/9" } # CIDR10 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 { CIDRT=$= CIDR10="${QUAD1}\.${CIDRT}\.0\.0/10" } :0 E { CIDR10="${QUAD1}\.0\.0\.0/10" } # CIDR11 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 { CIDRT=$= CIDR11="${QUAD1}\.${CIDRT}\.0\.0/11" } :0 E { CIDR11="${QUAD1}\.0\.0\.0/11" } # CIDR12 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 { CIDRT=$= CIDR12="${QUAD1}\.${CIDRT}\.0\.0/12" } :0 E { CIDR12="${QUAD1}\.0\.0\.0/12" } # CIDR13 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 { CIDRT=$= CIDR13="${QUAD1}\.${CIDRT}\.0\.0/13" } :0 E { CIDR13="${QUAD1}\.0\.0\.0/13" } # CIDR14 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 * $ ${BIT2}^0 { CIDRT=$= CIDR14="${QUAD1}\.${CIDRT}\.0\.0/14" } :0 E { CIDR14="${QUAD1}\.0\.0\.0/14" } # CIDR15 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 * $ ${BIT2}^0 * $ ${BIT1}^0 { CIDRT=$= CIDR15="${QUAD1}\.${CIDRT}\.0\.0/15" } :0 E { CIDR15="${QUAD1}\.0\.0\.0/15" } # CIDR16 CIDR16="${QUAD1}\.${QUAD2}\.0\.0/16" Q1A=${QUAD3} # Bit7 :0 * 1^0 * $ ${Q1A}^0 * -128^0 { BIT7=128 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT7=0 } # Bit6 :0 * 1^0 * $ ${Q1A}^0 * -64^0 { BIT6=64 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT6=0 } # Bit5 :0 * 1^0 * $ ${Q1A}^0 * -32^0 { BIT5=32 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT5=0 } # Bit4 :0 * 1^0 * $ ${Q1A}^0 * -16^0 { BIT4=16 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT4=0 } # Bit3 :0 * 1^0 * $ ${Q1A}^0 * -8^0 { BIT3=8 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT3=0 } # Bit2 :0 * 1^0 * $ ${Q1A}^0 * -4^0 { BIT2=4 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT2=0 } # Bit1 :0 * 1^0 * $ ${Q1A}^0 * -2^0 { BIT1=2 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT1=0 } # Bit0 is implied # CIDR17 :0 * $ ${BIT7}^0 { CIDRT=$= CIDR17="${QUAD1}\.${QUAD2}\.${CIDRT}\.0/17" } :0 E { CIDR17="${QUAD1}\.${QUAD2}\.0\.0/17" } # CIDR18 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 { CIDRT=$= CIDR18="${QUAD1}\.${QUAD2}\.${CIDRT}\.0/18" } :0 E { CIDR18="${QUAD1}\.${QUAD2}\.0\.0/18" } # CIDR19 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 { CIDRT=$= CIDR19="${QUAD1}\.${QUAD2}\.${CIDRT}\.0/19" } :0 E { CIDR19="${QUAD1}\.${QUAD2}\.0\.0/19" } # CIDR20 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 { CIDRT=$= CIDR20="${QUAD1}\.${QUAD2}\.${CIDRT}\.0/20" } :0 E { CIDR20="${QUAD1}\.${QUAD2}\.0\.0/20" } # CIDR21 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 { CIDRT=$= CIDR21="${QUAD1}\.${QUAD2}\.${CIDRT}\.0/21" } :0 E { CIDR21="${QUAD1}\.${QUAD2}\.0\.0/21" } # CIDR22 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 * $ ${BIT2}^0 { CIDRT=$= CIDR22="${QUAD1}\.${QUAD2}\.${CIDRT}\.0/22" } :0 E { CIDR22="${QUAD1}\.${QUAD2}\.0\.0/22" } # CIDR23 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 * $ ${BIT2}^0 * $ ${BIT1}^0 { CIDRT=$= CIDR23="${QUAD1}\.${QUAD2}\.${CIDRT}\.0/23" } :0 E { CIDR23="${QUAD1}\.${QUAD2}\.0\.0/23" } # CIDR24 CIDR24="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/24" Q1A=${QUAD4} # Bit7 :0 * 1^0 * $ ${Q1A}^0 * -128^0 { BIT7=128 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT7=0 } # Bit6 :0 * 1^0 * $ ${Q1A}^0 * -64^0 { BIT6=64 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT6=0 } # Bit5 :0 * 1^0 * $ ${Q1A}^0 * -32^0 { BIT5=32 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT5=0 } # Bit4 :0 * 1^0 * $ ${Q1A}^0 * -16^0 { BIT4=16 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT4=0 } # Bit3 :0 * 1^0 * $ ${Q1A}^0 * -8^0 { BIT3=8 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT3=0 } # Bit2 :0 * 1^0 * $ ${Q1A}^0 * -4^0 { BIT2=4 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT2=0 } # Bit1 :0 * 1^0 * $ ${Q1A}^0 * -2^0 { BIT1=2 Q1A=$= :0 * $ ${Q1A}^0 * -1^0 { Q1A=$= } :0 E { Q1A=0 } } :0 E { BIT1=0 } # Bit0 is implied # CIDR25 :0 * $ ${BIT7}^0 { CIDRT=$= CIDR25="${QUAD1}\.${QUAD2}\.${QUAD3}\.${CIDRT}/25" } :0 E { CIDR25="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/25" } # CIDR26 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 { CIDRT=$= CIDR26="${QUAD1}\.${QUAD2}\.${QUAD3}\.${CIDRT}/26" } :0 E { CIDR26="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/26" } # CIDR27 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 { CIDRT=$= CIDR27="${QUAD1}\.${QUAD2}\.${QUAD3}\.${CIDRT}/27" } :0 E { CIDR27="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/27" } # CIDR28 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 { CIDRT=$= CIDR28="${QUAD1}\.${QUAD2}\.${QUAD3}\.${CIDRT}/28" } :0 E { CIDR28="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/28" } # CIDR29 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 { CIDRT=$= CIDR29="${QUAD1}\.${QUAD2}\.${QUAD3}\.${CIDRT}/29" } :0 E { CIDR29="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/29" } # CIDR30 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 * $ ${BIT2}^0 { CIDRT=$= CIDR30="${QUAD1}\.${QUAD2}\.${QUAD3}\.${CIDRT}/30" } :0 E { CIDR30="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/30" } # CIDR31 :0 * $ ${BIT7}^0 * $ ${BIT6}^0 * $ ${BIT5}^0 * $ ${BIT4}^0 * $ ${BIT3}^0 * $ ${BIT2}^0 * $ ${BIT1}^0 { CIDRT=$= CIDR31="${QUAD1}\.${QUAD2}\.${QUAD3}\.${CIDRT}/31" } :0 E { CIDR31="${QUAD1}\.${QUAD2}\.${QUAD3}\.0/31" } # CIDR32 CIDR32="${QUAD1}\.${QUAD2}\.${QUAD3}\.${QUAD4}(/32)?" LOCALIPREGEXP="^(${CIDR8}|${CIDR9}|${CIDR10}|${CIDR11}|${CIDR12}|${CIDR13}|${CIDR14}|${CIDR15}|${CIDR16}|${CIDR17}|${CIDR18}|${CIDR19}|${CIDR20}|${CIDR21}|${CIDR22}|${CIDR23}|${CIDR24}|${CIDR25}|${CIDR26}|${CIDR27}|${CIDR28}|${CIDR29}|${CIDR30}|${CIDR31}|${CIDR32})$" SBLOG="L9-functions/cidrmatch.rc: Debug: LOCALIP=${LOCALIP}" INCLUDERC=${SBDIR}/functions/loglevel.rc SBLOG="L9-functions/cidrmatch.rc: Debug: LOCALIPREGEXP=${LOCALIPREGEXP}" INCLUDERC=${SBDIR}/functions/loglevel.rc } :0 E { SBLOG="L8-functions/cidrmatch.rc: Debug: LOCALIP=${LOCALIP} Setting LOCALIPREGEXP='NULL'" INCLUDERC=${SBDIR}/functions/loglevel.rc LOCALIPREGEXP='NULL' }