Currently peer port is defined as a patch port property. However, peer
ports can be used as generic netdevice property to accelerate peer ports
forwarding. Introduce a generic method for retreiving peer port name.

Signed-off-by: Eli Britstein <[email protected]>
Reviewed-by: Oz Shlomo <[email protected]>
---
 lib/netdev-provider.h |  6 ++++++
 lib/netdev.c          | 13 +++++++++++++
 lib/netdev.h          |  1 +
 3 files changed, 20 insertions(+)

diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index fb0c27e6e..967760fb3 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -775,6 +775,12 @@ struct netdev_class {
      * used to send and receive packets until a successful configuration is
      * applied. */
     int (*reconfigure)(struct netdev *netdev);
+
+    /* If the netdev class of 'netdev' supports peer option, returns the name
+     * of its peer as a malloc()'d string that the caller must free.
+     *
+     * If peer is not supported, returns NULL. */
+    char *(*get_peer_name)(const struct netdev *netdev);
 /* ## -------------------- ## */
 /* ## netdev_rxq Functions ## */
 /* ## -------------------- ## */
diff --git a/lib/netdev.c b/lib/netdev.c
index 7d7ecf6f0..c6b9c7e96 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -913,6 +913,19 @@ netdev_get_name(const struct netdev *netdev)
     return netdev->name;
 }
 
+char *
+netdev_get_peer_name(const struct netdev *netdev)
+{
+    const struct netdev_class *class = netdev->netdev_class;
+    char *peer = NULL;
+
+    if (class->get_peer_name) {
+        peer = class->get_peer_name(netdev);
+    }
+
+    return peer;
+}
+
 /* Retrieves the MTU of 'netdev'.  The MTU is the maximum size of transmitted
  * (and received) packets, in bytes, not including the hardware header; thus,
  * this is typically 1500 bytes for Ethernet devices.
diff --git a/lib/netdev.h b/lib/netdev.h
index d94817fb6..d65b1ffcf 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -170,6 +170,7 @@ int netdev_get_numa_id(const struct netdev *);
 
 /* Basic properties. */
 const char *netdev_get_name(const struct netdev *);
+char *netdev_get_peer_name(const struct netdev *);
 const char *netdev_get_type(const struct netdev *);
 const char *netdev_get_type_from_name(const char *);
 int netdev_get_mtu(const struct netdev *, int *mtup);
-- 
2.17.2

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

Reply via email to