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)  * Copyright (C)2003-2006 Helsinki University of Technology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C)2003-2006 USAGI/WIDE Project
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Noriaki TAKAMIYA @USAGI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	Masahide NAKAMURA @USAGI
^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) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <net/ip6_checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <net/rawv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/mip6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static inline unsigned int calc_padlen(unsigned int len, unsigned int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	return (n - len + 16) & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static inline void *mip6_padn(__u8 *data, __u8 padlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (padlen == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		data[0] = IPV6_TLV_PAD1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	} else if (padlen > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		data[0] = IPV6_TLV_PADN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		data[1] = padlen - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (padlen > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			memset(data+2, 0, data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return data + padlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static inline void mip6_param_prob(struct sk_buff *skb, u8 code, int pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	icmpv6_send(skb, ICMPV6_PARAMPROB, code, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static int mip6_mh_len(int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	case IP6_MH_TYPE_BRR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	case IP6_MH_TYPE_HOTI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	case IP6_MH_TYPE_COTI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	case IP6_MH_TYPE_BU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	case IP6_MH_TYPE_BACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	case IP6_MH_TYPE_HOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	case IP6_MH_TYPE_COT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	case IP6_MH_TYPE_BERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		len = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int mip6_mh_filter(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct ip6_mh _hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	const struct ip6_mh *mh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	mh = skb_header_pointer(skb, skb_transport_offset(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				sizeof(_hdr), &_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (!mh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (((mh->ip6mh_hdrlen + 1) << 3) > skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (mh->ip6mh_hdrlen < mip6_mh_len(mh->ip6mh_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		net_dbg_ratelimited("mip6: MH message too short: %d vs >=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				    mh->ip6mh_hdrlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				    mip6_mh_len(mh->ip6mh_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		mip6_param_prob(skb, 0, offsetof(struct ip6_mh, ip6mh_hdrlen) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				skb_network_header_len(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (mh->ip6mh_proto != IPPROTO_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		net_dbg_ratelimited("mip6: MH invalid payload proto = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				    mh->ip6mh_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		mip6_param_prob(skb, 0, offsetof(struct ip6_mh, ip6mh_proto) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				skb_network_header_len(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct mip6_report_rate_limiter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ktime_t stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	int iif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct in6_addr src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct in6_addr dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static struct mip6_report_rate_limiter mip6_report_rl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.lock = __SPIN_LOCK_UNLOCKED(mip6_report_rl.lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int mip6_destopt_input(struct xfrm_state *x, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	const struct ipv6hdr *iph = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct ipv6_destopt_hdr *destopt = (struct ipv6_destopt_hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int err = destopt->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	spin_lock(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!ipv6_addr_equal(&iph->saddr, (struct in6_addr *)x->coaddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	    !ipv6_addr_any((struct in6_addr *)x->coaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	spin_unlock(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Destination Option Header is inserted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * IP Header's src address is replaced with Home Address Option in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * Destination Option Header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int mip6_destopt_output(struct xfrm_state *x, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct ipv6hdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct ipv6_destopt_hdr *dstopt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct ipv6_destopt_hao *hao;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	u8 nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	skb_push(skb, -skb_network_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	iph = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	nexthdr = *skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	*skb_mac_header(skb) = IPPROTO_DSTOPTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	dstopt = (struct ipv6_destopt_hdr *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	dstopt->nexthdr = nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	hao = mip6_padn((char *)(dstopt + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			calc_padlen(sizeof(*dstopt), 6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	hao->type = IPV6_TLV_HAO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	BUILD_BUG_ON(sizeof(*hao) != 18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	hao->length = sizeof(*hao) - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	len = ((char *)hao - (char *)dstopt) + sizeof(*hao);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	memcpy(&hao->addr, &iph->saddr, sizeof(hao->addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	spin_lock_bh(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	memcpy(&iph->saddr, x->coaddr, sizeof(iph->saddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	spin_unlock_bh(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	WARN_ON(len != x->props.header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	dstopt->hdrlen = (x->props.header_len >> 3) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline int mip6_report_rl_allow(ktime_t stamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				       const struct in6_addr *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				       const struct in6_addr *src, int iif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	int allow = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	spin_lock_bh(&mip6_report_rl.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (mip6_report_rl.stamp != stamp ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	    mip6_report_rl.iif != iif ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	    !ipv6_addr_equal(&mip6_report_rl.src, src) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	    !ipv6_addr_equal(&mip6_report_rl.dst, dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		mip6_report_rl.stamp = stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		mip6_report_rl.iif = iif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		mip6_report_rl.src = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		mip6_report_rl.dst = *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		allow = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	spin_unlock_bh(&mip6_report_rl.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return allow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			       const struct flowi *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct net *net = xs_net(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct inet6_skb_parm *opt = (struct inet6_skb_parm *)skb->cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	const struct flowi6 *fl6 = &fl->u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct ipv6_destopt_hao *hao = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct xfrm_selector sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	ktime_t stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (unlikely(fl6->flowi6_proto == IPPROTO_MH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		     fl6->fl6_mh_type <= IP6_MH_TYPE_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (likely(opt->dsthao)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		offset = ipv6_find_tlv(skb, opt->dsthao, IPV6_TLV_HAO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (likely(offset >= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			hao = (struct ipv6_destopt_hao *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 					(skb_network_header(skb) + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	stamp = skb_get_ktime(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!mip6_report_rl_allow(stamp, &ipv6_hdr(skb)->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				  hao ? &hao->addr : &ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				  opt->iif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	memset(&sel, 0, sizeof(sel));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	memcpy(&sel.daddr, (xfrm_address_t *)&ipv6_hdr(skb)->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	       sizeof(sel.daddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	sel.prefixlen_d = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	memcpy(&sel.saddr, (xfrm_address_t *)&ipv6_hdr(skb)->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	       sizeof(sel.saddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	sel.prefixlen_s = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	sel.family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	sel.proto = fl6->flowi6_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	sel.dport = xfrm_flowi_dport(fl, &fl6->uli);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (sel.dport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		sel.dport_mask = htons(~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	sel.sport = xfrm_flowi_sport(fl, &fl6->uli);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (sel.sport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		sel.sport_mask = htons(~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	sel.ifindex = fl6->flowi6_oif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	err = km_report(net, IPPROTO_DSTOPTS, &sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			(hao ? (xfrm_address_t *)&hao->addr : NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int mip6_destopt_offset(struct xfrm_state *x, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			       u8 **nexthdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	u16 offset = sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct ipv6_opt_hdr *exthdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				   (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	const unsigned char *nh = skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	unsigned int packet_len = skb_tail_pointer(skb) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	int found_rhdr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	*nexthdr = &ipv6_hdr(skb)->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	while (offset + 1 <= packet_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		switch (**nexthdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		case NEXTHDR_HOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		case NEXTHDR_ROUTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			found_rhdr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		case NEXTHDR_DEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			 * HAO MUST NOT appear more than once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			 * XXX: It is better to try to find by the end of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			 * XXX: packet if HAO exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				net_dbg_ratelimited("mip6: hao exists already, override\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			if (found_rhdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		offset += ipv6_optlen(exthdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		*nexthdr = &exthdr->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		exthdr = (struct ipv6_opt_hdr *)(nh + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int mip6_destopt_init_state(struct xfrm_state *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (x->id.spi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		pr_info("%s: spi is not 0: %u\n", __func__, x->id.spi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (x->props.mode != XFRM_MODE_ROUTEOPTIMIZATION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		pr_info("%s: state's mode is not %u: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			__func__, XFRM_MODE_ROUTEOPTIMIZATION, x->props.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	x->props.header_len = sizeof(struct ipv6_destopt_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		calc_padlen(sizeof(struct ipv6_destopt_hdr), 6) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		sizeof(struct ipv6_destopt_hao);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	WARN_ON(x->props.header_len != 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * Do nothing about destroying since it has no specific operation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * destination options header unlike IPsec protocols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static void mip6_destopt_destroy(struct xfrm_state *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static const struct xfrm_type mip6_destopt_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	.description	= "MIP6DESTOPT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.proto		= IPPROTO_DSTOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.flags		= XFRM_TYPE_NON_FRAGMENT | XFRM_TYPE_LOCAL_COADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.init_state	= mip6_destopt_init_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.destructor	= mip6_destopt_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.input		= mip6_destopt_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.output		= mip6_destopt_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.reject		= mip6_destopt_reject,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	.hdr_offset	= mip6_destopt_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int mip6_rthdr_input(struct xfrm_state *x, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	const struct ipv6hdr *iph = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct rt2_hdr *rt2 = (struct rt2_hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	int err = rt2->rt_hdr.nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	spin_lock(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (!ipv6_addr_equal(&iph->daddr, (struct in6_addr *)x->coaddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	    !ipv6_addr_any((struct in6_addr *)x->coaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	spin_unlock(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /* Routing Header type 2 is inserted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * IP Header's dst address is replaced with Routing Header's Home Address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static int mip6_rthdr_output(struct xfrm_state *x, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct ipv6hdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	struct rt2_hdr *rt2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	u8 nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	skb_push(skb, -skb_network_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	iph = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	nexthdr = *skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	*skb_mac_header(skb) = IPPROTO_ROUTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	rt2 = (struct rt2_hdr *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	rt2->rt_hdr.nexthdr = nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	rt2->rt_hdr.hdrlen = (x->props.header_len >> 3) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	rt2->rt_hdr.type = IPV6_SRCRT_TYPE_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	rt2->rt_hdr.segments_left = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	memset(&rt2->reserved, 0, sizeof(rt2->reserved));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	WARN_ON(rt2->rt_hdr.hdrlen != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	memcpy(&rt2->addr, &iph->daddr, sizeof(rt2->addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	spin_lock_bh(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	memcpy(&iph->daddr, x->coaddr, sizeof(iph->daddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	spin_unlock_bh(&x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static int mip6_rthdr_offset(struct xfrm_state *x, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			     u8 **nexthdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	u16 offset = sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	struct ipv6_opt_hdr *exthdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				   (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	const unsigned char *nh = skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	unsigned int packet_len = skb_tail_pointer(skb) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	int found_rhdr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	*nexthdr = &ipv6_hdr(skb)->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	while (offset + 1 <= packet_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		switch (**nexthdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		case NEXTHDR_HOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		case NEXTHDR_ROUTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			if (offset + 3 <= packet_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				struct ipv6_rt_hdr *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 				rt = (struct ipv6_rt_hdr *)(nh + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 				if (rt->type != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 					return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			found_rhdr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		case NEXTHDR_DEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 				return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			if (found_rhdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 				return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		offset += ipv6_optlen(exthdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		*nexthdr = &exthdr->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		exthdr = (struct ipv6_opt_hdr *)(nh + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static int mip6_rthdr_init_state(struct xfrm_state *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (x->id.spi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		pr_info("%s: spi is not 0: %u\n", __func__, x->id.spi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (x->props.mode != XFRM_MODE_ROUTEOPTIMIZATION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		pr_info("%s: state's mode is not %u: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			__func__, XFRM_MODE_ROUTEOPTIMIZATION, x->props.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	x->props.header_len = sizeof(struct rt2_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  * Do nothing about destroying since it has no specific operation for routing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  * header type 2 unlike IPsec protocols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static void mip6_rthdr_destroy(struct xfrm_state *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static const struct xfrm_type mip6_rthdr_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	.description	= "MIP6RT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	.proto		= IPPROTO_ROUTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	.flags		= XFRM_TYPE_NON_FRAGMENT | XFRM_TYPE_REMOTE_COADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	.init_state	= mip6_rthdr_init_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	.destructor	= mip6_rthdr_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	.input		= mip6_rthdr_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	.output		= mip6_rthdr_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	.hdr_offset	= mip6_rthdr_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static int __init mip6_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	pr_info("Mobile IPv6\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (xfrm_register_type(&mip6_destopt_type, AF_INET6) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		pr_info("%s: can't add xfrm type(destopt)\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		goto mip6_destopt_xfrm_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	if (xfrm_register_type(&mip6_rthdr_type, AF_INET6) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		pr_info("%s: can't add xfrm type(rthdr)\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		goto mip6_rthdr_xfrm_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	if (rawv6_mh_filter_register(mip6_mh_filter) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		pr_info("%s: can't add rawv6 mh filter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		goto mip6_rawv6_mh_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  mip6_rawv6_mh_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	xfrm_unregister_type(&mip6_rthdr_type, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  mip6_rthdr_xfrm_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	xfrm_unregister_type(&mip6_destopt_type, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)  mip6_destopt_xfrm_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static void __exit mip6_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (rawv6_mh_filter_unregister(mip6_mh_filter) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		pr_info("%s: can't remove rawv6 mh filter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	xfrm_unregister_type(&mip6_rthdr_type, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	xfrm_unregister_type(&mip6_destopt_type, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) module_init(mip6_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) module_exit(mip6_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) MODULE_ALIAS_XFRM_TYPE(AF_INET6, XFRM_PROTO_DSTOPTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) MODULE_ALIAS_XFRM_TYPE(AF_INET6, XFRM_PROTO_ROUTING);