[ovs-dev] [sFlow 3/7] netdev: New function netdev_get_ifindex().

Ben Pfaff blp at nicira.com
Thu Nov 19 21:48:59 UTC 2009


sFlow needs the ifindex of an interface, so this commit adds a function
to retrieve it.
---
 lib/netdev-linux.c    |   13 +++++++++++++
 lib/netdev-provider.h |    4 ++++
 lib/netdev.c          |    8 ++++++++
 lib/netdev.h          |    1 +
 4 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 7324703..6eaf8df 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -548,6 +548,17 @@ netdev_linux_get_mtu(const struct netdev *netdev_, int *mtup)
     return 0;
 }
 
+/* Returns the ifindex of 'netdev', if successful, as a positive number.
+ * On failure, returns a negative errno value. */
+static int
+netdev_linux_get_ifindex(const struct netdev *netdev)
+{
+    int ifindex, error;
+
+    error = get_ifindex(netdev, &ifindex);
+    return error ? -error : ifindex;
+}
+
 static int
 netdev_linux_get_carrier(const struct netdev *netdev_, bool *carrier)
 {
@@ -1389,6 +1400,7 @@ const struct netdev_class netdev_linux_class = {
     netdev_linux_set_etheraddr,
     netdev_linux_get_etheraddr,
     netdev_linux_get_mtu,
+    netdev_linux_get_ifindex,
     netdev_linux_get_carrier,
     netdev_linux_get_stats,
 
@@ -1433,6 +1445,7 @@ const struct netdev_class netdev_tap_class = {
     netdev_linux_set_etheraddr,
     netdev_linux_get_etheraddr,
     netdev_linux_get_mtu,
+    netdev_linux_get_ifindex,
     netdev_linux_get_carrier,
     netdev_linux_get_stats,
 
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 3bc7fd4..1827b54 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -164,6 +164,10 @@ struct netdev_class {
      * bytes for Ethernet devices.*/
     int (*get_mtu)(const struct netdev *, int *mtup);
 
+    /* Returns the ifindex of 'netdev', if successful, as a positive number.
+     * On failure, returns a negative errno value. */
+    int (*get_ifindex)(const struct netdev *);
+
     /* Sets 'carrier' to true if carrier is active (link light is on) on
      * 'netdev'. */
     int (*get_carrier)(const struct netdev *netdev, bool *carrier);
diff --git a/lib/netdev.c b/lib/netdev.c
index 481671f..18c9a97 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -366,6 +366,14 @@ netdev_get_mtu(const struct netdev *netdev, int *mtup)
     return error;
 }
 
+/* Returns the ifindex of 'netdev', if successful, as a positive number.  On
+ * failure, returns a negative errno value. */
+int
+netdev_get_ifindex(const struct netdev *netdev)
+{
+    return netdev->class->get_ifindex(netdev);
+}
+
 /* Stores the features supported by 'netdev' into each of '*current',
  * '*advertised', '*supported', and '*peer' that are non-null.  Each value is a
  * bitmap of "enum ofp_port_features" bits, in host byte order.  Returns 0 if
diff --git a/lib/netdev.h b/lib/netdev.h
index 4a29cf3..b87d5b9 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -90,6 +90,7 @@ int netdev_enumerate(struct svec *);
 
 const char *netdev_get_name(const struct netdev *);
 int netdev_get_mtu(const struct netdev *, int *mtup);
+int netdev_get_ifindex(const struct netdev *);
 
 int netdev_recv(struct netdev *, struct ofpbuf *);
 void netdev_recv_wait(struct netdev *);
-- 
1.6.3.3





More information about the dev mailing list