[ovs-discuss] [PATCH 16/20] netdev: Make netdev_get_vlan_vid() take a netdev instead of a name.

Ben Pfaff blp at nicira.com
Fri Jul 24 21:19:59 UTC 2009


For consistency, it's best if every netdev function takes a netdev instead
of a device name.  The netdev_nodev_*() functions have always been a bit
ugly.
---
 lib/netdev.c      |   14 +++++++-------
 lib/netdev.h      |    2 +-
 vswitchd/bridge.c |    3 +--
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/lib/netdev.c b/lib/netdev.c
index a36ab97..79a6820 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1379,13 +1379,13 @@ netdev_nodev_get_etheraddr(const char *netdev_name, uint8_t mac[6])
     return get_etheraddr(netdev_name, mac, NULL);
 }
 
-/* If 'netdev_name' is the name of a VLAN network device (e.g. one created with
- * vconfig(8)), sets '*vlan_vid' to the VLAN VID associated with that device
- * and returns 0.  Otherwise returns a errno value (specifically ENOENT if
- * 'netdev_name' is the name of a network device that is not a VLAN device) and
- * sets '*vlan_vid' to -1. */
+/* If 'netdev' is a VLAN network device (e.g. one created with vconfig(8)),
+ * sets '*vlan_vid' to the VLAN VID associated with that device and returns 0.
+ * Otherwise returns a errno value (specifically ENOENT if 'netdev_name' is the
+ * name of a network device that is not a VLAN device) and sets '*vlan_vid' to
+ * -1. */
 int
-netdev_get_vlan_vid(const char *netdev_name, int *vlan_vid)
+netdev_get_vlan_vid(const struct netdev *netdev, int *vlan_vid)
 {
     struct ds line = DS_EMPTY_INITIALIZER;
     FILE *stream = NULL;
@@ -1393,7 +1393,7 @@ netdev_get_vlan_vid(const char *netdev_name, int *vlan_vid)
     char *fn;
 
     COVERAGE_INC(netdev_get_vlan_vid);
-    fn = xasprintf("/proc/net/vlan/%s", netdev_name);
+    fn = xasprintf("/proc/net/vlan/%s", netdev_get_name(netdev));
     stream = fopen(fn, "r");
     if (!stream) {
         error = errno;
diff --git a/lib/netdev.h b/lib/netdev.h
index 2ac0f2e..b6330e7 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -119,7 +119,7 @@ int netdev_nodev_arp_lookup(const char *netdev_name, uint32_t ip,
                             uint8_t mac[6]);
 int netdev_nodev_get_carrier(const char *netdev_name, bool *carrier);
 
-int netdev_get_vlan_vid(const char *netdev_name, int *vlan_vid);
+int netdev_get_vlan_vid(const struct netdev *, int *vlan_vid);
 
 struct netdev_monitor;
 int netdev_monitor_create(struct netdev_monitor **);
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 88cffed..d7637c6 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -715,8 +715,7 @@ bridge_pick_datapath_id(struct bridge *br,
 
     if (hw_addr_iface) {
         int vlan;
-        if (!netdev_get_vlan_vid(netdev_get_name(hw_addr_iface->netdev),
-                                 &vlan)) {
+        if (!netdev_get_vlan_vid(hw_addr_iface->netdev, &vlan)) {
             /*
              * A bridge whose MAC address is taken from a VLAN network device
              * (that is, a network device created with vconfig(8) or similar
-- 
1.6.3.3





More information about the discuss mailing list