From patchwork Wed Apr 4 13:26:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 894996 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A/zO5iey"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40GRZJ0KG7z9s08 for ; Wed, 4 Apr 2018 23:26:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751368AbeDDN0q (ORCPT ); Wed, 4 Apr 2018 09:26:46 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:37340 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750890AbeDDN0o (ORCPT ); Wed, 4 Apr 2018 09:26:44 -0400 Received: by mail-pl0-f67.google.com with SMTP id v5-v6so11968354plo.4 for ; Wed, 04 Apr 2018 06:26:44 -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; bh=1YnjhQYflT2BKAa+Y7ihEQn8TBe/qXvEHRRjZbzGNBg=; b=A/zO5ieyP904BFgcPiZHskei+MRi5Pq9TtUH4yVvOMEZXjHH2QHgb11zraojAtDQnN uRSsVFhRy25uqDucE7Hl0cia0eZ6H7vkyryc+z4BByXm1XTtc6mN8MBSTAxgsBDHHW7u tMvh7zXhgBhezn/Cm4CDUkZueVFOuNM9TNvlJvnbEWCEjQSg3kluH5DA1NhfMFNvuDHq p22g6wKzJjFa28GXYuqcC4figIqAcqlooS43UlqQMSkeqem6xxrAxcz/6SgeyUBash9R sKpDbLzXEkCsy7wJ39uxwyJ0IP87zqSWD22EqJSf2GPA4nto4XB8JjqNhOlnet4IALPC lYKg== 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; bh=1YnjhQYflT2BKAa+Y7ihEQn8TBe/qXvEHRRjZbzGNBg=; b=MH/5jkPHfrNzw2I8tX/dKXW0EeZp6mtcsPmYkbHWiWKLT927n+bbuYLXPiUO0sdb2d vLD2VhMr3IACsSMWD2U5t7QBjvMb8hGGAO+upc8XQeEW2RL+xIGPx59je3j5Qg09Z+T/ vq1EMtTelzK11UoTNCdjoIEpBbDzwiEgBqGh023vVNC+IbchjU4iVFpp1L3o3IrYf1Rc pVD8YH9hcFQfxqkPoT9IYKhh7ovHJ7GxuNCCpwG3ntVktD28sR6C056N0Q46ugUIpRPT 5GbWpu4kGfxT0Kki0z/3D3LE3EU9HqtU5BLMRz0kAHWOY2pNMkOxnv3f44K0BbdwV9Mf +/Jw== X-Gm-Message-State: AElRT7FZwZt5FrlcY8g5kcqYojXWT+F8CqiUSlTOYwCqsG23/EBZg4sG TUwhKADu2cC4X1VqyJc5bx18fHAL X-Google-Smtp-Source: AIpwx4/4Kouk+5xdiM1w50Xpk7qOhEi0kVv+lQe1roeah1acoQqeX11Qj5mx+0K/xh1nkyJojRFV+A== X-Received: by 10.99.95.75 with SMTP id t72mr12023367pgb.411.1522848403811; Wed, 04 Apr 2018 06:26:43 -0700 (PDT) Received: from leo.usersys.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id x5sm9781667pfm.49.2018.04.04.06.26.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Apr 2018 06:26:43 -0700 (PDT) From: Hangbin Liu To: netdev@vger.kernel.org Cc: Jiri Benc , Xin Long , "David S. Miller" , Hangbin Liu Subject: [PATCH net-next] vxlan: add ttl inherit support Date: Wed, 4 Apr 2018 21:26:21 +0800 Message-Id: <1522848381-9934-1-git-send-email-liuhangbin@gmail.com> X-Mailer: git-send-email 2.5.5 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Like tos inherit, ttl inherit should also means inherit the inner protocol's ttl values, which actually not implemented in vxlan yet. But we could not treat ttl == 0 as "use the inner TTL", because that would be used also when the "ttl" option is not specified and that would be a behavior change, and breaking real use cases. So add a different attribute IFLA_VXLAN_TTL_INHERIT when "ttl inherit" is specified with ip cmd. Reported-by: Jianlin Shi Suggested-by: Jiri Benc Signed-off-by: Hangbin Liu --- drivers/net/vxlan.c | 17 ++++++++++++++--- include/net/ip_tunnels.h | 11 +++++++++++ include/net/vxlan.h | 1 + include/uapi/linux/if_link.h | 1 + 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index aa5f034..209a840 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -2085,9 +2085,13 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, local_ip = vxlan->cfg.saddr; dst_cache = &rdst->dst_cache; md->gbp = skb->mark; - ttl = vxlan->cfg.ttl; - if (!ttl && vxlan_addr_multicast(dst)) - ttl = 1; + if (flags & VXLAN_F_TTL_INHERIT) { + ttl = ip_tunnel_get_ttl(old_iph, skb); + } else { + ttl = vxlan->cfg.ttl; + if (!ttl && vxlan_addr_multicast(dst)) + ttl = 1; + } tos = vxlan->cfg.tos; if (tos == 1) @@ -2709,6 +2713,7 @@ static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = { [IFLA_VXLAN_GBP] = { .type = NLA_FLAG, }, [IFLA_VXLAN_GPE] = { .type = NLA_FLAG, }, [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG }, + [IFLA_VXLAN_TTL_INHERIT] = { .type = NLA_FLAG }, }; static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[], @@ -3254,6 +3259,12 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[], if (data[IFLA_VXLAN_TTL]) conf->ttl = nla_get_u8(data[IFLA_VXLAN_TTL]); + if (data[IFLA_VXLAN_TTL_INHERIT]) { + if (changelink) + return -EOPNOTSUPP; + conf->flags |= VXLAN_F_TTL_INHERIT; + } + if (data[IFLA_VXLAN_LABEL]) conf->label = nla_get_be32(data[IFLA_VXLAN_LABEL]) & IPV6_FLOWLABEL_MASK; diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index cbe5add..6c3c421 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -377,6 +377,17 @@ static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph, return 0; } +static inline u8 ip_tunnel_get_ttl(const struct iphdr *iph, + const struct sk_buff *skb) +{ + if (skb->protocol == htons(ETH_P_IP)) + return iph->ttl; + else if (skb->protocol == htons(ETH_P_IPV6)) + return ((const struct ipv6hdr *)iph)->hop_limit; + else + return 0; +} + /* Propogate ECN bits out */ static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph, const struct sk_buff *skb) diff --git a/include/net/vxlan.h b/include/net/vxlan.h index ad73d8b..b99a02ae 100644 --- a/include/net/vxlan.h +++ b/include/net/vxlan.h @@ -262,6 +262,7 @@ struct vxlan_dev { #define VXLAN_F_COLLECT_METADATA 0x2000 #define VXLAN_F_GPE 0x4000 #define VXLAN_F_IPV6_LINKLOCAL 0x8000 +#define VXLAN_F_TTL_INHERIT 0x10000 /* Flags that are used in the receive path. These flags must match in * order for a socket to be shareable diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 11d0c0e..e771a63 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -516,6 +516,7 @@ enum { IFLA_VXLAN_COLLECT_METADATA, IFLA_VXLAN_LABEL, IFLA_VXLAN_GPE, + IFLA_VXLAN_TTL_INHERIT, __IFLA_VXLAN_MAX }; #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)