Skip to contentSkip to conversation

2.6.22.6 netfilter: sk_setup_caps in ip_make_route_harder

RFC PATCH In review lepton 2 participants 7 messages Sep 19, 2007 – Sep 21, 2007

Subsystems (3)
lore
Share & tools
lore

lepton

author
#0 lore raw

RFC PATCH 1/1 2.6.22.6 netfilter: sk_setup_caps in ip_make_route_harder

Hi,
For local src packets, it is better to update sk_route_caps in ip_route_me_harder.

net/ipv4/netfilter.c +4 -0
diff -pru -X linux-2.6.22.6/Documentation/dontdiff linux-2.6.22.6/net/ipv4/netfilter.c linux-2.6.22.6-lepton/net/ipv4/netfilter.c
@@ -37,6 +37,10 @@ int ip_route_me_harder(struct sk_buff **
 		/* Drop old route. */
 		dst_release((*pskb)->dst);
 		(*pskb)->dst = &rt->u.dst;
+		if((*pskb)->sk){
+			dst_hold((*pskb)->dst);
+			sk_setup_caps((*pskb)->sk, (*pskb)->dst);
+		}
 	} else {
 		/* non-local src, find valid iif to satisfy
 		 * rp-filter when calling ip_route_input. */
#1 lore raw
Quoted 3 lines · lepton

Hi,
For local src packets, it is better to update sk_route_caps in ip_route_me_harder.

This seems like a good idea to me. But why only for local src (address) packets? This function can also be used for locally generated packet that have been (f.i.) NATed to a foreign address ...

Quoted 17 lines

diff -pru -X linux-2.6.22.6/Documentation/dontdiff linux-2.6.22.6/net/ipv4/netfilter.c linux-2.6.22.6-lepton/net/ipv4/netfilter.c

net/ipv4/netfilter.c +4 -0
@@ -37,6 +37,10 @@ int ip_route_me_harder(struct sk_buff **
 		/* Drop old route. */
 		dst_release((*pskb)->dst);
 		(*pskb)->dst = &rt->u.dst;
+		if((*pskb)->sk){
+			dst_hold((*pskb)->dst);
+			sk_setup_caps((*pskb)->sk, (*pskb)->dst);
+		}
 	} else {
 		/* non-local src, find valid iif to satisfy
 		 * rp-filter when calling ip_route_input. */
#2 lore raw
Quoted 8 lines · Patrick McHardy
Quoted 3 lines · lepton

Hi,
For local src packets, it is better to update sk_route_caps in ip_route_me_harder.

Quoted 4 lines

This seems like a good idea to me. But why only for local src (address) packets? This function can also be used for locally generated packet that have been (f.i.) NATed to a foreign address ...

Actually, I'm afraid it might break some setups. Rerouting is done per packet, but if we cache the dst_entry for the socket, all packets from that socket will be routed similar.

author
#3 lore raw

Yes, you are right.
What do you think about this:
For all packets can be sent out, we just disable
all things in sk_route_caps in ip_route_me_harder

net/ipv4/netfilter.c +4 -0
diff -X linux-2.6.22.6/Documentation/dontdiff -pru linux-2.6.22.6/net/ipv4/netfilter.c linux-2.6.22.6-lepton/net/ipv4/netfilter.c
@@ -57,6 +57,10 @@ int ip_route_me_harder(struct sk_buff **
 	if ((*pskb)->dst->error)
 		return -1;
 
+	if((*pskb)->sk&&sk->sk_route_caps) 
+		/* This is overkill, but it is safe and simple */
+		sk->sk_route_caps=0;
+
 #ifdef CONFIG_XFRM
 	if (!(IPCB(*pskb)->flags & IPSKB_XFRM_TRANSFORMED) &&
 	    xfrm_decode_session(*pskb, &fl, AF_INET) == 0)
Quoted 19 lines · Patrick McHardy
Quoted 8 lines · Patrick McHardy
Quoted 3 lines · lepton

Hi,
For local src packets, it is better to update sk_route_caps in ip_route_me_harder.

Quoted 4 lines

This seems like a good idea to me. But why only for local src (address) packets? This function can also be used for locally generated packet that have been (f.i.) NATed to a foreign address ...

Actually, I'm afraid it might break some setups. Rerouting is done per packet, but if we cache the dst_entry for the socket, all packets from that socket will be routed similar.

#4 lore raw
Quoted 4 lines · lepton

Yes, you are right.
What do you think about this:
For all packets can be sent out, we just disable
all things in sk_route_caps in ip_route_me_harder

Whats the point of doing that? Is rerouting breaking anything for you?

author
#5 lore raw

Yes.
My situation is:
The default route device is a e1000 network card that can do TSO. So the tcp stack will try send big skb to netfilter frame work. But after rerouting, the packtes will go out from a device that can not do TSO. the packet is just get dropped..

I thinks if we can't get a way to tell tcp stack the sk_route_caps of the real out device, we can just disable all things for safety.

Quoted 8 lines · Patrick McHardy
Quoted 4 lines · lepton

Yes, you are right.
What do you think about this:
For all packets can be sent out, we just disable
all things in sk_route_caps in ip_route_me_harder

Whats the point of doing that? Is rerouting breaking anything for you?

#6 lore raw
Quoted 8 lines · lepton

My situation is:
The default route device is a e1000 network card that can do TSO. So the tcp stack will try send big skb to netfilter frame work. But after rerouting, the packtes will go out from a device that can not do TSO. the packet is just get dropped..

I thinks if we can't get a way to tell tcp stack the sk_route_caps of the real out device, we can just disable all things for safety.

As you already noticed yourself (in private email), this is handled properly in current kernels.