NULL link in address cache NL_ACT_DEL change event

Nicolas CARRIER nicolas.carrier at parrot.com
Thu Dec 19 05:24:34 EST 2013


Hello,
I monitor the network interfaces and addresses on a system with libnl's cache
management. I set up cache management for both "route/addr" and "route/link".
The version of libnl is 3.2.7.

When I receive a NL_ACT_DEL change event on, say, 192.168.4.1 for eth0, if I do
the following (1), in the change_func_t :

static void addr_event(struct nl_cache *cache, struct nl_object *object,
		int event, void *data)
{
	struct rtnl_addr *addr = (struct rtnl_addr *)object;
	struct rtnl_link *link;

	if (NULL == object) {
		verbose("NULL object in address event");
		return;
	}
	link = rtnl_addr_get_link(addr);
	if (NULL == link) {
		verbose("NULL link in address event");
		return;
	}
	... SNIP ...

Then link is NULL. But if I do (2) :

static void addr_event(struct nl_cache *cache, struct nl_object *object,
		int event, void *data)
{
	struct rtnl_addr *addr = (struct rtnl_addr *)object;
	char ifname[256];
	int ifindex;

	if (NULL == object) {
		verbose("NULL object in address event");
		return;
	}
	ifindex = rtnl_addr_get_ifindex(addr);
	rtnl_link_i2name(ctx->link_cache, ifindex, ifname, 256);
	if ('\0' == ifname[0]) {
		verbose("NULL name in address event");
		return;
	}
	... SNIP ...

then ifname is valid and I can use it.

What I want to do is to retrieve the interface name, so (2) is perfectly ok for me.

But is this behavior normal ? Shouldn't information returned by
rtnl_addr_get_ifindex and rtnl_addr_get_link be "the same" ?

Thank you in advance.







More information about the libnl mailing list