From patchwork Tue Jun 30 07:36:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 216823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D659C433DF for ; Tue, 30 Jun 2020 07:37:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5064206CB for ; Tue, 30 Jun 2020 07:37:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hw2cz92n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731089AbgF3HhC (ORCPT ); Tue, 30 Jun 2020 03:37:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731084AbgF3HhB (ORCPT ); Tue, 30 Jun 2020 03:37:01 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58BF6C061755 for ; Tue, 30 Jun 2020 00:37:01 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id f2so8136888plr.8 for ; Tue, 30 Jun 2020 00:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=lxTPN3o8HbcFbnlgDRluhb24sEeZGZmHsCdtaa0XQZA=; b=hw2cz92npJ53lRi0ODFswFp54HabVye0N5dJre9sKxaOpc+q0qELAsfNQeFtEaYc/G EGGXRt+jwndbu1KHQgbJPLR+MeUhdM4v98G+sfXQotD+woiAsnDHbqw+no6klUscCX7p jvF0REmfhrw4G2dB1rpaFBBLFw8SEPjNXV3LFmlSK8xxt9VnyDyObjm8zAewRitsQDA4 LVp5gjN3FjY1a/XA6wioLrvbEPWKC7+wuV/h1xrwFJ0yZrFr438uklioV0pXEhQXwWGI dZ/s0mfAo4tdUSdqUmCdn0nlGteJQc9YN13+U7JBsaE27084QzC49ZFunWpbC9t5qbu2 Jq5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=lxTPN3o8HbcFbnlgDRluhb24sEeZGZmHsCdtaa0XQZA=; b=PLFdfKUEoVczqM79oMJLllqHouggiJnZyKkZ2XkNPjmvqkN/fWZnFxr/OZMNt0BGuf 2wllmIZqC7wD0c+TCbZ59QU09K1YpSx1PIsPBb7TpZkK/gRDvS87KFnZHuKWEPWHpQ2V dhyq+kDAEUsMEy9ohaUrK025Mm6i6HDRwlly7SoKmLBdcGwQXpLzy+ZxWk8c/IqTO5jw ppv3GwCKFGoxs67MeL6Y3T36wRyXlw+wIj2EplwVrH3dn6eQTXxJaL9rf0JLccosgiT5 6f8FB6kFyhqxXJLZBmwADkdGavd2HSi+/aQLolUcO41v57/wJ7GixwavNg0+M06T140Z nOVA== X-Gm-Message-State: AOAM533VT8Sk/oCuc1Wb870HwnAG+zZ2cKqvVOD57hYUKQJhRijxlyjp AmKcvuKKU+viFeX1fJ4+nQijyA8p X-Google-Smtp-Source: ABdhPJyf098yqdLNni78/NuSO+55Fd/V4nIptnLgK21MctsZha5lsfBEossQviWSjBEaivlHwc9/ZQ== X-Received: by 2002:a17:90b:94f:: with SMTP id dw15mr8972262pjb.209.1593502620580; Tue, 30 Jun 2020 00:37:00 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id a17sm1410440pjh.31.2020.06.30.00.36.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2020 00:36:59 -0700 (PDT) From: Xin Long To: netdev@vger.kernel.org Cc: Jakub Kicinski , Steffen Klassert , Herbert Xu , "David S. Miller" , Sabrina Dubroca Subject: [PATCHv2 ipsec-next 02/10] tunnel4: add cb_handler to struct xfrm_tunnel Date: Tue, 30 Jun 2020 15:36:27 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <348f1f3d64495bde03a9ce0475f4fa7a34584e9c.1593502515.git.lucien.xin@gmail.com> References: <348f1f3d64495bde03a9ce0475f4fa7a34584e9c.1593502515.git.lucien.xin@gmail.com> In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- include/net/xfrm.h | 1 + net/ipv4/tunnel4.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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); From patchwork Tue Jun 30 07:36:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 216822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD59DC433E0 for ; Tue, 30 Jun 2020 07:37:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8216E206CB for ; Tue, 30 Jun 2020 07:37:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vc3D1svu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731103AbgF3HhS (ORCPT ); Tue, 30 Jun 2020 03:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730979AbgF3HhS (ORCPT ); Tue, 30 Jun 2020 03:37:18 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1709AC061755 for ; Tue, 30 Jun 2020 00:37:18 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id w2so8744324pgg.10 for ; Tue, 30 Jun 2020 00:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ehvx/gW1K4luTZ4SExqYT0y8xnZwFcfGdr73YcfIwo8=; b=Vc3D1svu7neztQn7TcG5NMCwLyt2RsjUGO4abQk+1HxBlfJ3Puqq8RGn1bqEpBGlYY jcrmPv3Xq4HjEd3KfiRYp8XOQOLIcj5TSwpLBAcAe4zXM/WXfCWK8aTMtrhrsabZddOR V+6vytoXs0RqbWSYmWkKAefsLyEYDpE6+31S4qlq8AmVJu/41Ph0GLFhinriwJGOd/iQ AgeUuGpE/zjDX+EpN36HjKo/E73qV8SjiL08eKygePsG8uWFRM/Ft3qvgS9bIj4hifWe FCP0wzW9BMrfNGmFVRqmOpODoTEbncS0DIsuC3fr80qx5qGf6CqMaUrU78jjCVp2SGfJ YTQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ehvx/gW1K4luTZ4SExqYT0y8xnZwFcfGdr73YcfIwo8=; b=lI+vfGO6j+jRTR9rTPTRT3yvwLy93YvZGRjV7td9s811uOyuPrn6oo1+FtU61E4/Cn /X+/GChmADiv0CegkD2yI8sQ/3UFoHZjIEHdSePAIJJbb5LN3q/zaSc1r9KYhCK+K9j+ O3NwZ3MHCxtW/p9uK799ylaf5VDvXVNRCXipUePpw3H+6tUUHPTutGdOoEjf0Zjtv0ws zlLlKhE4twT0MjXvPFHxOOYpGNAYTsuN0H2Z4olja88XdFeuOeRyH32j/ln+Uwef9NM3 65cAEX3Ef6MwXU0M9A+zp32SMkdbqWKSbimoHYckW4KCXAw26QfROw1j6G24Bb9/1jjU nmNQ== X-Gm-Message-State: AOAM530tvwe89f2DPlHiKlVuVh7l7cbcpox0r3YsDxxHEuf58d7dmm8R ciLCf4oJQLHw9r7VdD+BY6R2kGJK X-Google-Smtp-Source: ABdhPJxE8FXM4DWNrxN3UhXxqT0Fux6xL8+wfxlNslWONAAkRVk2Y7S2AglTy2yVwNJsEQzwliwqoA== X-Received: by 2002:a63:8b4c:: with SMTP id j73mr13624401pge.209.1593502637399; Tue, 30 Jun 2020 00:37:17 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y80sm1691353pfb.165.2020.06.30.00.37.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2020 00:37:16 -0700 (PDT) From: Xin Long To: netdev@vger.kernel.org Cc: Jakub Kicinski , Steffen Klassert , Herbert Xu , "David S. Miller" , Sabrina Dubroca Subject: [PATCHv2 ipsec-next 04/10] ip_vti: support IPIP tunnel processing with .cb_handler Date: Tue, 30 Jun 2020 15:36:29 +0800 Message-Id: <929721f47bfba5847e39897be8aa2d1620370592.1593502515.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <2bc9f58f60183a7148fad5d8bc954924f02374f8.1593502515.git.lucien.xin@gmail.com> References: <348f1f3d64495bde03a9ce0475f4fa7a34584e9c.1593502515.git.lucien.xin@gmail.com> <2bc9f58f60183a7148fad5d8bc954924f02374f8.1593502515.git.lucien.xin@gmail.com> In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With tunnel4_input_afinfo added, IPIP tunnel processing in ip_vti can be easily done with .cb_handler. So replace the processing by calling ip_tunnel_rcv() with it. Signed-off-by: Xin Long --- net/ipv4/ip_vti.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index 1d9c8cf..fd762d9 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -93,28 +93,10 @@ static int vti_rcv_proto(struct sk_buff *skb) static int vti_rcv_tunnel(struct sk_buff *skb) { - struct ip_tunnel_net *itn = net_generic(dev_net(skb->dev), vti_net_id); - const struct iphdr *iph = ip_hdr(skb); - struct ip_tunnel *tunnel; - - tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY, - iph->saddr, iph->daddr, 0); - if (tunnel) { - struct tnl_ptk_info tpi = { - .proto = htons(ETH_P_IP), - }; - - if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) - goto drop; - if (iptunnel_pull_header(skb, 0, tpi.proto, false)) - goto drop; - return ip_tunnel_rcv(tunnel, skb, &tpi, NULL, false); - } + XFRM_SPI_SKB_CB(skb)->family = AF_INET; + XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr); - return -EINVAL; -drop: - kfree_skb(skb); - return 0; + return vti_input(skb, IPPROTO_IPIP, ip_hdr(skb)->saddr, 0, false); } static int vti_rcv_cb(struct sk_buff *skb, int err) @@ -495,8 +477,9 @@ static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = { .priority = 100, }; -static struct xfrm_tunnel ipip_handler __read_mostly = { +static struct xfrm_tunnel vti_ipip_handler __read_mostly = { .handler = vti_rcv_tunnel, + .cb_handler = vti_rcv_cb, .err_handler = vti4_err, .priority = 0, }; @@ -670,7 +653,7 @@ static int __init vti_init(void) goto xfrm_proto_comp_failed; msg = "ipip tunnel"; - err = xfrm4_tunnel_register(&ipip_handler, AF_INET); + err = xfrm4_tunnel_register(&vti_ipip_handler, AF_INET); if (err < 0) goto xfrm_tunnel_failed; @@ -682,7 +665,7 @@ static int __init vti_init(void) return err; rtnl_link_failed: - xfrm4_tunnel_deregister(&ipip_handler, AF_INET); + xfrm4_tunnel_deregister(&vti_ipip_handler, AF_INET); xfrm_tunnel_failed: xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP); xfrm_proto_comp_failed: @@ -699,7 +682,7 @@ static int __init vti_init(void) static void __exit vti_fini(void) { rtnl_link_unregister(&vti_link_ops); - xfrm4_tunnel_deregister(&ipip_handler, AF_INET); + xfrm4_tunnel_deregister(&vti_ipip_handler, AF_INET); xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP); xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH); xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP); From patchwork Tue Jun 30 07:36:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 216821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C869FC433DF for ; Tue, 30 Jun 2020 07:37:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9586F20857 for ; Tue, 30 Jun 2020 07:37:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N/jZJthX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731122AbgF3Hhf (ORCPT ); Tue, 30 Jun 2020 03:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730979AbgF3Hhe (ORCPT ); Tue, 30 Jun 2020 03:37:34 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D683BC061755 for ; Tue, 30 Jun 2020 00:37:34 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id e9so9537182pgo.9 for ; Tue, 30 Jun 2020 00:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=WPSbLQ681FD6gaLQ+/C+OaDfV02GtaInJMLuiNhU08E=; b=N/jZJthXJZ89BrhuV47Jjo/FmXgx3sOwQYpKrdn+3yfWtgzKVEdmunESs2Hhgxs5gA Xpfb0YYLymnzkraiaw3GSDiRYKsZmhLkx5dtYrzs1Jl1ejHQfBDuzGkAYqtuZPqCAqkf aDCZZa9iC4fjpeEWVRNxY+0RvCM29e7DWCmhEnP6Q5ldM8/qqF1w7ViPvLNt+HYVfTfQ fA7i8jeQCANmE8s0/4MmuWwAv8Sw1djDzrBtmUy7fmzB5ckwWxVn2VobLy+g1PMxQvfP fs/MHSd3ypBS+6OpEhozlpsMd/zE5dmmbuVUtX8EtYEFu1nj7dkfLILJbR14f1YH+Le4 rhbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=WPSbLQ681FD6gaLQ+/C+OaDfV02GtaInJMLuiNhU08E=; b=SQC8s9cmkthbOK12ZwqDJYycbALOHN8l/CAt4kd9WfWnfjumhrME7iL2W+EVrpCclN dLlSyTf+R7JTf8+YEmDOnQigpADclRu9iqpPIqOqYeuQGFJSPCr/+t9DFqI+CbrXxWfj AHkd/L7kKzodfWMIhNTkLOhEM61b82Y/k9+LEzc3/bYrD4w2+1Ai8R03TleCT54WSzIa xhlv2XDygnZc8yM7WxlaAqsTonIpW8dWXd2HdNYMt1/V/u1QVeHWJ4/WUTdqnXoNEJ2E xlzRoiAGjyw2cP2ulhgSdC+pw9LjT4Xe23Cr78eFv82/iutW5goZXtvcZC0ky1MqMbXn feQQ== X-Gm-Message-State: AOAM533SNCLZYju8yPYxCL8p057TuQQj9XCFdqVWjw1he7KwVfM0MaUl buJm5SU0avnb04H3DCjEsLgYvXsf X-Google-Smtp-Source: ABdhPJyXK0dx6D6dfD6IMxP8+ZXSuou5j4KUP8SfedoCdMM1B1Yz9gVhKiaXTYxsfnEv5Yta/pImMA== X-Received: by 2002:a62:7e90:: with SMTP id z138mr16382870pfc.292.1593502654140; Tue, 30 Jun 2020 00:37:34 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id l12sm1605202pff.212.2020.06.30.00.37.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2020 00:37:33 -0700 (PDT) From: Xin Long To: netdev@vger.kernel.org Cc: Jakub Kicinski , Steffen Klassert , Herbert Xu , "David S. Miller" , Sabrina Dubroca Subject: [PATCHv2 ipsec-next 06/10] ip6_vti: support IP6IP6 tunnel processing with .cb_handler Date: Tue, 30 Jun 2020 15:36:31 +0800 Message-Id: <1b18c11f965775fed2647eb78071af89177a70b5.1593502515.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <348f1f3d64495bde03a9ce0475f4fa7a34584e9c.1593502515.git.lucien.xin@gmail.com> <2bc9f58f60183a7148fad5d8bc954924f02374f8.1593502515.git.lucien.xin@gmail.com> <929721f47bfba5847e39897be8aa2d1620370592.1593502515.git.lucien.xin@gmail.com> In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Similar to IPIP tunnel's processing, this patch is to support IP6IP6 tunnel processing with .cb_handler. Signed-off-by: Xin Long --- net/ipv6/ip6_vti.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 1147f64..2161648 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -343,6 +343,17 @@ static int vti6_rcv(struct sk_buff *skb) return vti6_input_proto(skb, nexthdr, 0, 0); } +static int vti6_rcv_tunnel(struct sk_buff *skb) +{ + const xfrm_address_t *saddr; + __be32 spi; + + saddr = (const xfrm_address_t *)&ipv6_hdr(skb)->saddr; + spi = xfrm6_tunnel_spi_lookup(dev_net(skb->dev), saddr); + + return vti6_input_proto(skb, IPPROTO_IPV6, spi, 0); +} + static int vti6_rcv_cb(struct sk_buff *skb, int err) { unsigned short family; @@ -1218,6 +1229,13 @@ static struct xfrm6_protocol vti_ipcomp6_protocol __read_mostly = { .priority = 100, }; +static struct xfrm6_tunnel vti_ipv6_handler __read_mostly = { + .handler = vti6_rcv_tunnel, + .cb_handler = vti6_rcv_cb, + .err_handler = vti6_err, + .priority = 0, +}; + /** * vti6_tunnel_init - register protocol and reserve needed resources * @@ -1243,6 +1261,10 @@ static int __init vti6_tunnel_init(void) err = xfrm6_protocol_register(&vti_ipcomp6_protocol, IPPROTO_COMP); if (err < 0) goto xfrm_proto_comp_failed; + msg = "ipv6 tunnel"; + err = xfrm6_tunnel_register(&vti_ipv6_handler, AF_INET6); + if (err < 0) + goto vti_tunnel_failed; msg = "netlink interface"; err = rtnl_link_register(&vti6_link_ops); @@ -1252,6 +1274,8 @@ static int __init vti6_tunnel_init(void) return 0; rtnl_link_failed: + err = xfrm6_tunnel_deregister(&vti_ipv6_handler, AF_INET6); +vti_tunnel_failed: xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP); xfrm_proto_comp_failed: xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH); @@ -1270,6 +1294,7 @@ static int __init vti6_tunnel_init(void) static void __exit vti6_tunnel_cleanup(void) { rtnl_link_unregister(&vti6_link_ops); + xfrm6_tunnel_deregister(&vti_ipv6_handler, AF_INET6); xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP); xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH); xfrm6_protocol_deregister(&vti_esp6_protocol, IPPROTO_ESP); From patchwork Tue Jun 30 07:36:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 216820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EE7FC433DF for ; Tue, 30 Jun 2020 07:37:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BBC320890 for ; Tue, 30 Jun 2020 07:37:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="suaWBpYT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731134AbgF3Hhw (ORCPT ); Tue, 30 Jun 2020 03:37:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730979AbgF3Hhv (ORCPT ); Tue, 30 Jun 2020 03:37:51 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA06DC061755 for ; Tue, 30 Jun 2020 00:37:51 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id o13so6586413pgf.0 for ; Tue, 30 Jun 2020 00:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=/2x+x6/EXHMosj9/XKEHqgqlxb+0TqzXOMFNfOMaTKM=; b=suaWBpYToyJpb7X37v+crZ2f0J8XCJB67/FDLdmuiebnesu4lGTHXaUO7sSVgCSDho HpgaxVe9I7VDn1XyF4JBlmIJ+9bJz3rgVoXUACZMELwwKkjfvzBmWaeYWr18yzL5WTMX jXcZV45SeAjnxSiQccGgiO9fL8uUL35kKuf2O4P+k3B9rDb/91SFi56e0UQywm6O5BYW xjVY4PK3dOym7vI1vo+9yGYhYX6jtRBx0DuPbINnz/kYQ/Lt18xshLgZtlBh1Wiu7G8A Dk9Pw2tXXADzmm8MWSwkaBCxKrJgHintB13/YJqbcXQlfQF881uCYLVyH/jx9oAIbrUO abUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=/2x+x6/EXHMosj9/XKEHqgqlxb+0TqzXOMFNfOMaTKM=; b=Ma9EchdW8f2/cGju+nbJtDdJh1uFcToIUedXJFcMczazUYKShESqI41uBtWVOuU2J7 cvvEvtt/bHVw4C3NK82D2umRdhn4H1pFz0DmpYvSTMzhiTNKk1GzkGSh19ew9TR/7Q2f QnPSikD+St7I5yOwtF0AkVL1n99/ysAmCfSxyhBgYILioffZlAaH4eacw98CovFklYMF dHt4yF7AMJH4X2pzN9QaoL2PChFEWKDwrxkXNCLNkSBA0B6nYvCDm0jairZvBhfulHR5 HsKCTpeNulIfiqMVxRoXnxQcPjetJ4Qv8hq9h1crJxQsmRdUHtjphaA+Ss0j4prLbSOi aARg== X-Gm-Message-State: AOAM532AptPOJOVFHaglV4cJ+jSGcj93TEfDbepayU47JgYrybL27kXk QEd/Jnaxe9MP6/KCnSW0J4rgmSTi X-Google-Smtp-Source: ABdhPJxSCAMpjW556sMv8gSaUZwSCLBj6mRdhalJ8shCA9rAYJ0Fd5pv5G6fXmjdhw7mzwW09usrzA== X-Received: by 2002:a63:7054:: with SMTP id a20mr13397226pgn.17.1593502671016; Tue, 30 Jun 2020 00:37:51 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d16sm1656484pfo.156.2020.06.30.00.37.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2020 00:37:50 -0700 (PDT) From: Xin Long To: netdev@vger.kernel.org Cc: Jakub Kicinski , Steffen Klassert , Herbert Xu , "David S. Miller" , Sabrina Dubroca Subject: [PATCHv2 ipsec-next 08/10] ipcomp: assign if_id to child tunnel from parent tunnel Date: Tue, 30 Jun 2020 15:36:33 +0800 Message-Id: <088d28eeaf2ba1d7d24cd112a813c57583c5547b.1593502515.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <66b5ef2dc7245ab1707ca8119831e58c26a552a0.1593502515.git.lucien.xin@gmail.com> References: <348f1f3d64495bde03a9ce0475f4fa7a34584e9c.1593502515.git.lucien.xin@gmail.com> <2bc9f58f60183a7148fad5d8bc954924f02374f8.1593502515.git.lucien.xin@gmail.com> <929721f47bfba5847e39897be8aa2d1620370592.1593502515.git.lucien.xin@gmail.com> <1b18c11f965775fed2647eb78071af89177a70b5.1593502515.git.lucien.xin@gmail.com> <66b5ef2dc7245ab1707ca8119831e58c26a552a0.1593502515.git.lucien.xin@gmail.com> In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The child tunnel if_id will be used for xfrm interface's lookup when processing the IP(6)IP(6) packets in the next patches. Signed-off-by: Xin Long --- net/ipv4/ipcomp.c | 1 + net/ipv6/ipcomp6.c | 1 + 2 files changed, 2 insertions(+) diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c index 59bfa38..b426832 100644 --- a/net/ipv4/ipcomp.c +++ b/net/ipv4/ipcomp.c @@ -72,6 +72,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) t->props.flags = x->props.flags; t->props.extra_flags = x->props.extra_flags; memcpy(&t->mark, &x->mark, sizeof(t->mark)); + t->if_id = x->if_id; if (xfrm_init_state(t)) goto error; diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c index 99668bf..daef890 100644 --- a/net/ipv6/ipcomp6.c +++ b/net/ipv6/ipcomp6.c @@ -91,6 +91,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) t->props.mode = x->props.mode; memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr)); memcpy(&t->mark, &x->mark, sizeof(t->mark)); + t->if_id = x->if_id; if (xfrm_init_state(t)) goto error; From patchwork Tue Jun 30 07:36:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 216819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C72EC433DF for ; Tue, 30 Jun 2020 07:38:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE87C207FF for ; Tue, 30 Jun 2020 07:38:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LP7C0K13" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731143AbgF3HiK (ORCPT ); Tue, 30 Jun 2020 03:38:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730979AbgF3HiI (ORCPT ); Tue, 30 Jun 2020 03:38:08 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C22C061755 for ; Tue, 30 Jun 2020 00:38:08 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id 67so4982239pfg.5 for ; Tue, 30 Jun 2020 00:38:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=WKu9u3hv9rVR67uUMDQunlL+aOETxRhcJUtcJ2h+N9s=; b=LP7C0K13m4I5eeTH1bs8C0LEILfMRT/+STSd8m5A57rNmF8Sia+VEfDEEsjbZXzQyD Ikql/PSJS1pCBd7s8tIbbP2MJcC1Tv8V+7mKHrLraI1meG3OzGTvrYGzzXTuGboFWxsm hDOuPToqAFsDbuR/NigwPyIJ60EiupxjbiCdL376sjQiF81q+oHtnnwabRoUx8ksYcR5 9fCgGNIFvCiw/LMqyMiy2XphosWi7zvxrNf0an7p+Y06V9EtXZcVEspjHaoBqQ/B7FRA CG69Gax/qRbMSCgOCO5S/7lmNeEQitpzo6iQIpx0q38qGu4Q6XaKMyaP+ymLkELz6EnU rAyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=WKu9u3hv9rVR67uUMDQunlL+aOETxRhcJUtcJ2h+N9s=; b=Yg1jpnnpiYOKwrr3dSKXBKQU7ynluTNOO7DgaXVOx0H7pZf04co//QEaG/xWDPW+19 WdSaWN5C7B8u8oTbdrRakgK3w7osp7gLwHup1oNniWsknGmyouErlsZQ4DWchkPhC+fE rd7A/e2BJ+LdnN6aMboCGR4j71YWKrRd3PnvqWrC98x6+9lE8Mwvx0tZzI0GipWeIfYV +bhwkWYQpjFYAZoFd9lEsT5kReF1X8Sv9KGSoi9ok5wF4HD8zTOcmb6004KoK0/qzECE OXyNshs9/wR2hlg5yqgS7LIjypP6Vkp5QP7cb5fALRM6Jp82QUpj3UK5q+kQwBBa4dA/ h/zA== X-Gm-Message-State: AOAM531CKDoJFZ9M7WQGCWfRaA+raA3ZLzVEMYA0v0q//X2BgwI83Bxq 7uCCCiBpaisAaICh6n4DqQJPF5Qv X-Google-Smtp-Source: ABdhPJxWRbQ0WbSl9HopXBbIyIbxr95U5ey4C0nBQ68uz3QRy8gXpMO8HG8jvlcFr8r2/hHaTKZcww== X-Received: by 2002:a63:d143:: with SMTP id c3mr13627518pgj.306.1593502687845; Tue, 30 Jun 2020 00:38:07 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id w135sm1713033pfc.106.2020.06.30.00.38.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2020 00:38:07 -0700 (PDT) From: Xin Long To: netdev@vger.kernel.org Cc: Jakub Kicinski , Steffen Klassert , Herbert Xu , "David S. Miller" , Sabrina Dubroca Subject: [PATCHv2 ipsec-next 10/10] xfrm: interface: support IPIP and IPIP6 tunnels processing with .cb_handler Date: Tue, 30 Jun 2020 15:36:35 +0800 Message-Id: <6fe4c44a598a64b55e08947851995e6d0aec6a93.1593502515.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <348f1f3d64495bde03a9ce0475f4fa7a34584e9c.1593502515.git.lucien.xin@gmail.com> <2bc9f58f60183a7148fad5d8bc954924f02374f8.1593502515.git.lucien.xin@gmail.com> <929721f47bfba5847e39897be8aa2d1620370592.1593502515.git.lucien.xin@gmail.com> <1b18c11f965775fed2647eb78071af89177a70b5.1593502515.git.lucien.xin@gmail.com> <66b5ef2dc7245ab1707ca8119831e58c26a552a0.1593502515.git.lucien.xin@gmail.com> <088d28eeaf2ba1d7d24cd112a813c57583c5547b.1593502515.git.lucien.xin@gmail.com> In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Similar to ip_vti, IPIP and IPIP6 tunnels processing can easily be done with .cb_handler for xfrm interface. Signed-off-by: Xin Long --- net/xfrm/xfrm_interface.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c index 7be4d0d..0ddcd57 100644 --- a/net/xfrm/xfrm_interface.c +++ b/net/xfrm/xfrm_interface.c @@ -840,6 +840,18 @@ static struct xfrm4_protocol xfrmi_ipcomp4_protocol __read_mostly = { .priority = 10, }; +static int xfrmi4_rcv_tunnel(struct sk_buff *skb) +{ + return xfrm4_rcv_spi(skb, IPPROTO_IPIP, ip_hdr(skb)->saddr); +} + +static struct xfrm_tunnel xfrmi_ipip_handler __read_mostly = { + .handler = xfrmi4_rcv_tunnel, + .cb_handler = xfrmi_rcv_cb, + .err_handler = xfrmi4_err, + .priority = -1, +}; + static int __init xfrmi4_init(void) { int err; @@ -853,9 +865,19 @@ static int __init xfrmi4_init(void) err = xfrm4_protocol_register(&xfrmi_ipcomp4_protocol, IPPROTO_COMP); if (err < 0) goto xfrm_proto_comp_failed; + err = xfrm4_tunnel_register(&xfrmi_ipip_handler, AF_INET); + if (err < 0) + goto xfrm_tunnel_ipip_failed; + err = xfrm4_tunnel_register(&xfrmi_ipip_handler, AF_INET6); + if (err < 0) + goto xfrm_tunnel_ipip6_failed; return 0; +xfrm_tunnel_ipip6_failed: + xfrm4_tunnel_deregister(&xfrmi_ipip_handler, AF_INET); +xfrm_tunnel_ipip_failed: + xfrm4_protocol_deregister(&xfrmi_ipcomp4_protocol, IPPROTO_COMP); xfrm_proto_comp_failed: xfrm4_protocol_deregister(&xfrmi_ah4_protocol, IPPROTO_AH); xfrm_proto_ah_failed: @@ -866,6 +888,8 @@ static int __init xfrmi4_init(void) static void xfrmi4_fini(void) { + xfrm4_tunnel_deregister(&xfrmi_ipip_handler, AF_INET6); + xfrm4_tunnel_deregister(&xfrmi_ipip_handler, AF_INET); xfrm4_protocol_deregister(&xfrmi_ipcomp4_protocol, IPPROTO_COMP); xfrm4_protocol_deregister(&xfrmi_ah4_protocol, IPPROTO_AH); xfrm4_protocol_deregister(&xfrmi_esp4_protocol, IPPROTO_ESP);