]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip6_gre: add support for ERSPAN tunnel
authorWilliam Tu <u9012063@gmail.com>
Tue, 7 Nov 2017 02:27:18 +0000 (18:27 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 9 Nov 2017 00:53:34 +0000 (09:53 +0900)
The patch adds ERSPAN type II tunnel support for IPv6.

Signed-off-by: William Tu <u9012063@gmail.com>
ip/ipaddress.c
ip/iplink.c
ip/link_gre6.c
man/man8/ip-address.8.in
man/man8/ip-link.8.in

index c8db769e52f4a1d96259bdbd0239c9a8b42e7e2f..a89972f861930165e2b00fcbcde173ec5f0b6404 100644 (file)
@@ -77,8 +77,9 @@ static void usage(void)
        fprintf(stderr, "LFT := forever | SECONDS\n");
        fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
        fprintf(stderr, "          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |\n");
-       fprintf(stderr, "          gre | gretap | erspan | ip6gre | ip6gretap | vti | nlmon | can |\n");
-       fprintf(stderr, "          bond_slave | ipvlan | geneve | bridge_slave | vrf | hsr | macsec }\n");
+       fprintf(stderr, "          gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan | vti |\n");
+       fprintf(stderr, "          nlmon | can | bond_slave | ipvlan | geneve | bridge_slave |\n");
+       fprintf(stderr, "          hsr | macsec\n");
 
        exit(-1);
 }
index 0daca3f9d476399e6d4ddd423bbfb83732a05a56..66ae407455f6a223218b89ea4005354e28530ff8 100644 (file)
@@ -112,9 +112,9 @@ void iplink_usage(void)
                        "\n"
                        "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n"
                        "          bridge | bond | team | ipoib | ip6tnl | ipip | sit | vxlan |\n"
-                       "          gre | gretap | erspan | ip6gre | ip6gretap | vti | nlmon |\n"
-                       "          team_slave | bond_slave | ipvlan | geneve | bridge_slave |\n"
-                       "          vrf | macsec }\n");
+                       "          gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan |\n"
+                       "          vti | nlmon | team_slave | bond_slave | ipvlan | geneve |\n"
+                       "          bridge_slave | vrf | macsec }\n");
        }
        exit(-1);
 }
index 2eedec85df6fa8318933af2607e5729467bc4e7e..50c1b804ceca784509d7ffc9b987827781d5b14e 100644 (file)
@@ -33,7 +33,7 @@
 static void print_usage(FILE *f)
 {
        fprintf(f,
-               "Usage: ... { ip6gre | ip6gretap } [ remote ADDR ]\n"
+               "Usage: ... { ip6gre | ip6gretap | ip6erspan} [ remote ADDR ]\n"
                "                                  [ local ADDR ]\n"
                "                                  [ [i|o]seq ]\n"
                "                                  [ [i|o]key KEY ]\n"
@@ -52,6 +52,7 @@ static void print_usage(FILE *f)
                "                                  [ [no]encap-csum ]\n"
                "                                  [ [no]encap-csum6 ]\n"
                "                                  [ [no]encap-remcsum ]\n"
+               "                                  [ erspan IDX ]\n"
                "\n"
                "Where: ADDR      := IPV6_ADDRESS\n"
                "       TTL       := { 0..255 } (default=%d)\n"
@@ -106,6 +107,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
        __u16 encapdport = 0;
        int len;
        __u32 fwmark = 0;
+       __u32 erspan_idx = 0;
 
        if (!(n->nlmsg_flags & NLM_F_CREATE)) {
                if (rtnl_talk(&rth, &req.n, &answer) < 0) {
@@ -182,6 +184,9 @@ get_failed:
                if (greinfo[IFLA_GRE_FWMARK])
                        fwmark = rta_getattr_u32(greinfo[IFLA_GRE_FWMARK]);
 
+               if (greinfo[IFLA_GRE_ERSPAN_INDEX])
+                       erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]);
+
                free(answer);
        }
 
@@ -372,6 +377,12 @@ get_failed:
                                encap_limit = uval;
                                flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
                        }
+               } else if (strcmp(*argv, "erspan") == 0) {
+                       NEXT_ARG();
+                       if (get_u32(&erspan_idx, *argv, 0))
+                               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
                        usage();
                argc--; argv++;
@@ -390,6 +401,8 @@ 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);
 
        addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
        addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
@@ -557,6 +570,11 @@ 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);
+       }
+
        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]);
@@ -639,3 +657,11 @@ struct link_util ip6gretap_link_util = {
        .print_opt = gre_print_opt,
        .print_help = gre_print_help,
 };
+
+struct link_util ip6erspan_link_util = {
+       .id = "ip6erspan",
+       .maxattr = IFLA_GRE_MAX,
+       .parse_opt = gre_parse_opt,
+       .print_opt = gre_print_opt,
+       .print_help = gre_print_help,
+};
index 988a79652f6f2601386bd0fb00063660fba74485..eaa179c6de9133383eca89152bad6ed094cb7d5d 100644 (file)
@@ -123,6 +123,7 @@ ip-address \- protocol address management
 .BR erspan " |"
 .BR ip6gre " |"
 .BR ip6gretap " |"
+.BR ip6erspan " |"
 .BR vti " |"
 .BR vrf " |"
 .BR nlmon " |"
index 0cd1cbd30e09aa8ef1c1469fae9e3cd01aa91266..a6a10e577b1f5f10813529f11060b52162608884 100644 (file)
@@ -205,6 +205,7 @@ ip-link \- network device configuration
 .BR erspan " |"
 .BR ip6gre " |"
 .BR ip6gretap " |"
+.BR ip6erspan " |"
 .BR vti " |"
 .BR nlmon " |"
 .BR ipvlan " |"
@@ -308,6 +309,9 @@ Link types:
 .BR ip6gretap
 - Virtual L2 tunnel interface GRE over IPv6
 .sp
+.BR ip6erspan
+- Encapsulated Remote SPAN over GRE and IPv6
+.sp
 .BR vti
 - Virtual tunnel interface
 .sp