From patchwork Tue Dec 18 09:53:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wenxu X-Patchwork-Id: 1015215 X-Patchwork-Delegate: shemminger@vyatta.com 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=fail (p=none dis=none) header.from=ucloud.cn Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43JtqJ4vsSz9s3Z for ; Tue, 18 Dec 2018 21:02:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726491AbeLRKCT (ORCPT ); Tue, 18 Dec 2018 05:02:19 -0500 Received: from m9785.mail.qiye.163.com ([220.181.97.85]:33465 "EHLO m9785.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbeLRKCT (ORCPT ); Tue, 18 Dec 2018 05:02:19 -0500 X-Greylist: delayed 514 seconds by postgrey-1.27 at vger.kernel.org; Tue, 18 Dec 2018 05:02:16 EST Received: from 10.19.61.167master (unknown [123.59.132.129]) by m9785.mail.qiye.163.com (Hmail) with ESMTPA id 9DC975C1876 for ; Tue, 18 Dec 2018 17:53:40 +0800 (CST) From: wenxu@ucloud.cn To: netdev@vger.kernel.org Subject: [PATCH iproute2] iproute: lwtunnel set TUNNEL_KEY on LWTUNNEL_IP_FLAGS Date: Tue, 18 Dec 2018 17:53:33 +0800 Message-Id: <1545126813-24284-1-git-send-email-wenxu@ucloud.cn> X-Mailer: git-send-email 1.8.3.1 X-HM-Spam-Status: e1kIGBQJHllBS1VLV1koWUFJQjdXWS1ZQUlXWQkOFx4IWUFZMjUtOjcyP0 FLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OBA6Dww5CTlNATk4TUoJKDEf VhlPCjpVSlVKTk9OSklNQ0lLTEhKVTMWGhIXVQweFQMOOw4YFxQOH1UYFUVZV1kSC1lBWUpJSFVO QlVKSElVSklCWVdZCAFZQUhITkM3Bg++ X-HM-Tid: 0a67c0bc3b292087kuqy9dc975c1876 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: wenxu ip l add dev tun type gretap external ip r a 10.0.0.1 encap ip dst 192.168.152.171 id 1000 dev gretap For gretap example when the command set the id but don't set the TUNNEL_KEY flags. There is no key field in the send packet Signed-off-by: wenxu --- include/uapi/linux/if_tunnel.h | 6 ++++++ ip/iproute_lwtunnel.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletions(-) diff --git a/include/uapi/linux/if_tunnel.h b/include/uapi/linux/if_tunnel.h index ecdc766..40b8009 100644 --- a/include/uapi/linux/if_tunnel.h +++ b/include/uapi/linux/if_tunnel.h @@ -160,4 +160,10 @@ enum { }; #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1) + +#define TUNNEL_CSUM __cpu_to_be16(0x01) +#define TUNNEL_KEY __cpu_to_be16(0x04) +#define TUNNEL_SEQ __cpu_to_be16(0x08) +#define TUNNEL_DONT_FRAGMENT __cpu_to_be16(0x0100) + #endif /* _IF_TUNNEL_H_ */ diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index aee18ac..c659035 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include static const char *format_encap_type(int type) { @@ -780,12 +780,14 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, char **argv = *argvp; int argc = *argcp; int ret = 0; + __u16 flags = 0; while (argc > 0) { if (strcmp(*argv, "id") == 0) { __u64 id; NEXT_ARG(); + flags |= TUNNEL_KEY; if (id_ok++) duparg2("id", *argv); if (get_be64(&id, *argv, 0)) @@ -835,6 +837,9 @@ static int parse_encap_ip(struct rtattr *rta, size_t len, argc--; argv++; } + if (flags) + ret = rta_addattr16(rta, len, LWTUNNEL_IP_FLAGS, flags); + /* argv is currently the first unparsed argument, * but the lwt_parse_encap() caller will move to the next, * so step back @@ -930,12 +935,14 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, char **argv = *argvp; int argc = *argcp; int ret = 0; + __u16 flags = 0; while (argc > 0) { if (strcmp(*argv, "id") == 0) { __u64 id; NEXT_ARG(); + flags |= TUNNEL_KEY; if (id_ok++) duparg2("id", *argv); if (get_be64(&id, *argv, 0)) @@ -987,6 +994,8 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len, argc--; argv++; } + if (flags) + ret = rta_addattr16(rta, len, LWTUNNEL_IP_FLAGS, flags); /* argv is currently the first unparsed argument, * but the lwt_parse_encap() caller will move to the next, * so step back