[ovs-dev] [PATCH 4/4] lib/tc: Support matching on ip tunnel tos and ttl

Or Gerlitz ogerlitz at mellanox.com
Wed Jul 25 18:20:09 UTC 2018


Support matching on tos and ttl of ip tunnels
for the TC data-path.

Signed-off-by: Or Gerlitz <ogerlitz at mellanox.com>
Reviewed-by: Roi Dayan <roid at mellanox.com>
---
 acinclude.m4             | 10 +++++-----
 include/linux/pkt_cls.h  |  7 ++++++-
 lib/netdev-tc-offloads.c |  8 ++++++++
 lib/tc.c                 | 30 +++++++++++++++++++++++++++++-
 lib/tc.h                 |  4 +++-
 5 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index a5ff325..1e42599 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -178,17 +178,17 @@ dnl Configure Linux tc compat.
 AC_DEFUN([OVS_CHECK_LINUX_TC], [
   AC_COMPILE_IFELSE([
     AC_LANG_PROGRAM([#include <linux/pkt_cls.h>], [
-        int x = TCA_FLOWER_KEY_CVLAN_PRIO;
+        int x = TCA_FLOWER_KEY_ENC_IP_TTL_MASK;
     ])],
-    [AC_DEFINE([HAVE_TCA_FLOWER_KEY_CVLAN_PRIO], [1],
-               [Define to 1 if TCA_FLOWER_KEY_CVLAN_PRIO is avaiable.])])
+    [AC_DEFINE([HAVE_TCA_FLOWER_KEY_ENC_IP_TTL_MASK], [1],
+               [Define to 1 if TCA_FLOWER_KEY_ENC_IP_TTL_MASK is available.])])
 
   AC_COMPILE_IFELSE([
     AC_LANG_PROGRAM([#include <linux/tc_act/tc_vlan.h>], [
         int x = TCA_VLAN_PUSH_VLAN_PRIORITY;
     ])],
     [AC_DEFINE([HAVE_TCA_VLAN_PUSH_VLAN_PRIORITY], [1],
-               [Define to 1 if TCA_VLAN_PUSH_VLAN_PRIORITY is avaiable.])])
+               [Define to 1 if TCA_VLAN_PUSH_VLAN_PRIORITY is available.])])
 
   AC_COMPILE_IFELSE([
     AC_LANG_PROGRAM([#include <linux/tc_act/tc_tunnel_key.h>], [
@@ -202,7 +202,7 @@ AC_DEFUN([OVS_CHECK_LINUX_TC], [
         int x = TCA_PEDIT_KEY_EX_HDR_TYPE_UDP;
     ])],
     [AC_DEFINE([HAVE_TCA_PEDIT_KEY_EX_HDR_TYPE_UDP], [1],
-               [Define to 1 if TCA_PEDIT_KEY_EX_HDR_TYPE_UDP is avaiable.])])
+               [Define to 1 if TCA_PEDIT_KEY_EX_HDR_TYPE_UDP is available.])])
 ])
 
 dnl OVS_CHECK_DPDK
diff --git a/include/linux/pkt_cls.h b/include/linux/pkt_cls.h
index 442323d..a330041 100644
--- a/include/linux/pkt_cls.h
+++ b/include/linux/pkt_cls.h
@@ -1,7 +1,7 @@
 #ifndef __LINUX_PKT_CLS_WRAPPER_H
 #define __LINUX_PKT_CLS_WRAPPER_H 1
 
-#if defined(__KERNEL__) || defined(HAVE_TCA_FLOWER_KEY_CVLAN_PRIO)
+#if defined(__KERNEL__) || defined(HAVE_TCA_FLOWER_KEY_ENC_IP_TTL_MASK)
 #include_next <linux/pkt_cls.h>
 #else
 
@@ -200,6 +200,11 @@ enum {
 	TCA_FLOWER_KEY_CVLAN_PRIO,	/* u8   */
 	TCA_FLOWER_KEY_CVLAN_ETH_TYPE,	/* be16 */
 
+	TCA_FLOWER_KEY_ENC_IP_TOS,	    /* u8 */
+	TCA_FLOWER_KEY_ENC_IP_TOS_MASK,	/* u8 */
+	TCA_FLOWER_KEY_ENC_IP_TTL,		/* u8 */
+	TCA_FLOWER_KEY_ENC_IP_TTL_MASK,	/* u8 */
+
 	__TCA_FLOWER_MAX,
 };
 
diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
index 7ed0844..7bc745e 100644
--- a/lib/netdev-tc-offloads.c
+++ b/lib/netdev-tc-offloads.c
@@ -510,6 +510,12 @@ parse_tc_flower_to_match(struct tc_flower *flower,
             match_set_tun_ipv6_src(match, &flower->tunnel.ipv6.ipv6_src);
             match_set_tun_ipv6_dst(match, &flower->tunnel.ipv6.ipv6_dst);
         }
+        if (flower->tunnel.tos) {
+            match_set_tun_tos(match, flower->tunnel.tos);
+        }
+        if (flower->tunnel.ttl) {
+            match_set_tun_ttl(match, flower->tunnel.ttl);
+        }
         if (flower->tunnel.tp_dst) {
             match_set_tun_tp_dst(match, flower->tunnel.tp_dst);
         }
@@ -963,6 +969,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,
         flower.tunnel.ipv4.ipv4_dst = tnl->ip_dst;
         flower.tunnel.ipv6.ipv6_src = tnl->ipv6_src;
         flower.tunnel.ipv6.ipv6_dst = tnl->ipv6_dst;
+        flower.tunnel.tos = tnl->ip_tos;
+        flower.tunnel.ttl = tnl->ip_ttl;
         flower.tunnel.tp_src = tnl->tp_src;
         flower.tunnel.tp_dst = tnl->tp_dst;
         flower.tunnel.tunnel = true;
diff --git a/lib/tc.c b/lib/tc.c
index aa3147f..f5901d1 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -298,6 +298,10 @@ static const struct nl_policy tca_flower_policy[] = {
                                           .optional = true, },
     [TCA_FLOWER_KEY_FLAGS] = { .type = NL_A_BE32, .optional = true, },
     [TCA_FLOWER_KEY_FLAGS_MASK] = { .type = NL_A_BE32, .optional = true, },
+    [TCA_FLOWER_KEY_TCP_FLAGS] = { .type = NL_A_U16,
+                                   .optional = true, },
+    [TCA_FLOWER_KEY_TCP_FLAGS_MASK] = { .type = NL_A_U16,
+                                        .optional = true, },
     [TCA_FLOWER_KEY_IP_TTL] = { .type = NL_A_U8,
                                 .optional = true, },
     [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NL_A_U8,
@@ -313,6 +317,14 @@ static const struct nl_policy tca_flower_policy[] = {
     [TCA_FLOWER_KEY_CVLAN_ID] = { .type = NL_A_U16, .optional = true, },
     [TCA_FLOWER_KEY_CVLAN_PRIO] = { .type = NL_A_U8, .optional = true, },
     [TCA_FLOWER_KEY_CVLAN_ETH_TYPE] = { .type = NL_A_U16, .optional = true, },
+    [TCA_FLOWER_KEY_ENC_IP_TOS] = { .type = NL_A_U8,
+                                    .optional = true, },
+    [TCA_FLOWER_KEY_ENC_IP_TOS_MASK] = { .type = NL_A_U8,
+                                         .optional = true, },
+    [TCA_FLOWER_KEY_ENC_IP_TTL] = { .type = NL_A_U8,
+                                    .optional = true, },
+    [TCA_FLOWER_KEY_ENC_IP_TTL_MASK] = { .type = NL_A_U8,
+                                         .optional = true, },
 };
 
 static void
@@ -407,6 +419,14 @@ nl_parse_flower_tunnel(struct nlattr **attrs, struct tc_flower *flower)
         flower->tunnel.tp_dst =
             nl_attr_get_be16(attrs[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]);
     }
+    if (attrs[TCA_FLOWER_KEY_ENC_IP_TOS]) {
+        flower->tunnel.tos =
+            nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ENC_IP_TOS]);
+    }
+    if (attrs[TCA_FLOWER_KEY_ENC_IP_TTL]) {
+        flower->tunnel.ttl =
+            nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ENC_IP_TTL]);
+    }
 }
 
 static void
@@ -1605,8 +1625,9 @@ nl_msg_put_flower_tunnel(struct ofpbuf *request, struct tc_flower *flower)
     struct in6_addr *ipv6_dst = &flower->tunnel.ipv6.ipv6_dst;
     ovs_be16 tp_dst = flower->tunnel.tp_dst;
     ovs_be32 id = be64_to_be32(flower->tunnel.id);
+    uint8_t tos = flower->tunnel.tos;
+    uint8_t ttl = flower->tunnel.ttl;
 
-    nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_KEY_ID, id);
     if (ipv4_dst) {
         nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_IPV4_SRC, ipv4_src);
         nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_IPV4_DST, ipv4_dst);
@@ -1614,7 +1635,14 @@ nl_msg_put_flower_tunnel(struct ofpbuf *request, struct tc_flower *flower)
         nl_msg_put_in6_addr(request, TCA_FLOWER_KEY_ENC_IPV6_SRC, ipv6_src);
         nl_msg_put_in6_addr(request, TCA_FLOWER_KEY_ENC_IPV6_DST, ipv6_dst);
     }
+    if (tos) {
+        nl_msg_put_u8(request, TCA_FLOWER_KEY_ENC_IP_TOS, tos);
+    }
+    if (ttl) {
+        nl_msg_put_u8(request, TCA_FLOWER_KEY_ENC_IP_TTL, ttl);
+    }
     nl_msg_put_be16(request, TCA_FLOWER_KEY_ENC_UDP_DST_PORT, tp_dst);
+    nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_KEY_ID, id);
 }
 
 #define FLOWER_PUT_MASKED_VALUE(member, type) \
diff --git a/lib/tc.h b/lib/tc.h
index 9a265f4..aa8805d 100644
--- a/lib/tc.h
+++ b/lib/tc.h
@@ -183,9 +183,11 @@ struct tc_flower {
             struct in6_addr ipv6_src;
             struct in6_addr ipv6_dst;
         } ipv6;
-        ovs_be64 id;
+        uint8_t tos;
+        uint8_t ttl;
         ovs_be16 tp_src;
         ovs_be16 tp_dst;
+        ovs_be64 id;
     } tunnel;
 
     struct tc_cookie act_cookie;
-- 
2.5.5



More information about the dev mailing list