From 5496074862b8ec62a6f50b87d96a65c771b504a6 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 19 Oct 2021 09:08:06 +0200 Subject: 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 --- netlink.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'netlink.c') diff --git a/netlink.c b/netlink.c index 10d8a92..2e72568 100644 --- a/netlink.c +++ b/netlink.c @@ -50,14 +50,15 @@ static int __nl_sock_init(void *arg) int *s = &nl_sock, v = 1; ns: - if (((*s) = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0 || - bind(*s, (struct sockaddr *)&addr, sizeof(addr)) || - setsockopt(*s, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &v, sizeof(v))) + if (((*s) = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0 || + bind(*s, (struct sockaddr *)&addr, sizeof(addr))) *s = -1; if (*s == -1 || !c || s == &nl_sock_ns) return 0; + setsockopt(*s, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &v, sizeof(v)); + ns_enter((struct ctx *)arg); s = &nl_sock_ns; goto ns; @@ -425,6 +426,8 @@ void nl_addr(int ns, unsigned int ifi, sa_family_t af, goto next; ifa = (struct ifaddrmsg *)NLMSG_DATA(nh); + if (ifa->ifa_index != ifi) + goto next; for (rta = (struct rtattr *)IFA_RTA(ifa), na = RTM_PAYLOAD(nh); RTA_OK(rta, na); rta = RTA_NEXT(rta, na)) { -- cgit v1.2.3