All of lore.kernel.org
 help / color / mirror / Atom feed
From: Radu Benea <radu.benea@evozon.com>
To: netdev@vger.kernel.org
Subject: under certain conditions netlink will not report adding a new ipv6 address
Date: Wed, 11 Feb 2015 12:50:33 +0200 (EET)	[thread overview]
Message-ID: <1143006151.25025.1423651833494.JavaMail.zimbra@evozon.com> (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;
			}
		}
	}
}

                 reply	other threads:[~2015-02-11 10:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1143006151.25025.1423651833494.JavaMail.zimbra@evozon.com \
    --to=radu.benea@evozon.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.