X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fnetdev.c;h=70f9678b20e176e65f988987a8d016111b3439c7;hb=3fd8d44544df9c4cdb6108a72154f7ebc5077dd0;hp=9fba077b6982c9f31e5db6cd1b5c54b1c61ed93f;hpb=9b02078077b62e4277e84c7f39382ce09986cf6b;p=openvswitch diff --git a/lib/netdev.c b/lib/netdev.c index 9fba077b..70f9678b 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -332,31 +332,23 @@ 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) +/* Parses 'netdev_name_', which is of the form [type@]name into its component + * pieces. 'name' and 'type' must be freed by the caller. */ +void +netdev_parse_name(const char *netdev_name_, char **name, char **type) { - struct shash_node *node; - int error = 0; - - netdev_initialize(); - sset_clear(sset); + char *netdev_name = xstrdup(netdev_name_); + char *separator; - 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; - } - } - } + separator = strchr(netdev_name, '@'); + if (separator) { + *separator = '\0'; + *type = netdev_name; + *name = xstrdup(separator + 1); + } else { + *name = netdev_name; + *type = xstrdup("system"); } - - return error; } /* Attempts to set up 'netdev' for receiving packets with netdev_recv(). @@ -512,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; } @@ -533,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)); @@ -1258,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