Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/ipv4: VTI support rx-path hook in xfrm4_mode_tunnel.

Incorporated David and Steffen's comments.
Add hook for rx-path xfmr4_mode_tunnel for VTI tunnel module.

Signed-off-by: Saurabh Mohan <saurabh.mohan@vyatta.com>
Reviewed-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Saurabh and committed by
David S. Miller
eb8637cd fcc24db5

+70
+2
include/net/xfrm.h
··· 1475 1475 extern int xfrm4_output_finish(struct sk_buff *skb); 1476 1476 extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family); 1477 1477 extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family); 1478 + extern int xfrm4_mode_tunnel_input_register(struct xfrm_tunnel *handler); 1479 + extern int xfrm4_mode_tunnel_input_deregister(struct xfrm_tunnel *handler); 1478 1480 extern int xfrm6_extract_header(struct sk_buff *skb); 1479 1481 extern int xfrm6_extract_input(struct xfrm_state *x, struct sk_buff *skb); 1480 1482 extern int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi);
+68
net/ipv4/xfrm4_mode_tunnel.c
··· 15 15 #include <net/ip.h> 16 16 #include <net/xfrm.h> 17 17 18 + /* Informational hook. The decap is still done here. */ 19 + static struct xfrm_tunnel __rcu *rcv_notify_handlers __read_mostly; 20 + static DEFINE_MUTEX(xfrm4_mode_tunnel_input_mutex); 21 + 22 + int xfrm4_mode_tunnel_input_register(struct xfrm_tunnel *handler) 23 + { 24 + struct xfrm_tunnel __rcu **pprev; 25 + struct xfrm_tunnel *t; 26 + int ret = -EEXIST; 27 + int priority = handler->priority; 28 + 29 + mutex_lock(&xfrm4_mode_tunnel_input_mutex); 30 + 31 + for (pprev = &rcv_notify_handlers; 32 + (t = rcu_dereference_protected(*pprev, 33 + lockdep_is_held(&xfrm4_mode_tunnel_input_mutex))) != NULL; 34 + pprev = &t->next) { 35 + if (t->priority > priority) 36 + break; 37 + if (t->priority == priority) 38 + goto err; 39 + 40 + } 41 + 42 + handler->next = *pprev; 43 + rcu_assign_pointer(*pprev, handler); 44 + 45 + ret = 0; 46 + 47 + err: 48 + mutex_unlock(&xfrm4_mode_tunnel_input_mutex); 49 + return ret; 50 + } 51 + EXPORT_SYMBOL_GPL(xfrm4_mode_tunnel_input_register); 52 + 53 + int xfrm4_mode_tunnel_input_deregister(struct xfrm_tunnel *handler) 54 + { 55 + struct xfrm_tunnel __rcu **pprev; 56 + struct xfrm_tunnel *t; 57 + int ret = -ENOENT; 58 + 59 + mutex_lock(&xfrm4_mode_tunnel_input_mutex); 60 + for (pprev = &rcv_notify_handlers; 61 + (t = rcu_dereference_protected(*pprev, 62 + lockdep_is_held(&xfrm4_mode_tunnel_input_mutex))) != NULL; 63 + pprev = &t->next) { 64 + if (t == handler) { 65 + *pprev = handler->next; 66 + ret = 0; 67 + break; 68 + } 69 + } 70 + mutex_unlock(&xfrm4_mode_tunnel_input_mutex); 71 + synchronize_net(); 72 + 73 + return ret; 74 + } 75 + EXPORT_SYMBOL_GPL(xfrm4_mode_tunnel_input_deregister); 76 + 18 77 static inline void ipip_ecn_decapsulate(struct sk_buff *skb) 19 78 { 20 79 struct iphdr *inner_iph = ipip_hdr(skb); ··· 123 64 return 0; 124 65 } 125 66 67 + #define for_each_input_rcu(head, handler) \ 68 + for (handler = rcu_dereference(head); \ 69 + handler != NULL; \ 70 + handler = rcu_dereference(handler->next)) 71 + 126 72 static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb) 127 73 { 74 + struct xfrm_tunnel *handler; 128 75 int err = -EINVAL; 129 76 130 77 if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPIP) ··· 138 73 139 74 if (!pskb_may_pull(skb, sizeof(struct iphdr))) 140 75 goto out; 76 + 77 + for_each_input_rcu(rcv_notify_handlers, handler) 78 + handler->handler(skb); 141 79 142 80 if (skb_cloned(skb) && 143 81 (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))