Skip to content

Commit eec2e61

Browse files
strssndktndavem330
authored andcommitted
ipv6: implement RFC3168 5.3 (ecn protection) for ipv6 fragmentation handling
Hello! After patch 1 got accepted to net-next I will also send a patch to netfilter-devel to make the corresponding changes to the netfilter reassembly logic. Thanks, Hannes -- >8 -- [PATCH 2/2] ipv6: implement RFC3168 5.3 (ecn protection) for ipv6 fragmentation handling This patch also ensures that INET_ECN_CE is propagated if one fragment had the codepoint set. Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: Jesper Dangaard Brouer <jbrouer@redhat.com> Cc: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Acked-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent be99197 commit eec2e61

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎include/net/ipv6.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ struct ip6_create_arg {
478478
u32 user;
479479
const struct in6_addr *src;
480480
const struct in6_addr *dst;
481+
u8 ecn;
481482
};
482483

483484
void ip6_frag_init(struct inet_frag_queue *q, void *a);
@@ -497,6 +498,7 @@ struct frag_queue {
497498
int iif;
498499
unsigned int csum;
499500
__u16 nhoffset;
501+
u8 ecn;
500502
};
501503

502504
void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq,

‎net/ipv6/reassembly.c‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <net/ndisc.h>
5959
#include <net/addrconf.h>
6060
#include <net/inet_frag.h>
61+
#include <net/inet_ecn.h>
6162

6263
struct ip6frag_skb_cb
6364
{
@@ -67,6 +68,10 @@ struct ip6frag_skb_cb
6768

6869
#define FRAG6_CB(skb) ((struct ip6frag_skb_cb*)((skb)->cb))
6970

71+
static inline u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
72+
{
73+
return 1 << (ipv6_get_dsfield(ipv6h) & INET_ECN_MASK);
74+
}
7075

7176
static struct inet_frags ip6_frags;
7277

@@ -119,6 +124,7 @@ void ip6_frag_init(struct inet_frag_queue *q, void *a)
119124
fq->user = arg->user;
120125
fq->saddr = *arg->src;
121126
fq->daddr = *arg->dst;
127+
fq->ecn = arg->ecn;
122128
}
123129
EXPORT_SYMBOL(ip6_frag_init);
124130

@@ -173,7 +179,8 @@ static void ip6_frag_expire(unsigned long data)
173179
}
174180

175181
static __inline__ struct frag_queue *
176-
fq_find(struct net *net, __be32 id, const struct in6_addr *src, const struct in6_addr *dst)
182+
fq_find(struct net *net, __be32 id, const struct in6_addr *src,
183+
const struct in6_addr *dst, u8 ecn)
177184
{
178185
struct inet_frag_queue *q;
179186
struct ip6_create_arg arg;
@@ -183,6 +190,7 @@ fq_find(struct net *net, __be32 id, const struct in6_addr *src, const struct in6
183190
arg.user = IP6_DEFRAG_LOCAL_DELIVER;
184191
arg.src = src;
185192
arg.dst = dst;
193+
arg.ecn = ecn;
186194

187195
read_lock(&ip6_frags.lock);
188196
hash = inet6_hash_frag(id, src, dst, ip6_frags.rnd);
@@ -202,6 +210,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
202210
struct net_device *dev;
203211
int offset, end;
204212
struct net *net = dev_net(skb_dst(skb)->dev);
213+
u8 ecn;
205214

206215
if (fq->q.last_in & INET_FRAG_COMPLETE)
207216
goto err;
@@ -219,6 +228,8 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
219228
return -1;
220229
}
221230

231+
ecn = ip6_frag_ecn(ipv6_hdr(skb));
232+
222233
if (skb->ip_summed == CHECKSUM_COMPLETE) {
223234
const unsigned char *nh = skb_network_header(skb);
224235
skb->csum = csum_sub(skb->csum,
@@ -319,6 +330,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
319330
}
320331
fq->q.stamp = skb->tstamp;
321332
fq->q.meat += skb->len;
333+
fq->ecn |= ecn;
322334
add_frag_mem_limit(&fq->q, skb->truesize);
323335

324336
/* The first fragment.
@@ -362,9 +374,14 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
362374
int payload_len;
363375
unsigned int nhoff;
364376
int sum_truesize;
377+
u8 ecn;
365378

366379
inet_frag_kill(&fq->q, &ip6_frags);
367380

381+
ecn = ip_frag_ecn_table[fq->ecn];
382+
if (unlikely(ecn == 0xff))
383+
goto out_fail;
384+
368385
/* Make the one we just received the head. */
369386
if (prev) {
370387
head = prev->next;
@@ -463,6 +480,7 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
463480
head->dev = dev;
464481
head->tstamp = fq->q.stamp;
465482
ipv6_hdr(head)->payload_len = htons(payload_len);
483+
ipv6_change_dsfield(ipv6_hdr(head), 0xff, ecn);
466484
IP6CB(head)->nhoff = nhoff;
467485

468486
/* Yes, and fold redundant checksum back. 8) */
@@ -526,7 +544,8 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
526544
IP6_ADD_STATS_BH(net, ip6_dst_idev(skb_dst(skb)),
527545
IPSTATS_MIB_REASMFAILS, evicted);
528546

529-
fq = fq_find(net, fhdr->identification, &hdr->saddr, &hdr->daddr);
547+
fq = fq_find(net, fhdr->identification, &hdr->saddr, &hdr->daddr,
548+
ip6_frag_ecn(hdr));
530549
if (fq != NULL) {
531550
int ret;
532551

0 commit comments

Comments
 (0)