From patchwork Wed Oct 4 17:35:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amine Kherbouche X-Patchwork-Id: 821414 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="rZ7YPzVq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3y6jmw4ffTz9t6n for ; Thu, 5 Oct 2017 04:38:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751219AbdJDRii (ORCPT ); Wed, 4 Oct 2017 13:38:38 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:51303 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751135AbdJDRiU (ORCPT ); Wed, 4 Oct 2017 13:38:20 -0400 Received: by mail-wm0-f44.google.com with SMTP id f4so16592464wme.0 for ; Wed, 04 Oct 2017 10:38:20 -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=bUtt1EyE5ZEUYbCioANZthGjqi5n1cJP9B8pGqZoEAQ=; b=rZ7YPzVqpDY0xRCyJbh7Be33ED92PAikW8jT403g1M6PNLqGwt3f6NRefgocFL0Cgn KqgAC1x2khybrzy5PdG6RZ4/czXFc6Ac6xF0mVqW5PZJC9UB/b9OKkJYLeXuZc92r1rN i2pRFkqXE+JVDVuFrvSf31pvsOf0IqJSyJ7ju09P0GVQekJBWcAxk4eWsI+1XqvRjSuF czVdGHd7q7RGPXOocQF1FmgO06IHkYR7G5eFwcUKmTyuG03LV2MDOEobSDw7mHFAvc/v weqzVEGFTXZsWLSsQVBC8bw/P9zMn2vyWi8EtpYAhOvgXsG0XCCmyYu+eFhKIBhzzQod osPA== 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=bUtt1EyE5ZEUYbCioANZthGjqi5n1cJP9B8pGqZoEAQ=; b=SuctDzBLYGu9YAE6BMMiuAVATbN8TsFTO8Z2WajQDfKw+7ADhfcQxMptZRQFWxxjmo 5TwQDxNOQUaFHPOK4gbWBkkPZSYDsrs6kroAWHII0hzvfYgwDC+cLtkm+miIII/9elVC 3tBtGwZ4GpKb/7mkYJq+0qMuBRq2KAb5HDlJH8ehTGq44Z3V/U8drF1SGfp4GFWDrvVt S1oxuVncRg40vRfllLBVCBO7P7wm8fj5H8B77UEoVLWrmGyBKLf71lgy8eY8sBe8Gx9I leZ3Ypjczf0BGX7NyU3MW9SFzWfN4dwuy+xGOJWq9kIpmx0qTPAqgkIATs/eoaexNnhI fd2w== X-Gm-Message-State: AMCzsaWAGcliBAV0zzG5m0mVx+u4Z/o8FuVpq23Fi9gFbmGW7mNIwM5e l9jKbedZ/atgJIfnm5lg9KMC/A== X-Google-Smtp-Source: AOwi7QBNagYOby/vX2JsFnbwoLfF4I5VWn/xqmwS7NYdSsWHuqGeqbcTVpmiewmS2M+JIK3f8eAtwg== X-Received: by 10.80.140.147 with SMTP id q19mr7627497edq.147.1507138699770; Wed, 04 Oct 2017 10:38:19 -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 a10sm14431868eda.37.2017.10.04.10.38.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 10:38:19 -0700 (PDT) From: Amine Kherbouche To: tom@herbertland.com, roopa@cumulusnetworks.com Cc: netdev@vger.kernel.org, amine.kherbouche@6wind.com, equinox@diac24.net Subject: [PATCH v6 1/1] ip_tunnel: add mpls over gre support Date: Wed, 4 Oct 2017 19:35:57 +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 by simply adding ipgre_tunnel_encap_(add|del)_mpls_ops() and the new tunnel type TUNNEL_ENCAP_MPLS. Signed-off-by: Amine Kherbouche --- include/uapi/linux/if_tunnel.h | 1 + net/mpls/af_mpls.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) 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/mpls/af_mpls.c b/net/mpls/af_mpls.c index c5b9ce4..9745e8f 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); @@ -2485,6 +2516,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; @@ -2502,6 +2537,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);