-/* 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 svec dev_list = SVEC_EMPTY_INITIALIZER;
- size_t i;
-
- netdev_enumerate(&dev_list);
- for (i = 0; i < dev_list.n; i++) {
- const char *name = dev_list.names[i];
- struct in_addr dev_in4;
-
- if (!netdev_open_default(name, &netdev)
- && !netdev_get_in4(netdev, &dev_in4, NULL)
- && dev_in4.s_addr == in4->s_addr) {
- goto exit;
- }
- netdev_close(netdev);
- }
- netdev = NULL;
-
-exit:
- svec_destroy(&dev_list);
- return netdev;
-}
-\f
-/* Initializes 'netdev_dev' as a netdev device named 'name' of the
- * specified 'netdev_class'.
- *
- * This function adds 'netdev_dev' to a netdev-owned shash, so it is
- * very important that 'netdev_dev' only be freed after calling
- * the refcount drops to zero. */
-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));
-
- memset(netdev_dev, 0, sizeof *netdev_dev);
- netdev_dev->netdev_class = netdev_class;
- netdev_dev->name = xstrdup(name);
- netdev_dev->node = shash_add(&netdev_dev_shash, name, netdev_dev);
- shash_init(&netdev_dev->args);
-}
-
-/* Undoes the results of initialization.