X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fnetdev.c;h=2d6360b58c6a697a5ef8892448e65e814bc8034d;hb=7fa0f73fb284b4406bcd085ee62552891b3fa6cd;hp=057a7264101a70ad328e9c78ff23ef1b91d27c43;hpb=f431bf7d78f3212d32bb3d122f783c5c796a1576;p=sliver-openvswitch.git diff --git a/lib/netdev.c b/lib/netdev.c index 057a72641..2d6360b58 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -17,7 +17,6 @@ #include #include "netdev.h" -#include #include #include #include @@ -74,17 +73,20 @@ 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); netdev_register_provider(&netdev_bsd_class); #endif + netdev_register_provider(&netdev_tunnel_class); + netdev_register_provider(&netdev_pltap_class); } } @@ -228,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); } @@ -309,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); @@ -320,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 @@ -404,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 @@ -1316,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; @@ -1336,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); @@ -1442,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) {