Skip to content

Commit b836c99

Browse files
Amerigo Wangdavem330
authored andcommitted
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. With this patch applied, I can see ICMP Time Exceeded sent from the receiver when the sender sent out 3/4 fragmented IPv6 UDP packet. Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Michal Kubeček <mkubecek@suse.cz> Cc: David Miller <davem@davemloft.net> Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org> Cc: Patrick McHardy <kaber@trash.net> Cc: Pablo Neira Ayuso <pablo@netfilter.org> Cc: netfilter-devel@vger.kernel.org Signed-off-by: Cong Wang <amwang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c038a76 commit b836c99

3 files changed

Lines changed: 57 additions & 99 deletions

File tree

‎include/net/ipv6.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,25 @@ struct ip6_create_arg {
411411
void ip6_frag_init(struct inet_frag_queue *q, void *a);
412412
bool ip6_frag_match(struct inet_frag_queue *q, void *a);
413413

414+
/*
415+
* Equivalent of ipv4 struct ip
416+
*/
417+
struct frag_queue {
418+
struct inet_frag_queue q;
419+
420+
__be32 id; /* fragment id */
421+
u32 user;
422+
struct in6_addr saddr;
423+
struct in6_addr daddr;
424+
425+
int iif;
426+
unsigned int csum;
427+
__u16 nhoffset;
428+
};
429+
430+
void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,
431+
struct inet_frags *frags);
432+
414433
static inline bool ipv6_addr_any(const struct in6_addr *a)
415434
{
416435
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64

‎net/ipv6/netfilter/nf_conntrack_reasm.c‎

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,6 @@ struct nf_ct_frag6_skb_cb
5757

5858
#define NFCT_FRAG6_CB(skb) ((struct nf_ct_frag6_skb_cb*)((skb)->cb))
5959

60-
struct nf_ct_frag6_queue
61-
{
62-
struct inet_frag_queue q;
63-
64-
__be32 id; /* fragment id */
65-
u32 user;
66-
struct in6_addr saddr;
67-
struct in6_addr daddr;
68-
69-
unsigned int csum;
70-
__u16 nhoffset;
71-
};
72-
7360
static struct inet_frags nf_frags;
7461

7562
#ifdef CONFIG_SYSCTL
@@ -151,9 +138,9 @@ static void __net_exit nf_ct_frags6_sysctl_unregister(struct net *net)
151138

152139
static unsigned int nf_hashfn(struct inet_frag_queue *q)
153140
{
154-
const struct nf_ct_frag6_queue *nq;
141+
const struct frag_queue *nq;
155142

156-
nq = container_of(q, struct nf_ct_frag6_queue, q);
143+
nq = container_of(q, struct frag_queue, q);
157144
return inet6_hash_frag(nq->id, &nq->saddr, &nq->daddr, nf_frags.rnd);
158145
}
159146

@@ -163,44 +150,21 @@ static void nf_skb_free(struct sk_buff *skb)
163150
kfree_skb(NFCT_FRAG6_CB(skb)->orig);
164151
}
165152

166-
/* Destruction primitives. */
167-
168-
static __inline__ void fq_put(struct nf_ct_frag6_queue *fq)
169-
{
170-
inet_frag_put(&fq->q, &nf_frags);
171-
}
172-
173-
/* Kill fq entry. It is not destroyed immediately,
174-
* because caller (and someone more) holds reference count.
175-
*/
176-
static __inline__ void fq_kill(struct nf_ct_frag6_queue *fq)
177-
{
178-
inet_frag_kill(&fq->q, &nf_frags);
179-
}
180-
181153
static void nf_ct_frag6_expire(unsigned long data)
182154
{
183-
struct nf_ct_frag6_queue *fq;
184-
185-
fq = container_of((struct inet_frag_queue *)data,
186-
struct nf_ct_frag6_queue, q);
155+
struct frag_queue *fq;
156+
struct net *net;
187157

188-
spin_lock(&fq->q.lock);
158+
fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
159+
net = container_of(fq->q.net, struct net, nf_frag.frags);
189160

190-
if (fq->q.last_in & INET_FRAG_COMPLETE)
191-
goto out;
192-
193-
fq_kill(fq);
194-
195-
out:
196-
spin_unlock(&fq->q.lock);
197-
fq_put(fq);
161+
ip6_expire_frag_queue(net, fq, &nf_frags);
198162
}
199163

200164
/* Creation primitives. */
201-
static inline struct nf_ct_frag6_queue *fq_find(struct net *net, __be32 id,
202-
u32 user, struct in6_addr *src,
203-
struct in6_addr *dst)
165+
static inline struct frag_queue *fq_find(struct net *net, __be32 id,
166+
u32 user, struct in6_addr *src,
167+
struct in6_addr *dst)
204168
{
205169
struct inet_frag_queue *q;
206170
struct ip6_create_arg arg;
@@ -219,14 +183,14 @@ static inline struct nf_ct_frag6_queue *fq_find(struct net *net, __be32 id,
219183
if (q == NULL)
220184
goto oom;
221185

222-
return container_of(q, struct nf_ct_frag6_queue, q);
186+
return container_of(q, struct frag_queue, q);
223187

224188
oom:
225189
return NULL;
226190
}
227191

228192

229-
static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
193+
static int nf_ct_frag6_queue(struct frag_queue *fq, struct sk_buff *skb,
230194
const struct frag_hdr *fhdr, int nhoff)
231195
{
232196
struct sk_buff *prev, *next;
@@ -367,7 +331,7 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
367331
return 0;
368332

369333
discard_fq:
370-
fq_kill(fq);
334+
inet_frag_kill(&fq->q, &nf_frags);
371335
err:
372336
return -1;
373337
}
@@ -382,12 +346,12 @@ static int nf_ct_frag6_queue(struct nf_ct_frag6_queue *fq, struct sk_buff *skb,
382346
* the last and the first frames arrived and all the bits are here.
383347
*/
384348
static struct sk_buff *
385-
nf_ct_frag6_reasm(struct nf_ct_frag6_queue *fq, struct net_device *dev)
349+
nf_ct_frag6_reasm(struct frag_queue *fq, struct net_device *dev)
386350
{
387351
struct sk_buff *fp, *op, *head = fq->q.fragments;
388352
int payload_len;
389353

390-
fq_kill(fq);
354+
inet_frag_kill(&fq->q, &nf_frags);
391355

392356
WARN_ON(head == NULL);
393357
WARN_ON(NFCT_FRAG6_CB(head)->offset != 0);
@@ -570,7 +534,7 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user)
570534
struct net *net = skb_dst(skb) ? dev_net(skb_dst(skb)->dev)
571535
: dev_net(skb->dev);
572536
struct frag_hdr *fhdr;
573-
struct nf_ct_frag6_queue *fq;
537+
struct frag_queue *fq;
574538
struct ipv6hdr *hdr;
575539
int fhoff, nhoff;
576540
u8 prevhdr;
@@ -619,7 +583,7 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user)
619583
if (nf_ct_frag6_queue(fq, clone, fhdr, nhoff) < 0) {
620584
spin_unlock_bh(&fq->q.lock);
621585
pr_debug("Can't insert skb to queue\n");
622-
fq_put(fq);
586+
inet_frag_put(&fq->q, &nf_frags);
623587
goto ret_orig;
624588
}
625589

@@ -631,7 +595,7 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user)
631595
}
632596
spin_unlock_bh(&fq->q.lock);
633597

634-
fq_put(fq);
598+
inet_frag_put(&fq->q, &nf_frags);
635599
return ret_skb;
636600

637601
ret_orig:
@@ -695,7 +659,7 @@ int nf_ct_frag6_init(void)
695659
nf_frags.constructor = ip6_frag_init;
696660
nf_frags.destructor = NULL;
697661
nf_frags.skb_free = nf_skb_free;
698-
nf_frags.qsize = sizeof(struct nf_ct_frag6_queue);
662+
nf_frags.qsize = sizeof(struct frag_queue);
699663
nf_frags.match = ip6_frag_match;
700664
nf_frags.frag_expire = nf_ct_frag6_expire;
701665
nf_frags.secret_interval = 10 * 60 * HZ;

‎net/ipv6/reassembly.c‎

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,6 @@ struct ip6frag_skb_cb
6565
#define FRAG6_CB(skb) ((struct ip6frag_skb_cb*)((skb)->cb))
6666

6767

68-
/*
69-
* Equivalent of ipv4 struct ipq
70-
*/
71-
72-
struct frag_queue
73-
{
74-
struct inet_frag_queue q;
75-
76-
__be32 id; /* fragment id */
77-
u32 user;
78-
struct in6_addr saddr;
79-
struct in6_addr daddr;
80-
81-
int iif;
82-
unsigned int csum;
83-
__u16 nhoffset;
84-
};
85-
8668
static struct inet_frags ip6_frags;
8769

8870
int ip6_frag_nqueues(struct net *net)
@@ -159,21 +141,6 @@ void ip6_frag_init(struct inet_frag_queue *q, void *a)
159141
}
160142
EXPORT_SYMBOL(ip6_frag_init);
161143

162-
/* Destruction primitives. */
163-
164-
static __inline__ void fq_put(struct frag_queue *fq)
165-
{
166-
inet_frag_put(&fq->q, &ip6_frags);
167-
}
168-
169-
/* Kill fq entry. It is not destroyed immediately,
170-
* because caller (and someone more) holds reference count.
171-
*/
172-
static __inline__ void fq_kill(struct frag_queue *fq)
173-
{
174-
inet_frag_kill(&fq->q, &ip6_frags);
175-
}
176-
177144
static void ip6_evictor(struct net *net, struct inet6_dev *idev)
178145
{
179146
int evicted;
@@ -183,22 +150,18 @@ static void ip6_evictor(struct net *net, struct inet6_dev *idev)
183150
IP6_ADD_STATS_BH(net, idev, IPSTATS_MIB_REASMFAILS, evicted);
184151
}
185152

186-
static void ip6_frag_expire(unsigned long data)
153+
void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,
154+
struct inet_frags *frags)
187155
{
188-
struct frag_queue *fq;
189156
struct net_device *dev = NULL;
190-
struct net *net;
191-
192-
fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
193157

194158
spin_lock(&fq->q.lock);
195159

196160
if (fq->q.last_in & INET_FRAG_COMPLETE)
197161
goto out;
198162

199-
fq_kill(fq);
163+
inet_frag_kill(&fq->q, frags);
200164

201-
net = container_of(fq->q.net, struct net, ipv6.frags);
202165
rcu_read_lock();
203166
dev = dev_get_by_index_rcu(net, fq->iif);
204167
if (!dev)
@@ -222,7 +185,19 @@ static void ip6_frag_expire(unsigned long data)
222185
rcu_read_unlock();
223186
out:
224187
spin_unlock(&fq->q.lock);
225-
fq_put(fq);
188+
inet_frag_put(&fq->q, frags);
189+
}
190+
EXPORT_SYMBOL(ip6_expire_frag_queue);
191+
192+
static void ip6_frag_expire(unsigned long data)
193+
{
194+
struct frag_queue *fq;
195+
struct net *net;
196+
197+
fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
198+
net = container_of(fq->q.net, struct net, ipv6.frags);
199+
200+
ip6_expire_frag_queue(net, fq, &ip6_frags);
226201
}
227202

228203
static __inline__ struct frag_queue *
@@ -391,7 +366,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
391366
return -1;
392367

393368
discard_fq:
394-
fq_kill(fq);
369+
inet_frag_kill(&fq->q, &ip6_frags);
395370
err:
396371
IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
397372
IPSTATS_MIB_REASMFAILS);
@@ -417,7 +392,7 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
417392
unsigned int nhoff;
418393
int sum_truesize;
419394

420-
fq_kill(fq);
395+
inet_frag_kill(&fq->q, &ip6_frags);
421396

422397
/* Make the one we just received the head. */
423398
if (prev) {
@@ -586,7 +561,7 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
586561
ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff);
587562

588563
spin_unlock(&fq->q.lock);
589-
fq_put(fq);
564+
inet_frag_put(&fq->q, &ip6_frags);
590565
return ret;
591566
}
592567

0 commit comments

Comments
 (0)