Skip to contentSkip to conversation

under certain conditions netlink will not report adding a new ipv6 address

DISCUSSION Radu Benea 1 participant 1 message Feb 11, 2015

Subsystems (2)
lore
Share & tools
lore

Radu Benea

author
#0 lore raw

Hello.

I found that the netlink monitoring interface does not report adding a new ipv6 address unless:
- the interface is up
- the network cable is plugged in

Deleting the ipv6 address is reported even in these conditions.

Only tested this with e1000e since it's the only network adapter I have.

To test this just turn the network interface down, add an ipv6 address, then remove it... you will only see the deladdr message.

Example test commands:
ip link set dev devname down
ip -6 addr add 2001::5 dev devname
ip -6 addr del 2001::5 dev devname

Sample test code below.
#include <string.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>

#include <stdio.h>
#include <unistd.h>

int main(int, char * [])

{
	struct sockaddr_nl sa;
	int fd;
	int len;
	char buf[4096];
	struct iovec iov = { buf, sizeof(buf) };
	struct msghdr msg;
	struct nlmsghdr *nh;

	memset(&sa, 0, sizeof(sa));
	sa.nl_family = AF_NETLINK;
	sa.nl_pid = getpid();
	sa.nl_groups = RTMGRP_IPV6_IFADDR;

	fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
	bind(fd, (struct sockaddr *)&sa, sizeof(sa));


	while (1) {
		msg = {&sa, sizeof(sa), &iov, 1, NULL, 0, 0};
		len = recvmsg(fd, &msg, 0);

		for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) {
			/* The end of multipart message. */
			switch (nh->nlmsg_type) {
				case RTM_NEWADDR:
					printf("Received newaddr from netlink monitor\n");
					break;
				case RTM_DELADDR:
					printf("Received deladdr from netlink monitor\n");
					break;
				default:
					printf("Received unexpected message type %d from netlink monitor\n", nh->nlmsg_type);
					break;
			}
		}
	}
}