Skip to contentSkip to conversation

Odd use of netmasks - Supported?

DISCUSSION tlhackque 2 participants 2 messages Oct 4, 2012

lore
Share & tools
lore

tlhackque

author
#0 lore raw

I have some very long (thousands of rules) rule chains, which I wish to shorten by dispatching on part of the address.

Clearly, I can do something like -A FOO -s 2001:db8:1000/36 -j SUBCHAIN-81.

But in IPV6, the high order bits really aren't interesting.

The syntax -A FOO -s 001:c000::0/0f:f000:: (note the leading 1s in the "netmask") seems to be accepted by iptables, and the rule appears with -L.

I would expect an address to be XORed with the -s address, ANDed with the mask, and be true if 0. Even though this is an illegal mask for routing, it's interesting for this.

Rather than experiment and rely on some undocumented behavior, I thought I should ask:

Is this usage supported (in the sense that it will behave as described and will continue to do so)? Or is this living dangerously?

Of course, it would be nice to have a chain type that didn't have sequential evaluation semantics and just dispatched based on netmask and address... but that's how things might be, not how they are...

(Why ridiculous chain lengths, you ask? Country blocking. But no philosophical discussions about why this is a bad idea/easy to subvert, please.)

Thanks.

Signature · 3 lines
---------------------------------------------------------
This communication may not represent my employer's views,
if any, on the matters discussed.
#1 lore raw
Quoted 3 lines · tlhackque

The syntax -A FOO -s 001:c000::0/0f:f000:: (note the leading 1s in the "netmask") seems to be accepted by iptables, and the rule appears with -L.

Yes, that is officially supported. So all that's lacking is the mention in iptables.8.

Quoted 7 lines

Of course, it would be nice to have a chain type that didn't have sequential evaluation semantics and just dispatched based on netmask and address... but that's how things might be, not how they are...

(Why ridiculous chain lengths, you ask? Country blocking. But no philosophical discussions about why this is a bad idea/easy to subvert, please.)

To match on countries, you can preferably use xt_geoip (space efficient and reasonably time efficient), or construct something handmade with ipsets (time efficient but space is secondary).