net/sched: tunnel_key: Allow to set tos and ttl for tc based ip tunnels
authorOr Gerlitz <ogerlitz@mellanox.com>
Tue, 17 Jul 2018 16:27:16 +0000 (19:27 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 20 Jul 2018 06:26:01 +0000 (23:26 -0700)
Allow user-space to provide tos and ttl to be set for the tunnel headers.

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/tc_act/tc_tunnel_key.h
net/sched/act_tunnel_key.c

index e284fec8c467cc7bfdb121432f63dadfce42b712..be384d63e1b56b297707cb5159c50ea4e3dff0dc 100644 (file)
@@ -39,6 +39,8 @@ enum {
        TCA_TUNNEL_KEY_ENC_OPTS,        /* Nested TCA_TUNNEL_KEY_ENC_OPTS_
                                         * attributes
                                         */
        TCA_TUNNEL_KEY_ENC_OPTS,        /* Nested TCA_TUNNEL_KEY_ENC_OPTS_
                                         * attributes
                                         */
+       TCA_TUNNEL_KEY_ENC_TOS,         /* u8 */
+       TCA_TUNNEL_KEY_ENC_TTL,         /* u8 */
        __TCA_TUNNEL_KEY_MAX,
 };
 
        __TCA_TUNNEL_KEY_MAX,
 };
 
index 3ec585d587629e282e9be08bb493c70c79dcbaa5..22f26e9ea8f15b4a569771fb6edcb1ed016e578b 100644 (file)
@@ -197,6 +197,8 @@ static const struct nla_policy tunnel_key_policy[TCA_TUNNEL_KEY_MAX + 1] = {
        [TCA_TUNNEL_KEY_ENC_DST_PORT] = {.type = NLA_U16},
        [TCA_TUNNEL_KEY_NO_CSUM]      = { .type = NLA_U8 },
        [TCA_TUNNEL_KEY_ENC_OPTS]     = { .type = NLA_NESTED },
        [TCA_TUNNEL_KEY_ENC_DST_PORT] = {.type = NLA_U16},
        [TCA_TUNNEL_KEY_NO_CSUM]      = { .type = NLA_U8 },
        [TCA_TUNNEL_KEY_ENC_OPTS]     = { .type = NLA_NESTED },
+       [TCA_TUNNEL_KEY_ENC_TOS]      = { .type = NLA_U8 },
+       [TCA_TUNNEL_KEY_ENC_TTL]      = { .type = NLA_U8 },
 };
 
 static int tunnel_key_init(struct net *net, struct nlattr *nla,
 };
 
 static int tunnel_key_init(struct net *net, struct nlattr *nla,
@@ -216,6 +218,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
        int opts_len = 0;
        __be64 key_id;
        __be16 flags;
        int opts_len = 0;
        __be64 key_id;
        __be16 flags;
+       u8 tos, ttl;
        int ret = 0;
        int err;
 
        int ret = 0;
        int err;
 
@@ -273,6 +276,13 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
                        }
                }
 
                        }
                }
 
+               tos = 0;
+               if (tb[TCA_TUNNEL_KEY_ENC_TOS])
+                       tos = nla_get_u8(tb[TCA_TUNNEL_KEY_ENC_TOS]);
+               ttl = 0;
+               if (tb[TCA_TUNNEL_KEY_ENC_TTL])
+                       ttl = nla_get_u8(tb[TCA_TUNNEL_KEY_ENC_TTL]);
+
                if (tb[TCA_TUNNEL_KEY_ENC_IPV4_SRC] &&
                    tb[TCA_TUNNEL_KEY_ENC_IPV4_DST]) {
                        __be32 saddr;
                if (tb[TCA_TUNNEL_KEY_ENC_IPV4_SRC] &&
                    tb[TCA_TUNNEL_KEY_ENC_IPV4_DST]) {
                        __be32 saddr;
@@ -281,7 +291,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
                        saddr = nla_get_in_addr(tb[TCA_TUNNEL_KEY_ENC_IPV4_SRC]);
                        daddr = nla_get_in_addr(tb[TCA_TUNNEL_KEY_ENC_IPV4_DST]);
 
                        saddr = nla_get_in_addr(tb[TCA_TUNNEL_KEY_ENC_IPV4_SRC]);
                        daddr = nla_get_in_addr(tb[TCA_TUNNEL_KEY_ENC_IPV4_DST]);
 
-                       metadata = __ip_tun_set_dst(saddr, daddr, 0, 0,
+                       metadata = __ip_tun_set_dst(saddr, daddr, tos, ttl,
                                                    dst_port, flags,
                                                    key_id, opts_len);
                } else if (tb[TCA_TUNNEL_KEY_ENC_IPV6_SRC] &&
                                                    dst_port, flags,
                                                    key_id, opts_len);
                } else if (tb[TCA_TUNNEL_KEY_ENC_IPV6_SRC] &&
@@ -292,7 +302,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
                        saddr = nla_get_in6_addr(tb[TCA_TUNNEL_KEY_ENC_IPV6_SRC]);
                        daddr = nla_get_in6_addr(tb[TCA_TUNNEL_KEY_ENC_IPV6_DST]);
 
                        saddr = nla_get_in6_addr(tb[TCA_TUNNEL_KEY_ENC_IPV6_SRC]);
                        daddr = nla_get_in6_addr(tb[TCA_TUNNEL_KEY_ENC_IPV6_DST]);
 
-                       metadata = __ipv6_tun_set_dst(&saddr, &daddr, 0, 0, dst_port,
+                       metadata = __ipv6_tun_set_dst(&saddr, &daddr, tos, ttl, dst_port,
                                                      0, flags,
                                                      key_id, 0);
                } else {
                                                      0, flags,
                                                      key_id, 0);
                } else {
@@ -504,6 +514,12 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,
                               !(key->tun_flags & TUNNEL_CSUM)) ||
                    tunnel_key_opts_dump(skb, info))
                        goto nla_put_failure;
                               !(key->tun_flags & TUNNEL_CSUM)) ||
                    tunnel_key_opts_dump(skb, info))
                        goto nla_put_failure;
+
+               if (key->tos && nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_TOS, key->tos))
+                       goto nla_put_failure;
+
+               if (key->ttl && nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_TTL, key->ttl))
+                       goto nla_put_failure;
        }
 
        tcf_tm_dump(&tm, &t->tcf_tm);
        }
 
        tcf_tm_dump(&tm, &t->tcf_tm);