- 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);
- }
- }
- memcpy(ea, ifr.ifr_hwaddr.sa_data, ETH_ADDR_LEN);
- return 0;
-}
-
-static int
-set_etheraddr(const char *netdev_name, int hwaddr_family,
- const uint8_t mac[ETH_ADDR_LEN])
-{
- struct ifreq ifr;
-
- memset(&ifr, 0, sizeof ifr);
- strncpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
- ifr.ifr_hwaddr.sa_family = hwaddr_family;
- memcpy(ifr.ifr_hwaddr.sa_data, mac, ETH_ADDR_LEN);
- COVERAGE_INC(netdev_set_hwaddr);
- if (ioctl(af_inet_sock, SIOCSIFHWADDR, &ifr) < 0) {
- VLOG_ERR("ioctl(SIOCSIFHWADDR) on %s device failed: %s",
- netdev_name, strerror(errno));
- return errno;
- }
- return 0;