Merge branch 'master' of git://openvswitch.org/openvswitch
[sliver-openvswitch.git] / lib / netdev.c
index ef1a6b9..2d6360b 100644 (file)
@@ -17,7 +17,6 @@
 #include <config.h>
 #include "netdev.h"
 
-#include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <netinet/in.h>
@@ -74,12 +73,13 @@ netdev_initialize(void)
         inited = true;
 
         fatal_signal_add_hook(close_all_netdevs, NULL, NULL, true);
+        netdev_vport_patch_register();
 
 #ifdef LINUX_DATAPATH
         netdev_register_provider(&netdev_linux_class);
         netdev_register_provider(&netdev_internal_class);
         netdev_register_provider(&netdev_tap_class);
-        netdev_vport_register();
+        netdev_vport_tunnel_register();
 #endif
 #ifdef __FreeBSD__
         netdev_register_provider(&netdev_tap_class);
@@ -230,7 +230,7 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp)
         if (error) {
             return error;
         }
-        assert(netdev_dev->netdev_class == class);
+        ovs_assert(netdev_dev->netdev_class == class);
 
     }
 
@@ -311,7 +311,7 @@ netdev_close(struct netdev *netdev)
     if (netdev) {
         struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
 
-        assert(netdev_dev->ref_cnt);
+        ovs_assert(netdev_dev->ref_cnt);
         netdev_dev->ref_cnt--;
         netdev_uninit(netdev, true);
 
@@ -322,35 +322,6 @@ netdev_close(struct netdev *netdev)
     }
 }
 
-/* Returns true if a network device named 'name' exists and may be opened,
- * otherwise false. */
-bool
-netdev_exists(const char *name)
-{
-    struct netdev *netdev;
-    int error;
-
-    error = netdev_open(name, "system", &netdev);
-    if (!error) {
-        netdev_close(netdev);
-        return true;
-    } else {
-        if (error != ENODEV) {
-            VLOG_WARN("failed to open network device %s: %s",
-                      name, strerror(error));
-        }
-        return false;
-    }
-}
-
-/* Returns true if a network device named 'name' is currently opened,
- * otherwise false. */
-bool
-netdev_is_open(const char *name)
-{
-    return !!shash_find_data(&netdev_dev_shash, name);
-}
-
 /* Parses 'netdev_name_', which is of the form [type@]name into its component
  * pieces.  'name' and 'type' must be freed by the caller. */
 void
@@ -406,8 +377,8 @@ netdev_recv(struct netdev *netdev, struct ofpbuf *buffer)
     int (*recv)(struct netdev *, void *, size_t);
     int retval;
 
-    assert(buffer->size == 0);
-    assert(ofpbuf_tailroom(buffer) >= ETH_TOTAL_MIN);
+    ovs_assert(buffer->size == 0);
+    ovs_assert(ofpbuf_tailroom(buffer) >= ETH_TOTAL_MIN);
 
     recv = netdev_get_dev(netdev)->netdev_class->recv;
     retval = (recv
@@ -1318,7 +1289,7 @@ void
 netdev_dev_init(struct netdev_dev *netdev_dev, const char *name,
                 const struct netdev_class *netdev_class)
 {
-    assert(!shash_find(&netdev_dev_shash, name));
+    ovs_assert(!shash_find(&netdev_dev_shash, name));
 
     memset(netdev_dev, 0, sizeof *netdev_dev);
     netdev_dev->netdev_class = netdev_class;
@@ -1338,7 +1309,7 @@ netdev_dev_uninit(struct netdev_dev *netdev_dev, bool destroy)
 {
     char *name = netdev_dev->name;
 
-    assert(!netdev_dev->ref_cnt);
+    ovs_assert(!netdev_dev->ref_cnt);
 
     shash_delete(&netdev_dev_shash, netdev_dev->node);
 
@@ -1444,6 +1415,14 @@ netdev_get_type(const struct netdev *netdev)
     return netdev_get_dev(netdev)->netdev_class->type;
 }
 
+
+const char *
+netdev_get_type_from_name(const char *name)
+{
+    const struct netdev_dev *dev = netdev_dev_from_name(name);
+    return dev ? netdev_dev_get_type(dev) : NULL;
+}
+
 struct netdev_dev *
 netdev_get_dev(const struct netdev *netdev)
 {