A future commit will enable the flow programming portion.

This may be slightly 'out-of-order' since we advertise the
feature without implementing it.  I did it this way to
at least make it easier to separate the feature test for
critique rather than squashing it.

Signed-off-by: Aaron Conole <[email protected]>
---
 ofproto/ofproto-dpif.c | 40 ++++++++++++++++++++++++++++++++++++++++
 ofproto/ofproto-dpif.h |  5 ++++-
 vswitchd/vswitch.xml   |  7 +++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index ed9e44ce2b..80726f88e5 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1655,6 +1655,45 @@ check_psample(struct dpif_backer *backer)
     return supported;
 }
 
+/* Tests whether 'backer''s datapath supports the
+ * OVS_ACTION_ATTR_SOCKET action. */
+static bool
+check_socket_action(struct dpif_backer *backer)
+{
+    struct odputil_keybuf keybuf;
+    struct ofpbuf actions;
+    struct ofpbuf key;
+    struct flow flow;
+    bool supported;
+
+    struct odp_flow_key_parms odp_parms = {
+        .flow = &flow,
+        .probe = true,
+    };
+
+    memset(&flow, 0, sizeof flow);
+    ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
+    odp_flow_key_from_flow(&odp_parms, &key);
+    ofpbuf_init(&actions, 64);
+    size_t sock_start;
+
+    sock_start = nl_msg_start_nested(&actions, OVS_ACTION_ATTR_SOCKET);
+    /* -1 as the netns ID and inode */
+    nl_msg_put_u32(&actions, OVS_SOCKET_ACTION_ATTR_NETNS_ID, 0xffffffff);
+    nl_msg_put_u64(&actions, OVS_SOCKET_ACTION_ATTR_INODE, ~0ULL);
+
+    nl_msg_put_flag(&actions, OVS_SOCKET_ACTION_ATTR_ACTIONS);
+    nl_msg_end_nested(&actions, sock_start);
+
+    supported = dpif_probe_feature(backer->dpif, "socket_action", &key,
+                                   &actions, NULL);
+    ofpbuf_uninit(&actions);
+    VLOG_INFO("%s: Datapath %s socket_action action",
+              dpif_name(backer->dpif), supported ? "supports"
+              : "does not support");
+    return supported;
+}
+
 #define CHECK_FEATURE__(NAME, SUPPORT, FIELD, VALUE, ETHTYPE)               \
 static bool                                                                 \
 check_##NAME(struct dpif_backer *backer)                                    \
@@ -1745,6 +1784,7 @@ check_support(struct dpif_backer *backer)
     backer->rt_support.ct_zero_snat = dpif_supports_ct_zero_snat(backer);
     backer->rt_support.add_mpls = check_add_mpls(backer);
     backer->rt_support.psample = check_psample(backer);
+    backer->rt_support.socket = check_socket_action(backer);
 
     /* Flow fields. */
     backer->rt_support.odp.ct_state = check_ct_state(backer);
diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h
index f8d3df5ab5..dc0b8bb237 100644
--- a/ofproto/ofproto-dpif.h
+++ b/ofproto/ofproto-dpif.h
@@ -216,7 +216,10 @@ struct group_dpif *group_dpif_lookup(struct ofproto_dpif *,
     DPIF_SUPPORT_FIELD(bool, add_mpls, "MPLS Label add")                    \
                                                                             \
     /* True if the datapath supports psample action. */                     \
-    DPIF_SUPPORT_FIELD(bool, psample, "psample action")
+    DPIF_SUPPORT_FIELD(bool, psample, "psample action")                     \
+                                                                            \
+    /* True if the datapath supports OVS_ACTION_ATTR_SOCKET. */             \
+    DPIF_SUPPORT_FIELD(bool, socket, "socket action")
 
 
 /* Stores the various features which the corresponding backer supports. */
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 3dcf744027..67de33faae 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -6523,6 +6523,13 @@ ovs-vsctl add-port br0 p0 -- set Interface p0 type=patch 
options:peer=p1 \
         True if the datapath supports OVS_ACTION_ATTR_PSAMPLE.  If false,
         local sampling will not be supported with the Linux kernel datapath.
       </column>
+      <column name="capabilities" key="socket_action"
+              type='{"type": "boolean"}'>
+        True if the datapath supports OVS_ACTION_ATTR_SOCKET.  If true,
+        Open vSwitch will attempt to use the <code>socket</code> action
+        when sending packets through the Open vSwitch datapath, which will
+        shortcut datapath flows.
+      </column>
     </group>
 
     <column name="ct_zone_default_limit">
-- 
2.51.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to