Skip to contentSkip to conversation

Nexthop match

PATCH In review Igor Fuks 2 participants 5 messages Nov 23, 2003 netfilter

lore
Share & tools
lore

Igor Fuks

author
#0 lore raw

PATCH 1/1 Nexthop match

Attached is a p-o-m patchset containing nexthop match support for the netfilter.

This patch adds CONFIG_IP_NF_MATCH_NEXTHOP which allows you to match firewall rules against address(es) of nexthop of matched packets.

Works for POSTROUTING, FORWARD and OUTPUT chains only.

Options:

--nexthop [!] <ipaddr>[/mask]

Example #1:

iptables -A OUTPUT -m nexthop --nexthop 10.1.1.5 -s 10.1.10.0/24 -j DROP

Means stations in 10.1.10.0/24 net will have not connectivity via 10.1.1.5 neighbour.

Example #2:

Match useful for per peer IP accounting, for example, on Internet eXchanges:

iptables -A FORWARD -m nexthop --nexthop 10.1.1.10 iptables -A FORWARD -m nexthop --nexthop 10.1.1.11 iptables -A FORWARD -m nexthop --nexthop 10.1.1.12 iptables -A FORWARD -m nexthop --nexthop 10.1.1.13

where 10.1.1.10-10.1.1.13 0 are IX peers to account

Example #3:

iptables -t mangle -A POSTROUTING -m nexthop --nexthop 10.1.16.0/24 \
         -j MARK --set-mark 16

Mark all packets going via set of gateways/interfaces identified by nexthop IP address in 10.1.16.0/24 range

iptables -t mangle -A POSTROUTING -o eth0 \
         -m nexthop --nexthop ! 10.1.64.128/29 -j MARK --set-mark 8

Mark all packets going out via eth0 interface and not via neighbours (peers) in 10.1.64.128/29 range

Example #4:

iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -o eth1 \
         -m nexthop --nexthop 1.1.1.1 -j SNAT --to-source 1.1.1.10
iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -o eth1 \
         -m nexthop --nexthop 2.2.2.2 -j SNAT --to-source 2.2.2.10

where eth1:0 have 1.1.1.10/24 address from ISP 1,

      eth1:1 have 2.2.2.10/24 address from ISP 2,
      1.1.1.1 is nexthop for ISP 1,
      2.2.2.2 is nexthop for ISP 2,
      10.0.0.0/8 is internal network, it needs Internet connectivity via NAT,
      and our system have dynamic routing from both ISPs.
 
                                                 1.1.1.1
                                             +--------- {ISP 1}----+
                          eth1:0 1.1.1.10/24 |                     |
                 eth0                   eth1 |                     |
   {10.0.0.0/8} -----[netfilter router]------+                 {Internet}
                                             |                     |
                          eth1:1 2.2.2.10/24 |    2.2.2.2          |
                                             +--------- {ISP 2}----+

--
Igor Fuks

#1 lore raw

Hi,

this is interesting, but I have a few questions :

Quoted 6 lines · Igor Fuks

Example #1:

iptables -A OUTPUT -m nexthop --nexthop 10.1.1.5 -s 10.1.10.0/24 -j DROP

Means stations in 10.1.10.0/24 net will have not connectivity via 10.1.1.5 neighbour.

It should have been in POSTROUTING or FORWARD for this, isn't it ?

Does it also match packets going TO the gateway, or only packets routed THROUGH the gateway ?

Cheers,
Willy

author
#2 lore raw

Hello Willy,

Sunday, November 23, 2003, 10:29:06 AM, you wrote:

WT> this is interesting, but I have a few questions :

Quoted 6 lines · Igor Fuks
Quoted 6 lines

Example #1:

iptables -A OUTPUT -m nexthop --nexthop 10.1.1.5 -s 10.1.10.0/24 -j DROP

Means stations in 10.1.10.0/24 net will have not connectivity via 10.1.1.5 neighbour.

WT> It should have been in POSTROUTING or FORWARD for this, isn't it ?

It works for POSTROUTING, FORWARD and OUTPUT.

WT> Does it also match packets going TO the gateway, or only packets routed WT> THROUGH the gateway ?

Not only THROUGH, it match packets going TO the gateway(s) too.

--
Igor Fuks

#3 lore raw
Quoted 9 lines · Igor Fuks
Quoted 5 lines
Quoted 5 lines

iptables -A OUTPUT -m nexthop --nexthop 10.1.1.5 -s 10.1.10.0/24 -j DROP

Means stations in 10.1.10.0/24 net will have not connectivity via 10.1.1.5 neighbour.

WT> It should have been in POSTROUTING or FORWARD for this, isn't it ?

It works for POSTROUTING, FORWARD and OUTPUT.

Sorry, I meant that the above rule only matches locally generated packets (OUTPUT), which is a bit in contradiction with the comment 'stations in...'.

Quoted 4 lines

WT> Does it also match packets going TO the gateway, or only packets routed WT> THROUGH the gateway ?

Not only THROUGH, it match packets going TO the gateway(s) too.

Thanks for this clarification.

Regards,
Willy

author
#4 lore raw

Hello Willy,

Sunday, November 23, 2003, 1:03:54 PM, you wrote:

Quoted 9 lines · Igor Fuks
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines

iptables -A OUTPUT -m nexthop --nexthop 10.1.1.5 -s 10.1.10.0/24 -j DROP

Means stations in 10.1.10.0/24 net will have not connectivity via 10.1.1.5 neighbour.

WT> It should have been in POSTROUTING or FORWARD for this, isn't it ?

It works for POSTROUTING, FORWARD and OUTPUT.

WT> Sorry, I meant that the above rule only matches locally generated packets WT> (OUTPUT), which is a bit in contradiction with the comment 'stations in...'.

You are right. Not a good example. This rule really matches locally generated packets only _with_ source 10.1.10.0/24. It is possible when netfilter box have several interfaces, including some in 10.1.10.0/24, and by some reason sends traffic via 10.1.1.5 with different source addresses. I agree, this is not so useful example...

Quoted 4 lines
Quoted 4 lines

WT> Does it also match packets going TO the gateway, or only packets routed WT> THROUGH the gateway ?

Not only THROUGH, it match packets going TO the gateway(s) too.

WT> Thanks for this clarification.

--
Igor Fuks