diff mbox series

[PATCHv2,ipsec-next,02/10] tunnel4: add cb_handler to struct xfrm_tunnel

Message ID b660e1514219be1d3723c203c91b0a04974ddac9.1593502515.git.lucien.xin@gmail.com
State New
Headers show
Series xfrm: support ipip and ipv6 tunnels in vti and xfrmi | expand

Commit Message

Xin Long June 30, 2020, 7:36 a.m. UTC
This patch is to register a callback function tunnel4_rcv_cb with
is_ipip set in a xfrm_input_afinfo object for tunnel4 and tunnel64.

It will be called by xfrm_rcv_cb() from xfrm_input() when family
is AF_INET 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
    tunnel4_init/fini(), as Sabrina noticed.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/xfrm.h |  1 +
 net/ipv4/tunnel4.c | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

Comments

Xin Long July 5, 2020, 6:30 p.m. UTC | #1
On Fri, Jul 3, 2020 at 4:54 AM kernel test robot <lkp@intel.com> wrote:
>

> Hi Xin,

>

> Thank you for the patch! Yet something to improve:

>

> [auto build test ERROR on ipsec-next/master]

>

> url:    https://github.com/0day-ci/linux/commits/Xin-Long/xfrm-support-ipip-and-ipv6-tunnels-in-vti-and-xfrmi/20200630-154042

> base:   https://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master

> config: h8300-randconfig-r001-20200701 (attached as .config)

> compiler: h8300-linux-gcc (GCC) 9.3.0

> reproduce (this is a W=1 build):

>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross

>         chmod +x ~/bin/make.cross

>         # save the attached .config to linux build tree

>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=h8300

>

> If you fix the issue, kindly add following tag as appropriate

> Reported-by: kernel test robot <lkp@intel.com>

>

> All errors (new ones prefixed by >>):

>

>    h8300-linux-ld: net/ipv4/tunnel4.o: in function `tunnel4_init':

>    net/ipv4/tunnel4.c:242: undefined reference to `xfrm_input_register_afinfo'

> >> h8300-linux-ld: net/ipv4/tunnel4.c:245: undefined reference to `xfrm_input_unregister_afinfo'

>    h8300-linux-ld: net/ipv4/tunnel4.c:250: undefined reference to `xfrm_input_unregister_afinfo'

I will add "#ifdef CONFIG_INET(6)_XFRM_TUNNEL" for this one too.

Thanks.
>

> ---

> 0-DAY CI Kernel Test Service, Intel Corporation

> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 4666bc9..c1ec629 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -1416,6 +1416,7 @@  struct xfrm6_protocol {
 /* XFRM tunnel handlers.  */
 struct xfrm_tunnel {
 	int (*handler)(struct sk_buff *skb);
+	int (*cb_handler)(struct sk_buff *skb, int err);
 	int (*err_handler)(struct sk_buff *skb, u32 info);
 
 	struct xfrm_tunnel __rcu *next;
diff --git a/net/ipv4/tunnel4.c b/net/ipv4/tunnel4.c
index c4b2ccb..5d98f49 100644
--- a/net/ipv4/tunnel4.c
+++ b/net/ipv4/tunnel4.c
@@ -110,6 +110,31 @@  static int tunnel4_rcv(struct sk_buff *skb)
 	return 0;
 }
 
+static int tunnel4_rcv_cb(struct sk_buff *skb, u8 proto, int err)
+{
+	struct xfrm_tunnel __rcu *head;
+	struct xfrm_tunnel *handler;
+	int ret;
+
+	head = (proto == IPPROTO_IPIP) ? tunnel4_handlers : tunnel64_handlers;
+
+	for_each_tunnel_rcu(head, handler) {
+		if (handler->cb_handler) {
+			ret = handler->cb_handler(skb, err);
+			if (ret <= 0)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+static const struct xfrm_input_afinfo tunnel4_input_afinfo = {
+	.family		=	AF_INET,
+	.is_ipip	=	true,
+	.callback	=	tunnel4_rcv_cb,
+};
+
 #if IS_ENABLED(CONFIG_IPV6)
 static int tunnel64_rcv(struct sk_buff *skb)
 {
@@ -214,16 +239,22 @@  static const struct net_protocol tunnelmpls4_protocol = {
 
 static int __init tunnel4_init(void)
 {
-	if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP))
+	if (xfrm_input_register_afinfo(&tunnel4_input_afinfo))
+		goto err;
+	if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)) {
+		xfrm_input_unregister_afinfo(&tunnel4_input_afinfo);
 		goto err;
+	}
 #if IS_ENABLED(CONFIG_IPV6)
 	if (inet_add_protocol(&tunnel64_protocol, IPPROTO_IPV6)) {
+		xfrm_input_unregister_afinfo(&tunnel4_input_afinfo);
 		inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
 		goto err;
 	}
 #endif
 #if IS_ENABLED(CONFIG_MPLS)
 	if (inet_add_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS)) {
+		xfrm_input_unregister_afinfo(&tunnel4_input_afinfo);
 		inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
 #if IS_ENABLED(CONFIG_IPV6)
 		inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6);
@@ -250,6 +281,8 @@  static void __exit tunnel4_fini(void)
 #endif
 	if (inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP))
 		pr_err("tunnel4 close: can't remove protocol\n");
+	if (xfrm_input_unregister_afinfo(&tunnel4_input_afinfo))
+		pr_err("tunnel4 close: can't remove input afinfo\n");
 }
 
 module_init(tunnel4_init);