libnl 1.1

Neighbour Tables

Routing Netlink

Allocation/Freeing

struct rtnl_neightbl * rtnl_neightbl_alloc (void)
void rtnl_neightbl_put (struct rtnl_neightbl *neightbl)

Neighbour Table Cache Management

struct nl_cache * rtnl_neightbl_alloc_cache (struct nl_handle *handle)
 Build a neighbour table cache including all neighbour tables currently configured in the kernel.
struct rtnl_neightbl * rtnl_neightbl_get (struct nl_cache *cache, const char *name, int ifindex)
 Lookup neighbour table by name and optional interface index.

Neighbour Table Modifications

struct nl_msg * rtnl_neightbl_build_change_request (struct rtnl_neightbl *old, struct rtnl_neightbl *tmpl)
 Builds a netlink change request message to change neighbour table attributes.
int rtnl_neightbl_change (struct nl_handle *handle, struct rtnl_neightbl *old, struct rtnl_neightbl *tmpl)
 Change neighbour table attributes.

Attribute Modification

void rtnl_neightbl_set_family (struct rtnl_neightbl *ntbl, int family)
void rtnl_neightbl_set_gc_interval (struct rtnl_neightbl *ntbl, uint64_t ms)
void rtnl_neightbl_set_gc_tresh1 (struct rtnl_neightbl *ntbl, int thresh)
void rtnl_neightbl_set_gc_tresh2 (struct rtnl_neightbl *ntbl, int thresh)
void rtnl_neightbl_set_gc_tresh3 (struct rtnl_neightbl *ntbl, int thresh)
void rtnl_neightbl_set_name (struct rtnl_neightbl *ntbl, const char *name)
void rtnl_neightbl_set_dev (struct rtnl_neightbl *ntbl, int ifindex)
void rtnl_neightbl_set_queue_len (struct rtnl_neightbl *ntbl, int len)
 Set the queue length for pending requests of a neighbour table to the specified value.
void rtnl_neightbl_set_proxy_queue_len (struct rtnl_neightbl *ntbl, int len)
 Set the queue length for delay proxy arp requests of a neighbour table to the specified value.
void rtnl_neightbl_set_app_probes (struct rtnl_neightbl *ntbl, int probes)
 Set the number of application probes of a neighbour table to the specified value.
void rtnl_neightbl_set_ucast_probes (struct rtnl_neightbl *ntbl, int probes)
 Set the number of unicast probes of a neighbour table to the specified value.
void rtnl_neightbl_set_mcast_probes (struct rtnl_neightbl *ntbl, int probes)
 Set the number of multicast probes of a neighbour table to the specified value.
void rtnl_neightbl_set_base_reachable_time (struct rtnl_neightbl *ntbl, uint64_t ms)
 Set the base reachable time of a neighbour table to the specified value.
void rtnl_neightbl_set_retrans_time (struct rtnl_neightbl *ntbl, uint64_t ms)
 Set the retransmit time of a neighbour table to the specified value.
void rtnl_neightbl_set_gc_stale_time (struct rtnl_neightbl *ntbl, uint64_t ms)
 Set the gc stale time of a neighbour table to the specified value.
void rtnl_neightbl_set_delay_probe_time (struct rtnl_neightbl *ntbl, uint64_t ms)
 Set the first probe delay time of a neighbour table to the specified value.
void rtnl_neightbl_set_anycast_delay (struct rtnl_neightbl *ntbl, uint64_t ms)
 Set the anycast delay of a neighbour table to the specified value.
void rtnl_neightbl_set_proxy_delay (struct rtnl_neightbl *ntbl, uint64_t ms)
 Set the proxy delay of a neighbour table to the specified value.
void rtnl_neightbl_set_locktime (struct rtnl_neightbl *ntbl, uint64_t ms)
 Set the locktime of a neighbour table to the specified value.

Function Documentation

struct nl_cache* rtnl_neightbl_alloc_cache ( struct nl_handle *  handle) [read]
Parameters:
handlenetlink handle

Allocates a new neighbour table cache, initializes it properly and updates it to include all neighbour tables currently configured in the kernel.

Note:
The caller is responsible for destroying and freeing the cache after using it.
Returns:
The new cache or NULL if an error occured.

Definition at line 407 of file neightbl.c.

References nl_cache_alloc(), nl_cache_free(), and nl_cache_refill().

{
        struct nl_cache * cache;
        
        cache = nl_cache_alloc(&rtnl_neightbl_ops);
        if (cache == NULL)
                return NULL;
        
        if (handle && nl_cache_refill(handle, cache) < 0) {
                nl_cache_free(cache);
                return NULL;
        }

        return cache;
}
struct rtnl_neightbl* rtnl_neightbl_get ( struct nl_cache *  cache,
const char *  name,
int  ifindex 
) [read]
Parameters:
cacheneighbour table cache
namename of table
ifindexoptional interface index

Looks up the neighbour table matching the specified name and optionally the specified ifindex to retrieve device specific parameter sets.

Returns:
ptr to neighbour table inside the cache or NULL if no match was found.

Definition at line 436 of file neightbl.c.

References nl_object_get().

{
        struct rtnl_neightbl *nt;

        if (cache->c_ops != &rtnl_neightbl_ops)
                return NULL;

        nl_list_for_each_entry(nt, &cache->c_items, ce_list) {
                if (!strcasecmp(nt->nt_name, name) &&
                    ((!ifindex && !nt->nt_parms.ntp_ifindex) ||
                     (ifindex && ifindex == nt->nt_parms.ntp_ifindex))) {
                        nl_object_get((struct nl_object *) nt);
                        return nt;
                }
        }

        return NULL;
}
struct nl_msg* rtnl_neightbl_build_change_request ( struct rtnl_neightbl *  old,
struct rtnl_neightbl *  tmpl 
) [read]
Parameters:
oldneighbour table to change
tmpltemplate with requested changes

Builds a new netlink message requesting a change of neighbour table attributes. The netlink message header isn't fully equipped with all relevant fields and must be sent out via nl_send_auto_complete() or supplemented as needed. old must point to a neighbour table currently configured in the kernel and tmpl must contain the attributes to be changed set via rtnl_neightbl_set_* functions.

Returns:
New netlink message

Definition at line 478 of file neightbl.c.

References nla_put_nested(), nla_put_string(), nla_put_u32(), nla_put_u64(), nlmsg_alloc(), nlmsg_alloc_simple(), nlmsg_append(), and nlmsg_free().

Referenced by rtnl_neightbl_change().

{
        struct nl_msg *m;
        struct ndtmsg ndt = {
                .ndtm_family = old->nt_family,
        };

        m = nlmsg_alloc_simple(RTM_SETNEIGHTBL, 0);
        nlmsg_append(m, &ndt, sizeof(ndt), NLMSG_ALIGNTO);

        nla_put_string(m, NDTA_NAME, old->nt_name);

        if (tmpl->ce_mask & NEIGHTBL_ATTR_THRESH1)
                nla_put_u32(m, NDTA_THRESH1, tmpl->nt_gc_thresh1);

        if (tmpl->ce_mask & NEIGHTBL_ATTR_THRESH2)
                nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);

        if (tmpl->ce_mask & NEIGHTBL_ATTR_THRESH2)
                nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);

        if (tmpl->ce_mask & NEIGHTBL_ATTR_GC_INTERVAL)
                nla_put_u64(m, NDTA_GC_INTERVAL,
                                      tmpl->nt_gc_interval);

        if (tmpl->ce_mask & NEIGHTBL_ATTR_PARMS) {
                struct rtnl_neightbl_parms *p = &tmpl->nt_parms;
                struct nl_msg *parms = nlmsg_alloc();

                if (old->nt_parms.ntp_mask & NEIGHTBLPARM_ATTR_IFINDEX)
                        nla_put_u32(parms, NDTPA_IFINDEX,
                                              old->nt_parms.ntp_ifindex);


                if (p->ntp_mask & NEIGHTBLPARM_ATTR_QUEUE_LEN)
                        nla_put_u32(parms, NDTPA_QUEUE_LEN, p->ntp_queue_len);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_APP_PROBES)
                        nla_put_u32(parms, NDTPA_APP_PROBES, p->ntp_app_probes);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_UCAST_PROBES)
                        nla_put_u32(parms, NDTPA_UCAST_PROBES,
                                    p->ntp_ucast_probes);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_MCAST_PROBES)
                        nla_put_u32(parms, NDTPA_MCAST_PROBES,
                                    p->ntp_mcast_probes);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_QLEN)
                        nla_put_u32(parms, NDTPA_PROXY_QLEN,
                                    p->ntp_proxy_qlen);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME)
                        nla_put_u64(parms, NDTPA_BASE_REACHABLE_TIME,
                                    p->ntp_base_reachable_time);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_RETRANS_TIME)
                        nla_put_u64(parms, NDTPA_RETRANS_TIME,
                                    p->ntp_retrans_time);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_GC_STALETIME)
                        nla_put_u64(parms, NDTPA_GC_STALETIME,
                                    p->ntp_gc_stale_time);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME)
                        nla_put_u64(parms, NDTPA_DELAY_PROBE_TIME,
                                    p->ntp_proxy_delay);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_ANYCAST_DELAY)
                        nla_put_u64(parms, NDTPA_ANYCAST_DELAY,
                                    p->ntp_anycast_delay);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_DELAY)
                        nla_put_u64(parms, NDTPA_PROXY_DELAY,
                                              p->ntp_proxy_delay);

                if (p->ntp_mask & NEIGHTBLPARM_ATTR_LOCKTIME)
                        nla_put_u64(parms, NDTPA_LOCKTIME, p->ntp_locktime);

                nla_put_nested(m, NDTA_PARMS, parms);
                nlmsg_free(parms);
        }
        
        return m;
}
int rtnl_neightbl_change ( struct nl_handle *  handle,
struct rtnl_neightbl *  old,
struct rtnl_neightbl *  tmpl 
)
Parameters:
handlenetlink handle
oldneighbour table to be changed
tmpltemplate with requested changes

Builds a new netlink message by calling rtnl_neightbl_build_change_request(), sends the request to the kernel and waits for the next ACK to be received, i.e. blocks until the request has been processed.

Returns:
0 on success or a negative error code

Definition at line 578 of file neightbl.c.

References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_neightbl_build_change_request().

{
        int err;
        struct nl_msg *msg;
        
        msg = rtnl_neightbl_build_change_request(old, tmpl);
        err = nl_send_auto_complete(handle, msg);
        if (err < 0)
                return err;

        nlmsg_free(msg);
        return nl_wait_for_ack(handle);
}
void rtnl_neightbl_set_queue_len ( struct rtnl_neightbl *  ntbl,
int  len 
)
Parameters:
ntblneighbour table to change
lennew queue len

Definition at line 648 of file neightbl.c.

{
        ntbl->nt_parms.ntp_queue_len = len;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_QUEUE_LEN;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_proxy_queue_len ( struct rtnl_neightbl *  ntbl,
int  len 
)
Parameters:
ntblneighbour table to change
lennew queue len

Definition at line 660 of file neightbl.c.

{
        ntbl->nt_parms.ntp_proxy_qlen = len;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_QLEN;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_app_probes ( struct rtnl_neightbl *  ntbl,
int  probes 
)
Parameters:
ntblneighbour table to change
probesnew probes value

Definition at line 672 of file neightbl.c.

{
        ntbl->nt_parms.ntp_app_probes = probes;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_APP_PROBES;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_ucast_probes ( struct rtnl_neightbl *  ntbl,
int  probes 
)
Parameters:
ntblneighbour table to change
probesnew probes value

Definition at line 684 of file neightbl.c.

{
        ntbl->nt_parms.ntp_ucast_probes = probes;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_UCAST_PROBES;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_mcast_probes ( struct rtnl_neightbl *  ntbl,
int  probes 
)
Parameters:
ntblneighbour table to change
probesnew probes value

Definition at line 696 of file neightbl.c.

{
        ntbl->nt_parms.ntp_mcast_probes = probes;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_MCAST_PROBES;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_base_reachable_time ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)
Parameters:
ntblneighbour table to change
msnew base reachable time in milliseconds

Definition at line 708 of file neightbl.c.

{
        ntbl->nt_parms.ntp_base_reachable_time = ms;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_retrans_time ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)
Parameters:
ntblneighbour table to change
msnew retransmit time

Definition at line 721 of file neightbl.c.

{
        ntbl->nt_parms.ntp_retrans_time = ms;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_RETRANS_TIME;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_gc_stale_time ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)
Parameters:
ntblneighbour table to change
msnew gc stale time in milliseconds

Definition at line 733 of file neightbl.c.

{
        ntbl->nt_parms.ntp_gc_stale_time = ms;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_GC_STALETIME;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_delay_probe_time ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)
Parameters:
ntblneighbour table to change
msnew first probe delay time in milliseconds

Definition at line 745 of file neightbl.c.

{
        ntbl->nt_parms.ntp_probe_delay = ms;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_anycast_delay ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)
Parameters:
ntblneighbour table to change
msnew anycast delay in milliseconds

Definition at line 757 of file neightbl.c.

{
        ntbl->nt_parms.ntp_anycast_delay = ms;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_ANYCAST_DELAY;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_proxy_delay ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)
Parameters:
ntblneighbour table to change
msnew proxy delay in milliseconds

Definition at line 769 of file neightbl.c.

{
        ntbl->nt_parms.ntp_proxy_delay = ms;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_DELAY;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}
void rtnl_neightbl_set_locktime ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)
Parameters:
ntblneighbour table to change
msnew locktime in milliseconds

Definition at line 781 of file neightbl.c.

{
        ntbl->nt_parms.ntp_locktime = ms;
        ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_LOCKTIME;
        ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
}