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

tunnel6: add tunnel6_input_afinfo for ipip and ipv6 tunnels

This patch is to register a callback function tunnel6_rcv_cb with
is_ipip set in a xfrm_input_afinfo object for tunnel6 and tunnel46.

It will be called by xfrm_rcv_cb() from xfrm_input() when family
is AF_INET6 and proto is IPPROTO_IPIP or IPPROTO_IPV6.

v1->v2:
- Fix a sparse warning caused by the missing "__rcu", as Jakub
noticed.
- Handle the err returned by xfrm_input_register_afinfo() in
tunnel6_init/fini(), as Sabrina noticed.
v2->v3:
- Add "#if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL)" to fix the build error
when xfrm is disabled, reported by kbuild test robot

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

authored by

Xin Long and committed by
Steffen Klassert
86afc703 6df2db5d

+42
+1
include/net/xfrm.h
··· 1425 1425 1426 1426 struct xfrm6_tunnel { 1427 1427 int (*handler)(struct sk_buff *skb); 1428 + int (*cb_handler)(struct sk_buff *skb, int err); 1428 1429 int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt, 1429 1430 u8 type, u8 code, int offset, __be32 info); 1430 1431 struct xfrm6_tunnel __rcu *next;
+41
net/ipv6/tunnel6.c
··· 155 155 return 0; 156 156 } 157 157 158 + #if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL) 159 + static int tunnel6_rcv_cb(struct sk_buff *skb, u8 proto, int err) 160 + { 161 + struct xfrm6_tunnel __rcu *head; 162 + struct xfrm6_tunnel *handler; 163 + int ret; 164 + 165 + head = (proto == IPPROTO_IPV6) ? tunnel6_handlers : tunnel46_handlers; 166 + 167 + for_each_tunnel_rcu(head, handler) { 168 + if (handler->cb_handler) { 169 + ret = handler->cb_handler(skb, err); 170 + if (ret <= 0) 171 + return ret; 172 + } 173 + } 174 + 175 + return 0; 176 + } 177 + 178 + static const struct xfrm_input_afinfo tunnel6_input_afinfo = { 179 + .family = AF_INET6, 180 + .is_ipip = true, 181 + .callback = tunnel6_rcv_cb, 182 + }; 183 + #endif 184 + 158 185 static int tunnel46_rcv(struct sk_buff *skb) 159 186 { 160 187 struct xfrm6_tunnel *handler; ··· 272 245 inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP); 273 246 return -EAGAIN; 274 247 } 248 + #if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL) 249 + if (xfrm_input_register_afinfo(&tunnel6_input_afinfo)) { 250 + pr_err("%s: can't add input afinfo\n", __func__); 251 + inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6); 252 + inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP); 253 + if (xfrm6_tunnel_mpls_supported()) 254 + inet6_del_protocol(&tunnelmpls6_protocol, IPPROTO_MPLS); 255 + return -EAGAIN; 256 + } 257 + #endif 275 258 return 0; 276 259 } 277 260 278 261 static void __exit tunnel6_fini(void) 279 262 { 263 + #if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL) 264 + if (xfrm_input_unregister_afinfo(&tunnel6_input_afinfo)) 265 + pr_err("%s: can't remove input afinfo\n", __func__); 266 + #endif 280 267 if (inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP)) 281 268 pr_err("%s: can't remove protocol\n", __func__); 282 269 if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6))