From patchwork Fri Dec 15 21:42:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 849392 X-Patchwork-Delegate: dsahern@gmail.com 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=gmail.com header.i=@gmail.com header.b="U4YT1tXW"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yz3nd5G8sz9s84 for ; Sat, 16 Dec 2017 08:43:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756501AbdLOVm6 (ORCPT ); Fri, 15 Dec 2017 16:42:58 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34533 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755727AbdLOVm5 (ORCPT ); Fri, 15 Dec 2017 16:42:57 -0500 Received: by mail-pf0-f194.google.com with SMTP id a90so7043369pfk.1 for ; Fri, 15 Dec 2017 13:42:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=/o36pueinFaD3qiJzwxbnrheW2gNAGTdz3ZZr0x9rac=; b=U4YT1tXWaN6vCHpYbgOKMK+eeuNYHxSt8zfymYUV6DwD/BPPo3iCFkZyTLiWSDEI9K wer0IvY6Ul3s/n/JWMROucmqC2jS1s/vCXnqJVcjm3HRcuqamtnOHG8NApoWLs7c6P3/ CY++8bWpIgEL7H7VdD1bWrbpHDhpJuwoJR5kiEGbNkiAHCGtmZLLaaSdWxJRWe4MoQP8 tn9IYCFvoRW9QYSLi/bdAHqwj15bCKs3C7W3ylWSCh1jIvQIsJ6aTqYNtndX5zIwvlCv 1U3zM3znef8tBnFZuDj1uESGoUSt/28y8xAGqVYhVJ2Vuld1w1KjdprzqCm2hnn7txMV LITg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=/o36pueinFaD3qiJzwxbnrheW2gNAGTdz3ZZr0x9rac=; b=mvS+LpTNNza00pWNOEW8pX9fRiNO4IBevOZVuibKtJKuZQLU9BfX/BjDixOGaWJKaA ACIl1VtKeb9YyPIL+7AC44PwqymFQchJMedQfFqLwkw3HBH3LikDkQ2NCieLWK7xKbE3 kgzKFywE6D2LPB2PZSYjiWgQa85HGSPX7M7pJGJKuu92CTHrt7ipxFxNhLUMkgrrRMwN qZLfx1KtShikIAIjtmV1JhRMGGtHNgm/2ewBU97jeNfIVRoFagNNYLAq5I+TDOCnGDFs bp1zmjEGwbP8BIbUxFk9Vvs3TzfjMKiqlzQxLfHmll0kbUwRP9/02CKFLbeJO72i70qJ Warw== X-Gm-Message-State: AKGB3mLtBXHt28YSOgQuKTyI4XPE61Ov1DULuUoJphPh7LldYqRgBjuQ 72Fm2Tqh3ZmczWuJEtihRQK/xKT+ X-Google-Smtp-Source: ACJfBosGDcfBSUSPm0Gxp6p0v9DBCx5z2bABBXg5yF3H4jD2onxBE+kaxh0nckxJ/keN0cOlrYbxOg== X-Received: by 10.98.161.25 with SMTP id b25mr14857510pff.103.1513374176632; Fri, 15 Dec 2017 13:42:56 -0800 (PST) Received: from sc9-mailhost3.vmware.com ([24.5.191.4]) by smtp.gmail.com with ESMTPSA id x15sm12414160pfh.27.2017.12.15.13.42.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Dec 2017 13:42:55 -0800 (PST) From: William Tu To: netdev@vger.kernel.org Subject: [PATCH v2 iproute2 net-next] erspan: add erspan version II support Date: Fri, 15 Dec 2017 13:42:52 -0800 Message-Id: <1513374172-5875-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The patch adds support for configuring the erspan v2, for both ipv4 and ipv6 erspan implementation. Three additional fields are added: 'erspan_ver' for distinguishing v1 or v2, 'erspan_dir' for specifying direction of the mirrored traffic, and 'erspan_hwid' for users to set ERSPAN engine ID within a system. As for manpage, the ERSPAN descriptions used to be under GRE, IPIP, SIT Type paragraph. Since IP6GRE/IP6GRETAP also supports ERSPAN, the patch removes the old one, creates a separate ERSPAN paragrah, and adds an example. Signed-off-by: William Tu --- change in v2: - clean up and update manpage. --- include/uapi/linux/if_ether.h | 1 + include/uapi/linux/if_tunnel.h | 3 ++ ip/link_gre.c | 59 ++++++++++++++++++++++++-- ip/link_gre6.c | 61 +++++++++++++++++++++++++-- man/man8/ip-link.8.in | 94 ++++++++++++++++++++++++++++++++++++------ 5 files changed, 199 insertions(+), 19 deletions(-) diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h index 2eb529a90250..5fd5c12ef8e9 100644 --- a/include/uapi/linux/if_ether.h +++ b/include/uapi/linux/if_ether.h @@ -47,6 +47,7 @@ #define ETH_P_PUP 0x0200 /* Xerox PUP packet */ #define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */ #define ETH_P_TSN 0x22F0 /* TSN (IEEE 1722) packet */ +#define ETH_P_ERsPAN2 0x22EB /* ERSPAN version 2 (type III) */ #define ETH_P_IP 0x0800 /* Internet Protocol packet */ #define ETH_P_X25 0x0805 /* CCITT X.25 */ #define ETH_P_ARP 0x0806 /* Address Resolution packet */ diff --git a/include/uapi/linux/if_tunnel.h b/include/uapi/linux/if_tunnel.h index 38cdf90692f8..29602df037e9 100644 --- a/include/uapi/linux/if_tunnel.h +++ b/include/uapi/linux/if_tunnel.h @@ -137,6 +137,9 @@ enum { IFLA_GRE_IGNORE_DF, IFLA_GRE_FWMARK, IFLA_GRE_ERSPAN_INDEX, + IFLA_GRE_ERSPAN_VER, + IFLA_GRE_ERSPAN_DIR, + IFLA_GRE_ERSPAN_HWID, __IFLA_GRE_MAX, }; diff --git a/ip/link_gre.c b/ip/link_gre.c index 43cb1af6196a..924a05530f5c 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -98,6 +98,9 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv, __u8 ignore_df = 0; __u32 fwmark = 0; __u32 erspan_idx = 0; + __u8 erspan_ver = 0; + __u8 erspan_dir = 0; + __u16 erspan_hwid = 0; if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (rtnl_talk(&rth, &req.n, &answer) < 0) { @@ -179,6 +182,15 @@ get_failed: if (greinfo[IFLA_GRE_ERSPAN_INDEX]) erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]); + if (greinfo[IFLA_GRE_ERSPAN_VER]) + erspan_ver = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_VER]); + + if (greinfo[IFLA_GRE_ERSPAN_DIR]) + erspan_dir = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_DIR]); + + if (greinfo[IFLA_GRE_ERSPAN_HWID]) + erspan_hwid = rta_getattr_u16(greinfo[IFLA_GRE_ERSPAN_HWID]); + free(answer); } @@ -343,6 +355,22 @@ get_failed: invarg("invalid erspan index\n", *argv); if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0) invarg("erspan index must be > 0 and <= 20-bit\n", *argv); + } else if (strcmp(*argv, "erspan_ver") == 0) { + NEXT_ARG(); + if (get_u8(&erspan_ver, *argv, 0)) + invarg("invalid erspan version\n", *argv); + if (erspan_ver != 1 && erspan_ver != 2) + invarg("erspan version must be 1 or 2\n", *argv); + } else if (strcmp(*argv, "erspan_dir") == 0) { + NEXT_ARG(); + if (get_u8(&erspan_dir, *argv, 0)) + invarg("invalid erspan direction\n", *argv); + if (erspan_dir != 0 && erspan_dir != 1) + invarg("erspan direction must be 0(Ingress) or 1(Egress)\n", *argv); + } else if (strcmp(*argv, "erspan_hwid") == 0) { + NEXT_ARG(); + if (get_u16(&erspan_hwid, *argv, 0)) + invarg("invalid erspan hwid\n", *argv); } else usage(); argc--; argv++; @@ -374,8 +402,15 @@ get_failed: addattr_l(n, 1024, IFLA_GRE_TTL, &ttl, 1); addattr_l(n, 1024, IFLA_GRE_TOS, &tos, 1); addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark); - if (erspan_idx != 0) - addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx); + if (erspan_ver) { + addattr8(n, 1024, IFLA_GRE_ERSPAN_VER, erspan_ver); + if (erspan_ver == 1 && erspan_idx != 0) { + addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx); + } else if (erspan_ver == 2) { + addattr8(n, 1024, IFLA_GRE_ERSPAN_DIR, erspan_dir); + addattr16(n, 1024, IFLA_GRE_ERSPAN_HWID, erspan_hwid); + } + } } else { addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0); } @@ -514,7 +549,25 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_GRE_ERSPAN_INDEX]) { __u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]); - fprintf(f, "erspan_index %u ", erspan_idx); + print_uint(PRINT_ANY, "erspan_index", "erspan_index %u", erspan_idx); + } + + if (tb[IFLA_GRE_ERSPAN_VER]) { + __u8 erspan_ver = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_VER]); + + print_uint(PRINT_ANY, "erspan_ver", "erspan_ver %u", erspan_ver); + } + + if (tb[IFLA_GRE_ERSPAN_DIR]) { + __u8 erspan_dir = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_DIR]); + + print_uint(PRINT_ANY, "erspan_dir", "erspan_dir %u", erspan_dir); + } + + if (tb[IFLA_GRE_ERSPAN_HWID]) { + __u16 erspan_hwid = rta_getattr_u16(tb[IFLA_GRE_ERSPAN_HWID]); + + print_hex(PRINT_ANY, "erspan_hwid", "erspan_hwid %x", erspan_hwid); } if (tb[IFLA_GRE_ENCAP_TYPE] && diff --git a/ip/link_gre6.c b/ip/link_gre6.c index 2cb46ca116d0..71181af91bc8 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -109,6 +109,9 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv, int len; __u32 fwmark = 0; __u32 erspan_idx = 0; + __u8 erspan_ver = 0; + __u8 erspan_dir = 0; + __u16 erspan_hwid = 0; if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (rtnl_talk(&rth, &req.n, &answer) < 0) { @@ -191,6 +194,15 @@ get_failed: if (greinfo[IFLA_GRE_ERSPAN_INDEX]) erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]); + if (greinfo[IFLA_GRE_ERSPAN_VER]) + erspan_ver = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_VER]); + + if (greinfo[IFLA_GRE_ERSPAN_DIR]) + erspan_dir = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_DIR]); + + if (greinfo[IFLA_GRE_ERSPAN_HWID]) + erspan_hwid = rta_getattr_u16(greinfo[IFLA_GRE_ERSPAN_HWID]); + free(answer); } @@ -389,6 +401,22 @@ get_failed: invarg("invalid erspan index\n", *argv); if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0) invarg("erspan index must be > 0 and <= 20-bit\n", *argv); + } else if (strcmp(*argv, "erspan_ver") == 0) { + NEXT_ARG(); + if (get_u8(&erspan_ver, *argv, 0)) + invarg("invalid erspan version\n", *argv); + if (erspan_ver != 1 && erspan_ver != 2) + invarg("erspan version must be 1 or 2\n", *argv); + } else if (strcmp(*argv, "erspan_dir") == 0) { + NEXT_ARG(); + if (get_u8(&erspan_dir, *argv, 0)) + invarg("invalid erspan direction\n", *argv); + if (erspan_dir != 0 && erspan_dir != 1) + invarg("erspan direction must be 0(Ingress) or 1(Egress)\n", *argv); + } else if (strcmp(*argv, "erspan_hwid") == 0) { + NEXT_ARG(); + if (get_u16(&erspan_hwid, *argv, 0)) + invarg("invalid erspan hwid\n", *argv); } else usage(); argc--; argv++; @@ -408,9 +436,15 @@ get_failed: addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4); addattr32(n, 1024, IFLA_GRE_FLAGS, flags); addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark); - if (erspan_idx != 0) - addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx); - + if (erspan_ver) { + addattr8(n, 1024, IFLA_GRE_ERSPAN_VER, erspan_ver); + if (erspan_ver == 1 && erspan_idx != 0) { + addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx); + } else { + addattr8(n, 1024, IFLA_GRE_ERSPAN_DIR, erspan_dir); + addattr16(n, 1024, IFLA_GRE_ERSPAN_HWID, erspan_hwid); + } + } addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype); addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags); addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport)); @@ -587,9 +621,28 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_GRE_ERSPAN_INDEX]) { __u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]); - fprintf(f, "erspan_index %u ", erspan_idx); + print_uint(PRINT_ANY, "erspan_index", "erspan_index %u ", erspan_idx); } + if (tb[IFLA_GRE_ERSPAN_VER]) { + __u8 erspan_ver = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_VER]); + + print_uint(PRINT_ANY, "erspan_ver", "erspan_ver %u", erspan_ver); + } + + if (tb[IFLA_GRE_ERSPAN_DIR]) { + __u8 erspan_dir = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_DIR]); + + print_uint(PRINT_ANY, "erspan_dir", "erspan_dir %u", erspan_dir); + } + + if (tb[IFLA_GRE_ERSPAN_HWID]) { + __u16 erspan_hwid = rta_getattr_u16(tb[IFLA_GRE_ERSPAN_HWID]); + + print_hex(PRINT_ANY, "erspan_hwid", "erspan_hwid %x", erspan_hwid); + } + + if (tb[IFLA_GRE_ENCAP_TYPE] && rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) { __u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]); diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 9e9a5f0d2cef..6be6936185a3 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -665,13 +665,13 @@ keyword. .in -8 .TP -GRE, IPIP, SIT, ERSPAN Type Support +GRE, IPIP, SIT Type Support For a link of types -.I GRE/IPIP/SIT/ERSPAN +.I GRE/IPIP/SIT the following additional arguments are supported: .BI "ip link add " DEVICE -.BR type " { " gre " | " ipip " | " sit " | " erspan " }" +.BR type " { " gre " | " ipip " | " sit " }" .BI " remote " ADDR " local " ADDR [ .BR encap " { " fou " | " gue " | " none " }" @@ -685,8 +685,6 @@ the following additional arguments are supported: .I " [no]encap-remcsum " ] [ .I " mode " { ip6ip | ipip | mplsip | any } " -] [ -.BR erspan " \fIIDX " ] .in +8 @@ -731,13 +729,6 @@ MPLS-Over-IPv4, "any" indicates IPv6, IPv4 or MPLS Over IPv4. Supported for SIT where the default is "ip6ip" and IPIP where the default is "ipip". IPv6-Over-IPv4 is not supported for IPIP. -.sp -.BR erspan " \fIIDX " -- specifies the ERSPAN index field. -.IR IDX -indicates a 20 bit index/port number associated with the ERSPAN -traffic's source port and direction. - .in -8 .TP @@ -883,6 +874,78 @@ the following additional arguments are supported: - specifies the mode (datagram or connected) to use. .TP +ERSPAN Type Support +For a link of type +.I ERSPAN/IP6ERSPAN +the following additional arguments are supported: + +.BI "ip link add " DEVICE +.BR type " { " erspan " | " ip6erspan " }" +.BI remote " ADDR " local " ADDR " seq +.RB key +.I KEY +.BR erspan_ver " \fIversion " +[ +.BR erspan " \fIIDX " +] [ +.BR erspan_dir " \fIdirection " +] [ +.BR erspan_hwid " \fIhwid " +] [ +.RB external +] + +.in +8 +.sp +.BI remote " ADDR " +- specifies the remote address of the tunnel. + +.sp +.BI local " ADDR " +- specifies the fixed local address for tunneled packets. +It must be an address on another interface on this host. + +.sp +.BR erspan_ver " \fIversion " +- specifies the ERSPAN version number. +.IR version +indicates the ERSPAN version to be created: 1 for version 1 (type II) +or 2 for version 2 (type III). + +.sp +.BR erspan " \fIIDX " +- specifies the ERSPAN v1 index field. +.IR IDX +indicates a 20 bit index/port number associated with the ERSPAN +traffic's source port and direction. + +.sp +.BR erspan_dir " \fIdirection " +- specifies the ERSPAN v2 mirrored traffic's direction. +.IR direction +value (0) for ingress or (1) for egress. + +.sp +.BR erspan_hwid " \fIhwid " +- an unique identifier of an ERSPAN v2 engine within a system. +.IR hwid +is a 6-bit value for users to configure. + +.sp +.BR external +- make this tunnel externally controlled (or not, which is the default). +In the kernel, this is referred to as collect metadata mode. This flag is +mutually exclusive with the +.BR remote , +.BR local , +.BR erspan_ver , +.BR erspan , +.BR erspan_dir " and " erspan_hwid +options. + +.in -8 + +.TP GENEVE Type Support For a link of type .I GENEVE @@ -2062,6 +2125,13 @@ ip link add link wpan0 lowpan0 type lowpan Creates a 6LoWPAN interface named lowpan0 on the underlying IEEE 802.15.4 device wpan0. .RE +.PP +ip link add dev ip6erspan11 type ip6erspan seq key 102 +local fc00:100::2 remote fc00:100::1 +erspan_ver 2 erspan_dir 1 erspan_hwid 17 +.RS 4 +Creates a IP6ERSPAN version 2 interface named ip6erspan00. +.RE .SH SEE ALSO .br