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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* tunnel4.c: Generic IP tunnel transformer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2003 David S. Miller (davem@redhat.com)
^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) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/mpls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static struct xfrm_tunnel __rcu *tunnel4_handlers __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct xfrm_tunnel __rcu *tunnel64_handlers __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static struct xfrm_tunnel __rcu *tunnelmpls4_handlers __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static DEFINE_MUTEX(tunnel4_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static inline struct xfrm_tunnel __rcu **fam_handlers(unsigned short family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	return (family == AF_INET) ? &tunnel4_handlers :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		(family == AF_INET6) ? &tunnel64_handlers :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		&tunnelmpls4_handlers;
^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) int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct xfrm_tunnel __rcu **pprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct xfrm_tunnel *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^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(&tunnel4_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	for (pprev = fam_handlers(family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	     (t = rcu_dereference_protected(*pprev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			lockdep_is_held(&tunnel4_mutex))) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	     pprev = &t->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		if (t->priority > priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		if (t->priority == priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			goto err;
^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) 	handler->next = *pprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	rcu_assign_pointer(*pprev, handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	mutex_unlock(&tunnel4_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) EXPORT_SYMBOL(xfrm4_tunnel_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct xfrm_tunnel __rcu **pprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct xfrm_tunnel *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	mutex_lock(&tunnel4_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	for (pprev = fam_handlers(family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	     (t = rcu_dereference_protected(*pprev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			lockdep_is_held(&tunnel4_mutex))) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	     pprev = &t->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		if (t == handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			*pprev = handler->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	mutex_unlock(&tunnel4_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) EXPORT_SYMBOL(xfrm4_tunnel_deregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define for_each_tunnel_rcu(head, handler)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	for (handler = rcu_dereference(head);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	     handler != NULL;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	     handler = rcu_dereference(handler->next))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static int tunnel4_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct xfrm_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (!pskb_may_pull(skb, sizeof(struct iphdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	for_each_tunnel_rcu(tunnel4_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (!handler->handler(skb))
^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) 	icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int tunnel4_rcv_cb(struct sk_buff *skb, u8 proto, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct xfrm_tunnel __rcu *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct xfrm_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	head = (proto == IPPROTO_IPIP) ? tunnel4_handlers : tunnel64_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	for_each_tunnel_rcu(head, handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		if (handler->cb_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			ret = handler->cb_handler(skb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^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) static const struct xfrm_input_afinfo tunnel4_input_afinfo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.family		=	AF_INET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.is_ipip	=	true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	.callback	=	tunnel4_rcv_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int tunnel64_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct xfrm_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	for_each_tunnel_rcu(tunnel64_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (!handler->handler(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #if IS_ENABLED(CONFIG_MPLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int tunnelmpls4_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct xfrm_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (!pskb_may_pull(skb, sizeof(struct mpls_label)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	for_each_tunnel_rcu(tunnelmpls4_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		if (!handler->handler(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int tunnel4_err(struct sk_buff *skb, u32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct xfrm_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	for_each_tunnel_rcu(tunnel4_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if (!handler->err_handler(skb, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int tunnel64_err(struct sk_buff *skb, u32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct xfrm_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	for_each_tunnel_rcu(tunnel64_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (!handler->err_handler(skb, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #if IS_ENABLED(CONFIG_MPLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int tunnelmpls4_err(struct sk_buff *skb, u32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct xfrm_tunnel *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	for_each_tunnel_rcu(tunnelmpls4_handlers, handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if (!handler->err_handler(skb, info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static const struct net_protocol tunnel4_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	.handler	=	tunnel4_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	.err_handler	=	tunnel4_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	.no_policy	=	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.netns_ok	=	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static const struct net_protocol tunnel64_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	.handler	=	tunnel64_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	.err_handler	=	tunnel64_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	.no_policy	=	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	.netns_ok	=	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #if IS_ENABLED(CONFIG_MPLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static const struct net_protocol tunnelmpls4_protocol = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	.handler	=	tunnelmpls4_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	.err_handler	=	tunnelmpls4_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	.no_policy	=	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	.netns_ok	=	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int __init tunnel4_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (inet_add_protocol(&tunnel64_protocol, IPPROTO_IPV6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #if IS_ENABLED(CONFIG_MPLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (inet_add_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (xfrm_input_register_afinfo(&tunnel4_input_afinfo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #if IS_ENABLED(CONFIG_MPLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	pr_err("%s: can't add protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static void __exit tunnel4_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (xfrm_input_unregister_afinfo(&tunnel4_input_afinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		pr_err("tunnel4 close: can't remove input afinfo\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #if IS_ENABLED(CONFIG_MPLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		pr_err("tunnelmpls4 close: can't remove protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		pr_err("tunnel64 close: can't remove protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		pr_err("tunnel4 close: can't remove protocol\n");
^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) module_init(tunnel4_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) module_exit(tunnel4_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) MODULE_LICENSE("GPL");