ipv6: unify conntrack reassembly expire code with standard one
Subsystems (4)
RFC PATCH 1/1 ipv6: unify conntrack reassembly expire code with standard one
Two years ago, Shan Wei tried to fix this:
http://patchwork.ozlabs.org/patch/43905/
The problem is that RFC2460 requires an ICMP Time Exceeded -- Fragment Reassembly Time Exceeded message should be sent to the source of that fragment, if the defragmentation times out.
"
If insufficient fragments are received to complete reassembly of a packet within 60 seconds of the reception of the first-arriving fragment of that packet, reassembly of that packet must be abandoned and all the fragments that have been received for that packet must be discarded. If the first fragment (i.e., the one with a Fragment Offset of zero) has been received, an ICMP Time Exceeded -- Fragment Reassembly Time Exceeded message should be sent to the source of that fragment.
"
As Herbert suggested, we could actually use the standard IPv6 reassembly code which follows RFC2460.
---
include/net/ipv6.h +18 -0
@@ -408,6 +408,24 @@ struct ip6_create_arg {void ip6_frag_init (struct inet_frag_queue *q,void *a);bool ip6_frag_match (struct inet_frag_queue *q,void *a); +/* +* Equivalent of ipv4 struct ip +*/ +struct frag_queue { +struct inet_frag_queue q; + +__be32 id;/* fragment id */ +u32 user; +struct in6_addr saddr; +struct in6_addr daddr; + +int iif; +unsigned int csum; +__u16 nhoffset; +}; + +void ip6_expire_frag_queue (struct frag_queue *fq,struct inet_frags *frags); +static inline bool ipv6_addr_any (const struct in6_addr *a) {#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64
net/ipv6/netfilter/nf_conntrack_reasm.c +15 -53
151 lines not on this page · raw message
net/ipv6/reassembly.c +17 -42
110 lines not on this page · raw message
Quoted 3 lines · Cong Wang
Two years ago, Shan Wei tried to fix this:
http://patchwork.ozlabs.org/patch/43905/
...
Quoted 3 lines
As Herbert suggested, we could actually use the standard IPv6 reassembly code which follows RFC2460.
I tested the patch and I ran into a problem in this place in ip6_expire_frag_queue():
Quoted 1 line
net =
container_of(fq->q.net, struct net, ipv6.frags);
For frag queues coming from IPv6 conntrack, fq->q.net points to nf_init_frags which is not embedded into struct net so that the following device lookup leads to reading from an invalid address. The same problem has been discussed on the page linked above.
I didn't test with current net-next source but as far as I can tell, this hasn't changed. Did I miss something?
Michal Kubecek
Hi, Michal!
Quoted 14 lines · Michal Kubeček
Quoted 3 lines · Cong Wang
Two years ago, Shan Wei tried to fix this:
http://patchwork.ozlabs.org/patch/43905/...
Quoted 3 lines
As Herbert suggested, we could actually use the standard IPv6 reassembly code which follows RFC2460.
I tested the patch and I ran into a problem in this place in
ip6_expire_frag_queue():Quoted 1 line
net =
container_of(fq->q.net, struct net, ipv6.frags);
Quoted 8 lines
For frag queues coming from IPv6 conntrack,
fq->q.netpoints tonf_init_fragswhich is not embedded into struct net so that the following device lookup leads to reading from an invalid address. The same problem has been discussed on the page linked above.I didn't test with current net-next source but as far as I can tell, this hasn't changed. Did I miss something?
No, you don't miss anything. I missed that piece of code, you are right that nf_init_frags is not actually embedded, so that container_of() doesn't work. I think we probably can save the struct net pointer in struct netns_frags during inet_frags_init_net(), so that container_of() can be eliminated.
Thanks for testing! I tried to test it too, but seems I can't trigger a defragment. Any hints?
Thanks!
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Cong Wang
doesn't work. I think we probably can save the struct net pointer in struct
netns_fragsduringinet_frags_init_net(), so thatcontainer_of()can be eliminated.
This would work but one would have to check carefully that the pointer is always set to an usable value. Or we could just add a flag indicating whether the structure is embedded (and if it is not, use init_net). Another approach was suggested in the patchworks discussion: add a special namespace for IPv6 conntrack fragment handling.
Quoted 2 lines
Thanks for testing! I tried to test it too, but seems I can't trigger a defragment. Any hints?
I used netfilter on a computer between source and destination of the packets (generated with "ping6 -s 3000"):
ip6tables -A FORWARD -o ... -m frag --fragid 0:0xFFFFFFFF --fraglast -j DROP
The --fragid condition is needed to work around a bug in iptables (if frag module is loaded and there is no --fragid, only packets with zero fragment id match - patch for this is already in git). On the target, packet is defragmented automatically, by default by the "normal" code, with nf_conntrack_ipv6 module by the conntrack code.
Setting
echo 5 >/proc/sys/net/ipv6/ip6frag_time
echo 5 >/proc/sys/net/netfilter/nf_conntrack_frag6_timeout
on target also helps.
Michal Kubecek
Quoted 10 lines · Michal Kubecek
Quoted 3 lines · Cong Wang
doesn't work. I think we probably can save the struct net pointer in struct
netns_fragsduringinet_frags_init_net(), so thatcontainer_of()can be eliminated.This would work but one would have to check carefully that the pointer is always set to an usable value. Or we could just add a flag indicating whether the structure is embedded (and if it is not, use
init_net). Another approach was suggested in the patchworks discussion: add a special namespace for IPv6 conntrack fragment handling.
I think your former solution is easier, I will try it.
Quoted 15 lines
Quoted 3 lines
Thanks for testing! I tried to test it too, but seems I can't trigger a defragment. Any hints?
I used netfilter on a computer between source and destination of the packets (generated with "ping6 -s 3000"):
ip6tables -A FORWARD -o ... -m frag --fragid 0:0xFFFFFFFF --fraglast -j DROP
The --fragid condition is needed to work around a bug in iptables (if frag module is loaded and there is no --fragid, only packets with zero fragment id match - patch for this is already in git). On the target, packet is defragmented automatically, by default by the "normal" code, with
nf_conntrack_ipv6module by the conntrack code.
Quoted 7 lines
Setting
echo 5 >/proc/sys/net/ipv6/ip6frag_time
echo 5 >/proc/sys/net/netfilter/nf_conntrack_frag6_timeouton target also helps.
Great! This helps!
Thanks!
Hi, Michal,
Could you help to test my updated patches?
You can find them (the most top 4 patches) in my github tree:
https://github.com/congwang/linux/commits/ipv6
which is based on net-next.
I tried to setup the environment to reproduce it, but failed. I also tried scapy, but I still can't trigger "Fragment Reassembly Timeout".
Thanks a lot!