【发布时间】:2019-09-09 12:56:18
【问题描述】:
我需要获取给定 VLAN 接口的real_dev(例如 ID)。
我用libnl写了一些测试sn-p:
int main(void) {
struct nl_sock *sock;
struct nl_cache *cache;
char iface[] = "eno1.10";
//char iface[] = "eno1";
if (!(sock = nl_socket_alloc())) {
perror("nl_socket_alloc");
return -1;
}
if (nl_connect(sock, NETLINK_ROUTE) < 0) {
perror("nl_connect");
nl_socket_free( sock );
return -1;
}
if (rtnl_link_alloc_cache(sock, AF_UNSPEC, &cache) < 0) {
perror("rtnl_link_alloc_cache");
nl_socket_free( sock );
nl_close( sock );
return -1;
}
{
int ifindex;
struct rtnl_link *link = NULL;
if (!(ifindex = rtnl_link_name2i(cache, iface))) {
perror("rtnl_link_name2i");
return -1;
}
printf("ind: %d\n", ifindex);
if (!(link = rtnl_link_get(cache, ifindex))) {
perror("rtnl_link_get");
return -1;
}
if (rtnl_link_is_vlan(link)) {
puts("It's VLAN link");
/* alas it's not about the 'real' device */
printf("master: %d\n", rtnl_link_get_master(link));
} else
puts("It's 'real' link");
}
return 0;
}
所以我有一些接口 ID,我可以检查它是否是 VLAN 接口,但我不知道 如何获取 vlan 所连接的接口 em>。 libnl 的 API 似乎没有提供这种可能性。
有没有办法通过libnl或者native netlink API获取VLAN的“父”接口ID?
【问题讨论】:
标签: c linux linux-kernel netlink vlan