From b5d57fc87925cb3c029de19d0a94de5ca07ae28e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 15 Mar 2013 15:54:36 -0700 Subject: [PATCH 1/1] netdev: Get rid of netdev_dev. The distinction between struct netdev_dev and struct netdev has always been confusing. Now that previous commits have eliminated all interesting state from struct netdev, this commit deletes it and renames struct netdev_dev to take its place. Now the situation makes much more sense and I won't have to continue making embarrassed explanations in the future. Good riddance. Signed-off-by: Ben Pfaff --- lib/netdev-bsd.c | 291 +++++++---------- lib/netdev-dummy.c | 195 ++++-------- lib/netdev-linux.c | 724 ++++++++++++++++++------------------------ lib/netdev-provider.h | 85 ++--- lib/netdev-vport.c | 142 ++++----- lib/netdev.c | 365 +++++++++------------ 6 files changed, 723 insertions(+), 1079 deletions(-) diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c index 23a0ad200..ca43d07e7 100644 --- a/lib/netdev-bsd.c +++ b/lib/netdev-bsd.c @@ -55,33 +55,6 @@ VLOG_DEFINE_THIS_MODULE(netdev_bsd); -/* - * This file implements objects to access interfaces. - * Externally, interfaces are represented by three structures: - * + struct netdev_dev, representing a network device, - * containing e.g. name and a refcount; - * We can have private variables by embedding the - * struct netdev_dev into our own structure - * (e.g. netdev_dev_bsd) - * - * + struct netdev, representing an instance of an open netdev_dev. - * The structure contains a pointer to the 'struct netdev' - * representing the device. - * - * + struct netdev_rx, which represents a netdev open to capture received - * packets. Again, private information such as file descriptor etc. are - * stored in our own struct netdev_rx_bsd which includes a struct - * netdev_rx. - * - * 'struct netdev', 'struct netdev_dev', and 'struct netdev_rx' are referenced - * in containers which hold pointers to the data structures. We can reach our - * own struct netdev_XXX_bsd by putting a struct netdev_XXX within our own - * struct, and using CONTAINER_OF to access the parent structure. - */ -struct netdev_bsd { - struct netdev up; -}; - struct netdev_rx_bsd { struct netdev_rx up; @@ -96,8 +69,8 @@ struct netdev_rx_bsd { static const struct netdev_rx_class netdev_rx_bsd_class; -struct netdev_dev_bsd { - struct netdev_dev up; +struct netdev_bsd { + struct netdev up; unsigned int cache_valid; unsigned int change_seq; @@ -149,7 +122,7 @@ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); static int netdev_bsd_do_ioctl(const char *, struct ifreq *, unsigned long cmd, const char *cmd_name); static void destroy_tap(int fd, const char *name); -static int get_flags(const struct netdev_dev *, int *flagsp); +static int get_flags(const struct netdev *, int *flagsp); static int set_flags(const char *, int flags); static int do_set_addr(struct netdev *netdev, int ioctl_nr, const char *ioctl_name, @@ -170,18 +143,10 @@ is_netdev_bsd_class(const struct netdev_class *netdev_class) static struct netdev_bsd * netdev_bsd_cast(const struct netdev *netdev) { - ovs_assert(is_netdev_bsd_class(netdev_dev_get_class( - netdev_get_dev(netdev)))); + ovs_assert(is_netdev_bsd_class(netdev_get_class(netdev))); return CONTAINER_OF(netdev, struct netdev_bsd, up); } -static struct netdev_dev_bsd * -netdev_dev_bsd_cast(const struct netdev_dev *netdev_dev) -{ - ovs_assert(is_netdev_bsd_class(netdev_dev_get_class(netdev_dev))); - return CONTAINER_OF(netdev_dev, struct netdev_dev_bsd, up); -} - static struct netdev_rx_bsd * netdev_rx_bsd_cast(const struct netdev_rx *rx) { @@ -230,7 +195,7 @@ netdev_bsd_wait(void) } static void -netdev_dev_bsd_changed(struct netdev_dev_bsd *dev) +netdev_bsd_changed(struct netdev_bsd *dev) { dev->change_seq++; if (!dev->change_seq) { @@ -243,19 +208,19 @@ static void netdev_bsd_cache_cb(const struct rtbsd_change *change, void *aux OVS_UNUSED) { - struct netdev_dev_bsd *dev; + struct netdev_bsd *dev; if (change) { - struct netdev_dev *base_dev = netdev_dev_from_name(change->if_name); + struct netdev *base_dev = netdev_from_name(change->if_name); if (base_dev) { const struct netdev_class *netdev_class = - netdev_dev_get_class(base_dev); + netdev_get_class(base_dev); if (is_netdev_bsd_class(netdev_class)) { - dev = netdev_dev_bsd_cast(base_dev); + dev = netdev_bsd_cast(base_dev); dev->cache_valid = 0; - netdev_dev_bsd_changed(dev); + netdev_bsd_changed(dev); } } } else { @@ -267,11 +232,11 @@ netdev_bsd_cache_cb(const struct rtbsd_change *change, struct shash_node *node; shash_init(&device_shash); - netdev_dev_get_devices(&netdev_bsd_class, &device_shash); + netdev_get_devices(&netdev_bsd_class, &device_shash); SHASH_FOR_EACH (node, &device_shash) { dev = node->data; dev->cache_valid = 0; - netdev_dev_bsd_changed(dev); + netdev_bsd_changed(dev); } shash_destroy(&device_shash); } @@ -303,12 +268,13 @@ cache_notifier_unref(void) return 0; } -/* Allocate a netdev_dev_bsd structure */ +/* Allocate a netdev_bsd structure */ static int netdev_bsd_create_system(const struct netdev_class *class, const char *name, - struct netdev_dev **netdev_devp) + struct netdev **netdevp) { - struct netdev_dev_bsd *netdev_dev; + struct netdev_bsd *netdev; + enum netdev_flags flags; int error; error = cache_notifier_ref(); @@ -316,23 +282,32 @@ netdev_bsd_create_system(const struct netdev_class *class, const char *name, return error; } - netdev_dev = xzalloc(sizeof *netdev_dev); - netdev_dev->change_seq = 1; - netdev_dev_init(&netdev_dev->up, name, class); - netdev_dev->tap_fd = -1; - *netdev_devp = &netdev_dev->up; + netdev = xzalloc(sizeof *netdev); + netdev->change_seq = 1; + netdev_init(&netdev->up, name, class); + netdev->tap_fd = -1; + /* Verify that the netdev really exists by attempting to read its flags */ + error = netdev_get_flags(&netdev->up, &flags); + if (error == ENXIO) { + netdev_uninit(&netdev->up, false); + free(netdev); + cache_notifier_unref(); + return error; + } + + *netdevp = &netdev->up; return 0; } /* - * Allocate a netdev_dev_bsd structure with 'tap' class. + * Allocate a netdev_bsd structure with 'tap' class. */ static int netdev_bsd_create_tap(const struct netdev_class *class, const char *name, - struct netdev_dev **netdev_devp) + struct netdev **netdevp) { - struct netdev_dev_bsd *netdev_dev = NULL; + struct netdev_bsd *netdev = NULL; int error = 0; struct ifreq ifr; @@ -342,22 +317,22 @@ netdev_bsd_create_tap(const struct netdev_class *class, const char *name, } /* allocate the device structure and set the internal flag */ - netdev_dev = xzalloc(sizeof *netdev_dev); + netdev = xzalloc(sizeof *netdev); memset(&ifr, 0, sizeof(ifr)); /* Create a tap device by opening /dev/tap. The TAPGIFNAME ioctl is used * to retrieve the name of the tap device. */ - netdev_dev->tap_fd = open("/dev/tap", O_RDWR); - netdev_dev->change_seq = 1; - if (netdev_dev->tap_fd < 0) { + netdev->tap_fd = open("/dev/tap", O_RDWR); + netdev->change_seq = 1; + if (netdev->tap_fd < 0) { error = errno; VLOG_WARN("opening \"/dev/tap\" failed: %s", strerror(error)); goto error_undef_notifier; } /* Retrieve tap name (e.g. tap0) */ - if (ioctl(netdev_dev->tap_fd, TAPGIFNAME, &ifr) == -1) { + if (ioctl(netdev->tap_fd, TAPGIFNAME, &ifr) == -1) { /* XXX Need to destroy the device? */ error = errno; goto error_undef_notifier; @@ -367,14 +342,14 @@ netdev_bsd_create_tap(const struct netdev_class *class, const char *name, ifr.ifr_data = (void *)name; if (ioctl(af_inet_sock, SIOCSIFNAME, &ifr) == -1) { error = errno; - destroy_tap(netdev_dev->tap_fd, ifr.ifr_name); + destroy_tap(netdev->tap_fd, ifr.ifr_name); goto error_undef_notifier; } /* set non-blocking. */ - error = set_nonblocking(netdev_dev->tap_fd); + error = set_nonblocking(netdev->tap_fd); if (error) { - destroy_tap(netdev_dev->tap_fd, name); + destroy_tap(netdev->tap_fd, name); goto error_undef_notifier; } @@ -384,74 +359,37 @@ netdev_bsd_create_tap(const struct netdev_class *class, const char *name, strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); if (ioctl(af_inet_sock, SIOCSIFFLAGS, &ifr) == -1) { error = errno; - destroy_tap(netdev_dev->tap_fd, name); + destroy_tap(netdev->tap_fd, name); goto error_undef_notifier; } /* initialize the device structure and * link the structure to its netdev */ - netdev_dev_init(&netdev_dev->up, name, class); - *netdev_devp = &netdev_dev->up; + netdev_init(&netdev->up, name, class); + *netdevp = &netdev->up; return 0; error_undef_notifier: cache_notifier_unref(); error: - free(netdev_dev); + free(netdev); return error; } static void -netdev_bsd_destroy(struct netdev_dev *netdev_dev_) +netdev_bsd_destroy(struct netdev *netdev_) { - struct netdev_dev_bsd *netdev_dev = netdev_dev_bsd_cast(netdev_dev_); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); cache_notifier_unref(); - if (netdev_dev->tap_fd >= 0) { - destroy_tap(netdev_dev->tap_fd, netdev_dev_get_name(netdev_dev_)); + if (netdev->tap_fd >= 0) { + destroy_tap(netdev->tap_fd, netdev_get_name(netdev_)); } - if (netdev_dev->pcap) { - pcap_close(netdev_dev->pcap); + if (netdev->pcap) { + pcap_close(netdev->pcap); } - free(netdev_dev); -} - - -static int -netdev_bsd_open_system(struct netdev_dev *netdev_dev_, struct netdev **netdevp) -{ - struct netdev_bsd *netdev; - int error; - enum netdev_flags flags; - - /* Allocate network device. */ - netdev = xcalloc(1, sizeof *netdev); - netdev_init(&netdev->up, netdev_dev_); - - /* Verify that the netdev really exists by attempting to read its flags */ - error = netdev_get_flags(&netdev->up, &flags); - if (error == ENXIO) { - goto error; - } - - *netdevp = &netdev->up; - return 0; - -error: - netdev_uninit(&netdev->up, true); - return error; -} - - - -/* Close a 'netdev'. */ -static void -netdev_bsd_close(struct netdev *netdev_) -{ - struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); - free(netdev); } @@ -527,8 +465,7 @@ error: static int netdev_bsd_rx_open(struct netdev *netdev_, struct netdev_rx **rxp) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); struct netdev_rx_bsd *rx; pcap_t *pcap; @@ -536,18 +473,18 @@ netdev_bsd_rx_open(struct netdev *netdev_, struct netdev_rx **rxp) if (!strcmp(netdev_get_type(netdev_), "tap")) { pcap = NULL; - fd = netdev_dev->tap_fd; + fd = netdev->tap_fd; } else { int error = netdev_bsd_open_pcap(netdev_get_name(netdev_), &pcap, &fd); if (error) { return error; } - netdev_dev_bsd_changed(netdev_dev); + netdev_bsd_changed(netdev); } rx = xmalloc(sizeof *rx); - netdev_rx_init(&rx->up, netdev_get_dev(netdev_), &netdev_rx_bsd_class); + netdev_rx_init(&rx->up, netdev_, &netdev_rx_bsd_class); rx->pcap_handle = pcap; rx->fd = fd; @@ -707,7 +644,7 @@ netdev_rx_bsd_drain(struct netdev_rx *rx_) static int netdev_bsd_send(struct netdev *netdev_, const void *data, size_t size) { - struct netdev_dev_bsd *dev = netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *dev = netdev_bsd_cast(netdev_); const char *name = netdev_get_name(netdev_); if (dev->tap_fd < 0 && !dev->pcap) { @@ -750,7 +687,7 @@ netdev_bsd_send(struct netdev *netdev_, const void *data, size_t size) static void netdev_bsd_send_wait(struct netdev *netdev_) { - struct netdev_dev_bsd *dev = netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *dev = netdev_bsd_cast(netdev_); if (dev->tap_fd >= 0) { /* TAP device always accepts packets. */ @@ -771,18 +708,17 @@ static int netdev_bsd_set_etheraddr(struct netdev *netdev_, const uint8_t mac[ETH_ADDR_LEN]) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); int error; - if (!(netdev_dev->cache_valid & VALID_ETHERADDR) - || !eth_addr_equals(netdev_dev->etheraddr, mac)) { + if (!(netdev->cache_valid & VALID_ETHERADDR) + || !eth_addr_equals(netdev->etheraddr, mac)) { error = set_etheraddr(netdev_get_name(netdev_), AF_LINK, ETH_ADDR_LEN, mac); if (!error) { - netdev_dev->cache_valid |= VALID_ETHERADDR; - memcpy(netdev_dev->etheraddr, mac, ETH_ADDR_LEN); - netdev_dev_bsd_changed(netdev_dev); + netdev->cache_valid |= VALID_ETHERADDR; + memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN); + netdev_bsd_changed(netdev); } } else { error = 0; @@ -798,18 +734,17 @@ static int netdev_bsd_get_etheraddr(const struct netdev *netdev_, uint8_t mac[ETH_ADDR_LEN]) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); - if (!(netdev_dev->cache_valid & VALID_ETHERADDR)) { + if (!(netdev->cache_valid & VALID_ETHERADDR)) { int error = get_etheraddr(netdev_get_name(netdev_), - netdev_dev->etheraddr); + netdev->etheraddr); if (error) { return error; } - netdev_dev->cache_valid |= VALID_ETHERADDR; + netdev->cache_valid |= VALID_ETHERADDR; } - memcpy(mac, netdev_dev->etheraddr, ETH_ADDR_LEN); + memcpy(mac, netdev->etheraddr, ETH_ADDR_LEN); return 0; } @@ -822,10 +757,9 @@ netdev_bsd_get_etheraddr(const struct netdev *netdev_, static int netdev_bsd_get_mtu(const struct netdev *netdev_, int *mtup) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); - if (!(netdev_dev->cache_valid & VALID_MTU)) { + if (!(netdev->cache_valid & VALID_MTU)) { struct ifreq ifr; int error; @@ -834,11 +768,11 @@ netdev_bsd_get_mtu(const struct netdev *netdev_, int *mtup) if (error) { return error; } - netdev_dev->mtu = ifr.ifr_mtu; - netdev_dev->cache_valid |= VALID_MTU; + netdev->mtu = ifr.ifr_mtu; + netdev->cache_valid |= VALID_MTU; } - *mtup = netdev_dev->mtu; + *mtup = netdev->mtu; return 0; } @@ -854,10 +788,9 @@ netdev_bsd_get_ifindex(const struct netdev *netdev) static int netdev_bsd_get_carrier(const struct netdev *netdev_, bool *carrier) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); - if (!(netdev_dev->cache_valid & VALID_CARRIER)) { + if (!(netdev->cache_valid & VALID_CARRIER)) { struct ifmediareq ifmr; memset(&ifmr, 0, sizeof(ifmr)); @@ -869,16 +802,16 @@ netdev_bsd_get_carrier(const struct netdev *netdev_, bool *carrier) return errno; } - netdev_dev->carrier = (ifmr.ifm_status & IFM_ACTIVE) == IFM_ACTIVE; - netdev_dev->cache_valid |= VALID_CARRIER; + netdev->carrier = (ifmr.ifm_status & IFM_ACTIVE) == IFM_ACTIVE; + netdev->cache_valid |= VALID_CARRIER; /* If the interface doesn't report whether the media is active, * just assume it is active. */ if ((ifmr.ifm_status & IFM_AVALID) == 0) { - netdev_dev->carrier = true; + netdev->carrier = true; } } - *carrier = netdev_dev->carrier; + *carrier = netdev->carrier; return 0; } @@ -1097,10 +1030,9 @@ static int netdev_bsd_get_in4(const struct netdev *netdev_, struct in_addr *in4, struct in_addr *netmask) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); - if (!(netdev_dev->cache_valid & VALID_IN4)) { + if (!(netdev->cache_valid & VALID_IN4)) { const struct sockaddr_in *sin; struct ifreq ifr; int error; @@ -1113,8 +1045,8 @@ netdev_bsd_get_in4(const struct netdev *netdev_, struct in_addr *in4, } sin = (struct sockaddr_in *) &ifr.ifr_addr; - netdev_dev->in4 = sin->sin_addr; - netdev_dev->cache_valid |= VALID_IN4; + netdev->in4 = sin->sin_addr; + netdev->cache_valid |= VALID_IN4; error = netdev_bsd_do_ioctl(netdev_get_name(netdev_), &ifr, SIOCGIFNETMASK, "SIOCGIFNETMASK"); if (error) { @@ -1122,7 +1054,7 @@ netdev_bsd_get_in4(const struct netdev *netdev_, struct in_addr *in4, } *netmask = ((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr; } - *in4 = netdev_dev->in4; + *in4 = netdev->in4; return in4->s_addr == INADDR_ANY ? EADDRNOTAVAIL : 0; } @@ -1136,19 +1068,18 @@ static int netdev_bsd_set_in4(struct netdev *netdev_, struct in_addr addr, struct in_addr mask) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); int error; error = do_set_addr(netdev_, SIOCSIFADDR, "SIOCSIFADDR", addr); if (!error) { - netdev_dev->cache_valid |= VALID_IN4; - netdev_dev->in4 = addr; + netdev->cache_valid |= VALID_IN4; + netdev->in4 = addr; if (addr.s_addr != INADDR_ANY) { error = do_set_addr(netdev_, SIOCSIFNETMASK, "SIOCSIFNETMASK", mask); } - netdev_dev_bsd_changed(netdev_dev); + netdev_bsd_changed(netdev); } return error; } @@ -1156,9 +1087,8 @@ netdev_bsd_set_in4(struct netdev *netdev_, struct in_addr addr, static int netdev_bsd_get_in6(const struct netdev *netdev_, struct in6_addr *in6) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); - if (!(netdev_dev->cache_valid & VALID_IN6)) { + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); + if (!(netdev->cache_valid & VALID_IN6)) { struct ifaddrs *ifa, *head; struct sockaddr_in6 *sin6; const char *netdev_name = netdev_get_name(netdev_); @@ -1174,9 +1104,9 @@ netdev_bsd_get_in6(const struct netdev *netdev_, struct in6_addr *in6) !strcmp(ifa->ifa_name, netdev_name)) { sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; if (sin6) { - memcpy(&netdev_dev->in6, &sin6->sin6_addr, sin6->sin6_len); - netdev_dev->cache_valid |= VALID_IN6; - *in6 = netdev_dev->in6; + memcpy(&netdev->in6, &sin6->sin6_addr, sin6->sin6_len); + netdev->cache_valid |= VALID_IN6; + *in6 = netdev->in6; freeifaddrs(head); return 0; } @@ -1184,7 +1114,7 @@ netdev_bsd_get_in6(const struct netdev *netdev_, struct in6_addr *in6) } return EADDRNOTAVAIL; } - *in6 = netdev_dev->in6; + *in6 = netdev->in6; return 0; } @@ -1238,21 +1168,20 @@ iff_to_nd_flags(int iff) } static int -netdev_bsd_update_flags(struct netdev_dev *dev_, enum netdev_flags off, +netdev_bsd_update_flags(struct netdev *netdev_, enum netdev_flags off, enum netdev_flags on, enum netdev_flags *old_flagsp) { - struct netdev_dev_bsd *netdev_dev; + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); int old_flags, new_flags; int error; - netdev_dev = netdev_dev_bsd_cast(dev_); - error = get_flags(dev_, &old_flags); + error = get_flags(netdev_, &old_flags); if (!error) { *old_flagsp = iff_to_nd_flags(old_flags); new_flags = (old_flags & ~nd_to_iff_flags(off)) | nd_to_iff_flags(on); if (new_flags != old_flags) { - error = set_flags(netdev_dev_get_name(dev_), new_flags); - netdev_dev_bsd_changed(netdev_dev); + error = set_flags(netdev_get_name(netdev_), new_flags); + netdev_bsd_changed(netdev); } } return error; @@ -1261,7 +1190,7 @@ netdev_bsd_update_flags(struct netdev_dev *dev_, enum netdev_flags off, static unsigned int netdev_bsd_change_seq(const struct netdev *netdev) { - return netdev_dev_bsd_cast(netdev_get_dev(netdev))->change_seq; + return netdev_bsd_cast(netdev)->change_seq; } @@ -1276,8 +1205,6 @@ const struct netdev_class netdev_bsd_class = { NULL, /* get_config */ NULL, /* set_config */ NULL, /* get_tunnel_config */ - netdev_bsd_open_system, - netdev_bsd_close, netdev_bsd_rx_open, @@ -1333,8 +1260,6 @@ const struct netdev_class netdev_tap_class = { NULL, /* get_config */ NULL, /* set_config */ NULL, /* get_tunnel_config */ - netdev_bsd_open_system, - netdev_bsd_close, netdev_bsd_rx_open, @@ -1399,12 +1324,13 @@ destroy_tap(int fd, const char *name) } static int -get_flags(const struct netdev_dev *dev, int *flags) +get_flags(const struct netdev *netdev, int *flags) { struct ifreq ifr; int error; - error = netdev_bsd_do_ioctl(dev->name, &ifr, SIOCGIFFLAGS, "SIOCGIFFLAGS"); + error = netdev_bsd_do_ioctl(netdev->name, &ifr, + SIOCGIFFLAGS, "SIOCGIFFLAGS"); *flags = 0xFFFF0000 & (ifr.ifr_flagshigh << 16); *flags |= 0x0000FFFF & ifr.ifr_flags; @@ -1426,18 +1352,17 @@ set_flags(const char *name, int flags) static int get_ifindex(const struct netdev *netdev_, int *ifindexp) { - struct netdev_dev_bsd *netdev_dev = - netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); *ifindexp = 0; - if (!(netdev_dev->cache_valid & VALID_IFINDEX)) { + if (!(netdev->cache_valid & VALID_IFINDEX)) { int ifindex = if_nametoindex(netdev_get_name(netdev_)); if (ifindex <= 0) { return errno; } - netdev_dev->cache_valid |= VALID_IFINDEX; - netdev_dev->ifindex = ifindex; + netdev->cache_valid |= VALID_IFINDEX; + netdev->ifindex = ifindex; } - *ifindexp = netdev_dev->ifindex; + *ifindexp = netdev->ifindex; return 0; } diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index dabff18a9..908fef242 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -42,8 +42,8 @@ VLOG_DEFINE_THIS_MODULE(netdev_dummy); #define FREE_BSD 0 #endif -struct netdev_dev_dummy { - struct netdev_dev up; +struct netdev_dummy { + struct netdev up; uint8_t hwaddr[ETH_ADDR_LEN]; int mtu; struct netdev_stats stats; @@ -54,28 +54,20 @@ struct netdev_dev_dummy { struct list rxes; /* List of child "netdev_rx_dummy"s. */ }; -struct netdev_dummy { - struct netdev up; -}; - struct netdev_rx_dummy { struct netdev_rx up; - struct list node; /* In netdev_dev_dummy's "rxes" list. */ + struct list node; /* In netdev_dummy's "rxes" list. */ struct list recv_queue; }; -static struct shash dummy_netdev_devs = SHASH_INITIALIZER(&dummy_netdev_devs); +static struct shash dummy_netdevs = SHASH_INITIALIZER(&dummy_netdevs); static const struct netdev_rx_class netdev_rx_dummy_class; static unixctl_cb_func netdev_dummy_set_admin_state; static int netdev_dummy_create(const struct netdev_class *, const char *, - struct netdev_dev **); -static void netdev_dev_dummy_poll_notify(struct netdev_dev_dummy *); -static int netdev_dev_dummy_update_flags(struct netdev_dev_dummy *, - enum netdev_flags off, - enum netdev_flags on, - enum netdev_flags *old_flagsp); + struct netdev **); +static void netdev_dummy_poll_notify(struct netdev_dummy *); static bool is_dummy_class(const struct netdev_class *class) @@ -83,18 +75,10 @@ is_dummy_class(const struct netdev_class *class) return class->create == netdev_dummy_create; } -static struct netdev_dev_dummy * -netdev_dev_dummy_cast(const struct netdev_dev *netdev_dev) -{ - ovs_assert(is_dummy_class(netdev_dev_get_class(netdev_dev))); - return CONTAINER_OF(netdev_dev, struct netdev_dev_dummy, up); -} - static struct netdev_dummy * netdev_dummy_cast(const struct netdev *netdev) { - struct netdev_dev *netdev_dev = netdev_get_dev(netdev); - ovs_assert(is_dummy_class(netdev_dev_get_class(netdev_dev))); + ovs_assert(is_dummy_class(netdev_get_class(netdev))); return CONTAINER_OF(netdev, struct netdev_dummy, up); } @@ -107,94 +91,73 @@ netdev_rx_dummy_cast(const struct netdev_rx *rx) static int netdev_dummy_create(const struct netdev_class *class, const char *name, - struct netdev_dev **netdev_devp) + struct netdev **netdevp) { static unsigned int n = 0xaa550000; - struct netdev_dev_dummy *netdev_dev; - - netdev_dev = xzalloc(sizeof *netdev_dev); - netdev_dev_init(&netdev_dev->up, name, class); - netdev_dev->hwaddr[0] = 0xaa; - netdev_dev->hwaddr[1] = 0x55; - netdev_dev->hwaddr[2] = n >> 24; - netdev_dev->hwaddr[3] = n >> 16; - netdev_dev->hwaddr[4] = n >> 8; - netdev_dev->hwaddr[5] = n; - netdev_dev->mtu = 1500; - netdev_dev->flags = 0; - netdev_dev->change_seq = 1; - netdev_dev->ifindex = -EOPNOTSUPP; - list_init(&netdev_dev->rxes); - - shash_add(&dummy_netdev_devs, name, netdev_dev); + struct netdev_dummy *netdev; + + netdev = xzalloc(sizeof *netdev); + netdev_init(&netdev->up, name, class); + netdev->hwaddr[0] = 0xaa; + netdev->hwaddr[1] = 0x55; + netdev->hwaddr[2] = n >> 24; + netdev->hwaddr[3] = n >> 16; + netdev->hwaddr[4] = n >> 8; + netdev->hwaddr[5] = n; + netdev->mtu = 1500; + netdev->flags = 0; + netdev->change_seq = 1; + netdev->ifindex = -EOPNOTSUPP; + list_init(&netdev->rxes); + + shash_add(&dummy_netdevs, name, netdev); n++; - *netdev_devp = &netdev_dev->up; + *netdevp = &netdev->up; return 0; } static void -netdev_dummy_destroy(struct netdev_dev *netdev_dev_) +netdev_dummy_destroy(struct netdev *netdev_) { - struct netdev_dev_dummy *netdev_dev = netdev_dev_dummy_cast(netdev_dev_); + struct netdev_dummy *netdev = netdev_dummy_cast(netdev_); - shash_find_and_delete(&dummy_netdev_devs, - netdev_dev_get_name(netdev_dev_)); - free(netdev_dev); + shash_find_and_delete(&dummy_netdevs, + netdev_get_name(netdev_)); + free(netdev); } static int -netdev_dummy_get_config(struct netdev_dev *netdev_dev_, struct smap *args) +netdev_dummy_get_config(const struct netdev *netdev_, struct smap *args) { - struct netdev_dev_dummy *netdev_dev = netdev_dev_dummy_cast(netdev_dev_); + struct netdev_dummy *netdev = netdev_dummy_cast(netdev_); - if (netdev_dev->ifindex >= 0) { - smap_add_format(args, "ifindex", "%d", netdev_dev->ifindex); + if (netdev->ifindex >= 0) { + smap_add_format(args, "ifindex", "%d", netdev->ifindex); } return 0; } static int -netdev_dummy_set_config(struct netdev_dev *netdev_dev_, - const struct smap *args) -{ - struct netdev_dev_dummy *netdev_dev = netdev_dev_dummy_cast(netdev_dev_); - - netdev_dev->ifindex = smap_get_int(args, "ifindex", -EOPNOTSUPP); - return 0; -} - -static int -netdev_dummy_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp) +netdev_dummy_set_config(struct netdev *netdev_, const struct smap *args) { - struct netdev_dummy *netdev; - - netdev = xmalloc(sizeof *netdev); - netdev_init(&netdev->up, netdev_dev_); + struct netdev_dummy *netdev = netdev_dummy_cast(netdev_); - *netdevp = &netdev->up; + netdev->ifindex = smap_get_int(args, "ifindex", -EOPNOTSUPP); return 0; } -static void -netdev_dummy_close(struct netdev *netdev_) -{ - struct netdev_dummy *netdev = netdev_dummy_cast(netdev_); - free(netdev); -} - static int netdev_dummy_rx_open(struct netdev *netdev_, struct netdev_rx **rxp) { - struct netdev_dev_dummy *dev - = netdev_dev_dummy_cast(netdev_get_dev(netdev_)); + struct netdev_dummy *netdev = netdev_dummy_cast(netdev_); struct netdev_rx_dummy *rx; rx = xmalloc(sizeof *rx); - netdev_rx_init(&rx->up, &dev->up, &netdev_rx_dummy_class); - list_push_back(&dev->rxes, &rx->node); + netdev_rx_init(&rx->up, &netdev->up, &netdev_rx_dummy_class); + list_push_back(&netdev->rxes, &rx->node); list_init(&rx->recv_queue); *rxp = &rx->up; @@ -254,8 +217,7 @@ static int netdev_dummy_send(struct netdev *netdev, const void *buffer OVS_UNUSED, size_t size) { - struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + struct netdev_dummy *dev = netdev_dummy_cast(netdev); dev->stats.tx_packets++; dev->stats.tx_bytes += size; @@ -267,12 +229,11 @@ static int netdev_dummy_set_etheraddr(struct netdev *netdev, const uint8_t mac[ETH_ADDR_LEN]) { - struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + struct netdev_dummy *dev = netdev_dummy_cast(netdev); if (!eth_addr_equals(dev->hwaddr, mac)) { memcpy(dev->hwaddr, mac, ETH_ADDR_LEN); - netdev_dev_dummy_poll_notify(dev); + netdev_dummy_poll_notify(dev); } return 0; @@ -282,8 +243,7 @@ static int netdev_dummy_get_etheraddr(const struct netdev *netdev, uint8_t mac[ETH_ADDR_LEN]) { - const struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + const struct netdev_dummy *dev = netdev_dummy_cast(netdev); memcpy(mac, dev->hwaddr, ETH_ADDR_LEN); return 0; @@ -292,8 +252,7 @@ netdev_dummy_get_etheraddr(const struct netdev *netdev, static int netdev_dummy_get_mtu(const struct netdev *netdev, int *mtup) { - const struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + const struct netdev_dummy *dev = netdev_dummy_cast(netdev); *mtup = dev->mtu; return 0; @@ -302,8 +261,7 @@ netdev_dummy_get_mtu(const struct netdev *netdev, int *mtup) static int netdev_dummy_set_mtu(const struct netdev *netdev, int mtu) { - struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + struct netdev_dummy *dev = netdev_dummy_cast(netdev); dev->mtu = mtu; return 0; @@ -312,8 +270,7 @@ netdev_dummy_set_mtu(const struct netdev *netdev, int mtu) static int netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats) { - const struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + const struct netdev_dummy *dev = netdev_dummy_cast(netdev); *stats = dev->stats; return 0; @@ -322,8 +279,7 @@ netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats) static int netdev_dummy_set_stats(struct netdev *netdev, const struct netdev_stats *stats) { - struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + struct netdev_dummy *dev = netdev_dummy_cast(netdev); dev->stats = *stats; return 0; @@ -332,36 +288,27 @@ netdev_dummy_set_stats(struct netdev *netdev, const struct netdev_stats *stats) static int netdev_dummy_get_ifindex(const struct netdev *netdev) { - struct netdev_dev_dummy *dev = - netdev_dev_dummy_cast(netdev_get_dev(netdev)); + struct netdev_dummy *dev = netdev_dummy_cast(netdev); return dev->ifindex; } static int -netdev_dummy_update_flags(struct netdev_dev *dev_, +netdev_dummy_update_flags(struct netdev *netdev_, enum netdev_flags off, enum netdev_flags on, enum netdev_flags *old_flagsp) { - struct netdev_dev_dummy *dev = netdev_dev_dummy_cast(dev_); - - return netdev_dev_dummy_update_flags(dev, off, on, old_flagsp); -} + struct netdev_dummy *netdev = netdev_dummy_cast(netdev_); -static int -netdev_dev_dummy_update_flags(struct netdev_dev_dummy *dev, - enum netdev_flags off, enum netdev_flags on, - enum netdev_flags *old_flagsp) -{ if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) { return EINVAL; } - *old_flagsp = dev->flags; - dev->flags |= on; - dev->flags &= ~off; - if (*old_flagsp != dev->flags) { - netdev_dev_dummy_poll_notify(dev); + *old_flagsp = netdev->flags; + netdev->flags |= on; + netdev->flags &= ~off; + if (*old_flagsp != netdev->flags) { + netdev_dummy_poll_notify(netdev); } return 0; } @@ -369,13 +316,13 @@ netdev_dev_dummy_update_flags(struct netdev_dev_dummy *dev, static unsigned int netdev_dummy_change_seq(const struct netdev *netdev) { - return netdev_dev_dummy_cast(netdev_get_dev(netdev))->change_seq; + return netdev_dummy_cast(netdev)->change_seq; } /* Helper functions. */ static void -netdev_dev_dummy_poll_notify(struct netdev_dev_dummy *dev) +netdev_dummy_poll_notify(struct netdev_dummy *dev) { dev->change_seq++; if (!dev->change_seq) { @@ -395,9 +342,6 @@ static const struct netdev_class dummy_class = { netdev_dummy_set_config, NULL, /* get_tunnel_config */ - netdev_dummy_open, - netdev_dummy_close, - netdev_dummy_rx_open, netdev_dummy_send, /* send */ @@ -493,11 +437,11 @@ static void netdev_dummy_receive(struct unixctl_conn *conn, int argc, const char *argv[], void *aux OVS_UNUSED) { - struct netdev_dev_dummy *dummy_dev; + struct netdev_dummy *dummy_dev; int n_listeners; int i; - dummy_dev = shash_find_data(&dummy_netdev_devs, argv[1]); + dummy_dev = shash_find_data(&dummy_netdevs, argv[1]); if (!dummy_dev) { unixctl_command_reply_error(conn, "no such dummy netdev"); return; @@ -534,15 +478,14 @@ netdev_dummy_receive(struct unixctl_conn *conn, } static void -netdev_dev_dummy_set_admin_state(struct netdev_dev_dummy *dev, - bool admin_state) +netdev_dummy_set_admin_state__(struct netdev_dummy *dev, bool admin_state) { enum netdev_flags old_flags; if (admin_state) { - netdev_dev_dummy_update_flags(dev, 0, NETDEV_UP, &old_flags); + netdev_dummy_update_flags(&dev->up, 0, NETDEV_UP, &old_flags); } else { - netdev_dev_dummy_update_flags(dev, NETDEV_UP, 0, &old_flags); + netdev_dummy_update_flags(&dev->up, NETDEV_UP, 0, &old_flags); } } @@ -562,11 +505,11 @@ netdev_dummy_set_admin_state(struct unixctl_conn *conn, int argc, } if (argc > 2) { - struct netdev_dev_dummy *dummy_dev; + struct netdev_dummy *dummy_dev; - dummy_dev = shash_find_data(&dummy_netdev_devs, argv[1]); + dummy_dev = shash_find_data(&dummy_netdevs, argv[1]); if (dummy_dev) { - netdev_dev_dummy_set_admin_state(dummy_dev, up); + netdev_dummy_set_admin_state__(dummy_dev, up); } else { unixctl_command_reply_error(conn, "Unknown Dummy Interface"); return; @@ -574,8 +517,8 @@ netdev_dummy_set_admin_state(struct unixctl_conn *conn, int argc, } else { struct shash_node *node; - SHASH_FOR_EACH (node, &dummy_netdev_devs) { - netdev_dev_dummy_set_admin_state(node->data, up); + SHASH_FOR_EACH (node, &dummy_netdevs) { + netdev_dummy_set_admin_state__(node->data, up); } } unixctl_command_reply(conn, "OK"); diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index d5a3a935a..b548996b9 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -354,8 +354,8 @@ static void tc_put_rtab(struct ofpbuf *, uint16_t type, const struct tc_ratespec *rate); static int tc_calc_buffer(unsigned int Bps, int mtu, uint64_t burst_bytes); -struct netdev_dev_linux { - struct netdev_dev up; +struct netdev_linux { + struct netdev up; struct shash_node *shash_node; unsigned int cache_valid; @@ -397,10 +397,6 @@ struct netdev_dev_linux { } state; }; -struct netdev_linux { - struct netdev up; -}; - struct netdev_rx_linux { struct netdev_rx up; bool is_tap; @@ -427,7 +423,7 @@ static int netdev_linux_do_ioctl(const char *name, struct ifreq *, int cmd, const char *cmd_name); static int netdev_linux_get_ipv4(const struct netdev *, struct in_addr *, int cmd, const char *cmd_name); -static int get_flags(const struct netdev_dev *, unsigned int *flags); +static int get_flags(const struct netdev *, unsigned int *flags); static int set_flags(const char *, unsigned int flags); static int do_get_ifindex(const char *netdev_name); static int get_ifindex(const struct netdev *, int *ifindexp); @@ -451,24 +447,13 @@ is_netdev_linux_class(const struct netdev_class *netdev_class) static bool is_tap_netdev(const struct netdev *netdev) { - return netdev_dev_get_class(netdev_get_dev(netdev)) == &netdev_tap_class; -} - -static struct netdev_dev_linux * -netdev_dev_linux_cast(const struct netdev_dev *netdev_dev) -{ - const struct netdev_class *netdev_class = netdev_dev_get_class(netdev_dev); - ovs_assert(is_netdev_linux_class(netdev_class)); - - return CONTAINER_OF(netdev_dev, struct netdev_dev_linux, up); + return netdev_get_class(netdev) == &netdev_tap_class; } static struct netdev_linux * netdev_linux_cast(const struct netdev *netdev) { - struct netdev_dev *netdev_dev = netdev_get_dev(netdev); - const struct netdev_class *netdev_class = netdev_dev_get_class(netdev_dev); - ovs_assert(is_netdev_linux_class(netdev_class)); + ovs_assert(is_netdev_linux_class(netdev_get_class(netdev))); return CONTAINER_OF(netdev, struct netdev_linux, up); } @@ -519,9 +504,8 @@ netdev_linux_wait(void) } static void -netdev_dev_linux_changed(struct netdev_dev_linux *dev, - unsigned int ifi_flags, - unsigned int mask) +netdev_linux_changed(struct netdev_linux *dev, + unsigned int ifi_flags, unsigned int mask) { dev->change_seq++; if (!dev->change_seq) { @@ -537,12 +521,12 @@ netdev_dev_linux_changed(struct netdev_dev_linux *dev, } static void -netdev_dev_linux_update(struct netdev_dev_linux *dev, - const struct rtnetlink_link_change *change) +netdev_linux_update(struct netdev_linux *dev, + const struct rtnetlink_link_change *change) { if (change->nlmsg_type == RTM_NEWLINK) { /* Keep drv-info */ - netdev_dev_linux_changed(dev, change->ifi_flags, VALID_DRVINFO); + netdev_linux_changed(dev, change->ifi_flags, VALID_DRVINFO); /* Update netdev from rtnl-change msg. */ if (change->mtu) { @@ -562,7 +546,7 @@ netdev_dev_linux_update(struct netdev_dev_linux *dev, dev->get_ifindex_error = 0; } else { - netdev_dev_linux_changed(dev, change->ifi_flags, 0); + netdev_linux_changed(dev, change->ifi_flags, 0); } } @@ -570,31 +554,25 @@ static void netdev_linux_cache_cb(const struct rtnetlink_link_change *change, void *aux OVS_UNUSED) { - struct netdev_dev_linux *dev; + struct netdev_linux *dev; if (change) { - struct netdev_dev *base_dev = netdev_dev_from_name(change->ifname); - if (base_dev) { - const struct netdev_class *netdev_class = - netdev_dev_get_class(base_dev); - - if (is_netdev_linux_class(netdev_class)) { - dev = netdev_dev_linux_cast(base_dev); - netdev_dev_linux_update(dev, change); - } + struct netdev *base_dev = netdev_from_name(change->ifname); + if (base_dev && is_netdev_linux_class(netdev_get_class(base_dev))) { + netdev_linux_update(netdev_linux_cast(base_dev), change); } } else { struct shash device_shash; struct shash_node *node; shash_init(&device_shash); - netdev_dev_get_devices(&netdev_linux_class, &device_shash); + netdev_get_devices(&netdev_linux_class, &device_shash); SHASH_FOR_EACH (node, &device_shash) { unsigned int flags; dev = node->data; get_flags(&dev->up, &flags); - netdev_dev_linux_changed(dev, flags, 0); + netdev_linux_changed(dev, flags, 0); } shash_destroy(&device_shash); } @@ -632,9 +610,9 @@ cache_notifier_unref(void) /* Creates system and internal devices. */ static int netdev_linux_create(const struct netdev_class *class, const char *name, - struct netdev_dev **netdev_devp) + struct netdev **netdevp) { - struct netdev_dev_linux *netdev_dev; + struct netdev_linux *netdev; int error; error = cache_notifier_ref(); @@ -642,12 +620,26 @@ netdev_linux_create(const struct netdev_class *class, const char *name, return error; } - netdev_dev = xzalloc(sizeof *netdev_dev); - netdev_dev->change_seq = 1; - netdev_dev_init(&netdev_dev->up, name, class); - get_flags(&netdev_dev->up, &netdev_dev->ifi_flags); + netdev = xzalloc(sizeof *netdev); + netdev->change_seq = 1; + netdev_init(&netdev->up, name, class); + error = get_flags(&netdev->up, &netdev->ifi_flags); + if (error == ENODEV) { + if (class != &netdev_internal_class) { + /* The device does not exist, so don't allow it to be opened. */ + netdev_uninit(&netdev->up, false); + cache_notifier_unref(); + free(netdev); + return ENODEV; + } else { + /* "Internal" netdevs have to be created as netdev objects before + * they exist in the kernel, because creating them in the kernel + * happens by passing a netdev object to dpif_port_add(). + * Therefore, ignore the error. */ + } + } - *netdev_devp = &netdev_dev->up; + *netdevp = &netdev->up; return 0; } @@ -659,16 +651,16 @@ netdev_linux_create(const struct netdev_class *class, const char *name, * be unavailable to other reads for tap devices. */ static int netdev_linux_create_tap(const struct netdev_class *class OVS_UNUSED, - const char *name, struct netdev_dev **netdev_devp) + const char *name, struct netdev **netdevp) { - struct netdev_dev_linux *netdev_dev; + struct netdev_linux *netdev; struct tap_state *state; static const char tap_dev[] = "/dev/net/tun"; struct ifreq ifr; int error; - netdev_dev = xzalloc(sizeof *netdev_dev); - state = &netdev_dev->state.tap; + netdev = xzalloc(sizeof *netdev); + state = &netdev->state.tap; error = cache_notifier_ref(); if (error) { @@ -699,102 +691,56 @@ netdev_linux_create_tap(const struct netdev_class *class OVS_UNUSED, goto error_unref_notifier; } - netdev_dev_init(&netdev_dev->up, name, &netdev_tap_class); - *netdev_devp = &netdev_dev->up; + netdev_init(&netdev->up, name, &netdev_tap_class); + *netdevp = &netdev->up; return 0; error_unref_notifier: cache_notifier_unref(); error: - free(netdev_dev); + free(netdev); return error; } static void -destroy_tap(struct netdev_dev_linux *netdev_dev) +destroy_tap(struct netdev_linux *netdev) { - struct tap_state *state = &netdev_dev->state.tap; + struct tap_state *state = &netdev->state.tap; if (state->fd >= 0) { close(state->fd); } } -/* Destroys the netdev device 'netdev_dev_'. */ +/* Destroys the netdev device 'netdev_'. */ static void -netdev_linux_destroy(struct netdev_dev *netdev_dev_) +netdev_linux_destroy(struct netdev *netdev_) { - struct netdev_dev_linux *netdev_dev = netdev_dev_linux_cast(netdev_dev_); - const struct netdev_class *class = netdev_dev_get_class(netdev_dev_); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (netdev_dev->tc && netdev_dev->tc->ops->tc_destroy) { - netdev_dev->tc->ops->tc_destroy(netdev_dev->tc); + if (netdev->tc && netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); } - if (class == &netdev_tap_class) { - destroy_tap(netdev_dev); + if (netdev_get_class(netdev_) == &netdev_tap_class) { + destroy_tap(netdev); } - free(netdev_dev); + free(netdev); cache_notifier_unref(); } -static int -netdev_linux_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp) -{ - struct netdev_linux *netdev; - enum netdev_flags flags; - int error; - - /* Allocate network device. */ - netdev = xzalloc(sizeof *netdev); - netdev_init(&netdev->up, netdev_dev_); - - /* Verify that the device really exists, by attempting to read its flags. - * (The flags might be cached, in which case this won't actually do an - * ioctl.) - * - * Don't do this for "internal" netdevs, though, because those have to be - * created as netdev objects before they exist in the kernel, because - * creating them in the kernel happens by passing a netdev object to - * dpif_port_add(). */ - if (netdev_dev_get_class(netdev_dev_) != &netdev_internal_class) { - error = netdev_get_flags(&netdev->up, &flags); - if (error == ENODEV) { - goto error; - } - } - - *netdevp = &netdev->up; - return 0; - -error: - netdev_uninit(&netdev->up, true); - return error; -} - -/* Closes and destroys 'netdev'. */ -static void -netdev_linux_close(struct netdev *netdev_) -{ - struct netdev_linux *netdev = netdev_linux_cast(netdev_); - - free(netdev); -} - static int netdev_linux_rx_open(struct netdev *netdev_, struct netdev_rx **rxp) { struct netdev_linux *netdev = netdev_linux_cast(netdev_); - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); bool is_tap = is_tap_netdev(netdev_); struct netdev_rx_linux *rx; int error; int fd; if (is_tap) { - fd = netdev_dev->state.tap.fd; + fd = netdev->state.tap.fd; } else { struct sockaddr_ll sll; int ifindex; @@ -833,7 +779,7 @@ netdev_linux_rx_open(struct netdev *netdev_, struct netdev_rx **rxp) } rx = xmalloc(sizeof *rx); - netdev_rx_init(&rx->up, netdev_get_dev(netdev_), &netdev_rx_linux_class); + netdev_rx_init(&rx->up, netdev_, &netdev_rx_linux_class); rx->is_tap = is_tap; rx->fd = fd; @@ -965,10 +911,9 @@ netdev_linux_send(struct netdev *netdev_, const void *data, size_t size) * tap devices, because packets sent to a tap device with an * AF_PACKET socket will loop back to be *received* again on the * tap device. */ - struct netdev_dev_linux *dev - = netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - retval = write(dev->state.tap.fd, data, size); + retval = write(netdev->state.tap.fd, data, size); } if (retval < 0) { @@ -1016,19 +961,18 @@ static int netdev_linux_set_etheraddr(struct netdev *netdev_, const uint8_t mac[ETH_ADDR_LEN]) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct netdev_saved_flags *sf = NULL; int error; - if (netdev_dev->cache_valid & VALID_ETHERADDR) { - if (netdev_dev->ether_addr_error) { - return netdev_dev->ether_addr_error; + if (netdev->cache_valid & VALID_ETHERADDR) { + if (netdev->ether_addr_error) { + return netdev->ether_addr_error; } - if (eth_addr_equals(netdev_dev->etheraddr, mac)) { + if (eth_addr_equals(netdev->etheraddr, mac)) { return 0; } - netdev_dev->cache_valid &= ~VALID_ETHERADDR; + netdev->cache_valid &= ~VALID_ETHERADDR; } /* Tap devices must be brought down before setting the address. */ @@ -1041,10 +985,10 @@ netdev_linux_set_etheraddr(struct netdev *netdev_, } error = set_etheraddr(netdev_get_name(netdev_), mac); if (!error || error == ENODEV) { - netdev_dev->ether_addr_error = error; - netdev_dev->cache_valid |= VALID_ETHERADDR; + netdev->ether_addr_error = error; + netdev->cache_valid |= VALID_ETHERADDR; if (!error) { - memcpy(netdev_dev->etheraddr, mac, ETH_ADDR_LEN); + memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN); } } @@ -1058,22 +1002,21 @@ static int netdev_linux_get_etheraddr(const struct netdev *netdev_, uint8_t mac[ETH_ADDR_LEN]) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (!(netdev_dev->cache_valid & VALID_ETHERADDR)) { + if (!(netdev->cache_valid & VALID_ETHERADDR)) { int error = get_etheraddr(netdev_get_name(netdev_), - netdev_dev->etheraddr); + netdev->etheraddr); - netdev_dev->ether_addr_error = error; - netdev_dev->cache_valid |= VALID_ETHERADDR; + netdev->ether_addr_error = error; + netdev->cache_valid |= VALID_ETHERADDR; } - if (!netdev_dev->ether_addr_error) { - memcpy(mac, netdev_dev->etheraddr, ETH_ADDR_LEN); + if (!netdev->ether_addr_error) { + memcpy(mac, netdev->etheraddr, ETH_ADDR_LEN); } - return netdev_dev->ether_addr_error; + return netdev->ether_addr_error; } /* Returns the maximum size of transmitted (and received) packets on 'netdev', @@ -1082,24 +1025,23 @@ netdev_linux_get_etheraddr(const struct netdev *netdev_, static int netdev_linux_get_mtu(const struct netdev *netdev_, int *mtup) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); - if (!(netdev_dev->cache_valid & VALID_MTU)) { + struct netdev_linux *netdev = netdev_linux_cast(netdev_); + if (!(netdev->cache_valid & VALID_MTU)) { struct ifreq ifr; int error; error = netdev_linux_do_ioctl(netdev_get_name(netdev_), &ifr, SIOCGIFMTU, "SIOCGIFMTU"); - netdev_dev->netdev_mtu_error = error; - netdev_dev->mtu = ifr.ifr_mtu; - netdev_dev->cache_valid |= VALID_MTU; + netdev->netdev_mtu_error = error; + netdev->mtu = ifr.ifr_mtu; + netdev->cache_valid |= VALID_MTU; } - if (!netdev_dev->netdev_mtu_error) { - *mtup = netdev_dev->mtu; + if (!netdev->netdev_mtu_error) { + *mtup = netdev->mtu; } - return netdev_dev->netdev_mtu_error; + return netdev->netdev_mtu_error; } /* Sets the maximum size of transmitted (MTU) for given device using linux @@ -1108,27 +1050,26 @@ netdev_linux_get_mtu(const struct netdev *netdev_, int *mtup) static int netdev_linux_set_mtu(const struct netdev *netdev_, int mtu) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct ifreq ifr; int error; - if (netdev_dev->cache_valid & VALID_MTU) { - if (netdev_dev->netdev_mtu_error) { - return netdev_dev->netdev_mtu_error; + if (netdev->cache_valid & VALID_MTU) { + if (netdev->netdev_mtu_error) { + return netdev->netdev_mtu_error; } - if (netdev_dev->mtu == mtu) { + if (netdev->mtu == mtu) { return 0; } - netdev_dev->cache_valid &= ~VALID_MTU; + netdev->cache_valid &= ~VALID_MTU; } ifr.ifr_mtu = mtu; error = netdev_linux_do_ioctl(netdev_get_name(netdev_), &ifr, SIOCSIFMTU, "SIOCSIFMTU"); if (!error || error == ENODEV) { - netdev_dev->netdev_mtu_error = error; - netdev_dev->mtu = ifr.ifr_mtu; - netdev_dev->cache_valid |= VALID_MTU; + netdev->netdev_mtu_error = error; + netdev->mtu = ifr.ifr_mtu; + netdev->cache_valid |= VALID_MTU; } return error; } @@ -1147,13 +1088,12 @@ netdev_linux_get_ifindex(const struct netdev *netdev) static int netdev_linux_get_carrier(const struct netdev *netdev_, bool *carrier) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (netdev_dev->miimon_interval > 0) { - *carrier = netdev_dev->miimon; + if (netdev->miimon_interval > 0) { + *carrier = netdev->miimon; } else { - *carrier = (netdev_dev->ifi_flags & IFF_RUNNING) != 0; + *carrier = (netdev->ifi_flags & IFF_RUNNING) != 0; } return 0; @@ -1162,7 +1102,7 @@ netdev_linux_get_carrier(const struct netdev *netdev_, bool *carrier) static long long int netdev_linux_get_carrier_resets(const struct netdev *netdev) { - return netdev_dev_linux_cast(netdev_get_dev(netdev))->carrier_resets; + return netdev_linux_cast(netdev)->carrier_resets; } static int @@ -1228,14 +1168,12 @@ static int netdev_linux_set_miimon_interval(struct netdev *netdev_, long long int interval) { - struct netdev_dev_linux *netdev_dev; - - netdev_dev = netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); interval = interval > 0 ? MAX(interval, 100) : 0; - if (netdev_dev->miimon_interval != interval) { - netdev_dev->miimon_interval = interval; - timer_set_expired(&netdev_dev->miimon_timer); + if (netdev->miimon_interval != interval) { + netdev->miimon_interval = interval; + timer_set_expired(&netdev->miimon_timer); } return 0; @@ -1248,9 +1186,9 @@ netdev_linux_miimon_run(void) struct shash_node *node; shash_init(&device_shash); - netdev_dev_get_devices(&netdev_linux_class, &device_shash); + netdev_get_devices(&netdev_linux_class, &device_shash); SHASH_FOR_EACH (node, &device_shash) { - struct netdev_dev_linux *dev = node->data; + struct netdev_linux *dev = node->data; bool miimon; if (dev->miimon_interval <= 0 || !timer_expired(&dev->miimon_timer)) { @@ -1260,7 +1198,7 @@ netdev_linux_miimon_run(void) netdev_linux_get_miimon(dev->up.name, &miimon); if (miimon != dev->miimon) { dev->miimon = miimon; - netdev_dev_linux_changed(dev, dev->ifi_flags, 0); + netdev_linux_changed(dev, dev->ifi_flags, 0); } timer_set_duration(&dev->miimon_timer, dev->miimon_interval); @@ -1276,9 +1214,9 @@ netdev_linux_miimon_wait(void) struct shash_node *node; shash_init(&device_shash); - netdev_dev_get_devices(&netdev_linux_class, &device_shash); + netdev_get_devices(&netdev_linux_class, &device_shash); SHASH_FOR_EACH (node, &device_shash) { - struct netdev_dev_linux *dev = node->data; + struct netdev_linux *dev = node->data; if (dev->miimon_interval > 0) { timer_wait(&dev->miimon_timer); @@ -1379,11 +1317,10 @@ static void get_stats_via_vport(const struct netdev *netdev_, struct netdev_stats *stats) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (!netdev_dev->vport_stats_error || - !(netdev_dev->cache_valid & VALID_VPORT_STAT_ERROR)) { + if (!netdev->vport_stats_error || + !(netdev->cache_valid & VALID_VPORT_STAT_ERROR)) { int error; error = get_stats_via_vport__(netdev_, stats); @@ -1391,8 +1328,8 @@ get_stats_via_vport(const struct netdev *netdev_, VLOG_WARN_RL(&rl, "%s: obtaining netdev stats via vport failed " "(%s)", netdev_get_name(netdev_), strerror(error)); } - netdev_dev->vport_stats_error = error; - netdev_dev->cache_valid |= VALID_VPORT_STAT_ERROR; + netdev->vport_stats_error = error; + netdev->cache_valid |= VALID_VPORT_STAT_ERROR; } } @@ -1431,8 +1368,7 @@ static int netdev_linux_get_stats(const struct netdev *netdev_, struct netdev_stats *stats) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct netdev_stats dev_stats; int error; @@ -1441,14 +1377,14 @@ netdev_linux_get_stats(const struct netdev *netdev_, error = netdev_linux_sys_get_stats(netdev_, &dev_stats); if (error) { - if (netdev_dev->vport_stats_error) { + if (netdev->vport_stats_error) { return error; } else { return 0; } } - if (netdev_dev->vport_stats_error) { + if (netdev->vport_stats_error) { /* stats not available from OVS then use ioctl stats. */ *stats = dev_stats; } else { @@ -1479,8 +1415,7 @@ static int netdev_tap_get_stats(const struct netdev *netdev_, struct netdev_stats *stats) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct netdev_stats dev_stats; int error; @@ -1488,7 +1423,7 @@ netdev_tap_get_stats(const struct netdev *netdev_, error = netdev_linux_sys_get_stats(netdev_, &dev_stats); if (error) { - if (netdev_dev->vport_stats_error) { + if (netdev->vport_stats_error) { return error; } else { return 0; @@ -1501,7 +1436,7 @@ netdev_tap_get_stats(const struct netdev *netdev_, * them back here. This does not apply if we are getting stats from the * vport layer because it always tracks stats from the perspective of the * switch. */ - if (netdev_dev->vport_stats_error) { + if (netdev->vport_stats_error) { *stats = dev_stats; swap_uint64(&stats->rx_packets, &stats->tx_packets); swap_uint64(&stats->rx_bytes, &stats->tx_bytes); @@ -1535,11 +1470,10 @@ static int netdev_internal_get_stats(const struct netdev *netdev_, struct netdev_stats *stats) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); get_stats_via_vport(netdev_, stats); - return netdev_dev->vport_stats_error; + return netdev->vport_stats_error; } static int @@ -1578,138 +1512,138 @@ netdev_internal_set_stats(struct netdev *netdev, } static void -netdev_linux_read_features(struct netdev_dev_linux *netdev_dev) +netdev_linux_read_features(struct netdev_linux *netdev) { struct ethtool_cmd ecmd; uint32_t speed; int error; - if (netdev_dev->cache_valid & VALID_FEATURES) { + if (netdev->cache_valid & VALID_FEATURES) { return; } COVERAGE_INC(netdev_get_ethtool); memset(&ecmd, 0, sizeof ecmd); - error = netdev_linux_do_ethtool(netdev_dev->up.name, &ecmd, + error = netdev_linux_do_ethtool(netdev->up.name, &ecmd, ETHTOOL_GSET, "ETHTOOL_GSET"); if (error) { goto out; } /* Supported features. */ - netdev_dev->supported = 0; + netdev->supported = 0; if (ecmd.supported & SUPPORTED_10baseT_Half) { - netdev_dev->supported |= NETDEV_F_10MB_HD; + netdev->supported |= NETDEV_F_10MB_HD; } if (ecmd.supported & SUPPORTED_10baseT_Full) { - netdev_dev->supported |= NETDEV_F_10MB_FD; + netdev->supported |= NETDEV_F_10MB_FD; } if (ecmd.supported & SUPPORTED_100baseT_Half) { - netdev_dev->supported |= NETDEV_F_100MB_HD; + netdev->supported |= NETDEV_F_100MB_HD; } if (ecmd.supported & SUPPORTED_100baseT_Full) { - netdev_dev->supported |= NETDEV_F_100MB_FD; + netdev->supported |= NETDEV_F_100MB_FD; } if (ecmd.supported & SUPPORTED_1000baseT_Half) { - netdev_dev->supported |= NETDEV_F_1GB_HD; + netdev->supported |= NETDEV_F_1GB_HD; } if (ecmd.supported & SUPPORTED_1000baseT_Full) { - netdev_dev->supported |= NETDEV_F_1GB_FD; + netdev->supported |= NETDEV_F_1GB_FD; } if (ecmd.supported & SUPPORTED_10000baseT_Full) { - netdev_dev->supported |= NETDEV_F_10GB_FD; + netdev->supported |= NETDEV_F_10GB_FD; } if (ecmd.supported & SUPPORTED_TP) { - netdev_dev->supported |= NETDEV_F_COPPER; + netdev->supported |= NETDEV_F_COPPER; } if (ecmd.supported & SUPPORTED_FIBRE) { - netdev_dev->supported |= NETDEV_F_FIBER; + netdev->supported |= NETDEV_F_FIBER; } if (ecmd.supported & SUPPORTED_Autoneg) { - netdev_dev->supported |= NETDEV_F_AUTONEG; + netdev->supported |= NETDEV_F_AUTONEG; } if (ecmd.supported & SUPPORTED_Pause) { - netdev_dev->supported |= NETDEV_F_PAUSE; + netdev->supported |= NETDEV_F_PAUSE; } if (ecmd.supported & SUPPORTED_Asym_Pause) { - netdev_dev->supported |= NETDEV_F_PAUSE_ASYM; + netdev->supported |= NETDEV_F_PAUSE_ASYM; } /* Advertised features. */ - netdev_dev->advertised = 0; + netdev->advertised = 0; if (ecmd.advertising & ADVERTISED_10baseT_Half) { - netdev_dev->advertised |= NETDEV_F_10MB_HD; + netdev->advertised |= NETDEV_F_10MB_HD; } if (ecmd.advertising & ADVERTISED_10baseT_Full) { - netdev_dev->advertised |= NETDEV_F_10MB_FD; + netdev->advertised |= NETDEV_F_10MB_FD; } if (ecmd.advertising & ADVERTISED_100baseT_Half) { - netdev_dev->advertised |= NETDEV_F_100MB_HD; + netdev->advertised |= NETDEV_F_100MB_HD; } if (ecmd.advertising & ADVERTISED_100baseT_Full) { - netdev_dev->advertised |= NETDEV_F_100MB_FD; + netdev->advertised |= NETDEV_F_100MB_FD; } if (ecmd.advertising & ADVERTISED_1000baseT_Half) { - netdev_dev->advertised |= NETDEV_F_1GB_HD; + netdev->advertised |= NETDEV_F_1GB_HD; } if (ecmd.advertising & ADVERTISED_1000baseT_Full) { - netdev_dev->advertised |= NETDEV_F_1GB_FD; + netdev->advertised |= NETDEV_F_1GB_FD; } if (ecmd.advertising & ADVERTISED_10000baseT_Full) { - netdev_dev->advertised |= NETDEV_F_10GB_FD; + netdev->advertised |= NETDEV_F_10GB_FD; } if (ecmd.advertising & ADVERTISED_TP) { - netdev_dev->advertised |= NETDEV_F_COPPER; + netdev->advertised |= NETDEV_F_COPPER; } if (ecmd.advertising & ADVERTISED_FIBRE) { - netdev_dev->advertised |= NETDEV_F_FIBER; + netdev->advertised |= NETDEV_F_FIBER; } if (ecmd.advertising & ADVERTISED_Autoneg) { - netdev_dev->advertised |= NETDEV_F_AUTONEG; + netdev->advertised |= NETDEV_F_AUTONEG; } if (ecmd.advertising & ADVERTISED_Pause) { - netdev_dev->advertised |= NETDEV_F_PAUSE; + netdev->advertised |= NETDEV_F_PAUSE; } if (ecmd.advertising & ADVERTISED_Asym_Pause) { - netdev_dev->advertised |= NETDEV_F_PAUSE_ASYM; + netdev->advertised |= NETDEV_F_PAUSE_ASYM; } /* Current settings. */ speed = ecmd.speed; if (speed == SPEED_10) { - netdev_dev->current = ecmd.duplex ? NETDEV_F_10MB_FD : NETDEV_F_10MB_HD; + netdev->current = ecmd.duplex ? NETDEV_F_10MB_FD : NETDEV_F_10MB_HD; } else if (speed == SPEED_100) { - netdev_dev->current = ecmd.duplex ? NETDEV_F_100MB_FD : NETDEV_F_100MB_HD; + netdev->current = ecmd.duplex ? NETDEV_F_100MB_FD : NETDEV_F_100MB_HD; } else if (speed == SPEED_1000) { - netdev_dev->current = ecmd.duplex ? NETDEV_F_1GB_FD : NETDEV_F_1GB_HD; + netdev->current = ecmd.duplex ? NETDEV_F_1GB_FD : NETDEV_F_1GB_HD; } else if (speed == SPEED_10000) { - netdev_dev->current = NETDEV_F_10GB_FD; + netdev->current = NETDEV_F_10GB_FD; } else if (speed == 40000) { - netdev_dev->current = NETDEV_F_40GB_FD; + netdev->current = NETDEV_F_40GB_FD; } else if (speed == 100000) { - netdev_dev->current = NETDEV_F_100GB_FD; + netdev->current = NETDEV_F_100GB_FD; } else if (speed == 1000000) { - netdev_dev->current = NETDEV_F_1TB_FD; + netdev->current = NETDEV_F_1TB_FD; } else { - netdev_dev->current = 0; + netdev->current = 0; } if (ecmd.port == PORT_TP) { - netdev_dev->current |= NETDEV_F_COPPER; + netdev->current |= NETDEV_F_COPPER; } else if (ecmd.port == PORT_FIBRE) { - netdev_dev->current |= NETDEV_F_FIBER; + netdev->current |= NETDEV_F_FIBER; } if (ecmd.autoneg) { - netdev_dev->current |= NETDEV_F_AUTONEG; + netdev->current |= NETDEV_F_AUTONEG; } /* Peer advertisements. */ - netdev_dev->peer = 0; /* XXX */ + netdev->peer = 0; /* XXX */ out: - netdev_dev->cache_valid |= VALID_FEATURES; - netdev_dev->get_features_error = error; + netdev->cache_valid |= VALID_FEATURES; + netdev->get_features_error = error; } /* Stores the features supported by 'netdev' into each of '*current', @@ -1723,18 +1657,17 @@ netdev_linux_get_features(const struct netdev *netdev_, enum netdev_features *supported, enum netdev_features *peer) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - netdev_linux_read_features(netdev_dev); + netdev_linux_read_features(netdev); - if (!netdev_dev->get_features_error) { - *current = netdev_dev->current; - *advertised = netdev_dev->advertised; - *supported = netdev_dev->supported; - *peer = netdev_dev->peer; + if (!netdev->get_features_error) { + *current = netdev->current; + *advertised = netdev->advertised; + *supported = netdev->supported; + *peer = netdev->peer; } - return netdev_dev->get_features_error; + return netdev->get_features_error; } /* Set the features advertised by 'netdev' to 'advertise'. */ @@ -1798,12 +1731,11 @@ netdev_linux_set_advertisements(struct netdev *netdev, /* Attempts to set input rate limiting (policing) policy. Returns 0 if * successful, otherwise a positive errno value. */ static int -netdev_linux_set_policing(struct netdev *netdev, +netdev_linux_set_policing(struct netdev *netdev_, uint32_t kbits_rate, uint32_t kbits_burst) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); - const char *netdev_name = netdev_get_name(netdev); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); + const char *netdev_name = netdev_get_name(netdev_); int error; @@ -1811,22 +1743,22 @@ netdev_linux_set_policing(struct netdev *netdev, : !kbits_burst ? 1000 /* Default to 1000 kbits if 0. */ : kbits_burst); /* Stick with user-specified value. */ - if (netdev_dev->cache_valid & VALID_POLICING) { - if (netdev_dev->netdev_policing_error) { - return netdev_dev->netdev_policing_error; + if (netdev->cache_valid & VALID_POLICING) { + if (netdev->netdev_policing_error) { + return netdev->netdev_policing_error; } - if (netdev_dev->kbits_rate == kbits_rate && - netdev_dev->kbits_burst == kbits_burst) { + if (netdev->kbits_rate == kbits_rate && + netdev->kbits_burst == kbits_burst) { /* Assume that settings haven't changed since we last set them. */ return 0; } - netdev_dev->cache_valid &= ~VALID_POLICING; + netdev->cache_valid &= ~VALID_POLICING; } COVERAGE_INC(netdev_set_policing); /* Remove any existing ingress qdisc. */ - error = tc_add_del_ingress_qdisc(netdev, false); + error = tc_add_del_ingress_qdisc(netdev_, false); if (error) { VLOG_WARN_RL(&rl, "%s: removing policing failed: %s", netdev_name, strerror(error)); @@ -1834,14 +1766,14 @@ netdev_linux_set_policing(struct netdev *netdev, } if (kbits_rate) { - error = tc_add_del_ingress_qdisc(netdev, true); + error = tc_add_del_ingress_qdisc(netdev_, true); if (error) { VLOG_WARN_RL(&rl, "%s: adding policing qdisc failed: %s", netdev_name, strerror(error)); goto out; } - error = tc_add_policer(netdev, kbits_rate, kbits_burst); + error = tc_add_policer(netdev_, kbits_rate, kbits_burst); if (error){ VLOG_WARN_RL(&rl, "%s: adding policing action failed: %s", netdev_name, strerror(error)); @@ -1849,13 +1781,13 @@ netdev_linux_set_policing(struct netdev *netdev, } } - netdev_dev->kbits_rate = kbits_rate; - netdev_dev->kbits_burst = kbits_burst; + netdev->kbits_rate = kbits_rate; + netdev->kbits_burst = kbits_burst; out: if (!error || error == ENODEV) { - netdev_dev->netdev_policing_error = error; - netdev_dev->cache_valid |= VALID_POLICING; + netdev->netdev_policing_error = error; + netdev->cache_valid |= VALID_POLICING; } return error; } @@ -1904,14 +1836,13 @@ tc_lookup_linux_name(const char *name) } static struct tc_queue * -tc_find_queue__(const struct netdev *netdev, unsigned int queue_id, +tc_find_queue__(const struct netdev *netdev_, unsigned int queue_id, size_t hash) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct tc_queue *queue; - HMAP_FOR_EACH_IN_BUCKET (queue, hmap_node, hash, &netdev_dev->tc->queues) { + HMAP_FOR_EACH_IN_BUCKET (queue, hmap_node, hash, &netdev->tc->queues) { if (queue->queue_id == queue_id) { return queue; } @@ -1939,30 +1870,28 @@ netdev_linux_get_qos_capabilities(const struct netdev *netdev OVS_UNUSED, } static int -netdev_linux_get_qos(const struct netdev *netdev, +netdev_linux_get_qos(const struct netdev *netdev_, const char **typep, struct smap *details) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; } - *typep = netdev_dev->tc->ops->ovs_name; - return (netdev_dev->tc->ops->qdisc_get - ? netdev_dev->tc->ops->qdisc_get(netdev, details) + *typep = netdev->tc->ops->ovs_name; + return (netdev->tc->ops->qdisc_get + ? netdev->tc->ops->qdisc_get(netdev_, details) : 0); } static int -netdev_linux_set_qos(struct netdev *netdev, +netdev_linux_set_qos(struct netdev *netdev_, const char *type, const struct smap *details) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); const struct tc_ops *new_ops; int error; @@ -1971,105 +1900,101 @@ netdev_linux_set_qos(struct netdev *netdev, return EOPNOTSUPP; } - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; } - if (new_ops == netdev_dev->tc->ops) { - return new_ops->qdisc_set ? new_ops->qdisc_set(netdev, details) : 0; + if (new_ops == netdev->tc->ops) { + return new_ops->qdisc_set ? new_ops->qdisc_set(netdev_, details) : 0; } else { /* Delete existing qdisc. */ - error = tc_del_qdisc(netdev); + error = tc_del_qdisc(netdev_); if (error) { return error; } - ovs_assert(netdev_dev->tc == NULL); + ovs_assert(netdev->tc == NULL); /* Install new qdisc. */ - error = new_ops->tc_install(netdev, details); - ovs_assert((error == 0) == (netdev_dev->tc != NULL)); + error = new_ops->tc_install(netdev_, details); + ovs_assert((error == 0) == (netdev->tc != NULL)); return error; } } static int -netdev_linux_get_queue(const struct netdev *netdev, +netdev_linux_get_queue(const struct netdev *netdev_, unsigned int queue_id, struct smap *details) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; } else { - struct tc_queue *queue = tc_find_queue(netdev, queue_id); + struct tc_queue *queue = tc_find_queue(netdev_, queue_id); return (queue - ? netdev_dev->tc->ops->class_get(netdev, queue, details) + ? netdev->tc->ops->class_get(netdev_, queue, details) : ENOENT); } } static int -netdev_linux_set_queue(struct netdev *netdev, +netdev_linux_set_queue(struct netdev *netdev_, unsigned int queue_id, const struct smap *details) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; - } else if (queue_id >= netdev_dev->tc->ops->n_queues - || !netdev_dev->tc->ops->class_set) { + } else if (queue_id >= netdev->tc->ops->n_queues + || !netdev->tc->ops->class_set) { return EINVAL; } - return netdev_dev->tc->ops->class_set(netdev, queue_id, details); + return netdev->tc->ops->class_set(netdev_, queue_id, details); } static int -netdev_linux_delete_queue(struct netdev *netdev, unsigned int queue_id) +netdev_linux_delete_queue(struct netdev *netdev_, unsigned int queue_id) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; - } else if (!netdev_dev->tc->ops->class_delete) { + } else if (!netdev->tc->ops->class_delete) { return EINVAL; } else { - struct tc_queue *queue = tc_find_queue(netdev, queue_id); + struct tc_queue *queue = tc_find_queue(netdev_, queue_id); return (queue - ? netdev_dev->tc->ops->class_delete(netdev, queue) + ? netdev->tc->ops->class_delete(netdev_, queue) : ENOENT); } } static int -netdev_linux_get_queue_stats(const struct netdev *netdev, +netdev_linux_get_queue_stats(const struct netdev *netdev_, unsigned int queue_id, struct netdev_queue_stats *stats) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; - } else if (!netdev_dev->tc->ops->class_get_stats) { + } else if (!netdev->tc->ops->class_get_stats) { return EOPNOTSUPP; } else { - const struct tc_queue *queue = tc_find_queue(netdev, queue_id); + const struct tc_queue *queue = tc_find_queue(netdev_, queue_id); return (queue - ? netdev_dev->tc->ops->class_get_stats(netdev, queue, stats) + ? netdev->tc->ops->class_get_stats(netdev_, queue, stats) : ENOENT); } } @@ -2091,30 +2016,29 @@ start_queue_dump(const struct netdev *netdev, struct nl_dump *dump) } static int -netdev_linux_dump_queues(const struct netdev *netdev, +netdev_linux_dump_queues(const struct netdev *netdev_, netdev_dump_queues_cb *cb, void *aux) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct tc_queue *queue, *next_queue; struct smap details; int last_error; int error; - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; - } else if (!netdev_dev->tc->ops->class_get) { + } else if (!netdev->tc->ops->class_get) { return EOPNOTSUPP; } last_error = 0; smap_init(&details); HMAP_FOR_EACH_SAFE (queue, next_queue, hmap_node, - &netdev_dev->tc->queues) { + &netdev->tc->queues) { smap_clear(&details); - error = netdev_dev->tc->ops->class_get(netdev, queue, &details); + error = netdev->tc->ops->class_get(netdev_, queue, &details); if (!error) { (*cb)(queue->queue_id, &details, aux); } else { @@ -2127,29 +2051,28 @@ netdev_linux_dump_queues(const struct netdev *netdev, } static int -netdev_linux_dump_queue_stats(const struct netdev *netdev, +netdev_linux_dump_queue_stats(const struct netdev *netdev_, netdev_dump_queue_stats_cb *cb, void *aux) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct nl_dump dump; struct ofpbuf msg; int last_error; int error; - error = tc_query_qdisc(netdev); + error = tc_query_qdisc(netdev_); if (error) { return error; - } else if (!netdev_dev->tc->ops->class_dump_stats) { + } else if (!netdev->tc->ops->class_dump_stats) { return EOPNOTSUPP; } last_error = 0; - if (!start_queue_dump(netdev, &dump)) { + if (!start_queue_dump(netdev_, &dump)) { return ENODEV; } while (nl_dump_next(&dump, &msg)) { - error = netdev_dev->tc->ops->class_dump_stats(netdev, &msg, cb, aux); + error = netdev->tc->ops->class_dump_stats(netdev_, &msg, cb, aux); if (error) { last_error = error; } @@ -2163,28 +2086,27 @@ static int netdev_linux_get_in4(const struct netdev *netdev_, struct in_addr *address, struct in_addr *netmask) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (!(netdev_dev->cache_valid & VALID_IN4)) { + if (!(netdev->cache_valid & VALID_IN4)) { int error; - error = netdev_linux_get_ipv4(netdev_, &netdev_dev->address, + error = netdev_linux_get_ipv4(netdev_, &netdev->address, SIOCGIFADDR, "SIOCGIFADDR"); if (error) { return error; } - error = netdev_linux_get_ipv4(netdev_, &netdev_dev->netmask, + error = netdev_linux_get_ipv4(netdev_, &netdev->netmask, SIOCGIFNETMASK, "SIOCGIFNETMASK"); if (error) { return error; } - netdev_dev->cache_valid |= VALID_IN4; + netdev->cache_valid |= VALID_IN4; } - *address = netdev_dev->address; - *netmask = netdev_dev->netmask; + *address = netdev->address; + *netmask = netdev->netmask; return address->s_addr == INADDR_ANY ? EADDRNOTAVAIL : 0; } @@ -2192,15 +2114,14 @@ static int netdev_linux_set_in4(struct netdev *netdev_, struct in_addr address, struct in_addr netmask) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; error = do_set_addr(netdev_, SIOCSIFADDR, "SIOCSIFADDR", address); if (!error) { - netdev_dev->cache_valid |= VALID_IN4; - netdev_dev->address = address; - netdev_dev->netmask = netmask; + netdev->cache_valid |= VALID_IN4; + netdev->address = address; + netdev->netmask = netmask; if (address.s_addr != INADDR_ANY) { error = do_set_addr(netdev_, SIOCSIFNETMASK, "SIOCSIFNETMASK", netmask); @@ -2230,13 +2151,12 @@ parse_if_inet6_line(const char *line, static int netdev_linux_get_in6(const struct netdev *netdev_, struct in6_addr *in6) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); - if (!(netdev_dev->cache_valid & VALID_IN6)) { + struct netdev_linux *netdev = netdev_linux_cast(netdev_); + if (!(netdev->cache_valid & VALID_IN6)) { FILE *file; char line[128]; - netdev_dev->in6 = in6addr_any; + netdev->in6 = in6addr_any; file = fopen("/proc/net/if_inet6", "r"); if (file != NULL) { @@ -2247,15 +2167,15 @@ netdev_linux_get_in6(const struct netdev *netdev_, struct in6_addr *in6) if (parse_if_inet6_line(line, &in6_tmp, ifname) && !strcmp(name, ifname)) { - netdev_dev->in6 = in6_tmp; + netdev->in6 = in6_tmp; break; } } fclose(file); } - netdev_dev->cache_valid |= VALID_IN6; + netdev->cache_valid |= VALID_IN6; } - *in6 = netdev_dev->in6; + *in6 = netdev->in6; return 0; } @@ -2366,30 +2286,29 @@ netdev_linux_get_next_hop(const struct in_addr *host, struct in_addr *next_hop, } static int -netdev_linux_get_status(const struct netdev *netdev, struct smap *smap) +netdev_linux_get_status(const struct netdev *netdev_, struct smap *smap) { - struct netdev_dev_linux *netdev_dev; + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error = 0; - netdev_dev = netdev_dev_linux_cast(netdev_get_dev(netdev)); - if (!(netdev_dev->cache_valid & VALID_DRVINFO)) { - struct ethtool_cmd *cmd = (struct ethtool_cmd *) &netdev_dev->drvinfo; + if (!(netdev->cache_valid & VALID_DRVINFO)) { + struct ethtool_cmd *cmd = (struct ethtool_cmd *) &netdev->drvinfo; COVERAGE_INC(netdev_get_ethtool); - memset(&netdev_dev->drvinfo, 0, sizeof netdev_dev->drvinfo); - error = netdev_linux_do_ethtool(netdev_dev->up.name, + memset(&netdev->drvinfo, 0, sizeof netdev->drvinfo); + error = netdev_linux_do_ethtool(netdev->up.name, cmd, ETHTOOL_GDRVINFO, "ETHTOOL_GDRVINFO"); if (!error) { - netdev_dev->cache_valid |= VALID_DRVINFO; + netdev->cache_valid |= VALID_DRVINFO; } } if (!error) { - smap_add(smap, "driver_name", netdev_dev->drvinfo.driver); - smap_add(smap, "driver_version", netdev_dev->drvinfo.version); - smap_add(smap, "firmware_version", netdev_dev->drvinfo.fw_version); + smap_add(smap, "driver_name", netdev->drvinfo.driver); + smap_add(smap, "driver_version", netdev->drvinfo.version); + smap_add(smap, "firmware_version", netdev->drvinfo.fw_version); } return error; } @@ -2461,20 +2380,19 @@ iff_to_nd_flags(int iff) } static int -netdev_linux_update_flags(struct netdev_dev *dev_, enum netdev_flags off, +netdev_linux_update_flags(struct netdev *netdev_, enum netdev_flags off, enum netdev_flags on, enum netdev_flags *old_flagsp) { - struct netdev_dev_linux *netdev_dev; + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int old_flags, new_flags; int error = 0; - netdev_dev = netdev_dev_linux_cast(dev_); - old_flags = netdev_dev->ifi_flags; + old_flags = netdev->ifi_flags; *old_flagsp = iff_to_nd_flags(old_flags); new_flags = (old_flags & ~nd_to_iff_flags(off)) | nd_to_iff_flags(on); if (new_flags != old_flags) { - error = set_flags(netdev_dev_get_name(dev_), new_flags); - get_flags(&netdev_dev->up, &netdev_dev->ifi_flags); + error = set_flags(netdev_get_name(netdev_), new_flags); + get_flags(netdev_, &netdev->ifi_flags); } return error; } @@ -2482,7 +2400,7 @@ netdev_linux_update_flags(struct netdev_dev *dev_, enum netdev_flags off, static unsigned int netdev_linux_change_seq(const struct netdev *netdev) { - return netdev_dev_linux_cast(netdev_get_dev(netdev))->change_seq; + return netdev_linux_cast(netdev)->change_seq; } #define NETDEV_LINUX_CLASS(NAME, CREATE, GET_STATS, SET_STATS, \ @@ -2500,9 +2418,6 @@ netdev_linux_change_seq(const struct netdev *netdev) NULL, /* set_config */ \ NULL, /* get_tunnel_config */ \ \ - netdev_linux_open, \ - netdev_linux_close, \ - \ netdev_linux_rx_open, \ \ netdev_linux_send, \ @@ -2599,25 +2514,23 @@ struct htb_class { }; static struct htb * -htb_get__(const struct netdev *netdev) +htb_get__(const struct netdev *netdev_) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); - return CONTAINER_OF(netdev_dev->tc, struct htb, tc); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); + return CONTAINER_OF(netdev->tc, struct htb, tc); } static void -htb_install__(struct netdev *netdev, uint64_t max_rate) +htb_install__(struct netdev *netdev_, uint64_t max_rate) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct htb *htb; htb = xmalloc(sizeof *htb); tc_init(&htb->tc, &tc_ops_htb); htb->max_rate = max_rate; - netdev_dev->tc = &htb->tc; + netdev->tc = &htb->tc; } /* Create an HTB qdisc. @@ -3078,11 +2991,10 @@ struct hfsc_class { }; static struct hfsc * -hfsc_get__(const struct netdev *netdev) +hfsc_get__(const struct netdev *netdev_) { - struct netdev_dev_linux *netdev_dev; - netdev_dev = netdev_dev_linux_cast(netdev_get_dev(netdev)); - return CONTAINER_OF(netdev_dev->tc, struct hfsc, tc); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); + return CONTAINER_OF(netdev->tc, struct hfsc, tc); } static struct hfsc_class * @@ -3092,16 +3004,15 @@ hfsc_class_cast__(const struct tc_queue *queue) } static void -hfsc_install__(struct netdev *netdev, uint32_t max_rate) +hfsc_install__(struct netdev *netdev_, uint32_t max_rate) { - struct netdev_dev_linux * netdev_dev; + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct hfsc *hfsc; - netdev_dev = netdev_dev_linux_cast(netdev_get_dev(netdev)); hfsc = xmalloc(sizeof *hfsc); tc_init(&hfsc->tc, &tc_ops_hfsc); hfsc->max_rate = max_rate; - netdev_dev->tc = &hfsc->tc; + netdev->tc = &hfsc->tc; } static void @@ -3572,15 +3483,14 @@ static const struct tc_ops tc_ops_hfsc = { * the "" (empty string) QoS type in the OVS database. */ static void -default_install__(struct netdev *netdev) +default_install__(struct netdev *netdev_) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); static const struct tc tc = TC_INITIALIZER(&tc, &tc_ops_default); /* Nothing but a tc class implementation is allowed to write to a tc. This * class never does that, so we can legitimately use a const tc object. */ - netdev_dev->tc = CONST_CAST(struct tc *, &tc); + netdev->tc = CONST_CAST(struct tc *, &tc); } static int @@ -3619,15 +3529,14 @@ static const struct tc_ops tc_ops_default = { * */ static int -other_tc_load(struct netdev *netdev, struct ofpbuf *nlmsg OVS_UNUSED) +other_tc_load(struct netdev *netdev_, struct ofpbuf *nlmsg OVS_UNUSED) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); static const struct tc tc = TC_INITIALIZER(&tc, &tc_ops_other); /* Nothing but a tc class implementation is allowed to write to a tc. This * class never does that, so we can legitimately use a const tc object. */ - netdev_dev->tc = CONST_CAST(struct tc *, &tc); + netdev->tc = CONST_CAST(struct tc *, &tc); return 0; } @@ -4109,15 +4018,14 @@ tc_delete_class(const struct netdev *netdev, unsigned int handle) /* Equivalent to "tc qdisc del dev root". */ static int -tc_del_qdisc(struct netdev *netdev) +tc_del_qdisc(struct netdev *netdev_) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct ofpbuf request; struct tcmsg *tcmsg; int error; - tcmsg = tc_make_request(netdev, RTM_DELQDISC, 0, &request); + tcmsg = tc_make_request(netdev_, RTM_DELQDISC, 0, &request); if (!tcmsg) { return ENODEV; } @@ -4130,11 +4038,11 @@ tc_del_qdisc(struct netdev *netdev) * case we've accomplished our purpose. */ error = 0; } - if (!error && netdev_dev->tc) { - if (netdev_dev->tc->ops->tc_destroy) { - netdev_dev->tc->ops->tc_destroy(netdev_dev->tc); + if (!error && netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); } - netdev_dev->tc = NULL; + netdev->tc = NULL; } return error; } @@ -4143,17 +4051,16 @@ tc_del_qdisc(struct netdev *netdev) * kernel to determine what they are. Returns 0 if successful, otherwise a * positive errno value. */ static int -tc_query_qdisc(const struct netdev *netdev) +tc_query_qdisc(const struct netdev *netdev_) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct ofpbuf request, *qdisc; const struct tc_ops *ops; struct tcmsg *tcmsg; int load_error; int error; - if (netdev_dev->tc) { + if (netdev->tc) { return 0; } @@ -4171,7 +4078,7 @@ tc_query_qdisc(const struct netdev *netdev) * * We could check for Linux 2.6.35+ and use a more straightforward method * there. */ - tcmsg = tc_make_request(netdev, RTM_GETQDISC, NLM_F_ECHO, &request); + tcmsg = tc_make_request(netdev_, RTM_GETQDISC, NLM_F_ECHO, &request); if (!tcmsg) { return ENODEV; } @@ -4204,13 +4111,13 @@ tc_query_qdisc(const struct netdev *netdev) } else { /* Who knows? Maybe the device got deleted. */ VLOG_WARN_RL(&rl, "query %s qdisc failed (%s)", - netdev_get_name(netdev), strerror(error)); + netdev_get_name(netdev_), strerror(error)); ops = &tc_ops_other; } /* Instantiate it. */ - load_error = ops->tc_load(CONST_CAST(struct netdev *, netdev), qdisc); - ovs_assert((load_error == 0) == (netdev_dev->tc != NULL)); + load_error = ops->tc_load(CONST_CAST(struct netdev *, netdev_), qdisc); + ovs_assert((load_error == 0) == (netdev->tc != NULL)); ofpbuf_delete(qdisc); return error ? error : load_error; @@ -4481,7 +4388,7 @@ get_stats_via_proc(const char *netdev_name, struct netdev_stats *stats) } static int -get_flags(const struct netdev_dev *dev, unsigned int *flags) +get_flags(const struct netdev *dev, unsigned int *flags) { struct ifreq ifr; int error; @@ -4522,24 +4429,23 @@ do_get_ifindex(const char *netdev_name) static int get_ifindex(const struct netdev *netdev_, int *ifindexp) { - struct netdev_dev_linux *netdev_dev = - netdev_dev_linux_cast(netdev_get_dev(netdev_)); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (!(netdev_dev->cache_valid & VALID_IFINDEX)) { + if (!(netdev->cache_valid & VALID_IFINDEX)) { int ifindex = do_get_ifindex(netdev_get_name(netdev_)); if (ifindex < 0) { - netdev_dev->get_ifindex_error = -ifindex; - netdev_dev->ifindex = 0; + netdev->get_ifindex_error = -ifindex; + netdev->ifindex = 0; } else { - netdev_dev->get_ifindex_error = 0; - netdev_dev->ifindex = ifindex; + netdev->get_ifindex_error = 0; + netdev->ifindex = ifindex; } - netdev_dev->cache_valid |= VALID_IFINDEX; + netdev->cache_valid |= VALID_IFINDEX; } - *ifindexp = netdev_dev->ifindex; - return netdev_dev->get_ifindex_error; + *ifindexp = netdev->ifindex; + return netdev->get_ifindex_error; } static int diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h index bfdcd30b3..a9de2adbc 100644 --- a/lib/netdev-provider.h +++ b/lib/netdev-provider.h @@ -30,9 +30,8 @@ extern "C" { /* A network device (e.g. an Ethernet device). * - * This structure should be treated as opaque by network device - * implementations. */ -struct netdev_dev { + * Network device implementations should treat this structure as opaque. */ +struct netdev { char *name; /* Name of network device. */ const struct netdev_class *netdev_class; /* Functions to control this device. */ @@ -41,39 +40,20 @@ struct netdev_dev { struct list saved_flags_list; /* Contains "struct netdev_saved_flags". */ }; -void netdev_dev_init(struct netdev_dev *, const char *name, - const struct netdev_class *); -void netdev_dev_uninit(struct netdev_dev *, bool destroy); -const char *netdev_dev_get_type(const struct netdev_dev *); -const struct netdev_class *netdev_dev_get_class(const struct netdev_dev *); -const char *netdev_dev_get_name(const struct netdev_dev *); -struct netdev_dev *netdev_dev_from_name(const char *name); -void netdev_dev_get_devices(const struct netdev_class *, - struct shash *device_list); - -static inline void netdev_dev_assert_class(const struct netdev_dev *netdev_dev, - const struct netdev_class *class_) -{ - ovs_assert(netdev_dev->netdev_class == class_); -} - -/* A instance of an open network device. - * - * This structure should be treated as opaque by network device - * implementations. */ -struct netdev { - struct netdev_dev *netdev_dev; /* Parent netdev_dev. */ - struct list node; /* Element in global list. */ -}; - -void netdev_init(struct netdev *, struct netdev_dev *); -void netdev_uninit(struct netdev *, bool close); -struct netdev_dev *netdev_get_dev(const struct netdev *); +void netdev_init(struct netdev *, const char *name, + const struct netdev_class *); +void netdev_uninit(struct netdev *, bool destroy); +const char *netdev_get_type(const struct netdev *); +const struct netdev_class *netdev_get_class(const struct netdev *); +const char *netdev_get_name(const struct netdev *); +struct netdev *netdev_from_name(const char *name); +void netdev_get_devices(const struct netdev_class *, + struct shash *device_list); static inline void netdev_assert_class(const struct netdev *netdev, - const struct netdev_class *netdev_class) + const struct netdev_class *class_) { - netdev_dev_assert_class(netdev_get_dev(netdev), netdev_class); + ovs_assert(netdev->netdev_class == class_); } /* Network device class structure, to be defined by each implementation of a @@ -110,44 +90,37 @@ struct netdev_class { void (*wait)(void); /* Attempts to create a network device named 'name' in 'netdev_class'. On - * success sets 'netdev_devp' to the newly created device. */ + * success sets 'netdevp' to the newly created device. */ int (*create)(const struct netdev_class *netdev_class, const char *name, - struct netdev_dev **netdev_devp); + struct netdev **netdevp); - /* Destroys 'netdev_dev'. + /* Destroys 'netdev'. * * Netdev devices maintain a reference count that is incremented on - * netdev_open() and decremented on netdev_close(). If 'netdev_dev' + * netdev_open() and decremented on netdev_close(). If 'netdev' * has a non-zero reference count, then this function will not be * called. */ - void (*destroy)(struct netdev_dev *netdev_dev); + void (*destroy)(struct netdev *netdev); - /* Fetches the device 'netdev_dev''s configuration, storing it in 'args'. + /* Fetches the device 'netdev''s configuration, storing it in 'args'. * The caller owns 'args' and pre-initializes it to an empty smap. * * If this netdev class does not have any configuration options, this may * be a null pointer. */ - int (*get_config)(struct netdev_dev *netdev_dev, struct smap *args); + int (*get_config)(const struct netdev *netdev, struct smap *args); - /* Changes the device 'netdev_dev''s configuration to 'args'. + /* Changes the device 'netdev''s configuration to 'args'. * * If this netdev class does not support configuration, this may be a null * pointer. */ - int (*set_config)(struct netdev_dev *netdev_dev, const struct smap *args); + int (*set_config)(struct netdev *netdev, const struct smap *args); - /* Returns the tunnel configuration of 'netdev_dev'. If 'netdev_dev' is + /* Returns the tunnel configuration of 'netdev'. If 'netdev' is * not a tunnel, returns null. * * If this function would always return null, it may be null instead. */ const struct netdev_tunnel_config * - (*get_tunnel_config)(const struct netdev_dev *netdev_dev); - - /* Attempts to open a network device. On success, sets 'netdevp' - * to the new network device. */ - int (*open)(struct netdev_dev *netdev_dev, struct netdev **netdevp); - - /* Closes 'netdev'. */ - void (*close)(struct netdev *netdev); + (*get_tunnel_config)(const struct netdev *netdev); /* Attempts to open a netdev_rx for receiving packets from 'netdev'. * Returns 0 if successful, otherwise a positive errno value. Returns @@ -531,14 +504,14 @@ struct netdev_class { int (*arp_lookup)(const struct netdev *netdev, ovs_be32 ip, uint8_t mac[6]); - /* Retrieves the current set of flags on 'dev' into '*old_flags'. Then, + /* Retrieves the current set of flags on 'netdev' into '*old_flags'. Then, * turns off the flags that are set to 1 in 'off' and turns on the flags * that are set to 1 in 'on'. (No bit will be set to 1 in both 'off' and * 'on'; that is, off & on == 0.) * * This function may be invoked from a signal handler. Therefore, it * should not do anything that is not signal-safe (such as logging). */ - int (*update_flags)(struct netdev_dev *dev, enum netdev_flags off, + int (*update_flags)(struct netdev *netdev, enum netdev_flags off, enum netdev_flags on, enum netdev_flags *old_flags); /* Returns a sequence number which indicates changes in one of 'netdev''s @@ -559,13 +532,13 @@ struct netdev_class { * implementations. */ struct netdev_rx { const struct netdev_rx_class *rx_class; - struct netdev_dev *netdev_dev; + struct netdev *netdev; }; -void netdev_rx_init(struct netdev_rx *, struct netdev_dev *, +void netdev_rx_init(struct netdev_rx *, struct netdev *, const struct netdev_rx_class *); void netdev_rx_uninit(struct netdev_rx *); -struct netdev_dev *netdev_rx_get_dev(const struct netdev_rx *); +struct netdev *netdev_rx_get_netdev(const struct netdev_rx *); struct netdev_rx_class { /* Destroys 'rx'. */ diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c index 3d4b31464..699ed71e3 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -46,8 +46,8 @@ VLOG_DEFINE_THIS_MODULE(netdev_vport); #define DEFAULT_TTL 64 -struct netdev_dev_vport { - struct netdev_dev up; +struct netdev_vport { + struct netdev up; unsigned int change_seq; uint8_t etheraddr[ETH_ADDR_LEN]; struct netdev_stats stats; @@ -65,10 +65,10 @@ struct vport_class { }; static int netdev_vport_create(const struct netdev_class *, const char *, - struct netdev_dev **); -static int get_patch_config(struct netdev_dev *, struct smap *args); -static int get_tunnel_config(struct netdev_dev *, struct smap *args); -static void netdev_vport_poll_notify(struct netdev_dev_vport *); + struct netdev **); +static int get_patch_config(const struct netdev *, struct smap *args); +static int get_tunnel_config(const struct netdev *, struct smap *args); +static void netdev_vport_poll_notify(struct netdev_vport *); static bool is_vport_class(const struct netdev_class *class) @@ -83,39 +83,32 @@ vport_class_cast(const struct netdev_class *class) return CONTAINER_OF(class, struct vport_class, netdev_class); } -static struct netdev_dev_vport * -netdev_dev_vport_cast(const struct netdev_dev *netdev_dev) +static struct netdev_vport * +netdev_vport_cast(const struct netdev *netdev) { - ovs_assert(is_vport_class(netdev_dev_get_class(netdev_dev))); - return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, up); -} - -static struct netdev_dev_vport * -netdev_vport_get_dev(const struct netdev *netdev) -{ - return netdev_dev_vport_cast(netdev_get_dev(netdev)); + ovs_assert(is_vport_class(netdev_get_class(netdev))); + return CONTAINER_OF(netdev, struct netdev_vport, up); } static const struct netdev_tunnel_config * -get_netdev_tunnel_config(const struct netdev_dev *netdev_dev) +get_netdev_tunnel_config(const struct netdev *netdev) { - return &netdev_dev_vport_cast(netdev_dev)->tnl_cfg; + return &netdev_vport_cast(netdev)->tnl_cfg; } bool netdev_vport_is_patch(const struct netdev *netdev) { - const struct netdev_dev *dev = netdev_get_dev(netdev); - const struct netdev_class *class = netdev_dev_get_class(dev); + const struct netdev_class *class = netdev_get_class(netdev); return class->get_config == get_patch_config; } static bool -netdev_vport_needs_dst_port(const struct netdev_dev *dev) +netdev_vport_needs_dst_port(const struct netdev *dev) { - const struct netdev_class *class = netdev_dev_get_class(dev); - const char *type = netdev_dev_get_type(dev); + const struct netdev_class *class = netdev_get_class(dev); + const char *type = netdev_get_type(dev); return (class->get_config == get_tunnel_config && (!strcmp("vxlan", type) || !strcmp("lisp", type))); @@ -124,13 +117,11 @@ netdev_vport_needs_dst_port(const struct netdev_dev *dev) const char * netdev_vport_get_dpif_port(const struct netdev *netdev) { - const struct netdev_dev *dev = netdev_get_dev(netdev); - const struct netdev_class *class = netdev_dev_get_class(dev); const char *dpif_port; - if (netdev_vport_needs_dst_port(dev)) { - const struct netdev_dev_vport *vport = netdev_vport_get_dev(netdev); - const char *type = netdev_dev_get_type(dev); + if (netdev_vport_needs_dst_port(netdev)) { + const struct netdev_vport *vport = netdev_vport_cast(netdev); + const char *type = netdev_get_type(netdev); static char dpif_port_combined[IFNAMSIZ]; /* @@ -144,6 +135,7 @@ netdev_vport_get_dpif_port(const struct netdev *netdev) ntohs(vport->tnl_cfg.dst_port)); return dpif_port_combined; } else { + const struct netdev_class *class = netdev_get_class(netdev); dpif_port = (is_vport_class(class) ? vport_class_cast(class)->dpif_port : NULL); @@ -154,52 +146,38 @@ netdev_vport_get_dpif_port(const struct netdev *netdev) static int netdev_vport_create(const struct netdev_class *netdev_class, const char *name, - struct netdev_dev **netdev_devp) + struct netdev **netdevp) { - struct netdev_dev_vport *dev; + struct netdev_vport *dev; dev = xzalloc(sizeof *dev); - netdev_dev_init(&dev->up, name, netdev_class); + netdev_init(&dev->up, name, netdev_class); dev->change_seq = 1; eth_addr_random(dev->etheraddr); - *netdev_devp = &dev->up; + *netdevp = &dev->up; route_table_register(); return 0; } static void -netdev_vport_destroy(struct netdev_dev *netdev_dev_) +netdev_vport_destroy(struct netdev *netdev_) { - struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_); + struct netdev_vport *netdev = netdev_vport_cast(netdev_); route_table_unregister(); - free(netdev_dev->peer); - free(netdev_dev); -} - -static int -netdev_vport_open(struct netdev_dev *netdev_dev, struct netdev **netdevp) -{ - *netdevp = xmalloc(sizeof **netdevp); - netdev_init(*netdevp, netdev_dev); - return 0; -} - -static void -netdev_vport_close(struct netdev *netdev) -{ + free(netdev->peer); free(netdev); } static int -netdev_vport_set_etheraddr(struct netdev *netdev, +netdev_vport_set_etheraddr(struct netdev *netdev_, const uint8_t mac[ETH_ADDR_LEN]) { - struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev); - memcpy(dev->etheraddr, mac, ETH_ADDR_LEN); - netdev_vport_poll_notify(dev); + struct netdev_vport *netdev = netdev_vport_cast(netdev_); + memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN); + netdev_vport_poll_notify(netdev); return 0; } @@ -207,7 +185,7 @@ static int netdev_vport_get_etheraddr(const struct netdev *netdev, uint8_t mac[ETH_ADDR_LEN]) { - memcpy(mac, netdev_vport_get_dev(netdev)->etheraddr, ETH_ADDR_LEN); + memcpy(mac, netdev_vport_cast(netdev)->etheraddr, ETH_ADDR_LEN); return 0; } @@ -217,7 +195,7 @@ tunnel_get_status(const struct netdev *netdev, struct smap *smap) static char iface[IFNAMSIZ]; ovs_be32 route; - route = netdev_vport_get_dev(netdev)->tnl_cfg.ip_dst; + route = netdev_vport_cast(netdev)->tnl_cfg.ip_dst; if (route_table_get_name(route, iface)) { struct netdev *egress_netdev; @@ -234,9 +212,10 @@ tunnel_get_status(const struct netdev *netdev, struct smap *smap) } static int -netdev_vport_update_flags(struct netdev_dev *netdev_dev OVS_UNUSED, - enum netdev_flags off, enum netdev_flags on OVS_UNUSED, - enum netdev_flags *old_flagsp) +netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED, + enum netdev_flags off, + enum netdev_flags on OVS_UNUSED, + enum netdev_flags *old_flagsp) { if (off & (NETDEV_UP | NETDEV_PROMISC)) { return EOPNOTSUPP; @@ -249,7 +228,7 @@ netdev_vport_update_flags(struct netdev_dev *netdev_dev OVS_UNUSED, static unsigned int netdev_vport_change_seq(const struct netdev *netdev) { - return netdev_vport_get_dev(netdev)->change_seq; + return netdev_vport_cast(netdev)->change_seq; } static void @@ -267,7 +246,7 @@ netdev_vport_wait(void) /* Helper functions. */ static void -netdev_vport_poll_notify(struct netdev_dev_vport *ndv) +netdev_vport_poll_notify(struct netdev_vport *ndv) { ndv->change_seq++; if (!ndv->change_seq) { @@ -305,11 +284,11 @@ parse_key(const struct smap *args, const char *name, } static int -set_tunnel_config(struct netdev_dev *dev_, const struct smap *args) +set_tunnel_config(struct netdev *dev_, const struct smap *args) { - struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_); - const char *name = netdev_dev_get_name(dev_); - const char *type = netdev_dev_get_type(dev_); + struct netdev_vport *dev = netdev_vport_cast(dev_); + const char *name = netdev_get_name(dev_); + const char *type = netdev_get_type(dev_); bool ipsec_mech_set, needs_dst_port, has_csum; struct netdev_tunnel_config tnl_cfg; struct smap_node *node; @@ -478,10 +457,10 @@ set_tunnel_config(struct netdev_dev *dev_, const struct smap *args) } static int -get_tunnel_config(struct netdev_dev *dev, struct smap *args) +get_tunnel_config(const struct netdev *dev, struct smap *args) { const struct netdev_tunnel_config *tnl_cfg = - &netdev_dev_vport_cast(dev)->tnl_cfg; + &netdev_vport_cast(dev)->tnl_cfg; if (tnl_cfg->ip_dst) { smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(tnl_cfg->ip_dst)); @@ -530,7 +509,7 @@ get_tunnel_config(struct netdev_dev *dev, struct smap *args) if (tnl_cfg->dst_port) { uint16_t dst_port = ntohs(tnl_cfg->dst_port); - const char *type = netdev_dev_get_type(dev); + const char *type = netdev_get_type(dev); if ((!strcmp("vxlan", type) && dst_port != VXLAN_DST_PORT) || (!strcmp("lisp", type) && dst_port != LISP_DST_PORT)) { @@ -554,17 +533,17 @@ get_tunnel_config(struct netdev_dev *dev, struct smap *args) const char * netdev_vport_patch_peer(const struct netdev *netdev) { - return netdev_vport_is_patch(netdev) - ? netdev_vport_get_dev(netdev)->peer - : NULL; + return (netdev_vport_is_patch(netdev) + ? netdev_vport_cast(netdev)->peer + : NULL); } void netdev_vport_inc_rx(const struct netdev *netdev, const struct dpif_flow_stats *stats) { - if (is_vport_class(netdev_dev_get_class(netdev_get_dev(netdev)))) { - struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev); + if (is_vport_class(netdev_get_class(netdev))) { + struct netdev_vport *dev = netdev_vport_cast(netdev); dev->stats.rx_packets += stats->n_packets; dev->stats.rx_bytes += stats->n_bytes; } @@ -574,17 +553,17 @@ void netdev_vport_inc_tx(const struct netdev *netdev, const struct dpif_flow_stats *stats) { - if (is_vport_class(netdev_dev_get_class(netdev_get_dev(netdev)))) { - struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev); + if (is_vport_class(netdev_get_class(netdev))) { + struct netdev_vport *dev = netdev_vport_cast(netdev); dev->stats.tx_packets += stats->n_packets; dev->stats.tx_bytes += stats->n_bytes; } } static int -get_patch_config(struct netdev_dev *dev_, struct smap *args) +get_patch_config(const struct netdev *dev_, struct smap *args) { - struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_); + struct netdev_vport *dev = netdev_vport_cast(dev_); if (dev->peer) { smap_add(args, "peer", dev->peer); @@ -593,10 +572,10 @@ get_patch_config(struct netdev_dev *dev_, struct smap *args) } static int -set_patch_config(struct netdev_dev *dev_, const struct smap *args) +set_patch_config(struct netdev *dev_, const struct smap *args) { - struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_); - const char *name = netdev_dev_get_name(dev_); + struct netdev_vport *dev = netdev_vport_cast(dev_); + const char *name = netdev_get_name(dev_); const char *peer; peer = smap_get(args, "peer"); @@ -624,7 +603,7 @@ set_patch_config(struct netdev_dev *dev_, const struct smap *args) static int get_stats(const struct netdev *netdev, struct netdev_stats *stats) { - struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev); + struct netdev_vport *dev = netdev_vport_cast(netdev); memcpy(stats, &dev->stats, sizeof *stats); return 0; } @@ -641,9 +620,6 @@ get_stats(const struct netdev *netdev, struct netdev_stats *stats) SET_CONFIG, \ GET_TUNNEL_CONFIG, \ \ - netdev_vport_open, \ - netdev_vport_close, \ - \ NULL, /* rx_open */ \ \ NULL, /* send */ \ diff --git a/lib/netdev.c b/lib/netdev.c index aa0e0127a..d93526ae1 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -49,8 +49,8 @@ COVERAGE_DEFINE(netdev_add_router); COVERAGE_DEFINE(netdev_get_stats); struct netdev_saved_flags { - struct netdev_dev *dev; - struct list node; /* In struct netdev_dev's saved_flags_list. */ + struct netdev *netdev; + struct list node; /* In struct netdev's saved_flags_list. */ enum netdev_flags saved_flags; enum netdev_flags saved_values; }; @@ -58,17 +58,14 @@ struct netdev_saved_flags { static struct shash netdev_classes = SHASH_INITIALIZER(&netdev_classes); /* All created network devices. */ -static struct shash netdev_dev_shash = SHASH_INITIALIZER(&netdev_dev_shash); - -/* All open network devices. */ -static struct list netdev_list = LIST_INITIALIZER(&netdev_list); +static struct shash netdev_shash = SHASH_INITIALIZER(&netdev_shash); /* This is set pretty low because we probably won't learn anything from the * additional log messages. */ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); static void restore_all_flags(void *aux OVS_UNUSED); -void update_device_args(struct netdev_dev *, const struct shash *args); +void update_device_args(struct netdev *, const struct shash *args); static void netdev_initialize(void) @@ -157,7 +154,7 @@ netdev_register_provider(const struct netdev_class *new_class) int netdev_unregister_provider(const char *type) { - struct shash_node *del_node, *netdev_dev_node; + struct shash_node *del_node, *netdev_node; del_node = shash_find(&netdev_classes, type); if (!del_node) { @@ -166,9 +163,9 @@ netdev_unregister_provider(const char *type) return EAFNOSUPPORT; } - SHASH_FOR_EACH(netdev_dev_node, &netdev_dev_shash) { - struct netdev_dev *netdev_dev = netdev_dev_node->data; - if (!strcmp(netdev_dev->netdev_class->type, type)) { + SHASH_FOR_EACH (netdev_node, &netdev_shash) { + struct netdev *netdev = netdev_node->data; + if (!strcmp(netdev->netdev_class->type, type)) { VLOG_WARN("attempted to unregister in use netdev provider: %s", type); return EBUSY; @@ -213,15 +210,14 @@ netdev_enumerate_types(struct sset *types) int netdev_open(const char *name, const char *type, struct netdev **netdevp) { - struct netdev_dev *netdev_dev; + struct netdev *netdev; int error; *netdevp = NULL; netdev_initialize(); - netdev_dev = shash_find_data(&netdev_dev_shash, name); - - if (!netdev_dev) { + netdev = shash_find_data(&netdev_shash, name); + if (!netdev) { const struct netdev_class *class; class = netdev_lookup_provider(type); @@ -230,25 +226,17 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp) name, type); return EAFNOSUPPORT; } - error = class->create(class, name, &netdev_dev); + error = class->create(class, name, &netdev); if (error) { return error; } - ovs_assert(netdev_dev->netdev_class == class); - - } - - error = netdev_dev->netdev_class->open(netdev_dev, netdevp); + ovs_assert(netdev->netdev_class == class); - if (!error) { - netdev_dev->ref_cnt++; - } else { - if (!netdev_dev->ref_cnt) { - netdev_dev_uninit(netdev_dev, true); - } } + netdev->ref_cnt++; - return error; + *netdevp = netdev; + return 0; } /* Reconfigures the device 'netdev' with 'args'. 'args' may be empty @@ -256,12 +244,10 @@ netdev_open(const char *name, const char *type, struct netdev **netdevp) int netdev_set_config(struct netdev *netdev, const struct smap *args) { - struct netdev_dev *netdev_dev = netdev_get_dev(netdev); - - if (netdev_dev->netdev_class->set_config) { + if (netdev->netdev_class->set_config) { struct smap no_args = SMAP_INITIALIZER(&no_args); - return netdev_dev->netdev_class->set_config(netdev_dev, - args ? args : &no_args); + return netdev->netdev_class->set_config(netdev, + args ? args : &no_args); } else if (args && !smap_is_empty(args)) { VLOG_WARN("%s: arguments provided to device that is not configurable", netdev_get_name(netdev)); @@ -280,12 +266,11 @@ netdev_set_config(struct netdev *netdev, const struct smap *args) int netdev_get_config(const struct netdev *netdev, struct smap *args) { - struct netdev_dev *netdev_dev = netdev_get_dev(netdev); int error; smap_clear(args); - if (netdev_dev->netdev_class->get_config) { - error = netdev_dev->netdev_class->get_config(netdev_dev, args); + if (netdev->netdev_class->get_config) { + error = netdev->netdev_class->get_config(netdev, args); if (error) { smap_clear(args); } @@ -299,21 +284,19 @@ netdev_get_config(const struct netdev *netdev, struct smap *args) 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); + if (netdev->netdev_class->get_tunnel_config) { + return netdev->netdev_class->get_tunnel_config(netdev); } else { return NULL; } } static void -netdev_dev_unref(struct netdev_dev *dev) +netdev_unref(struct netdev *dev) { ovs_assert(dev->ref_cnt); if (!--dev->ref_cnt) { - netdev_dev_uninit(dev, true); + netdev_uninit(dev, true); } } @@ -322,10 +305,7 @@ void netdev_close(struct netdev *netdev) { if (netdev) { - struct netdev_dev *dev = netdev_get_dev(netdev); - - netdev_uninit(netdev, true); - netdev_dev_unref(dev); + netdev_unref(netdev); } } @@ -351,15 +331,14 @@ netdev_parse_name(const char *netdev_name_, char **name, char **type) int netdev_rx_open(struct netdev *netdev, struct netdev_rx **rxp) { - struct netdev_dev *dev = netdev_get_dev(netdev); int error; - error = (dev->netdev_class->rx_open - ? dev->netdev_class->rx_open(netdev, rxp) + error = (netdev->netdev_class->rx_open + ? netdev->netdev_class->rx_open(netdev, rxp) : EOPNOTSUPP); if (!error) { - ovs_assert((*rxp)->netdev_dev == dev); - dev->ref_cnt++; + ovs_assert((*rxp)->netdev == netdev); + netdev->ref_cnt++; } else { *rxp = NULL; } @@ -370,10 +349,10 @@ void netdev_rx_close(struct netdev_rx *rx) { if (rx) { - struct netdev_dev *dev = rx->netdev_dev; + struct netdev *dev = rx->netdev; rx->rx_class->destroy(rx); - netdev_dev_unref(dev); + netdev_unref(dev); } } @@ -425,11 +404,11 @@ netdev_rx_drain(struct netdev_rx *rx) int netdev_send(struct netdev *netdev, const struct ofpbuf *buffer) { - int (*send)(struct netdev *, const void *, size_t); int error; - send = netdev_get_dev(netdev)->netdev_class->send; - error = send ? (send)(netdev, buffer->data, buffer->size) : EOPNOTSUPP; + error = (netdev->netdev_class->send + ? netdev->netdev_class->send(netdev, buffer->data, buffer->size) + : EOPNOTSUPP); if (!error) { COVERAGE_INC(netdev_sent); } @@ -446,11 +425,8 @@ netdev_send(struct netdev *netdev, const struct ofpbuf *buffer) void netdev_send_wait(struct netdev *netdev) { - void (*send_wait)(struct netdev *); - - send_wait = netdev_get_dev(netdev)->netdev_class->send_wait; - if (send_wait) { - send_wait(netdev); + if (netdev->netdev_class->send_wait) { + netdev->netdev_class->send_wait(netdev); } } @@ -459,7 +435,7 @@ netdev_send_wait(struct netdev *netdev) int netdev_set_etheraddr(struct netdev *netdev, const uint8_t mac[ETH_ADDR_LEN]) { - return netdev_get_dev(netdev)->netdev_class->set_etheraddr(netdev, mac); + return netdev->netdev_class->set_etheraddr(netdev, mac); } /* Retrieves 'netdev''s MAC address. If successful, returns 0 and copies the @@ -468,7 +444,7 @@ netdev_set_etheraddr(struct netdev *netdev, const uint8_t mac[ETH_ADDR_LEN]) int netdev_get_etheraddr(const struct netdev *netdev, uint8_t mac[ETH_ADDR_LEN]) { - return netdev_get_dev(netdev)->netdev_class->get_etheraddr(netdev, mac); + return netdev->netdev_class->get_etheraddr(netdev, mac); } /* Returns the name of the network device that 'netdev' represents, @@ -476,7 +452,7 @@ netdev_get_etheraddr(const struct netdev *netdev, uint8_t mac[ETH_ADDR_LEN]) const char * netdev_get_name(const struct netdev *netdev) { - return netdev_get_dev(netdev)->name; + return netdev->name; } /* Retrieves the MTU of 'netdev'. The MTU is the maximum size of transmitted @@ -490,7 +466,7 @@ netdev_get_name(const struct netdev *netdev) int netdev_get_mtu(const struct netdev *netdev, int *mtup) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; int error; error = class->get_mtu ? class->get_mtu(netdev, mtup) : EOPNOTSUPP; @@ -513,7 +489,7 @@ netdev_get_mtu(const struct netdev *netdev, int *mtup) int netdev_set_mtu(const struct netdev *netdev, int mtu) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; int error; error = class->set_mtu ? class->set_mtu(netdev, mtu) : EOPNOTSUPP; @@ -542,7 +518,7 @@ netdev_get_ifindex(const struct netdev *netdev) { int (*get_ifindex)(const struct netdev *); - get_ifindex = netdev_get_dev(netdev)->netdev_class->get_ifindex; + get_ifindex = netdev->netdev_class->get_ifindex; return get_ifindex ? get_ifindex(netdev) : -EOPNOTSUPP; } @@ -583,7 +559,7 @@ netdev_get_features(const struct netdev *netdev, peer = &dummy[3]; } - get_features = netdev_get_dev(netdev)->netdev_class->get_features; + get_features = netdev->netdev_class->get_features; error = get_features ? get_features(netdev, current, advertised, supported, peer) @@ -637,8 +613,8 @@ int netdev_set_advertisements(struct netdev *netdev, enum netdev_features advertise) { - return (netdev_get_dev(netdev)->netdev_class->set_advertisements - ? netdev_get_dev(netdev)->netdev_class->set_advertisements( + return (netdev->netdev_class->set_advertisements + ? netdev->netdev_class->set_advertisements( netdev, advertise) : EOPNOTSUPP); } @@ -663,8 +639,8 @@ netdev_get_in4(const struct netdev *netdev, struct in_addr netmask; int error; - error = (netdev_get_dev(netdev)->netdev_class->get_in4 - ? netdev_get_dev(netdev)->netdev_class->get_in4(netdev, + error = (netdev->netdev_class->get_in4 + ? netdev->netdev_class->get_in4(netdev, &address, &netmask) : EOPNOTSUPP); if (address_) { @@ -682,8 +658,8 @@ netdev_get_in4(const struct netdev *netdev, int netdev_set_in4(struct netdev *netdev, struct in_addr addr, struct in_addr mask) { - return (netdev_get_dev(netdev)->netdev_class->set_in4 - ? netdev_get_dev(netdev)->netdev_class->set_in4(netdev, addr, mask) + return (netdev->netdev_class->set_in4 + ? netdev->netdev_class->set_in4(netdev, addr, mask) : EOPNOTSUPP); } @@ -713,8 +689,8 @@ int netdev_add_router(struct netdev *netdev, struct in_addr router) { COVERAGE_INC(netdev_add_router); - return (netdev_get_dev(netdev)->netdev_class->add_router - ? netdev_get_dev(netdev)->netdev_class->add_router(netdev, router) + return (netdev->netdev_class->add_router + ? netdev->netdev_class->add_router(netdev, router) : EOPNOTSUPP); } @@ -730,8 +706,8 @@ netdev_get_next_hop(const struct netdev *netdev, const struct in_addr *host, struct in_addr *next_hop, char **netdev_name) { - int error = (netdev_get_dev(netdev)->netdev_class->get_next_hop - ? netdev_get_dev(netdev)->netdev_class->get_next_hop( + int error = (netdev->netdev_class->get_next_hop + ? netdev->netdev_class->get_next_hop( host, next_hop, netdev_name) : EOPNOTSUPP); if (error) { @@ -749,10 +725,8 @@ netdev_get_next_hop(const struct netdev *netdev, int netdev_get_status(const struct netdev *netdev, struct smap *smap) { - struct netdev_dev *dev = netdev_get_dev(netdev); - - return (dev->netdev_class->get_status - ? dev->netdev_class->get_status(netdev, smap) + return (netdev->netdev_class->get_status + ? netdev->netdev_class->get_status(netdev, smap) : EOPNOTSUPP); } @@ -773,8 +747,8 @@ netdev_get_in6(const struct netdev *netdev, struct in6_addr *in6) struct in6_addr dummy; int error; - error = (netdev_get_dev(netdev)->netdev_class->get_in6 - ? netdev_get_dev(netdev)->netdev_class->get_in6(netdev, + error = (netdev->netdev_class->get_in6 + ? netdev->netdev_class->get_in6(netdev, in6 ? in6 : &dummy) : EOPNOTSUPP); if (error && in6) { @@ -790,12 +764,12 @@ do_update_flags(struct netdev *netdev, enum netdev_flags off, enum netdev_flags on, enum netdev_flags *old_flagsp, struct netdev_saved_flags **sfp) { - struct netdev_dev *dev = netdev_get_dev(netdev); struct netdev_saved_flags *sf = NULL; enum netdev_flags old_flags; int error; - error = dev->netdev_class->update_flags(dev, off & ~on, on, &old_flags); + error = netdev->netdev_class->update_flags(netdev, off & ~on, on, + &old_flags); if (error) { VLOG_WARN_RL(&rl, "failed to %s flags for network device %s: %s", off || on ? "set" : "get", netdev_get_name(netdev), @@ -806,12 +780,12 @@ do_update_flags(struct netdev *netdev, enum netdev_flags off, enum netdev_flags changed_flags = old_flags ^ new_flags; if (changed_flags) { *sfp = sf = xmalloc(sizeof *sf); - sf->dev = dev; - list_push_front(&dev->saved_flags_list, &sf->node); + sf->netdev = netdev; + list_push_front(&netdev->saved_flags_list, &sf->node); sf->saved_flags = changed_flags; sf->saved_values = changed_flags & new_flags; - dev->ref_cnt++; + netdev->ref_cnt++; } } @@ -877,17 +851,17 @@ void netdev_restore_flags(struct netdev_saved_flags *sf) { if (sf) { - struct netdev_dev *dev = sf->dev; + struct netdev *netdev = sf->netdev; enum netdev_flags old_flags; - dev->netdev_class->update_flags(dev, - sf->saved_flags & sf->saved_values, - sf->saved_flags & ~sf->saved_values, - &old_flags); + netdev->netdev_class->update_flags(netdev, + sf->saved_flags & sf->saved_values, + sf->saved_flags & ~sf->saved_values, + &old_flags); list_remove(&sf->node); free(sf); - netdev_dev_unref(dev); + netdev_unref(netdev); } } @@ -899,8 +873,8 @@ int netdev_arp_lookup(const struct netdev *netdev, ovs_be32 ip, uint8_t mac[ETH_ADDR_LEN]) { - int error = (netdev_get_dev(netdev)->netdev_class->arp_lookup - ? netdev_get_dev(netdev)->netdev_class->arp_lookup(netdev, + int error = (netdev->netdev_class->arp_lookup + ? netdev->netdev_class->arp_lookup(netdev, ip, mac) : EOPNOTSUPP); if (error) { @@ -922,11 +896,11 @@ netdev_get_carrier(const struct netdev *netdev) return false; } - if (!netdev_get_dev(netdev)->netdev_class->get_carrier) { + if (!netdev->netdev_class->get_carrier) { return true; } - error = netdev_get_dev(netdev)->netdev_class->get_carrier(netdev, + error = netdev->netdev_class->get_carrier(netdev, &carrier); if (error) { VLOG_DBG("%s: failed to get network device carrier status, assuming " @@ -941,8 +915,8 @@ netdev_get_carrier(const struct netdev *netdev) 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) + return (netdev->netdev_class->get_carrier_resets + ? netdev->netdev_class->get_carrier_resets(netdev) : 0); } @@ -957,9 +931,8 @@ netdev_get_carrier_resets(const struct netdev *netdev) int netdev_set_miimon_interval(struct netdev *netdev, long long int interval) { - struct netdev_dev *netdev_dev = netdev_get_dev(netdev); - return (netdev_dev->netdev_class->set_miimon_interval - ? netdev_dev->netdev_class->set_miimon_interval(netdev, interval) + return (netdev->netdev_class->set_miimon_interval + ? netdev->netdev_class->set_miimon_interval(netdev, interval) : EOPNOTSUPP); } @@ -970,8 +943,8 @@ netdev_get_stats(const struct netdev *netdev, struct netdev_stats *stats) int error; COVERAGE_INC(netdev_get_stats); - error = (netdev_get_dev(netdev)->netdev_class->get_stats - ? netdev_get_dev(netdev)->netdev_class->get_stats(netdev, stats) + error = (netdev->netdev_class->get_stats + ? netdev->netdev_class->get_stats(netdev, stats) : EOPNOTSUPP); if (error) { memset(stats, 0xff, sizeof *stats); @@ -987,8 +960,8 @@ netdev_get_stats(const struct netdev *netdev, struct netdev_stats *stats) int netdev_set_stats(struct netdev *netdev, const struct netdev_stats *stats) { - return (netdev_get_dev(netdev)->netdev_class->set_stats - ? netdev_get_dev(netdev)->netdev_class->set_stats(netdev, stats) + return (netdev->netdev_class->set_stats + ? netdev->netdev_class->set_stats(netdev, stats) : EOPNOTSUPP); } @@ -999,8 +972,8 @@ int netdev_set_policing(struct netdev *netdev, uint32_t kbits_rate, uint32_t kbits_burst) { - return (netdev_get_dev(netdev)->netdev_class->set_policing - ? netdev_get_dev(netdev)->netdev_class->set_policing(netdev, + return (netdev->netdev_class->set_policing + ? netdev->netdev_class->set_policing(netdev, kbits_rate, kbits_burst) : EOPNOTSUPP); } @@ -1021,7 +994,7 @@ netdev_set_policing(struct netdev *netdev, uint32_t kbits_rate, int netdev_get_qos_types(const struct netdev *netdev, struct sset *types) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; return (class->get_qos_types ? class->get_qos_types(netdev, types) : 0); @@ -1036,7 +1009,7 @@ int netdev_get_qos_capabilities(const struct netdev *netdev, const char *type, struct netdev_qos_capabilities *caps) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; if (*type) { int retval = (class->get_qos_capabilities @@ -1091,7 +1064,7 @@ int netdev_get_qos(const struct netdev *netdev, const char **typep, struct smap *details) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; int retval; if (class->get_qos) { @@ -1130,7 +1103,7 @@ int netdev_set_qos(struct netdev *netdev, const char *type, const struct smap *details) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; if (!type) { type = ""; @@ -1165,7 +1138,7 @@ int netdev_get_queue(const struct netdev *netdev, unsigned int queue_id, struct smap *details) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; int retval; retval = (class->get_queue @@ -1193,7 +1166,7 @@ int netdev_set_queue(struct netdev *netdev, unsigned int queue_id, const struct smap *details) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; return (class->set_queue ? class->set_queue(netdev, queue_id, details) : EOPNOTSUPP); @@ -1212,7 +1185,7 @@ netdev_set_queue(struct netdev *netdev, int netdev_delete_queue(struct netdev *netdev, unsigned int queue_id) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; return (class->delete_queue ? class->delete_queue(netdev, queue_id) : EOPNOTSUPP); @@ -1226,7 +1199,7 @@ int netdev_get_queue_stats(const struct netdev *netdev, unsigned int queue_id, struct netdev_queue_stats *stats) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; int retval; retval = (class->get_queue_stats @@ -1258,7 +1231,7 @@ int netdev_dump_queues(const struct netdev *netdev, netdev_dump_queues_cb *cb, void *aux) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; return (class->dump_queues ? class->dump_queues(netdev, cb, aux) : EOPNOTSUPP); @@ -1280,7 +1253,7 @@ int netdev_dump_queue_stats(const struct netdev *netdev, netdev_dump_queue_stats_cb *cb, void *aux) { - const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class; + const struct netdev_class *class = netdev->netdev_class; return (class->dump_queue_stats ? class->dump_queue_stats(netdev, cb, aux) : EOPNOTSUPP); @@ -1296,27 +1269,26 @@ netdev_dump_queue_stats(const struct netdev *netdev, unsigned int netdev_change_seq(const struct netdev *netdev) { - return netdev_get_dev(netdev)->netdev_class->change_seq(netdev); + return netdev->netdev_class->change_seq(netdev); } -/* Initializes 'netdev_dev' as a netdev device named 'name' of the specified +/* Initializes 'netdev' as a netdev device named 'name' of the specified * 'netdev_class'. This function is ordinarily called from a netdev provider's * 'create' function. * - * 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. */ + * This function adds 'netdev' to a netdev-owned shash, so it is very important + * that 'netdev' only be freed after calling netdev_uninit(). */ void -netdev_dev_init(struct netdev_dev *netdev_dev, const char *name, - const struct netdev_class *netdev_class) +netdev_init(struct netdev *netdev, const char *name, + const struct netdev_class *netdev_class) { - ovs_assert(!shash_find(&netdev_dev_shash, name)); + ovs_assert(!shash_find(&netdev_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); - list_init(&netdev_dev->saved_flags_list); + memset(netdev, 0, sizeof *netdev); + netdev->netdev_class = netdev_class; + netdev->name = xstrdup(name); + netdev->node = shash_add(&netdev_shash, name, netdev); + list_init(&netdev->saved_flags_list); } /* Undoes the results of initialization. @@ -1327,66 +1299,57 @@ netdev_dev_init(struct netdev_dev *netdev_dev, const char *name, * that occurs after initialization. It this case netdev_close() would * never be called. */ void -netdev_dev_uninit(struct netdev_dev *netdev_dev, bool destroy) +netdev_uninit(struct netdev *netdev, bool destroy) { - char *name = netdev_dev->name; + char *name = netdev->name; - ovs_assert(!netdev_dev->ref_cnt); - ovs_assert(list_is_empty(&netdev_dev->saved_flags_list)); + ovs_assert(!netdev->ref_cnt); + ovs_assert(list_is_empty(&netdev->saved_flags_list)); - shash_delete(&netdev_dev_shash, netdev_dev->node); + shash_delete(&netdev_shash, netdev->node); if (destroy) { - netdev_dev->netdev_class->destroy(netdev_dev); + netdev->netdev_class->destroy(netdev); } free(name); } -/* Returns the class type of 'netdev_dev'. +/* Returns the class type of 'netdev'. * * The caller must not free the returned value. */ const char * -netdev_dev_get_type(const struct netdev_dev *netdev_dev) +netdev_get_type(const struct netdev *netdev) { - return netdev_dev->netdev_class->type; + return netdev->netdev_class->type; } -/* Returns the class associated with 'netdev_dev'. */ +/* Returns the class associated with 'netdev'. */ const struct netdev_class * -netdev_dev_get_class(const struct netdev_dev *netdev_dev) -{ - return netdev_dev->netdev_class; -} - -/* Returns the name of 'netdev_dev'. - * - * The caller must not free the returned value. */ -const char * -netdev_dev_get_name(const struct netdev_dev *netdev_dev) +netdev_get_class(const struct netdev *netdev) { - return netdev_dev->name; + return netdev->netdev_class; } -/* Returns the netdev_dev with 'name' or NULL if there is none. +/* Returns the netdev with 'name' or NULL if there is none. * * The caller must not free the returned value. */ -struct netdev_dev * -netdev_dev_from_name(const char *name) +struct netdev * +netdev_from_name(const char *name) { - return shash_find_data(&netdev_dev_shash, name); + return shash_find_data(&netdev_shash, name); } /* Fills 'device_list' with devices that match 'netdev_class'. * * The caller is responsible for initializing and destroying 'device_list' - * but the contained netdev_devs must not be freed. */ + * but the contained netdevs must not be freed. */ void -netdev_dev_get_devices(const struct netdev_class *netdev_class, - struct shash *device_list) +netdev_get_devices(const struct netdev_class *netdev_class, + struct shash *device_list) { struct shash_node *node; - SHASH_FOR_EACH (node, &netdev_dev_shash) { - struct netdev_dev *dev = node->data; + SHASH_FOR_EACH (node, &netdev_shash) { + struct netdev *dev = node->data; if (dev->netdev_class == netdev_class) { shash_add(device_list, node->name, node->data); @@ -1394,62 +1357,20 @@ netdev_dev_get_devices(const struct netdev_class *netdev_class, } } -/* Initializes 'netdev' as a instance of the netdev_dev. - * - * This function adds 'netdev' to a netdev-owned linked list, so it is very - * important that 'netdev' only be freed after calling netdev_close(). */ -void -netdev_init(struct netdev *netdev, struct netdev_dev *netdev_dev) -{ - memset(netdev, 0, sizeof *netdev); - netdev->netdev_dev = netdev_dev; - list_push_back(&netdev_list, &netdev->node); -} - -/* Undoes the results of initialization. - * - * Normally this function only needs to be called from netdev_close(). - * However, it may be called by providers due to an error on opening - * that occurs after initialization. It this case netdev_close() would - * never be called. */ -void -netdev_uninit(struct netdev *netdev, bool close) -{ - list_remove(&netdev->node); - if (close) { - netdev_get_dev(netdev)->netdev_class->close(netdev); - } -} - -/* Returns the class type of 'netdev'. - * - * The caller must not free the returned value. */ -const char * -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) -{ - return netdev->netdev_dev; + const struct netdev *dev = netdev_from_name(name); + return dev ? netdev_get_type(dev) : NULL; } void -netdev_rx_init(struct netdev_rx *rx, struct netdev_dev *dev, +netdev_rx_init(struct netdev_rx *rx, struct netdev *netdev, const struct netdev_rx_class *class) { - ovs_assert(dev->ref_cnt > 0); + ovs_assert(netdev->ref_cnt > 0); rx->rx_class = class; - rx->netdev_dev = dev; + rx->netdev = netdev; } void @@ -1458,17 +1379,17 @@ netdev_rx_uninit(struct netdev_rx *rx OVS_UNUSED) /* Nothing to do. */ } -struct netdev_dev * -netdev_rx_get_dev(const struct netdev_rx *rx) +struct netdev * +netdev_rx_get_netdev(const struct netdev_rx *rx) { - ovs_assert(rx->netdev_dev->ref_cnt > 0); - return rx->netdev_dev; + ovs_assert(rx->netdev->ref_cnt > 0); + return rx->netdev; } const char * netdev_rx_get_name(const struct netdev_rx *rx) { - return netdev_dev_get_name(netdev_rx_get_dev(rx)); + return netdev_get_name(netdev_rx_get_netdev(rx)); } static void @@ -1476,14 +1397,14 @@ restore_all_flags(void *aux OVS_UNUSED) { struct shash_node *node; - SHASH_FOR_EACH (node, &netdev_dev_shash) { - struct netdev_dev *dev = node->data; + SHASH_FOR_EACH (node, &netdev_shash) { + struct netdev *netdev = node->data; const struct netdev_saved_flags *sf; enum netdev_flags saved_values; enum netdev_flags saved_flags; saved_values = saved_flags = 0; - LIST_FOR_EACH (sf, node, &dev->saved_flags_list) { + LIST_FOR_EACH (sf, node, &netdev->saved_flags_list) { saved_flags |= sf->saved_flags; saved_values &= ~sf->saved_flags; saved_values |= sf->saved_flags & sf->saved_values; @@ -1491,10 +1412,10 @@ restore_all_flags(void *aux OVS_UNUSED) if (saved_flags) { enum netdev_flags old_flags; - dev->netdev_class->update_flags(dev, - saved_flags & saved_values, - saved_flags & ~saved_values, - &old_flags); + netdev->netdev_class->update_flags(netdev, + saved_flags & saved_values, + saved_flags & ~saved_values, + &old_flags); } } } -- 2.43.0