netlink: NETLINK_GET_STRICT_CHK is not available on older kernels
For example on 4.19. Don't fail if we can't set it, filter on interface index in nl_addr(). Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
8a874ecf58
commit
5496074862
1 changed files with 6 additions and 3 deletions
|
@ -51,13 +51,14 @@ static int __nl_sock_init(void *arg)
|
||||||
|
|
||||||
ns:
|
ns:
|
||||||
if (((*s) = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0 ||
|
if (((*s) = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0 ||
|
||||||
bind(*s, (struct sockaddr *)&addr, sizeof(addr)) ||
|
bind(*s, (struct sockaddr *)&addr, sizeof(addr)))
|
||||||
setsockopt(*s, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &v, sizeof(v)))
|
|
||||||
*s = -1;
|
*s = -1;
|
||||||
|
|
||||||
if (*s == -1 || !c || s == &nl_sock_ns)
|
if (*s == -1 || !c || s == &nl_sock_ns)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
setsockopt(*s, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &v, sizeof(v));
|
||||||
|
|
||||||
ns_enter((struct ctx *)arg);
|
ns_enter((struct ctx *)arg);
|
||||||
s = &nl_sock_ns;
|
s = &nl_sock_ns;
|
||||||
goto ns;
|
goto ns;
|
||||||
|
@ -425,6 +426,8 @@ void nl_addr(int ns, unsigned int ifi, sa_family_t af,
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
ifa = (struct ifaddrmsg *)NLMSG_DATA(nh);
|
ifa = (struct ifaddrmsg *)NLMSG_DATA(nh);
|
||||||
|
if (ifa->ifa_index != ifi)
|
||||||
|
goto next;
|
||||||
|
|
||||||
for (rta = (struct rtattr *)IFA_RTA(ifa), na = RTM_PAYLOAD(nh);
|
for (rta = (struct rtattr *)IFA_RTA(ifa), na = RTM_PAYLOAD(nh);
|
||||||
RTA_OK(rta, na); rta = RTA_NEXT(rta, na)) {
|
RTA_OK(rta, na); rta = RTA_NEXT(rta, na)) {
|
||||||
|
|
Loading…
Reference in a new issue