/* call ioctl system call */ int vrf_if_ioctl(unsigned long request, caddr_t buffer, vrf_id_t vrf_id) { int sock; int ret; int err = 0; frr_elevate_privs(&zserv_privs) { sock = vrf_socket(AF_INET, SOCK_DGRAM, 0, vrf_id, NULL); if (sock < 0) { zlog_err("Cannot create UDP socket: %s", safe_strerror(errno)); exit(1); } ret = vrf_ioctl(vrf_id, sock, request, buffer); if (ret < 0) err = errno; } close(sock); if (ret < 0) { errno = err; return ret; } return 0; }
static int get_iflink_speed(struct interface *interface) { struct ifreq ifdata; struct ethtool_cmd ecmd; int sd; int rc; const char *ifname = interface->name; /* initialize struct */ memset(&ifdata, 0, sizeof(ifdata)); /* set interface name */ strlcpy(ifdata.ifr_name, ifname, sizeof(ifdata.ifr_name)); /* initialize ethtool interface */ memset(&ecmd, 0, sizeof(ecmd)); ecmd.cmd = ETHTOOL_GSET; /* ETHTOOL_GLINK */ ifdata.ifr_data = (caddr_t)&ecmd; /* use ioctl to get IP address of an interface */ frr_elevate_privs(&zserv_privs) { sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP, interface->vrf_id, NULL); if (sd < 0) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Failure to read interface %s speed: %d %s", ifname, errno, safe_strerror(errno)); return 0; } /* Get the current link state for the interface */ rc = vrf_ioctl(interface->vrf_id, sd, SIOCETHTOOL, (char *)&ifdata); } if (rc < 0) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "IOCTL failure to read interface %s speed: %d %s", ifname, errno, safe_strerror(errno)); ecmd.speed_hi = 0; ecmd.speed = 0; } close(sd); return (ecmd.speed_hi << 16) | ecmd.speed; }