Skip to contentSkip to conversation

Working on a match extension (ipt_gateway)

DISCUSSION Samuel Jean 2 participants 2 messages Jul 17, 2004 – Jul 19, 2004 netfilter

lore
Share & tools
lore
#0 lore raw
Quoted 49 lines · Samuel Jean
Quoted 9 lines · Jozsef
Quoted 7 lines · Samuel Jean

I'm working on an extension used to match packets by next-hop ip. It is only valid with FORWARD & POST_ROUTING hooks.
It gets the routing decision via (struct rtable*)skb->dst and it works quite well.

I just finished on Linux 2.6 and I'm about to do it on 2.4.

Quoted 9 lines
Quoted 6 lines

I've done it after reading that unanswered post :
http://lists.netfilter.org/pipermail/netfilter/2004-July/054199.html

Please, could someone answer my questions :

1) Is that match useless? (Can this be done without such a match)

Could you give an example in which context can it be useful?

Sure, let me take the example given in that unanswered post.

  +-------------+ 200.0.0.0/24       +---------------+ 192.168.2.0/24
  | Router A    | 200.0.1.0/24       | Router B      | 192.168.3.0/24
  +------+------+ 200.0.2.0/24       +--------+------+ 192.168.4.0/24
         |                                    |
   192.168.0.2                          192.168.0.3
         |                                    |
         |                                    |
         +--------------------+---------------+
                              |
                         192.168.0.1
                              | [ETH1]
                       +-------------+
                       | Netfilter   |
                       +------+------+
                              |
                         192.168.5.0/24

Ok, I know this setup is a little strange, but it could be real.

If packets coming from 192.168.5.0/24 are going to Internet (Router A) we'd like to MASQUERADE it. But we can't use something like :

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE because everything going to 192.168.{2,3,4}.0/24 will be NATed too.

Using something like :

Quoted 8 lines

iptables -t nat -A POSTROUTING -m gateway --gateway 192.168.0.2 -j MASQUE= RADE

could be a solution.

MASQUERADE is just a silly example cause I don't know what that person really wants to do with matched packets. He just mentioned he want to match packets by next-hop.

Forget about the MASQUERADE example, it's not a good one at all ! I'm sorry for such a poor example which I've quickly writen whithout thinking.

(The netfilter box doesn't have to MASQUERADE packets since he's not attached to a public network.)

In my opinion, the only good use of this match would be for accounting purpose.

Maybe someone else will find other uses.

Have a nice day,

Signature · 3 lines
Samuel Jean
SysAdmin & NetAdmin
at cookinglinux.org
#1 lore raw
Quoted 3 lines · Samuel Jean

Forget about the MASQUERADE example, it's not a good one at all ! I'm sorry for such a poor example which I've quickly writen whithout thinking.

It is a reasonable example except that SNAT is probably more suited for the job...

Quoted 2 lines

(The netfilter box doesn't have to MASQUERADE packets since he's not attached to a public network.)

Doesn't really matter. There is situations on private networks where SNAT is equally needed/wanted to hide "internal" addressing details or otherwise simplify networking.

What can be said about using routing information in this manner (for any result, being it SNAT or accounting) is that it is only needed in situations where it is unfeasible to replicate the needed destination classifications in iptables. It should also be noted that the information needs to be trusted for this to be done in any meaningful manner.

The example discussed can be solved equally well using vlans with one router per vlan. The question is, should this be required by iptables in order to be able to access information about which route was selected by routing or is having a "gateway/route" match suitable? Also, not all such situations can be solved by using vlans.

Personally I would not mind having a POSTROUTING "route" match available in patch-o-matic-ng to match details about the selected route (next hop, metric, dynamic/static, whatelse is available).

Regards
Henrik