- struct netdev *netdev;
- LIST_FOR_EACH (netdev, struct netdev, node, &netdev_list) {
- restore_flags(netdev);
- }
-}
-
-static int
-get_flags(const char *netdev_name, int *flags)
-{
- struct ifreq ifr;
- strncpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
- COVERAGE_INC(netdev_get_flags);
- if (ioctl(af_inet_sock, SIOCGIFFLAGS, &ifr) < 0) {
- VLOG_ERR("ioctl(SIOCGIFFLAGS) on %s device failed: %s",
- netdev_name, strerror(errno));
- return errno;
- }
- *flags = ifr.ifr_flags;
- return 0;
-}
-
-static int
-set_flags(const char *netdev_name, int flags)
-{
- struct ifreq ifr;
- strncpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
- ifr.ifr_flags = flags;
- COVERAGE_INC(netdev_set_flags);
- if (ioctl(af_inet_sock, SIOCSIFFLAGS, &ifr) < 0) {
- VLOG_ERR("ioctl(SIOCSIFFLAGS) on %s device failed: %s",
- netdev_name, strerror(errno));
- return errno;
- }
- return 0;
-}
-
-static int
-do_get_ifindex(const char *netdev_name)
-{
- struct ifreq ifr;
-
- strncpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
- COVERAGE_INC(netdev_get_ifindex);
- if (ioctl(af_inet_sock, SIOCGIFINDEX, &ifr) < 0) {
- VLOG_WARN_RL(&rl, "ioctl(SIOCGIFINDEX) on %s device failed: %s",
- netdev_name, strerror(errno));
- return -errno;
- }
- return ifr.ifr_ifindex;
-}
-
-static int
-get_ifindex(const struct netdev *netdev, int *ifindexp)
-{
- *ifindexp = 0;
- if (netdev->ifindex < 0) {
- int ifindex = do_get_ifindex(netdev->name);
- if (ifindex < 0) {
- return -ifindex;
- }
- ((struct netdev *) netdev)->ifindex = ifindex;
- }
- *ifindexp = netdev->ifindex;
- return 0;
-}
-
-static int
-get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN],
- int *hwaddr_familyp)
-{
- struct ifreq ifr;
-
- memset(&ifr, 0, sizeof ifr);
- strncpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
- COVERAGE_INC(netdev_get_hwaddr);
- if (ioctl(af_inet_sock, SIOCGIFHWADDR, &ifr) < 0) {
- VLOG_ERR("ioctl(SIOCGIFHWADDR) on %s device failed: %s",
- netdev_name, strerror(errno));
- return errno;
- }
- if (hwaddr_familyp) {
- int hwaddr_family = ifr.ifr_hwaddr.sa_family;
- *hwaddr_familyp = hwaddr_family;
- if (hwaddr_family != AF_UNSPEC && hwaddr_family != ARPHRD_ETHER) {
- VLOG_WARN("%s device has unknown hardware address family %d",
- netdev_name, hwaddr_family);
- }