From 34290dbfe54a930258d4c1d00e82e7c3f51cea5f Mon Sep 17 00:00:00 2001 From: Giuseppe Lettieri Date: Thu, 15 Aug 2013 19:34:06 +0200 Subject: [PATCH] netdev-pltap: Make access to AF_INET socket thread-safe. --- lib/netdev-pltap.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/netdev-pltap.c b/lib/netdev-pltap.c index 0c492650a..8f4a67ac0 100644 --- a/lib/netdev-pltap.c +++ b/lib/netdev-pltap.c @@ -70,8 +70,6 @@ struct netdev_rx_pltap { int fd; }; -static int af_inet_sock = -1; - static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); static struct shash pltap_netdevs = SHASH_INITIALIZER(&pltap_netdevs); @@ -567,16 +565,13 @@ get_etheraddr(struct netdev_pltap *dev, uint8_t ea[ETH_ADDR_LEN]) { struct ifreq ifr; int hwaddr_family; + int error; memset(&ifr, 0, sizeof ifr); ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name); - if (ioctl(af_inet_sock, SIOCGIFHWADDR, &ifr) < 0) { - /* ENODEV probably means that a vif disappeared asynchronously and - * hasn't been removed from the database yet, so reduce the log level - * to INFO for that case. */ - VLOG(errno == ENODEV ? VLL_INFO : VLL_ERR, - "ioctl(SIOCGIFHWADDR) on %s device failed: %s", - dev->real_name, ovs_strerror(errno)); + error = af_inet_ifreq_ioctl(dev->real_name, &ifr, + SIOCGIFHWADDR, "SIOCGIFHWADDR"); + if (error) { return errno; } hwaddr_family = ifr.ifr_hwaddr.sa_family; @@ -592,11 +587,13 @@ static int get_flags(struct netdev_pltap *dev, enum netdev_flags *flags) { struct ifreq ifr; + int error; - memset(&ifr, 0, sizeof ifr); - ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name); - if (ioctl(af_inet_sock, SIOCGIFFLAGS, &ifr) < 0) - return errno; + error = af_inet_ifreq_ioctl(dev->real_name, &ifr, + SIOCGIFFLAGS, "SIOCGIFFLAGS"); + if (error) { + return error; + } *flags = 0; if (ifr.ifr_flags & IFF_UP) *flags |= NETDEV_UP; @@ -698,10 +695,6 @@ static int netdev_pltap_init(void) { list_init(&sync_list); - af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0); - if (af_inet_sock < 0) { - VLOG_ERR("failed to create inet socket: %s", ovs_strerror(errno)); - } unixctl_command_register("netdev-pltap/get-tapname", "port", 1, 1, netdev_pltap_get_real_name, NULL); return 0; -- 2.43.0