netifd: GRE Tos support
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 29 Sep 2014 15:36:04 +0000 (15:36 +0000)
committerSteven Barth <steven@midlink.org>
Mon, 29 Sep 2014 17:58:10 +0000 (19:58 +0200)
Tos support is added as a generic gre parameter which can have the following values :
     -inherit (outer header inherits the tos value of the inner header)
     -hex value

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
system-linux.c
system.c
system.h

index c4d89be1e5060192fdd0e9f76f4a68fbc9fc2667..aca30caff3aed65eabffeaf2a95bb2acc161bc5b 100644 (file)
@@ -1665,14 +1665,16 @@ static int tunnel_ioctl(const char *name, int cmd, void *p)
 }
 
 #ifdef IFLA_IPTUN_MAX
+#define IP6_FLOWINFO_TCLASS    htonl(0x0FF00000)
 static int system_add_gre_tunnel(const char *name, const char *kind,
                                 const unsigned int link, struct blob_attr **tb, bool v6)
 {
        struct nl_msg *nlm;
        struct ifinfomsg ifi = { .ifi_family = AF_UNSPEC, };
        struct blob_attr *cur;
-       uint32_t ikey = 0, okey = 0;
+       uint32_t ikey = 0, okey = 0, flags = 0, flowinfo = 0;
        uint16_t iflags = 0, oflags = 0;
+       uint8_t tos = 0;
        int ret = 0, ttl = 64;
 
        nlm = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE);
@@ -1703,6 +1705,29 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
 
        nla_put_u8(nlm, IFLA_GRE_TTL, ttl);
 
+       if ((cur = tb[TUNNEL_ATTR_TOS])) {
+               char *str = blobmsg_get_string(cur);
+               if (strcmp(str, "inherit")) {
+                       unsigned uval;
+                       char *e;
+
+                       uval = strtoul(str, &e, 16);
+                       if (e == str || *e || uval > 255) {
+                               ret = -EINVAL;
+                               goto failure;
+                       }
+                       if (v6)
+                               flowinfo |= htonl(uval << 20) & IP6_FLOWINFO_TCLASS;
+                       else
+                               tos = uval;
+               } else {
+                       if (v6)
+                               flags |= IP6_TNL_F_USE_ORIG_TCLASS;
+                       else
+                               tos = 1;
+               }
+        }
+
        if ((cur = tb[TUNNEL_ATTR_INFO]) && (blobmsg_type(cur) == BLOBMSG_TYPE_STRING)) {
                uint8_t icsum, ocsum, iseqno, oseqno;
                if (sscanf(blobmsg_get_string(cur), "%u,%u,%hhu,%hhu,%hhu,%hhu",
@@ -1748,6 +1773,12 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
                        nla_put(nlm, IFLA_GRE_REMOTE, sizeof(in6buf), &in6buf);
                }
                nla_put_u8(nlm, IFLA_GRE_ENCAP_LIMIT, 4);
+
+               if (flowinfo)
+                       nla_put_u32(nlm, IFLA_GRE_FLOWINFO, flowinfo);
+
+               if (flags)
+                       nla_put_u32(nlm, IFLA_GRE_FLAGS, flags);
        } else {
                struct in_addr inbuf;
                bool set_df = true;
@@ -1784,6 +1815,8 @@ static int system_add_gre_tunnel(const char *name, const char *kind,
                        set_df = blobmsg_get_bool(cur);
 
                nla_put_u8(nlm, IFLA_GRE_PMTUDISC, set_df ? 1 : 0);
+
+               nla_put_u8(nlm, IFLA_GRE_TOS, tos);
        }
 
        if (oflags)
index d070fea303c1d956d06b4d0596c98487a23378e6..e57084f75555887e7c9e8e9f882ce53818ab2827 100644 (file)
--- a/system.c
+++ b/system.c
@@ -22,6 +22,7 @@ static const struct blobmsg_policy tunnel_attrs[__TUNNEL_ATTR_MAX] = {
        [TUNNEL_ATTR_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
        [TUNNEL_ATTR_DF] = { .name = "df", .type = BLOBMSG_TYPE_BOOL },
        [TUNNEL_ATTR_TTL] = { .name = "ttl", .type = BLOBMSG_TYPE_INT32 },
+       [TUNNEL_ATTR_TOS] = { .name = "tos", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_6RD_PREFIX] = {.name =  "6rd-prefix", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_6RD_RELAY_PREFIX] = { .name = "6rd-relay-prefix", .type = BLOBMSG_TYPE_STRING },
        [TUNNEL_ATTR_LINK] = { .name = "link", .type = BLOBMSG_TYPE_STRING },
index e3187fbfbbbd76900eca36e06d95cc1ff496cc76..b1215d13bb361b8a51f8c43db065b9b6ea071290 100644 (file)
--- a/system.h
+++ b/system.h
@@ -28,6 +28,7 @@ enum tunnel_param {
        TUNNEL_ATTR_MTU,
        TUNNEL_ATTR_DF,
        TUNNEL_ATTR_TTL,
+       TUNNEL_ATTR_TOS,
        TUNNEL_ATTR_6RD_PREFIX,
        TUNNEL_ATTR_6RD_RELAY_PREFIX,
        TUNNEL_ATTR_LINK,