| 621 | } |
| 622 | |
| 623 | void network_interface_up(const char *ifname) |
| 624 | { |
| 625 | struct ifreq ifr = {}; |
| 626 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); |
| 627 | int sockfd = Socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); |
| 628 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) { // SIOCGIFFLAGS - 请求获取网络接口的标志位 |
| 629 | perror("ioctl(SIOCGIFFLAGS)"); |
| 630 | exit(EXIT_FAILURE); |
| 631 | } |
| 632 | |
| 633 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); |
| 634 | ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); |
| 635 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) { // SIOCSIFFLAGS - 设置接口标志 |
| 636 | perror("ioctl(SIOCSIFFLAGS)"); |
| 637 | exit(EXIT_FAILURE); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | void create_dummy_network_interface(struct mnl_socket *route_socket, const char *ifname, u32 tx_queues, u32 mtu) |
| 642 | { // 对应的内核处理函数是 __rtnl_newlink() - 可看出输入结构: nlmsghdr + ifinfomsg + IFLA_LINKINFO |
no test coverage detected