Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	IPv6 fragment reassembly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	Linux INET6 implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	Pedro Roque		<roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	Based on: net/ipv4/ip_fragment.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *	Fixes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *	Andi Kleen	Make it work with multiple hosts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *			More RFC compliance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *      Horst von Brand Add missing #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *	Alexey Kuznetsov	SMP races, threading, cleanup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *	Patrick McHardy		LRU queue of frag heads for evictor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *	Mitsuru KANDA @USAGI	Register inet6_protocol{}.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *	David Stevens and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *	YOSHIFUJI,H. @USAGI	Always remove fragment header to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *				calculate ICV correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define pr_fmt(fmt) "IPv6: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/jhash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <net/snmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #include <net/transp_v6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #include <net/rawv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #include <net/ipv6_frag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static const char ip6_frag_cache_name[] = "ip6-frags";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return 1 << (ipv6_get_dsfield(ipv6h) & INET_ECN_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static struct inet_frags ip6_frags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			  struct sk_buff *prev_tail, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void ip6_frag_expire(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct inet_frag_queue *frag = from_timer(frag, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct frag_queue *fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	fq = container_of(frag, struct frag_queue, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	ip6frag_expire_frag_queue(fq->q.fqdir->net, fq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static struct frag_queue *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) fq_find(struct net *net, __be32 id, const struct ipv6hdr *hdr, int iif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct frag_v6_compare_key key = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		.id = id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		.saddr = hdr->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		.daddr = hdr->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.user = IP6_DEFRAG_LOCAL_DELIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		.iif = iif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct inet_frag_queue *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (!(ipv6_addr_type(&hdr->daddr) & (IPV6_ADDR_MULTICAST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 					    IPV6_ADDR_LINKLOCAL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		key.iif = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	q = inet_frag_find(net->ipv6.fqdir, &key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return container_of(q, struct frag_queue, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			  struct frag_hdr *fhdr, int nhoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			  u32 *prob_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct net *net = dev_net(skb_dst(skb)->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int offset, end, fragsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct sk_buff *prev_tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	u8 ecn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (fq->q.flags & INET_FRAG_COMPLETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	offset = ntohs(fhdr->frag_off) & ~0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	end = offset + (ntohs(ipv6_hdr(skb)->payload_len) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if ((unsigned int)end > IPV6_MAXPLEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		*prob_offset = (u8 *)&fhdr->frag_off - skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		/* note that if prob_offset is set, the skb is freed elsewhere,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		 * we do not free it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ecn = ip6_frag_ecn(ipv6_hdr(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (skb->ip_summed == CHECKSUM_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		const unsigned char *nh = skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		skb->csum = csum_sub(skb->csum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				     csum_partial(nh, (u8 *)(fhdr + 1) - nh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 						  0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* Is this the final fragment? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!(fhdr->frag_off & htons(IP6_MF))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		/* If we already have some bits beyond end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		 * or have different end, the segment is corrupted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (end < fq->q.len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		    ((fq->q.flags & INET_FRAG_LAST_IN) && end != fq->q.len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			goto discard_fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		fq->q.flags |= INET_FRAG_LAST_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		fq->q.len = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		/* Check if the fragment is rounded to 8 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		 * Required by the RFC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (end & 0x7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			/* RFC2460 says always send parameter problem in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			 * this case. -DaveM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			*prob_offset = offsetof(struct ipv6hdr, payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (end > fq->q.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			/* Some bits beyond end -> corruption. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			if (fq->q.flags & INET_FRAG_LAST_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				goto discard_fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			fq->q.len = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (end == offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		goto discard_fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* Point into the IP datagram 'data' part. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (!pskb_pull(skb, (u8 *) (fhdr + 1) - skb->data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		goto discard_fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	err = pskb_trim_rcsum(skb, end - offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		goto discard_fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* Note : skb->rbnode and skb->dev share the same location. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* Makes sure compiler wont do silly aliasing games */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	prev_tail = fq->q.fragments_tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	err = inet_frag_queue_insert(&fq->q, skb, offset, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto insert_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		fq->iif = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	fq->q.stamp = skb->tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	fq->q.meat += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	fq->ecn |= ecn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	add_frag_mem_limit(fq->q.fqdir, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	fragsize = -skb_network_offset(skb) + skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (fragsize > fq->q.max_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		fq->q.max_size = fragsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	/* The first fragment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 * nhoffset is obtained from the first fragment, of course.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (offset == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		fq->nhoffset = nhoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		fq->q.flags |= INET_FRAG_FIRST_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (fq->q.flags == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	    fq->q.meat == fq->q.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		unsigned long orefdst = skb->_skb_refdst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		skb->_skb_refdst = 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		err = ip6_frag_reasm(fq, skb, prev_tail, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		skb->_skb_refdst = orefdst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	skb_dst_drop(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) insert_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (err == IPFRAG_DUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			IPSTATS_MIB_REASM_OVERLAPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) discard_fq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	inet_frag_kill(&fq->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			IPSTATS_MIB_REASMFAILS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  *	Check if this packet is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  *	It is called with locked fq, and caller must check that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  *	queue is eligible for reassembly i.e. it is not COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  *	the last and the first frames arrived and all the bits are here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			  struct sk_buff *prev_tail, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct net *net = fq->q.fqdir->net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	unsigned int nhoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	void *reasm_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	int payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	u8 ecn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	inet_frag_kill(&fq->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	ecn = ip_frag_ecn_table[fq->ecn];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (unlikely(ecn == 0xff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	reasm_data = inet_frag_reasm_prepare(&fq->q, skb, prev_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (!reasm_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		goto out_oom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	payload_len = ((skb->data - skb_network_header(skb)) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		       sizeof(struct ipv6hdr) + fq->q.len -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		       sizeof(struct frag_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (payload_len > IPV6_MAXPLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		goto out_oversize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/* We have to remove fragment header from datagram and to relocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 * header in order to calculate ICV correctly. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	nhoff = fq->nhoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	skb_network_header(skb)[nhoff] = skb_transport_header(skb)[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	memmove(skb->head + sizeof(struct frag_hdr), skb->head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		(skb->data - skb->head) - sizeof(struct frag_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (skb_mac_header_was_set(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		skb->mac_header += sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	skb->network_header += sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	inet_frag_reasm_finish(&fq->q, skb, reasm_data, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	ipv6_hdr(skb)->payload_len = htons(payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	ipv6_change_dsfield(ipv6_hdr(skb), 0xff, ecn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	IP6CB(skb)->nhoff = nhoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	IP6CB(skb)->flags |= IP6SKB_FRAGMENTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	IP6CB(skb)->frag_max_size = fq->q.max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	/* Yes, and fold redundant checksum back. 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	skb_postpush_rcsum(skb, skb_network_header(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			   skb_network_header_len(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	__IP6_INC_STATS(net, __in6_dev_stats_get(dev, skb), IPSTATS_MIB_REASMOKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	fq->q.rb_fragments = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	fq->q.fragments_tail = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	fq->q.last_run_head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) out_oversize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	net_dbg_ratelimited("ip6_frag_reasm: payload len = %d\n", payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) out_oom:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	net_dbg_ratelimited("ip6_frag_reasm: no memory for reassembly\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	__IP6_INC_STATS(net, __in6_dev_stats_get(dev, skb), IPSTATS_MIB_REASMFAILS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	inet_frag_kill(&fq->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static int ipv6_frag_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct frag_hdr *fhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	struct frag_queue *fq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	const struct ipv6hdr *hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct net *net = dev_net(skb_dst(skb)->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	u8 nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	int iif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (IP6CB(skb)->flags & IP6SKB_FRAGMENTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		goto fail_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMREQDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/* Jumbo payload inhibits frag. header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (hdr->payload_len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		goto fail_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (!pskb_may_pull(skb, (skb_transport_offset(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				 sizeof(struct frag_hdr))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		goto fail_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	fhdr = (struct frag_hdr *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (!(fhdr->frag_off & htons(IP6_OFFSET | IP6_MF))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		/* It is not a fragmented frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		skb->transport_header += sizeof(struct frag_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		__IP6_INC_STATS(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 				ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMOKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		IP6CB(skb)->nhoff = (u8 *)fhdr - skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		IP6CB(skb)->flags |= IP6SKB_FRAGMENTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		IP6CB(skb)->frag_max_size = ntohs(hdr->payload_len) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					    sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	/* RFC 8200, Section 4.5 Fragment Header:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	 * If the first fragment does not include all headers through an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	 * Upper-Layer header, then that fragment should be discarded and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	 * an ICMP Parameter Problem, Code 3, message should be sent to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	 * the source of the fragment, with the Pointer field set to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	nexthdr = hdr->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (ipv6frag_thdr_truncated(skb, skb_transport_offset(skb), &nexthdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 				IPSTATS_MIB_INHDRERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		icmpv6_param_prob(skb, ICMPV6_HDR_INCOMP, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	iif = skb->dev ? skb->dev->ifindex : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	fq = fq_find(net, fhdr->identification, hdr, iif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (fq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		u32 prob_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		spin_lock(&fq->q.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		fq->iif = iif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		ret = ip6_frag_queue(fq, skb, fhdr, IP6CB(skb)->nhoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 				     &prob_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		spin_unlock(&fq->q.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		inet_frag_put(&fq->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		if (prob_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 					IPSTATS_MIB_INHDRERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			/* icmpv6_param_prob() calls kfree_skb(skb) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, prob_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	__IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_REASMFAILS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) fail_hdr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	__IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			IPSTATS_MIB_INHDRERRORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb_network_header_len(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static const struct inet6_protocol frag_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	.handler	=	ipv6_frag_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	.flags		=	INET6_PROTO_NOPOLICY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static struct ctl_table ip6_frags_ns_ctl_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		.procname	= "ip6frag_high_thresh",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		.maxlen		= sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		.proc_handler	= proc_doulongvec_minmax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		.procname	= "ip6frag_low_thresh",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		.maxlen		= sizeof(unsigned long),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		.proc_handler	= proc_doulongvec_minmax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		.procname	= "ip6frag_time",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		.proc_handler	= proc_dointvec_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /* secret interval has been deprecated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int ip6_frags_secret_interval_unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static struct ctl_table ip6_frags_ctl_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		.procname	= "ip6frag_secret_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		.data		= &ip6_frags_secret_interval_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		.proc_handler	= proc_dointvec_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	struct ctl_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct ctl_table_header *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	table = ip6_frags_ns_ctl_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (!net_eq(net, &init_net)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		if (!table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			goto err_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	table[0].data	= &net->ipv6.fqdir->high_thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	table[0].extra1	= &net->ipv6.fqdir->low_thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	table[1].data	= &net->ipv6.fqdir->low_thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	table[1].extra2	= &net->ipv6.fqdir->high_thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	table[2].data	= &net->ipv6.fqdir->timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	hdr = register_net_sysctl(net, "net/ipv6", table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		goto err_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	net->ipv6.sysctl.frags_hdr = hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) err_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	if (!net_eq(net, &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		kfree(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) err_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static void __net_exit ip6_frags_ns_sysctl_unregister(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	struct ctl_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	table = net->ipv6.sysctl.frags_hdr->ctl_table_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	unregister_net_sysctl_table(net->ipv6.sysctl.frags_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	if (!net_eq(net, &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		kfree(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static struct ctl_table_header *ip6_ctl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static int ip6_frags_sysctl_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	ip6_ctl_header = register_net_sysctl(&init_net, "net/ipv6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			ip6_frags_ctl_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	return ip6_ctl_header == NULL ? -ENOMEM : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static void ip6_frags_sysctl_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	unregister_net_sysctl_table(ip6_ctl_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static int ip6_frags_ns_sysctl_register(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static void ip6_frags_ns_sysctl_unregister(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int ip6_frags_sysctl_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static void ip6_frags_sysctl_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static int __net_init ipv6_frags_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	res = fqdir_init(&net->ipv6.fqdir, &ip6_frags, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	net->ipv6.fqdir->high_thresh = IPV6_FRAG_HIGH_THRESH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	net->ipv6.fqdir->low_thresh = IPV6_FRAG_LOW_THRESH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	net->ipv6.fqdir->timeout = IPV6_FRAG_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	res = ip6_frags_ns_sysctl_register(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		fqdir_exit(net->ipv6.fqdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static void __net_exit ipv6_frags_pre_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	fqdir_pre_exit(net->ipv6.fqdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static void __net_exit ipv6_frags_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	ip6_frags_ns_sysctl_unregister(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	fqdir_exit(net->ipv6.fqdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static struct pernet_operations ip6_frags_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	.init		= ipv6_frags_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.pre_exit	= ipv6_frags_pre_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.exit		= ipv6_frags_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static const struct rhashtable_params ip6_rhash_params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	.head_offset		= offsetof(struct inet_frag_queue, node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	.hashfn			= ip6frag_key_hashfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	.obj_hashfn		= ip6frag_obj_hashfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	.obj_cmpfn		= ip6frag_obj_cmpfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	.automatic_shrinking	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) int __init ipv6_frag_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	ip6_frags.constructor = ip6frag_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	ip6_frags.destructor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	ip6_frags.qsize = sizeof(struct frag_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	ip6_frags.frag_expire = ip6_frag_expire;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	ip6_frags.frags_cache_name = ip6_frag_cache_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	ip6_frags.rhash_params = ip6_rhash_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	ret = inet_frags_init(&ip6_frags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	ret = inet6_add_protocol(&frag_protocol, IPPROTO_FRAGMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		goto err_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	ret = ip6_frags_sysctl_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		goto err_sysctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	ret = register_pernet_subsys(&ip6_frags_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		goto err_pernet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) err_pernet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	ip6_frags_sysctl_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) err_sysctl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) err_protocol:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	inet_frags_fini(&ip6_frags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) void ipv6_frag_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	ip6_frags_sysctl_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	unregister_pernet_subsys(&ip6_frags_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	inet6_del_protocol(&frag_protocol, IPPROTO_FRAGMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	inet_frags_fini(&ip6_frags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }