This will be used in an upcoming commit, and allows the
vswitchd reconfiguration to set socket lookup on an
interface rather than port level.

Signed-off-by: Aaron Conole <[email protected]>
---
 lib/netdev-linux-private.h |  1 +
 lib/netdev-linux.c         | 28 ++++++++++++++++++++++++++++
 lib/netdev-provider.h      | 13 +++++++++++++
 lib/netdev.c               | 19 +++++++++++++++++++
 lib/netdev.h               |  2 ++
 5 files changed, 63 insertions(+)

diff --git a/lib/netdev-linux-private.h b/lib/netdev-linux-private.h
index 8e572e3b3b..ade8f36122 100644
--- a/lib/netdev-linux-private.h
+++ b/lib/netdev-linux-private.h
@@ -69,6 +69,7 @@ struct netdev_linux {
     struct timer miimon_timer;
 
     int netnsid;                    /* Network namespace ID. */
+    bool socket_lookup_enabled;    /* Socket lookup functionality enabled. */
     /* The following are figured out "on demand" only.  They are only valid
      * when the corresponding VALID_* bit in 'cache_valid' is set. */
     int ifindex;
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index ec28b14e43..e6547f4f50 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -957,6 +957,7 @@ netdev_linux_common_construct(struct netdev *netdev_)
 
     /* The device could be in the same network namespace or in another one. */
     netnsid_unset(&netdev->netnsid);
+    netdev->socket_lookup_enabled = false;
     ovs_mutex_init(&netdev->mutex);
 
     return 0;
@@ -4045,6 +4046,31 @@ out:
     return error;
 }
 
+static int
+netdev_linux_set_socket_lookup_enabled(struct netdev *netdev_, bool enabled)
+{
+    struct netdev_linux *netdev = netdev_linux_cast(netdev_);
+
+    ovs_mutex_lock(&netdev->mutex);
+    netdev->socket_lookup_enabled = enabled;
+    ovs_mutex_unlock(&netdev->mutex);
+
+    return 0;
+}
+
+static bool
+netdev_linux_get_socket_lookup_enabled(const struct netdev *netdev_)
+{
+    struct netdev_linux *netdev = netdev_linux_cast(netdev_);
+    bool enabled;
+
+    ovs_mutex_lock(&netdev->mutex);
+    enabled = netdev->socket_lookup_enabled;
+    ovs_mutex_unlock(&netdev->mutex);
+
+    return enabled;
+}
+
 static unsigned int
 nd_to_iff_flags(enum netdev_flags nd)
 {
@@ -4159,6 +4185,8 @@ exit:
     .get_next_hop = netdev_linux_get_next_hop,                  \
     .arp_lookup = netdev_linux_arp_lookup,                      \
     .get_target_ns = netdev_linux_get_target_ns,                \
+    .set_socket_lookup_enabled = netdev_linux_set_socket_lookup_enabled, \
+    .get_socket_lookup_enabled = netdev_linux_get_socket_lookup_enabled, \
     .get_socket_inode = netdev_linux_get_socket_inode,          \
     .update_flags = netdev_linux_update_flags,                  \
     .rxq_alloc = netdev_linux_rxq_alloc,                        \
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 914f0819a0..0d5d603d69 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -784,6 +784,19 @@ struct netdev_class {
      * anyhow. */
     int (*get_target_ns)(const struct netdev *netdev, int *target_ns);
 
+    /* Enables or disables socket lookup functionality for 'netdev'.
+     * When enabled, allows socket inode lookups via get_socket_inode.
+     *
+     * This function may be set to null if it would always return EOPNOTSUPP
+     * anyhow. */
+    int (*set_socket_lookup_enabled)(struct netdev *netdev, bool enabled);
+
+    /* Returns whether socket lookup functionality is enabled for 'netdev'.
+     * Returns false if socket lookup is not supported or disabled.
+     *
+     * This function may be set to null, in which case it defaults to false. */
+    bool (*get_socket_lookup_enabled)(const struct netdev *netdev);
+
     /* Retreives a socket inode from the target netns for 'netdev'.  On
      * success, stores the socket inode detail in the 'inode_out' variable.
      * Uses 'af' to determine 'src'/'dst' size.
diff --git a/lib/netdev.c b/lib/netdev.c
index 758354f2e7..4b633592b4 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1674,6 +1674,25 @@ netdev_get_target_ns(const struct netdev *netdev, int 
*target_ns)
             : EOPNOTSUPP);
 }
 
+/* Enables or disables socket lookup functionality for 'netdev'. */
+int
+netdev_set_socket_lookup_enabled(struct netdev *netdev, bool enabled)
+{
+    return (netdev->netdev_class->set_socket_lookup_enabled
+            ? netdev->netdev_class->set_socket_lookup_enabled(netdev, enabled)
+            : EOPNOTSUPP);
+}
+
+/* Returns whether socket lookup functionality is enabled for 'netdev'.
+ * Returns false if socket lookup is not supported or disabled. */
+bool
+netdev_get_socket_lookup_enabled(const struct netdev *netdev)
+{
+    return (netdev->netdev_class->get_socket_lookup_enabled
+            ? netdev->netdev_class->get_socket_lookup_enabled(netdev)
+            : false);
+}
+
 /* Retreives a socket inode from the target netns for 'netdev'.  On
  * success, stores the socket inode detail in the 'inode_out' variable.
  * Uses 'af' to determine 'src'/'dst' size. */
diff --git a/lib/netdev.h b/lib/netdev.h
index ed85889796..ff047d8923 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -302,6 +302,8 @@ int netdev_arp_lookup(const struct netdev *, ovs_be32 ip,
 
 int netdev_get_target_ns(const struct netdev *, int *target_ns);
 
+int netdev_set_socket_lookup_enabled(struct netdev *, bool enabled);
+bool netdev_get_socket_lookup_enabled(const struct netdev *);
 int netdev_get_socket_inode(const struct netdev *, int proto, int af,
                             const void *src, ovs_be16 sport,
                             const void *dst, ovs_be16 dport,
-- 
2.51.0

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

Reply via email to