[ovs-dev,ovs,V4,16/24] dpif-netlink: Use netdev flow get api to query a flow

Submitted by Roi Dayan on March 13, 2017, 1:37 p.m.

Details

Message ID 1489412234-30916-17-git-send-email-roid@mellanox.com
State Superseded
Headers show

Commit Message

Roi Dayan March 13, 2017, 1:37 p.m.
From: Paul Blakey <paulb@mellanox.com>

Search all datapath added netdevs for a given flow
using netdev flow api and parse it back to dpif flow.

Signed-off-by: Paul Blakey <paulb@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
---
 lib/dpif-netlink.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/netdev.c       |   16 ++++++++++++++++
 lib/netdev.h       |    4 ++++
 3 files changed, 69 insertions(+), 1 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 1964c42..6157484 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -1921,6 +1921,45 @@  dpif_netlink_operate__(struct dpif_netlink *dpif,
 }
 
 static int
+parse_flow_get(struct dpif_netlink *dpif, struct dpif_flow_get *get)
+{
+    struct dpif_flow *dpif_flow = get->flow;
+    struct match match;
+    struct nlattr *actions;
+    struct dpif_flow_stats stats;
+    struct ofpbuf buf;
+    uint64_t act_buf[1024 / 8];
+    struct odputil_keybuf maskbuf;
+    struct odputil_keybuf keybuf;
+    struct odputil_keybuf actbuf;
+    struct ofpbuf key, mask, act;
+    int err;
+
+    ofpbuf_use_stack(&buf, &act_buf, sizeof act_buf);
+    err = netdev_ports_flow_get(DPIF_HMAP_KEY(&dpif->dpif), &match,
+                                &actions, &stats, get->ufid, &buf);
+    if (err) {
+        return err;
+    }
+
+    VLOG_DBG("found flow from netdev, translating to dpif flow");
+
+    ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
+    ofpbuf_use_stack(&act, &actbuf, sizeof actbuf);
+    ofpbuf_use_stack(&mask, &maskbuf, sizeof maskbuf);
+    dpif_netlink_netdev_match_to_dpif_flow(&match, &key, &mask, actions,
+                                           &stats,
+                                           (ovs_u128 *) get->ufid,
+                                           dpif_flow,
+                                           false);
+    ofpbuf_put(get->buffer, nl_attr_get(actions), nl_attr_get_size(actions));
+    dpif_flow->actions = ofpbuf_at(get->buffer, 0, 0);
+    dpif_flow->actions_len = nl_attr_get_size(actions);
+
+    return 0;
+}
+
+static int
 parse_flow_put(struct dpif_netlink *dpif, struct dpif_flow_put *put)
 {
     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
@@ -2087,7 +2126,16 @@  try_send_to_netdev(struct dpif_netlink *dpif, struct dpif_op *op)
         return netdev_ports_flow_del(DPIF_HMAP_KEY(&dpif->dpif), del->ufid,
                                      del->stats);
     }
-    case DPIF_OP_FLOW_GET:
+    case DPIF_OP_FLOW_GET: {
+        struct dpif_flow_get *get = &op->u.flow_get;
+
+        if (!op->u.flow_get.ufid) {
+            break;
+        }
+        dbg_print_flow(get->key, get->key_len, NULL, 0, NULL, 0,
+                       get->ufid, "GET");
+        return parse_flow_get(dpif, get);
+    }
     case DPIF_OP_EXECUTE:
     default:
         break;
diff --git a/lib/netdev.c b/lib/netdev.c
index 5eb4dd0..e7d74ca 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -2284,6 +2284,22 @@  netdev_ports_flow_del(const void *obj, const ovs_u128 *ufid,
     return ENOENT;
 }
 
+int
+netdev_ports_flow_get(const void *obj, struct match *match,
+                      struct nlattr **actions, struct dpif_flow_stats *stats,
+                      const ovs_u128 *ufid, struct ofpbuf *buf)
+{
+    struct port_to_netdev_data *data;
+
+    HMAP_FOR_EACH(data, node, &port_to_netdev) {
+        if (data->obj == obj && !netdev_flow_get(data->netdev, match, actions,
+                                                 stats, ufid, buf)) {
+            return 0;
+        }
+    }
+    return ENOENT;
+}
+
 bool netdev_flow_api_enabled = false;
 
 #ifdef __linux__
diff --git a/lib/netdev.h b/lib/netdev.h
index ee8c401..00cbbdf 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -190,6 +190,10 @@  struct netdev_flow_dump **netdev_ports_flow_dumps_create(const void *obj,
 void netdev_ports_flow_flush(const void *obj);
 int netdev_ports_flow_del(const void *obj, const ovs_u128 *ufid,
                           struct dpif_flow_stats *stats);
+int netdev_ports_flow_get(const void *obj, struct match *match,
+                          struct nlattr **actions,
+                          struct dpif_flow_stats *stats,
+                          const ovs_u128 *ufid, struct ofpbuf *buf);
 odp_port_t netdev_hmap_port_get_byifidx(int ifindex);
 
 /* native tunnel APIs */