diff mbox series

[ovs-dev,1/6] netdev-offload-dpdk: Introduce a get_netdev_by_port helper function

Message ID 20210531064613.30636-2-noae@nvidia.com
State New
Headers show
Series Multiple destinations | expand

Commit Message

Noa Levy May 31, 2021, 6:46 a.m. UTC
Introduce a helper function to get the struct netdev * handle for the
target output odp_port, given in the netlink actions, as a pre-step
towards using it embedded in a sampled action.

Co-authored-by: Salem Sol <salems@nvidia.com>
Signed-off-by: Noa Levy <noae@nvidia.com>
Signed-off-by: Salem Sol <salems@nvidia.com>
---
 lib/netdev-offload-dpdk.c | 54 +++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/lib/netdev-offload-dpdk.c b/lib/netdev-offload-dpdk.c
index 503b6969f..d659f3a31 100644
--- a/lib/netdev-offload-dpdk.c
+++ b/lib/netdev-offload-dpdk.c
@@ -1339,21 +1339,44 @@  add_count_action(struct flow_actions *actions)
     add_flow_action(actions, RTE_FLOW_ACTION_TYPE_COUNT, count);
 }
 
-static int
+static void
 add_port_id_action(struct flow_actions *actions,
-                   struct netdev *outdev)
+                   int outdev_id)
 {
     struct rte_flow_action_port_id *port_id;
-    int outdev_id;
 
-    outdev_id = netdev_dpdk_get_port_id(outdev);
-    if (outdev_id < 0) {
-        return -1;
-    }
     port_id = xzalloc(sizeof *port_id);
     port_id->id = outdev_id;
     add_flow_action(actions, RTE_FLOW_ACTION_TYPE_PORT_ID, port_id);
-    return 0;
+}
+
+static int
+get_netdev_by_port(struct netdev *netdev,
+                   const struct nlattr *nla,
+                   int *outdev_id,
+                   struct netdev **outdev)
+{
+    odp_port_t port;
+
+    port = nl_attr_get_odp_port(nla);
+    *outdev = netdev_ports_get(port, netdev->dpif_type);
+    if (!*outdev) {
+        VLOG_DBG_RL(&rl, "Cannot find netdev for odp port %"PRIu32, port);
+        return -1;
+    }
+    if (!netdev_flow_api_equals(netdev, *outdev)) {
+        goto err;
+    }
+    *outdev_id = netdev_dpdk_get_port_id(*outdev);
+    if (*outdev_id < 0) {
+        goto err;
+    }
+     return 0;
+err:
+    VLOG_DBG_RL(&rl, "%s: Output to port \'%s\' cannot be offloaded.",
+                netdev_get_name(netdev), netdev_get_name(*outdev));
+    netdev_close(*outdev);
+    return -1;
 }
 
 static int
@@ -1362,21 +1385,14 @@  add_output_action(struct netdev *netdev,
                   const struct nlattr *nla)
 {
     struct netdev *outdev;
-    odp_port_t port;
+    int outdev_id;
     int ret = 0;
 
-    port = nl_attr_get_odp_port(nla);
-    outdev = netdev_ports_get(port, netdev->dpif_type);
-    if (outdev == NULL) {
-        VLOG_DBG_RL(&rl, "Cannot find netdev for odp port %"PRIu32, port);
+    if (get_netdev_by_port(netdev, nla, &outdev_id, &outdev)) {
         return -1;
     }
-    if (!netdev_flow_api_equals(netdev, outdev) ||
-        add_port_id_action(actions, outdev)) {
-        VLOG_DBG_RL(&rl, "%s: Output to port \'%s\' cannot be offloaded.",
-                    netdev_get_name(netdev), netdev_get_name(outdev));
-        ret = -1;
-    }
+    add_port_id_action(actions, outdev_id);
+
     netdev_close(outdev);
     return ret;
 }