[ovs-dev] [PATCH 5/5] Remove netdev_find_dev_by_in4

Simon Horman horms at verge.net.au
Thu Sep 22 12:24:14 UTC 2011


netdev_find_dev_by_in4() appears to no longer be used and thus
can be removed. This also allows netdev_enumerate(), the
enumerate member of struct netdev_class and netdev_linux_enumerate()
to be removed.

I noticed this as netdev_linux_enumerate() makes use of if_nameindex()
and if_freenameindex() which are not available when compiling using
the Android NDK r6b (Android API level 13).
---
 lib/netdev-dummy.c    |    2 -
 lib/netdev-linux.c    |   29 +-------------------------
 lib/netdev-provider.h |   10 ---------
 lib/netdev-vport.c    |    2 -
 lib/netdev.c          |   54 -------------------------------------------------
 lib/netdev.h          |    2 -
 6 files changed, 1 insertions(+), 98 deletions(-)

diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index c2c5311..7c30180 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -256,8 +256,6 @@ static const struct netdev_class dummy_class = {
     netdev_dummy_open,
     netdev_dummy_close,
 
-    NULL,                       /* enumerate */
-
     netdev_dummy_listen,        /* listen */
     netdev_dummy_recv,          /* recv */
     NULL,                       /* recv_wait */
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 85fcdf9..5bdb963 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -694,28 +694,6 @@ netdev_linux_close(struct netdev *netdev_)
     free(netdev);
 }
 
-/* Initializes 'sset' with a list of the names of all known network devices. */
-static int
-netdev_linux_enumerate(struct sset *sset)
-{
-    struct if_nameindex *names;
-
-    names = if_nameindex();
-    if (names) {
-        size_t i;
-
-        for (i = 0; names[i].if_name != NULL; i++) {
-            sset_add(sset, names[i].if_name);
-        }
-        if_freenameindex(names);
-        return 0;
-    } else {
-        VLOG_WARN("could not obtain list of network device names: %s",
-                  strerror(errno));
-        return errno;
-    }
-}
-
 static int
 netdev_linux_listen(struct netdev *netdev_)
 {
@@ -2340,7 +2318,7 @@ netdev_linux_change_seq(const struct netdev *netdev)
     return netdev_dev_linux_cast(netdev_get_dev(netdev))->change_seq;
 }
 
-#define NETDEV_LINUX_CLASS(NAME, CREATE, ENUMERATE, GET_STATS, SET_STATS)  \
+#define NETDEV_LINUX_CLASS(NAME, CREATE, GET_STATS, SET_STATS)  \
 {                                                               \
     NAME,                                                       \
                                                                 \
@@ -2356,8 +2334,6 @@ netdev_linux_change_seq(const struct netdev *netdev)
     netdev_linux_open,                                          \
     netdev_linux_close,                                         \
                                                                 \
-    ENUMERATE,                                                  \
-                                                                \
     netdev_linux_listen,                                        \
     netdev_linux_recv,                                          \
     netdev_linux_recv_wait,                                     \
@@ -2409,7 +2385,6 @@ const struct netdev_class netdev_linux_class =
     NETDEV_LINUX_CLASS(
         "system",
         netdev_linux_create,
-        netdev_linux_enumerate,
         netdev_linux_get_stats,
         NULL);                  /* set_stats */
 
@@ -2417,7 +2392,6 @@ const struct netdev_class netdev_tap_class =
     NETDEV_LINUX_CLASS(
         "tap",
         netdev_linux_create_tap,
-        NULL,                   /* enumerate */
         netdev_pseudo_get_stats,
         NULL);                  /* set_stats */
 
@@ -2425,7 +2399,6 @@ const struct netdev_class netdev_internal_class =
     NETDEV_LINUX_CLASS(
         "internal",
         netdev_linux_create,
-        NULL,                    /* enumerate */
         netdev_pseudo_get_stats,
         netdev_vport_set_stats);
 
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 22b00f7..0631229 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -144,16 +144,6 @@ struct netdev_class {
 
     /* Closes 'netdev'. */
     void (*close)(struct netdev *netdev);
-
-    /* Enumerates the names of all network devices of this class.
-     *
-     * The caller has already initialized 'all_names' and might already have
-     * added some names to it.  This function should not disturb any existing
-     * names in 'all_names'.
-     *
-     * If this netdev class does not support enumeration, this may be a null
-     * pointer. */
-    int (*enumerate)(struct sset *all_names);
 
 /* ## ----------------- ## */
 /* ## Receiving Packets ## */
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index d85d528..06ec8fb 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -885,8 +885,6 @@ unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
     netdev_vport_open,                                      \
     netdev_vport_close,                                     \
                                                             \
-    NULL,                       /* enumerate */             \
-                                                            \
     NULL,                       /* listen */                \
     NULL,                       /* recv */                  \
     NULL,                       /* recv_wait */             \
diff --git a/lib/netdev.c b/lib/netdev.c
index 1a668c8..70f9678 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -332,33 +332,6 @@ netdev_is_open(const char *name)
     return !!shash_find_data(&netdev_dev_shash, name);
 }
 
-/*  Clears 'sset' and enumerates the names of all known network devices. */
-int
-netdev_enumerate(struct sset *sset)
-{
-    struct shash_node *node;
-    int error = 0;
-
-    netdev_initialize();
-    sset_clear(sset);
-
-    SHASH_FOR_EACH(node, &netdev_classes) {
-        const struct netdev_class *netdev_class = node->data;
-        if (netdev_class->enumerate) {
-            int retval = netdev_class->enumerate(sset);
-            if (retval) {
-                VLOG_WARN("failed to enumerate %s network devices: %s",
-                          netdev_class->type, strerror(retval));
-                if (!error) {
-                    error = retval;
-                }
-            }
-        }
-    }
-
-    return error;
-}
-
 /* Parses 'netdev_name_', which is of the form [type@]name into its component
  * pieces.  'name' and 'type' must be freed by the caller. */
 void
@@ -1286,33 +1259,6 @@ netdev_get_vlan_vid(const struct netdev *netdev, int *vlan_vid)
     }
     return error;
 }
-
-/* Returns a network device that has 'in4' as its IP address, if one exists,
- * otherwise a null pointer. */
-struct netdev *
-netdev_find_dev_by_in4(const struct in_addr *in4)
-{
-    struct netdev *netdev;
-    struct sset dev_list = SSET_INITIALIZER(&dev_list);
-    const char *name;
-
-    netdev_enumerate(&dev_list);
-    SSET_FOR_EACH (name, &dev_list) {
-        struct in_addr dev_in4;
-
-        if (!netdev_open(name, "system", &netdev)
-            && !netdev_get_in4(netdev, &dev_in4, NULL)
-            && dev_in4.s_addr == in4->s_addr) {
-            goto exit;
-        }
-        netdev_close(netdev);
-    }
-    netdev = NULL;
-
-exit:
-    sset_destroy(&dev_list);
-    return netdev;
-}
 
 /* Initializes 'netdev_dev' as a netdev device named 'name' of the specified
  * 'netdev_class'.  This function is ordinarily called from a netdev provider's
diff --git a/lib/netdev.h b/lib/netdev.h
index 11b6925..f9add0b 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -90,8 +90,6 @@ void netdev_close(struct netdev *);
 bool netdev_exists(const char *name);
 bool netdev_is_open(const char *name);
 
-int netdev_enumerate(struct sset *);
-
 void netdev_parse_name(const char *netdev_name, char **name, char **type);
 
 /* Options. */
-- 
1.7.5.4




More information about the dev mailing list