From patchwork Thu Sep 28 16:34:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amine Kherbouche X-Patchwork-Id: 819679 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=6wind-com.20150623.gappssmtp.com header.i=@6wind-com.20150623.gappssmtp.com header.b="MOhohRyA"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3y30fY637qz9t3R for ; Fri, 29 Sep 2017 02:35:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752291AbdI1QfP (ORCPT ); Thu, 28 Sep 2017 12:35:15 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:53529 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751963AbdI1QfI (ORCPT ); Thu, 28 Sep 2017 12:35:08 -0400 Received: by mail-wm0-f54.google.com with SMTP id q132so3425538wmd.2 for ; Thu, 28 Sep 2017 09:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jMskhJ0utzzUjrDmmUAZZFrExKt8cQH2tbZj6VdRyRo=; b=MOhohRyANZb+u5f33R5ZVsoCiTvjvWQnFnRMzlMA29Jcdqtc8QDihVjrBKQNM1Cmi9 e8pcZEKibibZRw/pWNTIesLTlgg9Yfxu2P6S7iOO9qSNsNpSB5k4NKFc3XqYmggKD3Dh b5x+a0BY3qy+PCvZkgKgRFRp8B3PKGF328yBKXGTucl3rCt3etkqof9Utxs2hCLGAu7H QSO4TVUVG6RWv2zDflZr7maZO1YKL7MBmulD9hiUhF8+Jvt9l7n9PrMc9cNfR9kVNTDh tjN7NKw/iwMeOYuXs1Z68aIP0XEV4Go4kZjKr/aYgWHVurqhIgrX+Irw0QHdR13UvuZ7 TVkA== 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; bh=jMskhJ0utzzUjrDmmUAZZFrExKt8cQH2tbZj6VdRyRo=; b=e5pa9VeCaU/IYTr4k5TN1e3rFf/w3Wb5PIUEHc3mT6kRspAz3+Vbndfi7mKQWY7mf7 jgNJGXxb9HjzYvo5ZHBZVNffD+wfMwloiYdV0YfDIgxohU3vEoWvRYDkRAyQYMWFMhPS rH5aARqlZthtVxx+JfQbfOd3Q+2wRaHrLGgsA24QZ/Itv+FmrJ5ZC9+uFftzv5AyRRIL WkjgSyFFxz6UgS9INByIlK06JXZoPxq9ugG0F7eaw9Sy425sZYFhkbyGkYLDRdE84yqh tq0hygCwSoUQL44lrr+TGvPYDB8V+wwF1T7t1rXf9LUGkmD7WRBioVFN9WUdswYQ1DT+ HlOA== X-Gm-Message-State: AHPjjUjka+TImFjoNLLPhNmbohwkJiC8MTzx8RjmddGSIOTP0crMOSlY f3EouFPPHsyKIu5Hy6gez1mkVT37 X-Google-Smtp-Source: AOwi7QBfw6SghIn1BGcDCU7UmbOsnMKg8Ov0bJwZlHg07YnB5RgHd9zuyNLsEBcqJzr6c5SVZ+24Mg== X-Received: by 10.80.220.202 with SMTP id v10mr6456881edk.226.1506616506881; Thu, 28 Sep 2017 09:35:06 -0700 (PDT) Received: from griffon.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id r30sm1745488edb.59.2017.09.28.09.35.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Sep 2017 09:35:06 -0700 (PDT) From: Amine Kherbouche To: netdev@vger.kernel.org, davem@davemloft.net, xeb@mail.ru, roopa@cumulusnetworks.com Cc: amine.kherbouche@6wind.com, equinox@diac24.net Subject: [PATCH v5 1/2] mpls: export mpls_forward() Date: Thu, 28 Sep 2017 18:34:38 +0200 Message-Id: <1c741aad9bd9516d99a46192f561125d18b28fa4.1506616215.git.amine.kherbouche@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Exporting mpls_forward() function to be able to be called from elsewhere such as MPLSoverGRE in the next commit. Signed-off-by: Amine Kherbouche Acked-by: Roopa Prabhu --- include/linux/mpls.h | 4 ++++ net/mpls/af_mpls.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/mpls.h b/include/linux/mpls.h index 384fb22..b0579ab 100644 --- a/include/linux/mpls.h +++ b/include/linux/mpls.h @@ -2,10 +2,14 @@ #define _LINUX_MPLS_H #include +#include #define MPLS_TTL_MASK (MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT) #define MPLS_BOS_MASK (MPLS_LS_S_MASK >> MPLS_LS_S_SHIFT) #define MPLS_TC_MASK (MPLS_LS_TC_MASK >> MPLS_LS_TC_SHIFT) #define MPLS_LABEL_MASK (MPLS_LS_LABEL_MASK >> MPLS_LS_LABEL_SHIFT) +int mpls_forward(struct sk_buff *skb, struct net_device *dev, + struct packet_type *pt, struct net_device *orig_dev); + #endif /* _LINUX_MPLS_H */ diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c index c5b9ce4..36ea2ad 100644 --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -307,8 +307,8 @@ static bool mpls_egress(struct net *net, struct mpls_route *rt, return success; } -static int mpls_forward(struct sk_buff *skb, struct net_device *dev, - struct packet_type *pt, struct net_device *orig_dev) +int mpls_forward(struct sk_buff *skb, struct net_device *dev, + struct packet_type *pt, struct net_device *orig_dev) { struct net *net = dev_net(dev); struct mpls_shim_hdr *hdr; @@ -442,6 +442,7 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev, kfree_skb(skb); return NET_RX_DROP; } +EXPORT_SYMBOL(mpls_forward); static struct packet_type mpls_packet_type __read_mostly = { .type = cpu_to_be16(ETH_P_MPLS_UC), From patchwork Thu Sep 28 16:34:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amine Kherbouche X-Patchwork-Id: 819678 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=6wind-com.20150623.gappssmtp.com header.i=@6wind-com.20150623.gappssmtp.com header.b="GE+9wtrc"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3y30fS5vHZz9t3R for ; Fri, 29 Sep 2017 02:35:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752263AbdI1QfL (ORCPT ); Thu, 28 Sep 2017 12:35:11 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:55609 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751950AbdI1QfJ (ORCPT ); Thu, 28 Sep 2017 12:35:09 -0400 Received: by mail-wm0-f49.google.com with SMTP id u138so3401619wmu.4 for ; Thu, 28 Sep 2017 09:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MMjpiUKasFT5R+LmSsV8Y/4dolM4+yn6J64obJjHgus=; b=GE+9wtrcpatI2E6OwjpA2liMZ95to6HDlF5+GWX6FgDxY+kYWtaTnZmknhkpBva4Tw Kz0fYVE5VsIptFGqwdi6c4z4PhAYW+9kLfesML1j1z5ZB1HD8QtuNKCLMQltJw/+3VWW 4jfDxGNa9Ww69dnVga5COcLa4CkeD6Jy4vhrXgI37ALnagVt2N7hw7dKq3lAsTtjwkS8 /VobCK+TwMx+vTWxSPuzV/aTCAJeQj1OXzdEwturg7oGnQF5xZQiZBDtvyYbpl5SOkEY D2Ox4kj2kpJpU6LcQaGl/Dd3ukWQsFAUVJQrKEigEjbtx0dXQ8Yy07qJkDRiYSqbAeM8 Anbg== 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; bh=MMjpiUKasFT5R+LmSsV8Y/4dolM4+yn6J64obJjHgus=; b=P8ssOgRLbIiVpp29JjMU0iGgfw11ncZ3x0mikgcFt9YpiudzKRtqdn/97OnwfH+4v0 cIWG8PYwrsa2bNuG9cyKu/OC3kEGNy8W0mmwgbOJvhYsE66Fc0J/AcF6qJ6JUNOjnW5S KYlhw1CJZw7aTrk80LTQAkNnzNNH96+VX1tBivLimjXaBEw6PKfjhhuZ9mP7y10VTNms +fzJrG8g0FGrVaX3WaxXSyOqsQNW8z2KXFkBmN0BH9pkJF2WFnZ15/G2ZlGTRNLsHhF+ YWbr1YkXPktpgiZi86iieX+FeaYGqMKr5OcNg34b56jBlacmwlDXyg3gI6lyitWdlQPD z2lA== X-Gm-Message-State: AHPjjUhODTJYVkQJ8Io6E9FfrFIdyf0e6wIKevlufHaOkB5JilOEmtvK rQ2l0xmhlb13N7/Cc62MZXQ3x25K X-Google-Smtp-Source: AOwi7QCWGWQRTPTdehDZ4aJxyay8AqhLof4KqWzAaPPt/ObjsoBh8pNsHyMKYzpN/HV5BiyxbKNfuw== X-Received: by 10.80.146.56 with SMTP id i53mr6799016eda.148.1506616507823; Thu, 28 Sep 2017 09:35:07 -0700 (PDT) Received: from griffon.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id r30sm1745488edb.59.2017.09.28.09.35.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Sep 2017 09:35:07 -0700 (PDT) From: Amine Kherbouche To: netdev@vger.kernel.org, davem@davemloft.net, xeb@mail.ru, roopa@cumulusnetworks.com Cc: amine.kherbouche@6wind.com, equinox@diac24.net Subject: [PATCH v5 2/2] ip_tunnel: add mpls over gre encapsulation Date: Thu, 28 Sep 2017 18:34:39 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit introduces the MPLSoGRE support (RFC 4023), using ip tunnel API. Encap: - Add a new iptunnel type mpls. - Share tx path: gre type mpls loaded from skb->protocol. Decap: - pull gre hdr and call mpls_forward(). Signed-off-by: Amine Kherbouche Acked-by: Roopa Prabhu --- include/net/gre.h | 1 + include/uapi/linux/if_tunnel.h | 1 + net/ipv4/gre_demux.c | 27 +++++++++++++++++++++++++++ net/ipv4/ip_gre.c | 3 +++ net/ipv6/ip6_gre.c | 3 +++ net/mpls/af_mpls.c | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+) diff --git a/include/net/gre.h b/include/net/gre.h index d25d836..aa3c4d3 100644 --- a/include/net/gre.h +++ b/include/net/gre.h @@ -35,6 +35,7 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name, u8 name_assign_type); int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, bool *csum_err, __be16 proto, int nhs); +int mpls_gre_rcv(struct sk_buff *skb, int gre_hdr_len); static inline int gre_calc_hlen(__be16 o_flags) { diff --git a/include/uapi/linux/if_tunnel.h b/include/uapi/linux/if_tunnel.h index 2e52088..a2f48c0 100644 --- a/include/uapi/linux/if_tunnel.h +++ b/include/uapi/linux/if_tunnel.h @@ -84,6 +84,7 @@ enum tunnel_encap_types { TUNNEL_ENCAP_NONE, TUNNEL_ENCAP_FOU, TUNNEL_ENCAP_GUE, + TUNNEL_ENCAP_MPLS, }; #define TUNNEL_ENCAP_FLAG_CSUM (1<<0) diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c index b798862..40484a3 100644 --- a/net/ipv4/gre_demux.c +++ b/net/ipv4/gre_demux.c @@ -23,6 +23,9 @@ #include #include #include +#if IS_ENABLED(CONFIG_MPLS) +#include +#endif #include #include @@ -122,6 +125,30 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, } EXPORT_SYMBOL(gre_parse_header); +#if IS_ENABLED(CONFIG_MPLS) +int mpls_gre_rcv(struct sk_buff *skb, int gre_hdr_len) +{ + if (unlikely(!pskb_may_pull(skb, gre_hdr_len))) + goto drop; + + /* Pop GRE hdr and reset the skb */ + skb_pull(skb, gre_hdr_len); + skb_reset_network_header(skb); + + return mpls_forward(skb, skb->dev, NULL, NULL); +drop: + kfree_skb(skb); + return NET_RX_DROP; +} +#else +int mpls_gre_rcv(struct sk_buff *skb, int gre_hdr_len) +{ + kfree_skb(skb); + return NET_RX_DROP; +} +#endif +EXPORT_SYMBOL(mpls_gre_rcv); + static int gre_rcv(struct sk_buff *skb) { const struct gre_protocol *proto; diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 9cee986..7a50e4f 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -412,6 +412,9 @@ static int gre_rcv(struct sk_buff *skb) return 0; } + if (unlikely(tpi.proto == htons(ETH_P_MPLS_UC))) + return mpls_gre_rcv(skb, hdr_len); + if (ipgre_rcv(skb, &tpi, hdr_len) == PACKET_RCVD) return 0; diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index c82d41e..440efb1 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -476,6 +476,9 @@ static int gre_rcv(struct sk_buff *skb) if (hdr_len < 0) goto drop; + if (unlikely(tpi.proto == htons(ETH_P_MPLS_UC))) + return mpls_gre_rcv(skb, hdr_len); + if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false)) goto drop; diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c index 36ea2ad..4274243 100644 --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #if IS_ENABLED(CONFIG_IPV6) #include @@ -39,6 +40,36 @@ static int one = 1; static int label_limit = (1 << 20) - 1; static int ttl_max = 255; +#if IS_ENABLED(CONFIG_NET_IP_TUNNEL) +size_t ipgre_mpls_encap_hlen(struct ip_tunnel_encap *e) +{ + return sizeof(struct mpls_shim_hdr); +} + +static const struct ip_tunnel_encap_ops mpls_iptun_ops = { + .encap_hlen = ipgre_mpls_encap_hlen, +}; + +static int ipgre_tunnel_encap_add_mpls_ops(void) +{ + return ip_tunnel_encap_add_ops(&mpls_iptun_ops, TUNNEL_ENCAP_MPLS); +} + +static void ipgre_tunnel_encap_del_mpls_ops(void) +{ + ip_tunnel_encap_del_ops(&mpls_iptun_ops, TUNNEL_ENCAP_MPLS); +} +#else +static int ipgre_tunnel_encap_add_mpls_ops(void) +{ + return 0; +} + +static void ipgre_tunnel_encap_del_mpls_ops(void) +{ +} +#endif + static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt, struct nlmsghdr *nlh, struct net *net, u32 portid, unsigned int nlm_flags); @@ -2486,6 +2517,10 @@ static int __init mpls_init(void) 0); rtnl_register(PF_MPLS, RTM_GETNETCONF, mpls_netconf_get_devconf, mpls_netconf_dump_devconf, 0); + err = ipgre_tunnel_encap_add_mpls_ops(); + if (err) + pr_err("Can't add mpls over gre tunnel ops\n"); + err = 0; out: return err; @@ -2503,6 +2538,7 @@ static void __exit mpls_exit(void) dev_remove_pack(&mpls_packet_type); unregister_netdevice_notifier(&mpls_dev_notifier); unregister_pernet_subsys(&mpls_net_ops); + ipgre_tunnel_encap_del_mpls_ops(); } module_exit(mpls_exit);