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,2004 USAGI/WIDE Project
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Authors	Mitsuru KANDA  <mk@linux-ipv6.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *		YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define pr_fmt(fmt) "IPv6: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static struct xfrm6_tunnel __rcu *tunnel6_handlers __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static struct xfrm6_tunnel __rcu *tunnel46_handlers __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static struct xfrm6_tunnel __rcu *tunnelmpls6_handlers __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static DEFINE_MUTEX(tunnel6_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static inline int xfrm6_tunnel_mpls_supported(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	return IS_ENABLED(CONFIG_MPLS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct xfrm6_tunnel __rcu **pprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct xfrm6_tunnel *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int ret = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int priority = handler->priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	mutex_lock(&tunnel6_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	switch (family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		pprev = &tunnel6_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		pprev = &tunnel46_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	case AF_MPLS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		pprev = &tunnelmpls6_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	for (; (t = rcu_dereference_protected(*pprev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			lockdep_is_held(&tunnel6_mutex))) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	     pprev = &t->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		if (t->priority > priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		if (t->priority == priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	handler->next = *pprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	rcu_assign_pointer(*pprev, handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	mutex_unlock(&tunnel6_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) EXPORT_SYMBOL(xfrm6_tunnel_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct xfrm6_tunnel __rcu **pprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct xfrm6_tunnel *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	mutex_lock(&tunnel6_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	switch (family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		pprev = &tunnel6_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		pprev = &tunnel46_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	case AF_MPLS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		pprev = &tunnelmpls6_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	for (; (t = rcu_dereference_protected(*pprev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			lockdep_is_held(&tunnel6_mutex))) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	     pprev = &t->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (t == handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			*pprev = handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			break;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	mutex_unlock(&tunnel6_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) EXPORT_SYMBOL(xfrm6_tunnel_deregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define for_each_tunnel_rcu(head, handler)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	for (handler = rcu_dereference(head);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	     handler != NULL;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	     handler = rcu_dereference(handler->next))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int tunnelmpls6_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct xfrm6_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	for_each_tunnel_rcu(tunnelmpls6_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (!handler->handler(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int tunnel6_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct xfrm6_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	for_each_tunnel_rcu(tunnel6_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		if (!handler->handler(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int tunnel6_rcv_cb(struct sk_buff *skb, u8 proto, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct xfrm6_tunnel __rcu *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct xfrm6_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	head = (proto == IPPROTO_IPV6) ? tunnel6_handlers : tunnel46_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	for_each_tunnel_rcu(head, handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		if (handler->cb_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			ret = handler->cb_handler(skb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		}
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static const struct xfrm_input_afinfo tunnel6_input_afinfo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	.family		=	AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.is_ipip	=	true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.callback	=	tunnel6_rcv_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int tunnel46_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct xfrm6_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (!pskb_may_pull(skb, sizeof(struct iphdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	for_each_tunnel_rcu(tunnel46_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (!handler->handler(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int tunnel6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			u8 type, u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct xfrm6_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	for_each_tunnel_rcu(tunnel6_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (!handler->err_handler(skb, opt, type, code, offset, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int tunnel46_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			 u8 type, u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct xfrm6_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	for_each_tunnel_rcu(tunnel46_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (!handler->err_handler(skb, opt, type, code, offset, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int tunnelmpls6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			   u8 type, u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct xfrm6_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	for_each_tunnel_rcu(tunnelmpls6_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (!handler->err_handler(skb, opt, type, code, offset, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static const struct inet6_protocol tunnel6_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.handler	= tunnel6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.err_handler	= tunnel6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	.flags          = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static const struct inet6_protocol tunnel46_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	.handler	= tunnel46_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.err_handler	= tunnel46_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.flags          = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static const struct inet6_protocol tunnelmpls6_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	.handler	= tunnelmpls6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	.err_handler	= tunnelmpls6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	.flags          = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static int __init tunnel6_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (inet6_add_protocol(&tunnel6_protocol, IPPROTO_IPV6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		pr_err("%s: can't add protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (inet6_add_protocol(&tunnel46_protocol, IPPROTO_IPIP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		pr_err("%s: can't add protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (xfrm6_tunnel_mpls_supported() &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	    inet6_add_protocol(&tunnelmpls6_protocol, IPPROTO_MPLS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		pr_err("%s: can't add protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (xfrm_input_register_afinfo(&tunnel6_input_afinfo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		pr_err("%s: can't add input afinfo\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		if (xfrm6_tunnel_mpls_supported())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			inet6_del_protocol(&tunnelmpls6_protocol, IPPROTO_MPLS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void __exit tunnel6_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (xfrm_input_unregister_afinfo(&tunnel6_input_afinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		pr_err("%s: can't remove input afinfo\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		pr_err("%s: can't remove protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		pr_err("%s: can't remove protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (xfrm6_tunnel_mpls_supported() &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	    inet6_del_protocol(&tunnelmpls6_protocol, IPPROTO_MPLS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		pr_err("%s: can't remove protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) module_init(tunnel6_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) module_exit(tunnel6_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) MODULE_LICENSE("GPL");