X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fnetdev.c;h=434e2572e083b27fe51227d25808a8ed3e23e828;hb=112b76f6b96d1e796be17522ec765cccc99cbc07;hp=394d8957f2488b3640be292c7a219066234e9cf3;hpb=ebc56baa41db060b8783051e67b6fcbc148ebd60;p=sliver-openvswitch.git diff --git a/lib/netdev.c b/lib/netdev.c index 394d8957f..434e2572e 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ #include #include "netdev.h" -#include #include #include #include @@ -74,12 +73,13 @@ netdev_initialize(void) inited = true; fatal_signal_add_hook(close_all_netdevs, NULL, NULL, true); + netdev_vport_patch_register(); -#ifdef HAVE_NETLINK +#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); @@ -228,7 +228,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); } @@ -290,6 +290,18 @@ netdev_get_config(const struct netdev *netdev, struct smap *args) return error; } +const struct netdev_tunnel_config * +netdev_get_tunnel_config(const struct netdev *netdev) +{ + struct netdev_dev *netdev_dev = netdev_get_dev(netdev); + + if (netdev_dev->netdev_class->get_tunnel_config) { + return netdev_dev->netdev_class->get_tunnel_config(netdev_dev); + } else { + return NULL; + } +} + /* Closes and destroys 'netdev'. */ void netdev_close(struct netdev *netdev) @@ -297,7 +309,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); @@ -308,35 +320,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 @@ -392,8 +375,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 @@ -620,9 +603,10 @@ netdev_get_features(const struct netdev *netdev, /* Returns the maximum speed of a network connection that has the NETDEV_F_* * bits in 'features', in bits per second. If no bits that indicate a speed - * are set in 'features', assumes 100Mbps. */ + * are set in 'features', returns 'default_bps'. */ uint64_t -netdev_features_to_bps(enum netdev_features features) +netdev_features_to_bps(enum netdev_features features, + uint64_t default_bps) { enum { F_1000000MB = NETDEV_F_1TB_FD, @@ -641,7 +625,7 @@ netdev_features_to_bps(enum netdev_features features) : features & F_1000MB ? UINT64_C(1000000000) : features & F_100MB ? UINT64_C(100000000) : features & F_10MB ? UINT64_C(10000000) - : UINT64_C(100000000)); + : default_bps); } /* Returns true if any of the NETDEV_F_* bits that indicate a full-duplex link @@ -770,12 +754,12 @@ netdev_get_next_hop(const struct netdev *netdev, * information may be used to populate the status column of the Interface table * as defined in ovs-vswitchd.conf.db(5). */ int -netdev_get_drv_info(const struct netdev *netdev, struct smap *smap) +netdev_get_status(const struct netdev *netdev, struct smap *smap) { struct netdev_dev *dev = netdev_get_dev(netdev); - return (dev->netdev_class->get_drv_info - ? dev->netdev_class->get_drv_info(netdev, smap) + return (dev->netdev_class->get_status + ? dev->netdev_class->get_status(netdev, smap) : EOPNOTSUPP); } @@ -1131,7 +1115,7 @@ netdev_set_qos(struct netdev *netdev, if (class->set_qos) { if (!details) { - static struct smap empty = SMAP_INITIALIZER(&empty); + static const struct smap empty = SMAP_INITIALIZER(&empty); details = ∅ } return class->set_qos(netdev, type, details); @@ -1303,7 +1287,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; @@ -1323,7 +1307,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); @@ -1429,6 +1413,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) {