a927d52
From a99f73a22e6303555af3f93535d03c7537da5a9a Mon Sep 17 00:00:00 2001
a927d52
From: Roi Dayan <roid@mellanox.com>
a927d52
Date: Mon, 12 Mar 2018 14:58:47 +0200
a927d52
Subject: [PATCH 2/2] netdev-tc-offloads: Add support for IP fragmentation
a927d52
a927d52
Add support for frag no, first and later.
a927d52
a927d52
Signed-off-by: Roi Dayan <roid@mellanox.com>
a927d52
Reviewed-by: Shahar Klein <shahark@mellanox.com>
a927d52
Reviewed-by: Paul Blakey <paulb@mellanox.com>
a927d52
Signed-off-by: Simon Horman <simon.horman@netronome.com>
a927d52
---
a927d52
 acinclude.m4             |  6 +++---
a927d52
 include/linux/pkt_cls.h  |  5 +++--
a927d52
 lib/netdev-tc-offloads.c | 38 ++++++++++++++++++++++++++++++++------
a927d52
 lib/tc.c                 | 14 ++++++++++++++
a927d52
 lib/tc.h                 |  1 +
a927d52
 5 files changed, 53 insertions(+), 11 deletions(-)
a927d52
a927d52
diff --git a/acinclude.m4 b/acinclude.m4
a927d52
index 176b93e8e..6a02f6527 100644
a927d52
--- a/acinclude.m4
a927d52
+++ b/acinclude.m4
a927d52
@@ -178,10 +178,10 @@ dnl Configure Linux tc compat.
a927d52
 AC_DEFUN([OVS_CHECK_LINUX_TC], [
a927d52
   AC_COMPILE_IFELSE([
a927d52
     AC_LANG_PROGRAM([#include <linux/pkt_cls.h>], [
a927d52
-        int x = TCA_FLOWER_KEY_IP_TTL_MASK;
a927d52
+        int x = TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST;
a927d52
     ])],
a927d52
-    [AC_DEFINE([HAVE_TCA_FLOWER_KEY_IP_TTL_MASK], [1],
a927d52
-               [Define to 1 if TCA_FLOWER_KEY_IP_TTL_MASK is avaiable.])])
a927d52
+    [AC_DEFINE([HAVE_TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST], [1],
a927d52
+               [Define to 1 if TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST is avaiable.])])
a927d52
 
a927d52
   AC_COMPILE_IFELSE([
a927d52
     AC_LANG_PROGRAM([#include <linux/tc_act/tc_vlan.h>], [
a927d52
diff --git a/include/linux/pkt_cls.h b/include/linux/pkt_cls.h
a927d52
index f7bc7ea70..60976f3f7 100644
a927d52
--- a/include/linux/pkt_cls.h
a927d52
+++ b/include/linux/pkt_cls.h
a927d52
@@ -1,7 +1,7 @@
a927d52
 #ifndef __LINUX_PKT_CLS_WRAPPER_H
a927d52
 #define __LINUX_PKT_CLS_WRAPPER_H 1
a927d52
 
a927d52
-#if defined(__KERNEL__) || defined(HAVE_TCA_FLOWER_KEY_IP_TTL_MASK)
a927d52
+#if defined(__KERNEL__) || defined(HAVE_TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST)
a927d52
 #include_next <linux/pkt_cls.h>
a927d52
 #else
a927d52
 
a927d52
@@ -201,8 +201,9 @@ enum {
a927d52
 
a927d52
 enum {
a927d52
 	TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
a927d52
+	TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1),
a927d52
 };
a927d52
 
a927d52
-#endif /* __KERNEL__ || !HAVE_TCA_FLOWER_KEY_IP_TTL_MASK */
a927d52
+#endif /* __KERNEL__ || !HAVE_TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST */
a927d52
 
a927d52
 #endif /* __LINUX_PKT_CLS_WRAPPER_H */
a927d52
diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
a927d52
index 9364d94f0..f22415ee1 100644
a927d52
--- a/lib/netdev-tc-offloads.c
a927d52
+++ b/lib/netdev-tc-offloads.c
a927d52
@@ -428,6 +428,27 @@ parse_tc_flower_to_match(struct tc_flower *flower,
a927d52
 
a927d52
         match_set_nw_ttl_masked(match, key->ip_ttl, mask->ip_ttl);
a927d52
 
a927d52
+        if (mask->flags) {
a927d52
+            uint8_t flags = 0;
a927d52
+            uint8_t flags_mask = 0;
a927d52
+
a927d52
+            if (mask->flags & TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT) {
a927d52
+                if (key->flags & TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT) {
a927d52
+                    flags |= FLOW_NW_FRAG_ANY;
a927d52
+                }
a927d52
+                flags_mask |= FLOW_NW_FRAG_ANY;
a927d52
+            }
a927d52
+
a927d52
+            if (mask->flags & TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST) {
a927d52
+                if (!(key->flags & TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST)) {
a927d52
+                    flags |= FLOW_NW_FRAG_LATER;
a927d52
+                }
a927d52
+                flags_mask |= FLOW_NW_FRAG_LATER;
a927d52
+            }
a927d52
+
a927d52
+            match_set_nw_frag_masked(match, flags, flags_mask);
a927d52
+        }
a927d52
+
a927d52
         match_set_nw_src_masked(match, key->ipv4.ipv4_src, mask->ipv4.ipv4_src);
a927d52
         match_set_nw_dst_masked(match, key->ipv4.ipv4_dst, mask->ipv4.ipv4_dst);
a927d52
 
a927d52
@@ -780,11 +801,6 @@ test_key_and_mask(struct match *match)
a927d52
         return EOPNOTSUPP;
a927d52
     }
a927d52
 
a927d52
-    if (mask->nw_frag) {
a927d52
-        VLOG_DBG_RL(&rl, "offloading attribute nw_frag isn't supported");
a927d52
-        return EOPNOTSUPP;
a927d52
-    }
a927d52
-
a927d52
     for (int i = 0; i < FLOW_MAX_MPLS_LABELS; i++) {
a927d52
         if (mask->mpls_lse[i]) {
a927d52
             VLOG_DBG_RL(&rl, "offloading attribute mpls_lse isn't supported");
a927d52
@@ -932,6 +948,17 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,
a927d52
         flower.key.ip_ttl = key->nw_ttl;
a927d52
         flower.mask.ip_ttl = mask->nw_ttl;
a927d52
 
a927d52
+        if (mask->nw_frag) {
a927d52
+            if (key->nw_frag & FLOW_NW_FRAG_ANY)
a927d52
+                flower.key.flags |= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
a927d52
+            if (!(key->nw_frag & FLOW_NW_FRAG_LATER))
a927d52
+                flower.key.flags |= TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST;
a927d52
+
a927d52
+            flower.mask.flags |= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
a927d52
+            flower.mask.flags |= TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST;
a927d52
+            mask->nw_frag = 0;
a927d52
+        }
a927d52
+
a927d52
         if (key->nw_proto == IPPROTO_TCP) {
a927d52
             flower.key.tcp_dst = key->tp_dst;
a927d52
             flower.mask.tcp_dst = mask->tp_dst;
a927d52
@@ -958,7 +985,6 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,
a927d52
             mask->tp_dst = 0;
a927d52
         }
a927d52
 
a927d52
-        mask->nw_frag = 0;
a927d52
         mask->nw_tos = 0;
a927d52
         mask->nw_proto = 0;
a927d52
         mask->nw_ttl = 0;
a927d52
diff --git a/lib/tc.c b/lib/tc.c
a927d52
index b49bbe89b..c446d8407 100644
a927d52
--- a/lib/tc.c
a927d52
+++ b/lib/tc.c
a927d52
@@ -281,6 +281,8 @@ static const struct nl_policy tca_flower_policy[] = {
a927d52
                                            .optional = true, },
a927d52
     [TCA_FLOWER_KEY_ENC_UDP_DST_PORT] = { .type = NL_A_U16,
a927d52
                                           .optional = true, },
a927d52
+    [TCA_FLOWER_KEY_FLAGS] = { .type = NL_A_BE32, .optional = true, },
a927d52
+    [TCA_FLOWER_KEY_FLAGS_MASK] = { .type = NL_A_BE32, .optional = true, },
a927d52
     [TCA_FLOWER_KEY_IP_TTL] = { .type = NL_A_U8,
a927d52
                                 .optional = true, },
a927d52
     [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NL_A_U8,
a927d52
@@ -374,6 +376,11 @@ nl_parse_flower_ip(struct nlattr **attrs, struct tc_flower *flower) {
a927d52
         mask->ip_proto = UINT8_MAX;
a927d52
     }
a927d52
 
a927d52
+    if (attrs[TCA_FLOWER_KEY_FLAGS_MASK]) {
a927d52
+        key->flags = ntohl(nl_attr_get_u32(attrs[TCA_FLOWER_KEY_FLAGS]));
a927d52
+        mask->flags = ntohl(nl_attr_get_u32(attrs[TCA_FLOWER_KEY_FLAGS_MASK]));
a927d52
+    }
a927d52
+
a927d52
     if (attrs[TCA_FLOWER_KEY_IPV4_SRC_MASK]) {
a927d52
         key->ipv4.ipv4_src =
a927d52
             nl_attr_get_be32(attrs[TCA_FLOWER_KEY_IPV4_SRC]);
a927d52
@@ -1495,6 +1502,13 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower)
a927d52
                           flower->key.ip_proto);
a927d52
         }
a927d52
 
a927d52
+        if (flower->mask.flags) {
a927d52
+            nl_msg_put_u32(request, TCA_FLOWER_KEY_FLAGS,
a927d52
+                           htonl(flower->key.flags));
a927d52
+            nl_msg_put_u32(request, TCA_FLOWER_KEY_FLAGS_MASK,
a927d52
+                           htonl(flower->mask.flags));
a927d52
+        }
a927d52
+
a927d52
         if (flower->key.ip_proto == IPPROTO_UDP) {
a927d52
             FLOWER_PUT_MASKED_VALUE(udp_src, TCA_FLOWER_KEY_UDP_SRC);
a927d52
             FLOWER_PUT_MASKED_VALUE(udp_dst, TCA_FLOWER_KEY_UDP_DST);
a927d52
diff --git a/lib/tc.h b/lib/tc.h
a927d52
index 6af51c69b..4400a829e 100644
a927d52
--- a/lib/tc.h
a927d52
+++ b/lib/tc.h
a927d52
@@ -92,6 +92,7 @@ struct tc_flower_key {
a927d52
 
a927d52
     ovs_be16 encap_eth_type;
a927d52
 
a927d52
+    uint8_t flags;
a927d52
     uint8_t ip_ttl;
a927d52
 
a927d52
     struct {
a927d52
-- 
a927d52
2.14.3
a927d52