link cache fails to get updated when interface added to/removed from bridge

David Mosberger davidm at egauge.net
Thu Apr 3 22:04:39 PDT 2014


I'm trying to use libnl-3 v3.2.11 to track the interfaces that are
part of a bridge.
I can read the initial state fine but updates don't seem to get reflected in the
cache.  I attached a short test-program.

The test-program assumes a bridge called br0 exists.  show_bridge() is
supposed to list all the interfaces part of the bridge.  On startup, the correct
list is printed.  However, when I add/remove an interface to/from the bridge
with brctl addif br0 eth0/brctl delif br0 eth0, respectively, the cache doesn't
get updated, even though I do see route/link::new and route/link:del
messages coming from the kernel.

Is there a bug in my program?

Thanks,

  --david
--
eGauge Systems LLC, http://egauge.net/, 1.877-EGAUGE1, fax 720.545.9768

#include <netlink/route/link.h>
#include <netlink/route/addr.h>

static struct
  {
    struct nl_cache_mngr *manager;
    struct nl_cache *cache;
  }
nl;

struct cb_info
  {
    int bridge_ifindex;
  };

static void
handle_link (struct nl_object *obj, void *arg)
{
  struct rtnl_link *link = (void *) obj;
  struct cb_info *cbi = arg;

  if (rtnl_link_get_master (link) == cbi->bridge_ifindex)
    printf (" %s", rtnl_link_get_name (link));
}

static void
show_bridge (void)
{
  struct rtnl_link *bridge = rtnl_link_get_by_name (nl.cache, "br0");
  struct cb_info cbi;

  cbi.bridge_ifindex = rtnl_link_get_ifindex (bridge);

  printf ("br0:");
  nl_cache_foreach (nl.cache, handle_link, &cbi);
  printf ("\n");

  rtnl_link_put (bridge);
}

int
main (int argc, char **argv)
{
  nl_cache_mngr_alloc (NULL, NETLINK_ROUTE, NL_AUTO_PROVIDE, &nl.manager);
  nl_cache_mngr_add (nl.manager, "route/link", NULL, NULL, &nl.cache);

  show_bridge ();

  while (1)
    if (nl_cache_mngr_poll (nl.manager, 1000) > 0)
      {
        printf ("cache manager got update\n");
        show_bridge ();
      }
}



More information about the libnl mailing list