29 #include <linux/errno.h>
30 #include <linux/types.h>
31 #include <linux/string.h>
32 #include <linux/socket.h>
35 #include <linux/net.h>
36 #include <linux/list.h>
37 #include <linux/netdevice.h>
38 #include <linux/in6.h>
39 #include <linux/ipv6.h>
40 #include <linux/icmpv6.h>
41 #include <linux/random.h>
44 #include <linux/slab.h>
45 #include <linux/export.h>
65 #define FRAG6_CB(skb) ((struct ip6frag_skb_cb*)((skb)->cb))
82 c = jhash_3words((
__force u32)saddr->s6_addr32[0],
83 (
__force u32)saddr->s6_addr32[1],
84 (
__force u32)saddr->s6_addr32[2],
87 c = jhash_3words((
__force u32)saddr->s6_addr32[3],
88 (
__force u32)daddr->s6_addr32[0],
89 (
__force u32)daddr->s6_addr32[1],
92 c = jhash_3words((
__force u32)daddr->s6_addr32[2],
93 (
__force u32)daddr->s6_addr32[3],
115 return fq->
id == arg->
id &&
117 ipv6_addr_equal(&fq->
saddr, arg->
src) &&
118 ipv6_addr_equal(&fq->
daddr, arg->
dst);
139 spin_lock(&fq->
q.lock);
163 fq->
q.fragments->dev =
dev;
168 spin_unlock(&fq->
q.lock);
169 inet_frag_put(&fq->
q, frags);
173 static void ip6_frag_expire(
unsigned long data)
212 struct net *net = dev_net(skb_dst(skb)->dev);
219 ((
u8 *)(fhdr + 1) - (
u8 *)(ipv6_hdr(skb) + 1)));
226 skb_network_header(skb)));
231 const unsigned char *nh = skb_network_header(skb);
242 if (end < fq->q.
len ||
261 if (end > fq->
q.len) {
273 if (!pskb_pull(skb, (
u8 *) (fhdr + 1) - skb->
data))
276 if (pskb_trim_rcsum(skb, end - offset))
283 prev = fq->
q.fragments_tail;
284 if (!prev ||
FRAG6_CB(prev)->offset < offset) {
289 for(next = fq->
q.fragments; next !=
NULL; next = next->
next) {
290 if (
FRAG6_CB(next)->offset >= offset)
309 if (next &&
FRAG6_CB(next)->offset < end)
317 fq->
q.fragments_tail =
skb;
321 fq->
q.fragments =
skb;
329 fq->
q.meat += skb->
len;
341 fq->
q.meat == fq->
q.len)
342 return ip6_frag_reasm(fq, prev, dev);
345 list_move_tail(&fq->
q.lru_list, &fq->
q.net->lru_list);
370 struct net *net =
container_of(fq->
q.net,
struct net, ipv6.frags);
388 fq->
q.fragments_tail =
fp;
392 head->
next = fq->
q.fragments->next;
395 fq->
q.fragments =
head;
402 payload_len = ((head->
data - skb_network_header(head)) -
403 sizeof(
struct ipv6hdr) + fq->
q.len -
415 if (skb_has_frag_list(head)) {
423 skb_shinfo(clone)->frag_list = skb_shinfo(head)->frag_list;
424 skb_frag_list_init(head);
425 for (i = 0; i < skb_shinfo(head)->nr_frags; i++)
426 plen += skb_frag_size(&skb_shinfo(head)->frags[
i]);
438 skb_network_header(head)[nhoff] = skb_transport_header(head)[0];
444 skb_reset_transport_header(head);
448 for (fp = head->
next; fp;) {
462 if (!skb_shinfo(head)->frag_list)
463 skb_shinfo(head)->frag_list =
fp;
475 ipv6_hdr(head)->payload_len =
htons(payload_len);
476 IP6CB(head)->nhoff = nhoff;
481 skb_network_header_len(head),
487 fq->
q.fragments =
NULL;
488 fq->
q.fragments_tail =
NULL;
503 static int ipv6_frag_rcv(
struct sk_buff *skb)
508 struct net *net = dev_net(skb_dst(skb)->dev);
517 if (!pskb_may_pull(skb, (skb_transport_offset(skb) +
522 fhdr = (
struct frag_hdr *)skb_transport_header(skb);
530 IP6CB(skb)->nhoff = (
u8 *)fhdr - skb_network_header(skb);
543 spin_lock(&fq->
q.lock);
545 ret = ip6_frag_queue(fq, skb, fhdr,
IP6CB(skb)->nhoff);
547 spin_unlock(&fq->
q.lock);
548 inet_frag_put(&fq->
q, &ip6_frags);
562 static const struct inet6_protocol frag_protocol =
564 .handler = ipv6_frag_rcv,
565 .flags = INET6_PROTO_NOPOLICY,
569 static struct ctl_table ip6_frags_ns_ctl_table[] = {
572 .data = &
init_net.ipv6.frags.high_thresh,
573 .maxlen =
sizeof(
int),
578 .procname =
"ip6frag_low_thresh",
579 .data = &
init_net.ipv6.frags.low_thresh,
580 .maxlen =
sizeof(
int),
585 .procname =
"ip6frag_time",
586 .data = &
init_net.ipv6.frags.timeout,
587 .maxlen =
sizeof(
int),
594 static struct ctl_table ip6_frags_ctl_table[] = {
596 .
procname =
"ip6frag_secret_interval",
597 .data = &ip6_frags.secret_interval,
598 .maxlen =
sizeof(
int),
605 static int __net_init ip6_frags_ns_sysctl_register(
struct net *net)
610 table = ip6_frags_ns_ctl_table;
616 table[0].
data = &net->ipv6.frags.high_thresh;
617 table[1].
data = &net->ipv6.frags.low_thresh;
618 table[2].
data = &net->ipv6.frags.timeout;
625 net->ipv6.sysctl.frags_hdr =
hdr;
635 static void __net_exit ip6_frags_ns_sysctl_unregister(
struct net *net)
639 table = net->ipv6.sysctl.frags_hdr->ctl_table_arg;
647 static int ip6_frags_sysctl_register(
void)
650 ip6_frags_ctl_table);
654 static void ip6_frags_sysctl_unregister(
void)
659 static inline int ip6_frags_ns_sysctl_register(
struct net *net)
664 static inline void ip6_frags_ns_sysctl_unregister(
struct net *net)
668 static inline int ip6_frags_sysctl_register(
void)
673 static inline void ip6_frags_sysctl_unregister(
void)
678 static int __net_init ipv6_frags_init_net(
struct net *net)
686 return ip6_frags_ns_sysctl_register(net);
689 static void __net_exit ipv6_frags_exit_net(
struct net *net)
691 ip6_frags_ns_sysctl_unregister(net);
696 .init = ipv6_frags_init_net,
697 .exit = ipv6_frags_exit_net,
708 ret = ip6_frags_sysctl_register();
716 ip6_frags.hashfn = ip6_hashfn;
718 ip6_frags.destructor =
NULL;
719 ip6_frags.skb_free =
NULL;
722 ip6_frags.frag_expire = ip6_frag_expire;
723 ip6_frags.secret_interval = 10 * 60 *
HZ;
729 ip6_frags_sysctl_unregister();
738 ip6_frags_sysctl_unregister();