ROUTE target fixes for --iif
PATCH 1/1 ROUTE target fixes for --iif
Hello,
I mailed several ROUTE target fixes to Cédric de Launois about two weeks ago, but they weren't ACK'd, so I'm posting a combined patch against patch-o-matic-ng here.
Fixes:
o Insert missing dev_put() following dev_get_by_name().
o Don't decrement TTL on packets re-injected with route_iif().
o Fix cut-n-paste error in route_iif() debug message().
o Dead code removal and a few cleanups.
I'm using the ROUTE target --iif functionality, in combination with the teql round-robin packet scheduler, to remap incoming packets on multiple interfaces (in this case hdlc[0-3]) to teql0. [teql only schedules outgoing packets; incoming packets appear on the underlying interfaces.]
I'm (so far successfully) using the following rule,
iptables -t mangle -A PREROUTING -i hdlc\+ -j ROUTE --iif teql0
to workaround Quagga's neighbor logic, which is otherwise confused by the asymmetry between sending on teql0, and receiving on hdlc*.
Regards,
Bill Rugolsky
ROUTE/linux/net/ipv4/netfilter/ipt_ROUTE.c renamed from ROUTE/linux/net/ipv4/netfilter/ipt_ROUTE.c.iif +9 -13
@@ -203,25 +203,21 @@static unsigned int route_iif (const struct ipt_route_target_info *route_info,struct sk_buff *skb) { -struct net_device *dev_out =NULL ; -unsigned int ifindex =0 ; +struct net_device *dev_in =NULL ;/* Getting the current interface index. */ -if ((dev_out =dev_get_by_name (route_info->iif))) - ifindex = dev_out->ifindex; -else { -/* Unknown interface name : packet dropped */ +if (!(dev_in =dev_get_by_name (route_info->iif))) {if (net_ratelimit ()) -DEBUGP ("ipt_ROUTE: iif interface %s not found\n" , route_info->oif); +DEBUGP ("ipt_ROUTE: iif interface %s not found\n" , route_info->iif);return NF_DROP ; } - skb->dev = dev_out; + skb->dev = dev_in;dst_release (skb->dst); skb->dst =NULL ;netif_rx (skb); - +dev_put (dev_in);return NF_STOLEN ; }
@@ -253,8 +249,8 @@/* If we are at PREROUTING or INPUT hook * the TTL isn't decreased by the IP stack */ -if (hooknum ==NF_IP_PRE_ROUTING || - hooknum ==NF_IP_LOCAL_IN ) { +if (route_info->iif[0 ] =='\0' && (hooknum ==NF_IP_PRE_ROUTING || + hooknum ==NF_IP_LOCAL_IN )) {struct iphdr *iph = skb->nh.iph;
@@ -297,10 +293,10 @@#endif } -if (route_info->oif[0 ]) +if (route_info->oif[0 ] !='\0' )return route_oif (route_info, *pskb); -if (route_info->iif[0 ]) +if (route_info->iif[0 ] !='\0' )return route_iif (route_info, *pskb);if (route_info->gw)
ROUTE/linux-2.6/net/ipv4/netfilter/ipt_ROUTE.c renamed from ROUTE/linux-2.6/net/ipv4/netfilter/ipt_ROUTE.c.iif +9 -13
@@ -205,25 +205,21 @@static unsigned int route_iif (const struct ipt_route_target_info *route_info,struct sk_buff *skb) { -struct net_device *dev_out =NULL ; -unsigned int ifindex =0 ; +struct net_device *dev_in =NULL ;/* Getting the current interface index. */ -if ((dev_out =dev_get_by_name (route_info->iif))) - ifindex = dev_out->ifindex; -else { -/* Unknown interface name : packet dropped */ +if (!(dev_in =dev_get_by_name (route_info->iif))) {if (net_ratelimit ()) -DEBUGP ("ipt_ROUTE: iif interface %s not found\n" , route_info->oif); +DEBUGP ("ipt_ROUTE: iif interface %s not found\n" , route_info->iif);return NF_DROP ; } - skb->dev = dev_out; + skb->dev = dev_in;dst_release (skb->dst); skb->dst =NULL ;netif_rx (skb); - +dev_put (dev_in);return NF_STOLEN ; }
@@ -255,8 +251,8 @@/* If we are at PREROUTING or INPUT hook * the TTL isn't decreased by the IP stack */ -if (hooknum ==NF_IP_PRE_ROUTING || - hooknum ==NF_IP_LOCAL_IN ) { +if (route_info->iif[0 ] =='\0' && (hooknum ==NF_IP_PRE_ROUTING || + hooknum ==NF_IP_LOCAL_IN )) {struct iphdr *iph = skb->nh.iph;
@@ -299,10 +295,10 @@#endif } -if (route_info->oif[0 ]) +if (route_info->oif[0 ] !='\0' )return route_oif (route_info, *pskb); -if (route_info->iif[0 ]) +if (route_info->iif[0 ] !='\0' )return route_iif (route_info, *pskb);if (route_info->gw)
Hi Bill,
Quoted 6 lines · Bill Rugolsky Jr.
I mailed several ROUTE target fixes to Cédric de Launois about two weeks ago, but they weren't ACK'd, so I'm posting a combined patch against patch-o-matic-ng here.
Fixes:
Quoted 7 lines
o Insert missing
dev_put()followingdev_get_by_name().o Don't decrement TTL on packets re-injected with
route_iif().o Fix cut-n-paste error in
route_iif()debugmessage().o Dead code removal and a few cleanups.
Thanks, patch is applied.
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 3 lines · Bill Rugolsky Jr.
I mailed several ROUTE target fixes to Cédric de Launois about two weeks ago, but they weren't ACK'd, so I'm posting a combined patch against patch-o-matic-ng here.
Yes, apologies for that. I'm quite busy these days...
Quoted 5 lines
Fixes:
o Insert missingdev_put()followingdev_get_by_name().
o Don't decrement TTL on packets re-injected withroute_iif().
o Fix cut-n-paste error inroute_iif()debugmessage().
o Dead code removal and a few cleanups.
Thanks for your patch. Now I can drop this from my to-do list ;)
Concerning the TTL, what happens if you re-inject the packet on the same interface ? If you don't decrement the TTL, you might introduce a loop, no ? Could you check this ?
Quoted 4 lines
I'm using the ROUTE target --iif functionality, in combination with the teql round-robin packet scheduler, to remap incoming packets on multiple interfaces (in this case hdlc[0-3]) to teql0. [teql only schedules outgoing packets; incoming packets appear on the underlying interfaces.]
Great, maybe could you detail this example so that it can be added in the netfilter pom documentation ?
Cedric
Quoted 3 lines · Cedric de Launois
Concerning the TTL, what happens if you re-inject the packet on the same interface ? If you don't decrement the TTL, you might introduce a loop, no ? Could you check this ?
D'oh! You are of course correct that it will loop (and I've verified that it does). I had previously been using
iptables -t mangle -A PREROUTING -i hdlc\+ -j TTL --ttl-inc 1
to get the desired behavior, but changed ROUTE because the above seemed
inelegant. The original behavior is indeed the safer course. The attached
patch backs out the TTL change.
Quoted 7 lines
Quoted 4 lines
I'm using the ROUTE target --iif functionality, in combination with the teql round-robin packet scheduler, to remap incoming packets on multiple interfaces (in this case hdlc[0-3]) to teql0. [teql only schedules outgoing packets; incoming packets appear on the underlying interfaces.]
Great, maybe could you detail this example so that it can be added in the netfilter pom documentation ?
Sure.
The teql per-packet round-robin scheduler is used to aggregate the sending bandwidth on several slave interfaces; see the top of linux/net/sched/sch_teql.c for usage and caveats.
[For Ethernet, the bonding driver is preferred.]
Per-packet scheduling is most useful when a single flow might exceed the bandwidth of the individual interfaces, as is commonly the case with T1 links.
Using WAN interfaces hdlc[0-3] on a 4 T1/E1 WAN card, one might do the following:
modprobe sch_teql
for i in 0 1 2 3
ip link set dev hdlc${i} up
sysctl -w net.ipv4.conf.hdlc${i}.rp_filter=0 tc qdisc add dev hdlc${i} root teql0
done
ip link set dev teql0 up
sysctl -w net.ipv4.conf.teql0.rp_filter=0 ip address add $IPADDR peer $REMIP dev teql0 ip route add default via $REMIP dev teql0
Since teql0 is a send-only interface, incoming packets appear on the slave hdlc* interfaces, and the usual caveats regarding asymmetric routing apply. E.g., Quagga OSPF implements its own reverse-path filtering neighbor logic; replies from peers that are received on the wrong interface are dropped.
The following rule causes all incoming packets on the hdlc* interfaces to appear to have been received on teql0:
iptables -t mangle -A PREROUTING -i hdlc\+ -j TTL --ttl-inc 1 iptables -t mangle -A PREROUTING -i hdlc\+ -j ROUTE --iif teql0
The TTL increment is required to avoid dropping packets, as multicast and broadcast packets are typically sent with TTL = 1. In this example, Quagga also sets TTL = 1 on packets that it sends to its peers.
Regards,
Bill Rugolsky
ROUTE/linux/net/ipv4/netfilter/ipt_ROUTE.c renamed from ROUTE/linux/net/ipv4/netfilter/ipt_ROUTE.c.ttl +2 -2
@@ -249,8 +249,8 @@/* If we are at PREROUTING or INPUT hook * the TTL isn't decreased by the IP stack */ -if (route_info->iif[0 ] =='\0' && (hooknum ==NF_IP_PRE_ROUTING || - hooknum ==NF_IP_LOCAL_IN )) { +if (hooknum ==NF_IP_PRE_ROUTING || + hooknum ==NF_IP_LOCAL_IN ) {struct iphdr *iph = skb->nh.iph;
ROUTE/linux-2.6/net/ipv4/netfilter/ipt_ROUTE.c renamed from ROUTE/linux-2.6/net/ipv4/netfilter/ipt_ROUTE.c.ttl +2 -2
@@ -251,8 +251,8 @@/* If we are at PREROUTING or INPUT hook * the TTL isn't decreased by the IP stack */ -if (route_info->iif[0 ] =='\0' && (hooknum ==NF_IP_PRE_ROUTING || - hooknum ==NF_IP_LOCAL_IN )) { +if (hooknum ==NF_IP_PRE_ROUTING || + hooknum ==NF_IP_LOCAL_IN ) {struct iphdr *iph = skb->nh.iph;
Quoted 5 lines · Bill Rugolsky Jr.
Quoted 3 lines · Cedric de Launois
Concerning the TTL, what happens if you re-inject the packet on the same interface ? If you don't decrement the TTL, you might introduce a loop, no ? Could you check this ?
Quoted 8 lines
D'oh! You are of course correct that it will loop (and I've verified that it does). I had previously been using
iptables -t mangle -A PREROUTING -i hdlc\+ -j TTL --ttl-inc 1to get the desired behavior, but changed ROUTE because the above seemed
inelegant. The original behavior is indeed the safer course. The attached
patch backs out the TTL change.
Patch is applied. Quick fixes are highly appreciated. :-)
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary