X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fnetdev.c;h=e77fcdfa30b3c965545646e908542b28a49b1610;hb=6a542738b2a59f98831fa36e6208d388c007d0b8;hp=0074de025a4438da2d5933a0d218ffae2cc341fd;hpb=a75531e53e03d9fe9915f8041759601c07e47914;p=openvswitch diff --git a/lib/netdev.c b/lib/netdev.c index 0074de02..e77fcdfa 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 @@ -531,14 +504,21 @@ netdev_get_name(const struct netdev *netdev) * * If successful, returns 0 and stores the MTU size in '*mtup'. Returns * EOPNOTSUPP if 'netdev' does not have an MTU (as e.g. some tunnels do not). - * On other failure, returns a positive errno value. */ + * On other failure, returns a positive errno value. On failure, sets '*mtup' + * to 0. */ int netdev_get_mtu(const struct netdev *netdev, int *mtup) { - int error = netdev_get_dev(netdev)->netdev_class->get_mtu(netdev, mtup); - if (error && error != EOPNOTSUPP) { - VLOG_WARN_RL(&rl, "failed to retrieve MTU for network device %s: %s", - netdev_get_name(netdev), strerror(error)); + const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + int error; + + error = class->get_mtu ? class->get_mtu(netdev, mtup) : EOPNOTSUPP; + if (error) { + *mtup = 0; + if (error != EOPNOTSUPP) { + VLOG_WARN_RL(&rl, "failed to retrieve MTU for network device %s: " + "%s", netdev_get_name(netdev), strerror(error)); + } } return error; } @@ -552,8 +532,10 @@ netdev_get_mtu(const struct netdev *netdev, int *mtup) int netdev_set_mtu(const struct netdev *netdev, int mtu) { - int error = netdev_get_dev(netdev)->netdev_class->set_mtu(netdev, mtu); + const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + int error; + error = class->set_mtu ? class->set_mtu(netdev, mtu) : EOPNOTSUPP; if (error && error != EOPNOTSUPP) { VLOG_WARN_RL(&rl, "failed to retrieve MTU for network device %s: %s", netdev_get_name(netdev), strerror(error)); @@ -910,6 +892,15 @@ netdev_get_carrier(const struct netdev *netdev) return carrier; } +/* Returns the number of times 'netdev''s carrier has changed. */ +long long int +netdev_get_carrier_resets(const struct netdev *netdev) +{ + return (netdev_get_dev(netdev)->netdev_class->get_carrier_resets + ? netdev_get_dev(netdev)->netdev_class->get_carrier_resets(netdev) + : 0); +} + /* Attempts to force netdev_get_carrier() to poll 'netdev''s MII registers for * link status instead of checking 'netdev''s carrier. 'netdev''s MII * registers will be polled once ever 'interval' milliseconds. If 'netdev' @@ -1259,51 +1250,6 @@ netdev_change_seq(const struct netdev *netdev) { return netdev_get_dev(netdev)->netdev_class->change_seq(netdev); } - -/* 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 struct netdev *netdev, int *vlan_vid) -{ - int error = (netdev_get_dev(netdev)->netdev_class->get_vlan_vid - ? netdev_get_dev(netdev)->netdev_class->get_vlan_vid(netdev, - vlan_vid) - : ENOENT); - if (error) { - *vlan_vid = 0; - } - 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