[ovs-dev,V4,16/17] netdev-offload-dpdk: Support offload of set IPv4 actions
diff mbox series

Message ID 20191216151047.5967-17-elibr@mellanox.com
State Changes Requested
Delegated to: Ilya Maximets
Headers show
Series
  • netdev datapath actions offload
Related show

Commit Message

Eli Britstein Dec. 16, 2019, 3:10 p.m. UTC
Signed-off-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
---
 Documentation/howto/dpdk.rst |  1 +
 NEWS                         |  4 +--
 lib/netdev-offload-dpdk.c    | 69 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/Documentation/howto/dpdk.rst b/Documentation/howto/dpdk.rst
index 0e9939ddd..c440bf28e 100644
--- a/Documentation/howto/dpdk.rst
+++ b/Documentation/howto/dpdk.rst
@@ -393,6 +393,7 @@  Supported actions for hardware offload are:
 - Output.
 - Drop.
 - Modification of Ethernet (mod_dl_src/mod_dl_dst).
+- Modification of IPv4 (mod_nw_src/mod_nw_dst/mod_nw_ttl).
 
 Further Reading
 ---------------
diff --git a/NEWS b/NEWS
index 3ade86d49..297ca6fff 100644
--- a/NEWS
+++ b/NEWS
@@ -26,8 +26,8 @@  Post-v2.12.0
      * DPDK ring ports (dpdkr) are deprecated and will be removed in next
        releases.
      * Add support for DPDK 19.11.
-     * Add hardware offload support for output, drop and set MAC actions
-       (experimental).
+     * Add hardware offload support for output, drop and set actions of
+       MAC and IPv4 (experimental).
 
 v2.12.0 - 03 Sep 2019
 ---------------------
diff --git a/lib/netdev-offload-dpdk.c b/lib/netdev-offload-dpdk.c
index 83fb7a2ed..0f0685f4d 100644
--- a/lib/netdev-offload-dpdk.c
+++ b/lib/netdev-offload-dpdk.c
@@ -382,6 +382,29 @@  dump_flow_action(struct ds *s, const struct rte_flow_action *actions)
         } else {
             ds_put_format(s, "  Set-mac-%s = null\n", dirstr);
         }
+    } else if (actions->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ||
+               actions->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_DST) {
+        const struct rte_flow_action_set_ipv4 *set_ipv4 = actions->conf;
+        char *dirstr = actions->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_DST
+                       ? "dst" : "src";
+
+        ds_put_format(s, "rte flow set-ipv4-%s action:\n", dirstr);
+        if (set_ipv4) {
+            ds_put_format(s,
+                          "  Set-ipv4-%s: "IP_FMT"\n", dirstr,
+                          IP_ARGS(set_ipv4->ipv4_addr));
+        } else {
+            ds_put_format(s, "  Set-ipv4-%s = null\n", dirstr);
+        }
+    } else if (actions->type == RTE_FLOW_ACTION_TYPE_SET_TTL) {
+        const struct rte_flow_action_set_ttl *set_ttl = actions->conf;
+
+        ds_put_cstr(s, "rte flow set-ttl action:\n");
+        if (set_ttl) {
+            ds_put_format(s, "  Set-ttl: %d\n", set_ttl->ttl_value);
+        } else {
+            ds_put_cstr(s, "  Set-ttl = null\n");
+        }
     } else {
         ds_put_format(s, "unknown rte flow action (%d)\n", actions->type);
     }
@@ -888,6 +911,52 @@  parse_set_actions(struct flow_actions *actions,
                 VLOG_DBG_RL(&error_rl, "Unsupported ETHERNET set action");
                 return -1;
             }
+        } else if (nl_attr_type(sa) == OVS_KEY_ATTR_IPV4) {
+            const struct ovs_key_ipv4 *key = nl_attr_get(sa);
+            const struct ovs_key_ipv4 *mask = masked ?
+                get_mask(sa, struct ovs_key_ipv4) : NULL;
+            struct ovs_key_ipv4 consumed_mask;
+
+            if (masked) {
+                memcpy(&consumed_mask, mask, sizeof consumed_mask);
+            } else {
+                memset(&consumed_mask, 0, sizeof consumed_mask);
+            }
+
+            BUILD_ASSERT(sizeof(struct rte_flow_action_set_ipv4) ==
+                         sizeof key->ipv4_src);
+            if (add_set_flow_action(actions, &key->ipv4_src,
+                                    mask ? &mask->ipv4_src : NULL,
+                                    sizeof key->ipv4_src,
+                                    RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC)) {
+                return -1;
+            }
+            memset(&consumed_mask.ipv4_src, 0, sizeof consumed_mask.ipv4_src);
+
+            BUILD_ASSERT(sizeof(struct rte_flow_action_set_ipv4) ==
+                         sizeof key->ipv4_dst);
+            if (add_set_flow_action(actions, &key->ipv4_dst,
+                                    mask ? &mask->ipv4_dst : NULL,
+                                    sizeof key->ipv4_dst,
+                                    RTE_FLOW_ACTION_TYPE_SET_IPV4_DST)) {
+                return -1;
+            }
+            memset(&consumed_mask.ipv4_dst, 0, sizeof consumed_mask.ipv4_dst);
+
+            BUILD_ASSERT(sizeof(struct rte_flow_action_set_ttl) ==
+                         sizeof key->ipv4_ttl);
+            if (add_set_flow_action(actions, &key->ipv4_ttl,
+                                    mask ? &mask->ipv4_ttl : NULL,
+                                    sizeof key->ipv4_ttl,
+                                    RTE_FLOW_ACTION_TYPE_SET_TTL)) {
+                return -1;
+            }
+            memset(&consumed_mask.ipv4_ttl, 0, sizeof consumed_mask.ipv4_ttl);
+
+            if (!is_all_zeros(&consumed_mask, sizeof consumed_mask)) {
+                VLOG_DBG_RL(&error_rl, "Unsupported IPv4 set action");
+                return -1;
+            }
         } else {
             VLOG_DBG_RL(&error_rl,
                         "Unsupported set action type=%d", nl_attr_type(sa));