[ovs-dev,2/2] netdev-tc-offloads: Add support for offloading ip frag no

Message ID 1520166031-22709-3-git-send-email-roid@mellanox.com
State Superseded
Headers show
Series
  • TC offload dump fix and add frag
Related show

Commit Message

Roi Dayan March 4, 2018, 12:20 p.m.
TC flower only support frag yes/no while OVS support first/later/no.
Currently we can only support offloading of frag no.

Signed-off-by: Roi Dayan <roid@mellanox.com>
Reviewed-by: Shahar Klein <shahark@mellanox.com>
---
 lib/netdev-tc-offloads.c | 13 ++++++++++++-
 lib/tc.c                 | 28 ++++++++++++++++++++++++++++
 lib/tc.h                 |  1 +
 3 files changed, 41 insertions(+), 1 deletion(-)

Patch

diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
index 9364d94..b3e557f 100644
--- a/lib/netdev-tc-offloads.c
+++ b/lib/netdev-tc-offloads.c
@@ -428,6 +428,8 @@  parse_tc_flower_to_match(struct tc_flower *flower,
 
         match_set_nw_ttl_masked(match, key->ip_ttl, mask->ip_ttl);
 
+        match_set_nw_frag_masked(match, key->ip_frag, mask->ip_frag);
+
         match_set_nw_src_masked(match, key->ipv4.ipv4_src, mask->ipv4.ipv4_src);
         match_set_nw_dst_masked(match, key->ipv4.ipv4_dst, mask->ipv4.ipv4_dst);
 
@@ -932,6 +934,16 @@  netdev_tc_flow_put(struct netdev *netdev, struct match *match,
         flower.key.ip_ttl = key->nw_ttl;
         flower.mask.ip_ttl = mask->nw_ttl;
 
+        if (mask->nw_frag) {
+            if (key->nw_frag) {
+                return EOPNOTSUPP;
+            }
+
+            flower.key.ip_frag = key->nw_frag;
+            flower.mask.ip_frag = mask->nw_frag;
+            mask->nw_frag = 0;
+        }
+
         if (key->nw_proto == IPPROTO_TCP) {
             flower.key.tcp_dst = key->tp_dst;
             flower.mask.tcp_dst = mask->tp_dst;
@@ -958,7 +970,6 @@  netdev_tc_flow_put(struct netdev *netdev, struct match *match,
             mask->tp_dst = 0;
         }
 
-        mask->nw_frag = 0;
         mask->nw_tos = 0;
         mask->nw_proto = 0;
         mask->nw_ttl = 0;
diff --git a/lib/tc.c b/lib/tc.c
index b49bbe8..74dd8fc 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -281,6 +281,8 @@  static const struct nl_policy tca_flower_policy[] = {
                                            .optional = true, },
     [TCA_FLOWER_KEY_ENC_UDP_DST_PORT] = { .type = NL_A_U16,
                                           .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_IP_TTL] = { .type = NL_A_U8,
                                 .optional = true, },
     [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NL_A_U8,
@@ -374,6 +376,15 @@  nl_parse_flower_ip(struct nlattr **attrs, struct tc_flower *flower) {
         mask->ip_proto = UINT8_MAX;
     }
 
+    if (attrs[TCA_FLOWER_KEY_FLAGS_MASK]) {
+        uint32_t flags = ntohl(nl_attr_get_u32(attrs[TCA_FLOWER_KEY_FLAGS]));
+        uint32_t flags_mask =
+            ntohl(nl_attr_get_u32(attrs[TCA_FLOWER_KEY_FLAGS_MASK]));
+
+        key->ip_frag = flags & TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
+        mask->ip_frag = flags_mask & TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
+    }
+
     if (attrs[TCA_FLOWER_KEY_IPV4_SRC_MASK]) {
         key->ipv4.ipv4_src =
             nl_attr_get_be32(attrs[TCA_FLOWER_KEY_IPV4_SRC]);
@@ -1490,11 +1501,28 @@  nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower)
     FLOWER_PUT_MASKED_VALUE(src_mac, TCA_FLOWER_KEY_ETH_SRC);
 
     if (host_eth_type == ETH_P_IP || host_eth_type == ETH_P_IPV6) {
+        uint32_t flags = 0;
+        uint32_t flags_mask = 0;
+
         if (flower->mask.ip_proto && flower->key.ip_proto) {
             nl_msg_put_u8(request, TCA_FLOWER_KEY_IP_PROTO,
                           flower->key.ip_proto);
         }
 
+        if (flower->mask.ip_frag) {
+            flags_mask |= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
+
+            if (flower->key.ip_frag) {
+                flags |= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
+            }
+        }
+
+        if (flags_mask) {
+            nl_msg_put_u32(request, TCA_FLOWER_KEY_FLAGS, htonl(flags));
+            nl_msg_put_u32(request, TCA_FLOWER_KEY_FLAGS_MASK,
+                htonl(flags_mask));
+        }
+
         if (flower->key.ip_proto == IPPROTO_UDP) {
             FLOWER_PUT_MASKED_VALUE(udp_src, TCA_FLOWER_KEY_UDP_SRC);
             FLOWER_PUT_MASKED_VALUE(udp_dst, TCA_FLOWER_KEY_UDP_DST);
diff --git a/lib/tc.h b/lib/tc.h
index 6af51c6..b061829 100644
--- a/lib/tc.h
+++ b/lib/tc.h
@@ -93,6 +93,7 @@  struct tc_flower_key {
     ovs_be16 encap_eth_type;
 
     uint8_t ip_ttl;
+    uint8_t ip_frag;
 
     struct {
         ovs_be32 ipv4_src;