]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/link_gre6.c
ip/tunnel: No need to free answer after rtnl_talk() on error
[mirror_iproute2.git] / ip / link_gre6.c
index 4c9c536538cc30041ad974e40b0ee9b45ccf23bc..a3e8e088378ed11c060ede62c789aa59b695e0a7 100644 (file)
 
 #define DEFAULT_TNL_HOP_LIMIT  (64)
 
+static void print_usage(FILE *f)
+{
+       fprintf(f,
+               "Usage: ... { ip6gre | ip6gretap | ip6erspan} [ remote ADDR ]\n"
+               "                                  [ local ADDR ]\n"
+               "                                  [ [i|o]seq ]\n"
+               "                                  [ [i|o]key KEY ]\n"
+               "                                  [ [i|o]csum ]\n"
+               "                                  [ hoplimit TTL ]\n"
+               "                                  [ encaplimit ELIM ]\n"
+               "                                  [ tclass TCLASS ]\n"
+               "                                  [ flowlabel FLOWLABEL ]\n"
+               "                                  [ dscp inherit ]\n"
+               "                                  [ fwmark MARK ]\n"
+               "                                  [ dev PHYS_DEV ]\n"
+               "                                  [ noencap ]\n"
+               "                                  [ encap { fou | gue | none } ]\n"
+               "                                  [ encap-sport PORT ]\n"
+               "                                  [ encap-dport PORT ]\n"
+               "                                  [ [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"
+               "       KEY       := { DOTTED_QUAD | NUMBER }\n"
+               "       ELIM      := { none | 0..255 }(default=%d)\n"
+               "       TCLASS    := { 0x0..0xff | inherit }\n"
+               "       FLOWLABEL := { 0x0..0xfffff | inherit }\n"
+               "       MARK      := { 0x0..0xffffffff | inherit }\n",
+               DEFAULT_TNL_HOP_LIMIT, IPV6_DEFAULT_TNL_ENCAP_LIMIT
+       );
+}
+
 static void usage(void) __attribute__((noreturn));
 static void usage(void)
 {
-       fprintf(stderr, "Usage: ip link { add | set | change | replace | del } NAME\n");
-       fprintf(stderr, "          type { ip6gre | ip6gretap } [ remote ADDR ] [ local ADDR ]\n");
-       fprintf(stderr, "          [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
-       fprintf(stderr, "          [ hoplimit TTL ] [ encaplimit ELIM ]\n");
-       fprintf(stderr, "          [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n");
-       fprintf(stderr, "          [ dscp inherit ] [ dev PHYS_DEV ]\n");
-       fprintf(stderr, "\n");
-       fprintf(stderr, "Where: NAME      := STRING\n");
-       fprintf(stderr, "       ADDR      := IPV6_ADDRESS\n");
-       fprintf(stderr, "       TTL       := { 0..255 } (default=%d)\n",
-               DEFAULT_TNL_HOP_LIMIT);
-       fprintf(stderr, "       KEY       := { DOTTED_QUAD | NUMBER }\n");
-       fprintf(stderr, "       ELIM      := { none | 0..255 }(default=%d)\n",
-               IPV6_DEFAULT_TNL_ENCAP_LIMIT);
-       fprintf(stderr, "       TCLASS    := { 0x0..0xff | inherit }\n");
-       fprintf(stderr, "       FLOWLABEL := { 0x0..0xfffff | inherit }\n");
+       print_usage(stderr);
        exit(-1);
 }
 
 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
                         struct nlmsghdr *n)
 {
+       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
        struct {
                struct nlmsghdr n;
                struct ifinfomsg i;
-               char buf[1024];
-       } req;
-       struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
+       } req = {
+               .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
+               .n.nlmsg_flags = NLM_F_REQUEST,
+               .n.nlmsg_type = RTM_GETLINK,
+               .i.ifi_family = preferred_family,
+               .i.ifi_index = ifi->ifi_index,
+       };
+       struct nlmsghdr *answer;
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct rtattr *greinfo[IFLA_GRE_MAX + 1];
        __u16 iflags = 0;
        __u16 oflags = 0;
-       unsigned ikey = 0;
-       unsigned okey = 0;
+       __be32 ikey = 0;
+       __be32 okey = 0;
        struct in6_addr raddr = IN6ADDR_ANY_INIT;
        struct in6_addr laddr = IN6ADDR_ANY_INIT;
-       unsigned link = 0;
-       unsigned flowinfo = 0;
-       unsigned flags = 0;
+       unsigned int link = 0;
+       unsigned int flowinfo = 0;
+       unsigned int flags = 0;
        __u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
        __u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
+       __u16 encaptype = 0;
+       __u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
+       __u16 encapsport = 0;
+       __u16 encapdport = 0;
        int len;
+       __u32 fwmark = 0;
+       __u32 erspan_idx = 0;
 
        if (!(n->nlmsg_flags & NLM_F_CREATE)) {
-               memset(&req, 0, sizeof(req));
-
-               req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
-               req.n.nlmsg_flags = NLM_F_REQUEST;
-               req.n.nlmsg_type = RTM_GETLINK;
-               req.i.ifi_family = preferred_family;
-               req.i.ifi_index = ifi->ifi_index;
-
-               if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
+               if (rtnl_talk(&rth, &req.n, &answer) < 0) {
 get_failed:
                        fprintf(stderr,
                                "Failed to get existing tunnel info.\n");
                        return -1;
                }
 
-               len = req.n.nlmsg_len;
+               len = answer->nlmsg_len;
                len -= NLMSG_LENGTH(sizeof(*ifi));
                if (len < 0)
                        goto get_failed;
 
-               parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
+               parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
 
                if (!tb[IFLA_LINKINFO])
                        goto get_failed;
@@ -143,57 +167,42 @@ get_failed:
 
                if (greinfo[IFLA_GRE_FLAGS])
                        flags = rta_getattr_u32(greinfo[IFLA_GRE_FLAGS]);
+
+               if (greinfo[IFLA_GRE_ENCAP_TYPE])
+                       encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]);
+
+               if (greinfo[IFLA_GRE_ENCAP_FLAGS])
+                       encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]);
+
+               if (greinfo[IFLA_GRE_ENCAP_SPORT])
+                       encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
+
+               if (greinfo[IFLA_GRE_ENCAP_DPORT])
+                       encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
+
+               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);
        }
 
        while (argc > 0) {
                if (!matches(*argv, "key")) {
-                       unsigned uval;
-
                        NEXT_ARG();
                        iflags |= GRE_KEY;
                        oflags |= GRE_KEY;
-                       if (strchr(*argv, '.'))
-                               uval = get_addr32(*argv);
-                       else {
-                               if (get_unsigned(&uval, *argv, 0) < 0) {
-                                       fprintf(stderr,
-                                               "Invalid value for \"key\"\n");
-                                       exit(-1);
-                               }
-                               uval = htonl(uval);
-                       }
-
-                       ikey = okey = uval;
+                       ikey = okey = tnl_parse_key("key", *argv);
                } else if (!matches(*argv, "ikey")) {
-                       unsigned uval;
-
                        NEXT_ARG();
                        iflags |= GRE_KEY;
-                       if (strchr(*argv, '.'))
-                               uval = get_addr32(*argv);
-                       else {
-                               if (get_unsigned(&uval, *argv, 0)<0) {
-                                       fprintf(stderr, "invalid value of \"ikey\"\n");
-                                       exit(-1);
-                               }
-                               uval = htonl(uval);
-                       }
-                       ikey = uval;
+                       ikey = tnl_parse_key("ikey", *argv);
                } else if (!matches(*argv, "okey")) {
-                       unsigned uval;
-
                        NEXT_ARG();
                        oflags |= GRE_KEY;
-                       if (strchr(*argv, '.'))
-                               uval = get_addr32(*argv);
-                       else {
-                               if (get_unsigned(&uval, *argv, 0)<0) {
-                                       fprintf(stderr, "invalid value of \"okey\"\n");
-                                       exit(-1);
-                               }
-                               uval = htonl(uval);
-                       }
-                       okey = uval;
+                       okey = tnl_parse_key("okey", *argv);
                } else if (!matches(*argv, "seq")) {
                        iflags |= GRE_SEQ;
                        oflags |= GRE_SEQ;
@@ -210,26 +219,28 @@ get_failed:
                        oflags |= GRE_CSUM;
                } else if (!matches(*argv, "remote")) {
                        inet_prefix addr;
+
                        NEXT_ARG();
-                       get_prefix(&addr, *argv, preferred_family);
-                       if (addr.family == AF_UNSPEC)
-                               invarg("\"remote\" address family is AF_UNSPEC", *argv);
+                       get_addr(&addr, *argv, AF_INET6);
                        memcpy(&raddr, &addr.data, sizeof(raddr));
                } else if (!matches(*argv, "local")) {
                        inet_prefix addr;
+
                        NEXT_ARG();
-                       get_prefix(&addr, *argv, preferred_family);
-                       if (addr.family == AF_UNSPEC)
-                               invarg("\"local\" address family is AF_UNSPEC", *argv);
+                       get_addr(&addr, *argv, AF_INET6);
                        memcpy(&laddr, &addr.data, sizeof(laddr));
                } else if (!matches(*argv, "dev")) {
                        NEXT_ARG();
                        link = if_nametoindex(*argv);
-                       if (link == 0)
+                       if (link == 0) {
+                               fprintf(stderr, "Cannot find device \"%s\"\n",
+                                       *argv);
                                exit(-1);
+                       }
                } else if (!matches(*argv, "ttl") ||
                           !matches(*argv, "hoplimit")) {
                        __u8 uval;
+
                        NEXT_ARG();
                        if (get_u8(&uval, *argv, 0))
                                invarg("invalid TTL", *argv);
@@ -238,18 +249,21 @@ get_failed:
                           !matches(*argv, "tclass") ||
                           !matches(*argv, "dsfield")) {
                        __u8 uval;
+
                        NEXT_ARG();
                        if (strcmp(*argv, "inherit") == 0)
                                flags |= IP6_TNL_F_USE_ORIG_TCLASS;
                        else {
                                if (get_u8(&uval, *argv, 16))
                                        invarg("invalid TClass", *argv);
+                               flowinfo &= ~IP6_FLOWINFO_TCLASS;
                                flowinfo |= htonl((__u32)uval << 20) & IP6_FLOWINFO_TCLASS;
                                flags &= ~IP6_TNL_F_USE_ORIG_TCLASS;
                        }
                } else if (strcmp(*argv, "flowlabel") == 0 ||
                           strcmp(*argv, "fl") == 0) {
                        __u32 uval;
+
                        NEXT_ARG();
                        if (strcmp(*argv, "inherit") == 0)
                                flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
@@ -258,6 +272,7 @@ get_failed:
                                        invarg("invalid Flowlabel", *argv);
                                if (uval > 0xFFFFF)
                                        invarg("invalid Flowlabel", *argv);
+                               flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
                                flowinfo |= htonl(uval) & IP6_FLOWINFO_FLOWLABEL;
                                flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL;
                        }
@@ -266,6 +281,68 @@ get_failed:
                        if (strcmp(*argv, "inherit") != 0)
                                invarg("not inherit", *argv);
                        flags |= IP6_TNL_F_RCV_DSCP_COPY;
+               } else if (strcmp(*argv, "noencap") == 0) {
+                       encaptype = TUNNEL_ENCAP_NONE;
+               } else if (strcmp(*argv, "encap") == 0) {
+                       NEXT_ARG();
+                       if (strcmp(*argv, "fou") == 0)
+                               encaptype = TUNNEL_ENCAP_FOU;
+                       else if (strcmp(*argv, "gue") == 0)
+                               encaptype = TUNNEL_ENCAP_GUE;
+                       else if (strcmp(*argv, "none") == 0)
+                               encaptype = TUNNEL_ENCAP_NONE;
+                       else
+                               invarg("Invalid encap type.", *argv);
+               } else if (strcmp(*argv, "encap-sport") == 0) {
+                       NEXT_ARG();
+                       if (strcmp(*argv, "auto") == 0)
+                               encapsport = 0;
+                       else if (get_u16(&encapsport, *argv, 0))
+                               invarg("Invalid source port.", *argv);
+               } else if (strcmp(*argv, "encap-dport") == 0) {
+                       NEXT_ARG();
+                       if (get_u16(&encapdport, *argv, 0))
+                               invarg("Invalid destination port.", *argv);
+               } else if (strcmp(*argv, "encap-csum") == 0) {
+                       encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
+               } else if (strcmp(*argv, "noencap-csum") == 0) {
+                       encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
+               } else if (strcmp(*argv, "encap-udp6-csum") == 0) {
+                       encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
+               } else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
+                       encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
+               } else if (strcmp(*argv, "encap-remcsum") == 0) {
+                       encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
+               } else if (strcmp(*argv, "noencap-remcsum") == 0) {
+                       encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
+               } else if (strcmp(*argv, "fwmark") == 0) {
+                       NEXT_ARG();
+                       if (strcmp(*argv, "inherit") == 0) {
+                               flags |= IP6_TNL_F_USE_ORIG_FWMARK;
+                               fwmark = 0;
+                       } else {
+                               if (get_u32(&fwmark, *argv, 0))
+                                       invarg("invalid fwmark\n", *argv);
+                               flags &= ~IP6_TNL_F_USE_ORIG_FWMARK;
+                       }
+               } else if (strcmp(*argv, "encaplimit") == 0) {
+                       NEXT_ARG();
+                       if (strcmp(*argv, "none") == 0) {
+                               flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
+                       } else {
+                               __u8 uval;
+
+                               if (get_u8(&uval, *argv, 0))
+                                       invarg("invalid ELIM", *argv);
+                               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++;
@@ -282,21 +359,28 @@ get_failed:
        addattr_l(n, 1024, IFLA_GRE_TTL, &hop_limit, 1);
        addattr_l(n, 1024, IFLA_GRE_ENCAP_LIMIT, &encap_limit, 1);
        addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4);
-       addattr_l(n, 1024, IFLA_GRE_FLAGS, &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);
+       addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
+       addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
 
        return 0;
 }
 
 static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
-       char s1[1024];
        char s2[64];
        const char *local = "any";
        const char *remote = "any";
-       unsigned iflags = 0;
-       unsigned oflags = 0;
-       unsigned flags = 0;
-       unsigned flowinfo = 0;
+       unsigned int iflags = 0;
+       unsigned int oflags = 0;
+       unsigned int flags = 0;
+       unsigned int flowinfo = 0;
        struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
 
        if (!tb)
@@ -306,56 +390,105 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                flags = rta_getattr_u32(tb[IFLA_GRE_FLAGS]);
 
        if (tb[IFLA_GRE_FLOWINFO])
-               flags = rta_getattr_u32(tb[IFLA_GRE_FLOWINFO]);
+               flowinfo = rta_getattr_u32(tb[IFLA_GRE_FLOWINFO]);
 
        if (tb[IFLA_GRE_REMOTE]) {
                struct in6_addr addr;
+
                memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr));
 
                if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
-                       remote = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1));
+                       remote = format_host(AF_INET6, sizeof(addr), &addr);
        }
 
-       fprintf(f, "remote %s ", remote);
+       print_string(PRINT_ANY, "remote", "remote %s ", remote);
 
        if (tb[IFLA_GRE_LOCAL]) {
                struct in6_addr addr;
+
                memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr));
 
                if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
-                       local = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1));
+                       local = format_host(AF_INET6, sizeof(addr), &addr);
        }
 
-       fprintf(f, "local %s ", local);
+       print_string(PRINT_ANY, "local", "local %s ", local);
 
        if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
-               unsigned link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
+               unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
                const char *n = if_indextoname(link, s2);
 
                if (n)
-                       fprintf(f, "dev %s ", n);
+                       print_string(PRINT_ANY, "link", "dev %s ", n);
                else
-                       fprintf(f, "dev %u ", link);
+                       print_uint(PRINT_ANY, "link_index", "dev %u ", link);
        }
 
-       if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
-               fprintf(f, "hoplimit %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
+       if (tb[IFLA_GRE_TTL]) {
+               __u8 ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]);
+
+               if (ttl)
+                       print_int(PRINT_ANY, "ttl", "hoplimit %d ", ttl);
+               else
+                       print_int(PRINT_JSON, "ttl", NULL, ttl);
+       }
 
        if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
-               fprintf(f, "encaplimit none ");
+               print_bool(PRINT_ANY,
+                          "ip6_tnl_f_ign_encap_limit",
+                          "encaplimit none ",
+                          true);
        else if (tb[IFLA_GRE_ENCAP_LIMIT]) {
                int encap_limit = rta_getattr_u8(tb[IFLA_GRE_ENCAP_LIMIT]);
 
-               fprintf(f, "encaplimit %d ", encap_limit);
+               print_int(PRINT_ANY,
+                         "encap_limit",
+                         "encaplimit %d ",
+                         encap_limit);
        }
 
-       if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
-               fprintf(f, "flowlabel inherit ");
-       else
-               fprintf(f, "flowlabel 0x%05x ", ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+       if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
+               print_bool(PRINT_ANY,
+                          "ip6_tnl_f_use_orig_flowlabel",
+                          "flowlabel inherit ",
+                          true);
+       } else {
+               if (is_json_context()) {
+                       SPRINT_BUF(b1);
+
+                       snprintf(b1, sizeof(b1), "0x%05x",
+                                ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+                       print_string(PRINT_JSON, "flowlabel", NULL, b1);
+
+               } else {
+                       fprintf(f, "flowlabel 0x%05x ",
+                               ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
+               }
+       }
+
+       if (flags & IP6_TNL_F_USE_ORIG_TCLASS) {
+               print_bool(PRINT_ANY,
+                          "ip6_tnl_f_use_orig_tclass",
+                          "tclass inherit ",
+                          true);
+       } else {
+               if (is_json_context()) {
+                       SPRINT_BUF(b1);
+
+                       snprintf(b1, sizeof(b1), "0x%05x",
+                                ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20);
+                       print_string(PRINT_JSON, "tclass", NULL, b1);
+               } else {
+                       fprintf(f, "tclass 0x%02x ",
+                                ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20);
+               }
+       }
 
        if (flags & IP6_TNL_F_RCV_DSCP_COPY)
-               fprintf(f, "dscp inherit ");
+               print_bool(PRINT_ANY,
+                          "ip6_tnl_f_rcv_dscp_copy",
+                          "dscp inherit ",
+                          true);
 
        if (tb[IFLA_GRE_IFLAGS])
                iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
@@ -365,22 +498,108 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 
        if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
                inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
-               fprintf(f, "ikey %s ", s2);
+               print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
        }
 
        if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
                inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
-               fprintf(f, "okey %s ", s2);
+               print_string(PRINT_ANY, "okey", "okey %s ", s2);
        }
 
        if (iflags & GRE_SEQ)
-               fputs("iseq ", f);
+               print_bool(PRINT_ANY, "iseq", "iseq ", true);
        if (oflags & GRE_SEQ)
-               fputs("oseq ", f);
+               print_bool(PRINT_ANY, "oseq", "oseq ", true);
        if (iflags & GRE_CSUM)
-               fputs("icsum ", f);
+               print_bool(PRINT_ANY, "icsum", "icsum ", true);
        if (oflags & GRE_CSUM)
-               fputs("ocsum ", f);
+               print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
+
+       if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
+               print_bool(PRINT_ANY,
+                          "ip6_tnl_f_use_orig_fwmark",
+                          "fwmark inherit ",
+                          true);
+       else if (tb[IFLA_GRE_FWMARK]) {
+               __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
+
+               if (fwmark) {
+                       snprintf(s2, sizeof(s2), "0x%x", fwmark);
+
+                       print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
+               }
+       }
+
+       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]);
+               __u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
+               __u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
+               __u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
+
+               open_json_object("encap");
+
+               print_string(PRINT_FP, NULL, "encap ", NULL);
+               switch (type) {
+               case TUNNEL_ENCAP_FOU:
+                       print_string(PRINT_ANY, "type", "%s ", "fou");
+                       break;
+               case TUNNEL_ENCAP_GUE:
+                       print_string(PRINT_ANY, "type", "%s ", "gue");
+                       break;
+               default:
+                       print_null(PRINT_ANY, "type", "unknown ", NULL);
+                       break;
+               }
+
+               if (is_json_context()) {
+                       print_uint(PRINT_JSON,
+                                  "sport",
+                                  NULL,
+                                  sport ? ntohs(sport) : 0);
+                       print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
+                       print_bool(PRINT_JSON, "csum", NULL,
+                                          flags & TUNNEL_ENCAP_FLAG_CSUM);
+                       print_bool(PRINT_JSON, "csum6", NULL,
+                                          flags & TUNNEL_ENCAP_FLAG_CSUM6);
+                       print_bool(PRINT_JSON, "remcsum", NULL,
+                                          flags & TUNNEL_ENCAP_FLAG_REMCSUM);
+                       close_json_object();
+               } else {
+                       if (sport == 0)
+                               fputs("encap-sport auto ", f);
+                       else
+                               fprintf(f, "encap-sport %u", ntohs(sport));
+
+                       fprintf(f, "encap-dport %u ", ntohs(dport));
+
+                       if (flags & TUNNEL_ENCAP_FLAG_CSUM)
+                               fputs("encap-csum ", f);
+                       else
+                               fputs("noencap-csum ", f);
+
+                       if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
+                               fputs("encap-csum6 ", f);
+                       else
+                               fputs("noencap-csum6 ", f);
+
+                       if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
+                               fputs("encap-remcsum ", f);
+                       else
+                               fputs("noencap-remcsum ", f);
+               }
+       }
+}
+
+static void gre_print_help(struct link_util *lu, int argc, char **argv,
+       FILE *f)
+{
+       print_usage(f);
 }
 
 struct link_util ip6gre_link_util = {
@@ -388,6 +607,7 @@ struct link_util ip6gre_link_util = {
        .maxattr = IFLA_GRE_MAX,
        .parse_opt = gre_parse_opt,
        .print_opt = gre_print_opt,
+       .print_help = gre_print_help,
 };
 
 struct link_util ip6gretap_link_util = {
@@ -395,4 +615,13 @@ struct link_util ip6gretap_link_util = {
        .maxattr = IFLA_GRE_MAX,
        .parse_opt = gre_parse_opt,
        .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,
 };