Exemplo n.º 1
0
static void
_j4status_nl_cache_change(struct nl_cache *cache, struct nl_object *object, int something, void *user_data)
{
    J4statusPluginContext *self = user_data;
        J4statusNlSection *section;

    if ( cache == self->link_cache )
    {
        struct rtnl_link *link = nl_object_priv(object);

        section = g_hash_table_lookup(self->sections, GINT_TO_POINTER(rtnl_link_get_ifindex(link)));
        if ( section == NULL )
            return;
        g_debug("Link cache update: %p = %s", object, rtnl_link_get_ifalias(link));

        if ( section->link != link )
        {
            nl_object_get(object);
            rtnl_link_put(section->link);
            section->link = link;
        }

    }
    else if ( cache == self->addr_cache )
    {
        struct rtnl_addr *addr = nl_object_priv(object);
        section = g_hash_table_lookup(self->sections, GINT_TO_POINTER(rtnl_addr_get_ifindex(addr)));
        if ( section == NULL )
            return;
        g_debug("Addr cache update: %p = %d", object, rtnl_addr_get_ifindex(addr));

        GList **list;
        switch ( rtnl_addr_get_family(addr) )
        {
        case AF_INET:
            list = &section->ipv4_addresses;
        break;
        case AF_INET6:
            list = &section->ipv6_addresses;
        break;
        default:
            /* Not supported */
            return;
        }

        if ( g_list_find_custom(*list, addr,_j4status_nl_address_compare)  != NULL )
            /* Already got it */
            return;

        nl_object_get(object);
        *list = g_list_prepend(*list, addr);
    }
    else
        g_assert_not_reached();
    _j4status_nl_section_update(section);
}
Exemplo n.º 2
0
void nl_bridge::set_bridge_interface(rtnl_link *bridge) {
  assert(bridge);
  assert(std::string("bridge").compare(rtnl_link_get_type(bridge)) == 0);

  this->bridge = bridge;
  nl_object_get(OBJ_CAST(bridge));
}
Exemplo n.º 3
0
/**
 * Add object to hashtable
 * @arg ht		Hashtable
 * @arg obj		Object to add
 *
 * Adds `obj` to the hashtable. Object type must support hashing, otherwise all
 * objects will be added to the chain `0`.
 *
 * @note The reference counter of the object is incremented.
 *
 * @return 0 on success or a negative error code
 * @retval -NLE_EXIST Identical object already present in hashtable
 */
int nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj)
{
	nl_hash_node_t *node;
	uint32_t key_hash;

	nl_object_keygen(obj, &key_hash, ht->size);
	node = ht->nodes[key_hash];

	while (node) {
	       if (nl_object_identical(node->obj, obj)) {
		   NL_DBG(2, "Warning: Add to hashtable found duplicate...\n");
		   return -NLE_EXIST;
	       }
	       node = node->next;
	}

	NL_DBG (5, "adding cache entry of obj %p in table %p, with hash 0x%x\n",
		obj, ht, key_hash);

	node = malloc(sizeof(nl_hash_node_t));
	if (!node)
		return -NLE_NOMEM;
	nl_object_get(obj);
	node->obj = obj;
	node->key = key_hash;
	node->key_size = sizeof(uint32_t);
	node->next = ht->nodes[key_hash];
	ht->nodes[key_hash] = node;

	return 0;
}
Exemplo n.º 4
0
static void
ref_object (struct nl_object *obj, void *data)
{
	struct nl_object **out = data;

	nl_object_get (obj);
	*out = obj;
}
Exemplo n.º 5
0
Arquivo: tc.c Projeto: acooks/libnl
/**
 * Get link of traffic control object
 * @arg tc		traffic control object
 *
 * Returns the link of a traffic control object. The link is only
 * returned if it has been set before via rtnl_tc_set_link() or
 * if a link cache was available while parsing the tc object. This
 * function may still return NULL even if an ifindex is assigned to
 * the tc object. It will _not_ look up the link by itself.
 *
 * @note The returned link will have its reference counter incremented.
 *       It is in the responsibility of the caller to return the
 *       reference.
 *
 * @return link object or NULL if not set.
 */
struct rtnl_link *rtnl_tc_get_link(struct rtnl_tc *tc)
{
	if (tc->tc_link) {
		nl_object_get(OBJ_CAST(tc->tc_link));
		return tc->tc_link;
	}

	return NULL;
}
Exemplo n.º 6
0
/**
 * Set link of traffic control object
 * @arg tc		traffic control object
 * @arg link		link object
 *
 * Sets the link of a traffic control object. This function serves
 * the same purpose as rtnl_tc_set_ifindex() but due to the continued
 * allowed access to the link object it gives it the possibility to
 * retrieve sane default values for the the MTU and the linktype.
 * Always prefer this function over rtnl_tc_set_ifindex() if you can
 * spare to have an additional link object around.
 */
void rtnl_tc_set_link(struct rtnl_tc *tc, struct rtnl_link *link)
{
	rtnl_link_put(tc->tc_link);

	if (!link)
		return;

	nl_object_get(OBJ_CAST(link));
	tc->tc_link = link;
	tc->tc_ifindex = link->l_index;
	tc->ce_mask |= TCA_ATTR_LINK | TCA_ATTR_IFINDEX;
}
Exemplo n.º 7
0
static int __store_answer(struct nl_object *obj, struct nl_parser_param *p)
{
	struct pickup_param *pp = p->pp_arg;
	/*
	 * the parser will put() the object at the end, expecting the cache
	 * to take the reference.
	 */
	nl_object_get(obj);
	pp->result =  obj;

	return 0;
}
Exemplo n.º 8
0
void netlink_wrapper::notify_cache_entries(struct nl_cache* cache) {
	nl_logfunc("--->netlink_wrapper::notify_cache_entries");
	g_nl_rcv_arg.msghdr = NULL;
	nl_object* obj = nl_cache_get_first(m_cache_neigh);
	while (obj) {
		nl_object_get(obj);
		neigh_cache_callback(cache, obj, 0);
		nl_object_put(obj);
		obj = nl_cache_get_next(obj);
	}
	nl_logfunc("<---netlink_wrapper::notify_cache_entries");

}
Exemplo n.º 9
0
int netlink_wrapper::get_neigh(const char* ipaddr, netlink_neigh_info* new_neigh_info)
{
	auto_unlocker lock(m_cache_lock);
	nl_logfunc("--->netlink_listener::get_neigh");
	nl_object* obj;
	rtnl_neigh* neigh;
	char addr_str[256];

	BULLSEYE_EXCLUDE_BLOCK_START
	if (!new_neigh_info) {
		nl_logerr("Illegal argument. user pass NULL neigh_info to fill");
		return -1;
	}
	BULLSEYE_EXCLUDE_BLOCK_END

	obj = nl_cache_get_first(m_cache_neigh);
	while (obj) {
		nl_object_get(obj); //Acquire a reference on a cache object. cache won't use/free it until calling to nl_object_put(obj)
		neigh = (rtnl_neigh*) obj;
		nl_addr* addr = rtnl_neigh_get_dst(neigh);
		if (addr) {
			nl_addr2str(addr, addr_str, 255);
			if (!strcmp(addr_str, ipaddr)) {
				new_neigh_info->fill(neigh);
				nl_object_put(obj);
				nl_logdbg("neigh - DST_IP:%s LLADDR:%s", addr_str, new_neigh_info->lladdr_str.c_str() );
				nl_logfunc("<---netlink_listener::get_neigh");
				return 1;
			}
		}
		nl_object_put(obj);
		obj = nl_cache_get_next(obj);
	}

	nl_logfunc("<---netlink_listener::get_neigh");
	return 0;
}
Exemplo n.º 10
0
void idiagnl_msg_get(struct idiagnl_msg *msg)
{
	nl_object_get((struct nl_object *) msg);
}
Exemplo n.º 11
0
void nl_dect_cell_get(struct nl_dect_cell *cell)
{
	nl_object_get((struct nl_object *)cell);
}
Exemplo n.º 12
0
void nfnl_log_get(struct nfnl_log *log)
{
    nl_object_get((struct nl_object *) log);
}
Exemplo n.º 13
0
void nfnl_ct_get(struct nfnl_ct *ct)
{
	nl_object_get((struct nl_object *) ct);
}
Exemplo n.º 14
0
void nfnl_exp_get(struct nfnl_exp *exp)
{
	nl_object_get((struct nl_object *) exp);
}
Exemplo n.º 15
0
TNlLink::TNlLink(std::shared_ptr<TNl> sock, struct rtnl_link *link) {
    Nl = sock;
    Link = link;
    nl_object_get(OBJ_CAST(Link));
}
Exemplo n.º 16
0
/* Callback used by nl_cache_foreach_filter in nl_cache_find.
 * Sets parameter p to point to parameter found
 */
void cb_found_cache_obj(struct nl_object *found, void *p)
{
	struct nl_object **out = (struct nl_object **)p;
	nl_object_get(found);
	*out = found;
}
Exemplo n.º 17
0
void nfnl_queue_get(struct nfnl_queue *queue)
{
	nl_object_get((struct nl_object *) queue);
}