static void get_flags_sync_cb (struct nl_object *obj, void *arg) { GetFlagsInfo *info = arg; /* Ensure this cache item matches our filter */ if (nl_object_match_filter (obj, OBJ_CAST (info->filter)) != 0) info->flags = rtnl_link_get_flags ((struct rtnl_link *) obj); }
static void get_neigh_cb_event(struct nl_object *obj, void *arg) { struct get_neigh_handler *neigh_handler = (struct get_neigh_handler *)arg; /* assumed serilized callback (no parallel execution of function) */ if (nl_object_match_filter( obj, (struct nl_object *)neigh_handler->filter_neigh)) { struct rtnl_neigh *neigh = (struct rtnl_neigh *)obj; /* check that we didn't set it already */ if (neigh_handler->found_ll_addr == NULL) { if (rtnl_neigh_get_lladdr(neigh) == NULL) return; neigh_handler->found_ll_addr = nl_addr_clone(rtnl_neigh_get_lladdr(neigh)); } } }
static void iface_mon_handler2(struct nl_object *obj, void *arg) { struct rtnl_link *filter; struct rtnl_link *link_obj; int flags, up; char *ifname; iface_mon_cb cb = (iface_mon_cb)arg; filter = rtnl_link_alloc(); if (!filter) { fprintf(stderr, "error allocating filter\n"); return; } if (nl_object_match_filter (obj, OBJ_CAST (filter)) == 0) { rtnl_link_put(filter); return; } link_obj = (struct rtnl_link *) obj; flags = rtnl_link_get_flags (link_obj); ifname = rtnl_link_get_name(link_obj); /* * You can't bind a PF_PACKET socket to an interface that's not * up, so an interface going down is an "interface should be * removed" indication. * * XXX - what indication, if any, do we get if the interface * *completely goes away*? * * XXX - can we get events if an interface's link-layer or * network addresses change? */ up = (flags & IFF_UP) ? 1 : 0; cb(ifname, up); rtnl_link_put(filter); return; }
static void link_msg_handler (struct nl_object *obj, void *arg) { NMNetlinkMonitor *self = NM_NETLINK_MONITOR (arg); struct rtnl_link *filter; struct rtnl_link *link_obj; guint flags; guint ifidx; filter = rtnl_link_alloc (); if (!filter) { log_error_limited (self, NM_NETLINK_MONITOR_ERROR_BAD_ALLOC, _("error processing netlink message: %s"), nl_geterror (ENOMEM)); return; } /* Ensure it's a link object */ if (nl_object_match_filter (obj, OBJ_CAST (filter)) == 0) { rtnl_link_put (filter); return; } link_obj = (struct rtnl_link *) obj; flags = rtnl_link_get_flags (link_obj); ifidx = rtnl_link_get_ifindex (link_obj); nm_log_dbg (LOGD_HW, "netlink link message: iface idx %d flags 0x%X", ifidx, flags); /* IFF_LOWER_UP is the indicator of carrier status since kernel commit * b00055aacdb172c05067612278ba27265fcd05ce in 2.6.17. */ if (flags & IFF_LOWER_UP) g_signal_emit (self, signals[CARRIER_ON], 0, ifidx); else g_signal_emit (self, signals[CARRIER_OFF], 0, ifidx); rtnl_link_put (filter); }