libnl 1.1.4

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.
 

Detailed Description

Function Documentation

◆ rtnl_neightbl_alloc()

struct rtnl_neightbl * rtnl_neightbl_alloc ( void  )

Definition at line 378 of file neightbl.c.

379{
380 return (struct rtnl_neightbl *) nl_object_alloc(&neightbl_obj_ops);
381}
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
Definition: object.c:42

◆ rtnl_neightbl_put()

void rtnl_neightbl_put ( struct rtnl_neightbl *  neightbl)

Definition at line 383 of file neightbl.c.

384{
385 nl_object_put((struct nl_object *) neightbl);
386}
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition: object.c:178

◆ rtnl_neightbl_alloc_cache()

struct nl_cache * rtnl_neightbl_alloc_cache ( struct nl_handle *  handle)
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.

408{
409 struct nl_cache * cache;
410
411 cache = nl_cache_alloc(&rtnl_neightbl_ops);
412 if (cache == NULL)
413 return NULL;
414
415 if (handle && nl_cache_refill(handle, cache) < 0) {
416 nl_cache_free(cache);
417 return NULL;
418 }
419
420 return cache;
421}
void nl_cache_free(struct nl_cache *cache)
Free a cache.
Definition: cache.c:277
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170
int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:680

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

◆ rtnl_neightbl_get()

struct rtnl_neightbl * rtnl_neightbl_get ( struct nl_cache *  cache,
const char *  name,
int  ifindex 
)
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.

438{
439 struct rtnl_neightbl *nt;
440
441 if (cache->c_ops != &rtnl_neightbl_ops)
442 return NULL;
443
444 nl_list_for_each_entry(nt, &cache->c_items, ce_list) {
445 if (!strcasecmp(nt->nt_name, name) &&
446 ((!ifindex && !nt->nt_parms.ntp_ifindex) ||
447 (ifindex && ifindex == nt->nt_parms.ntp_ifindex))) {
448 nl_object_get((struct nl_object *) nt);
449 return nt;
450 }
451 }
452
453 return NULL;
454}
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition: object.c:167

References nl_object_get().

◆ rtnl_neightbl_build_change_request()

struct nl_msg * rtnl_neightbl_build_change_request ( struct rtnl_neightbl *  old,
struct rtnl_neightbl *  tmpl 
)
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.

480{
481 struct nl_msg *m;
482 struct ndtmsg ndt = {
483 .ndtm_family = old->nt_family,
484 };
485
486 m = nlmsg_alloc_simple(RTM_SETNEIGHTBL, 0);
487 nlmsg_append(m, &ndt, sizeof(ndt), NLMSG_ALIGNTO);
488
489 nla_put_string(m, NDTA_NAME, old->nt_name);
490
491 if (tmpl->ce_mask & NEIGHTBL_ATTR_THRESH1)
492 nla_put_u32(m, NDTA_THRESH1, tmpl->nt_gc_thresh1);
493
494 if (tmpl->ce_mask & NEIGHTBL_ATTR_THRESH2)
495 nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);
496
497 if (tmpl->ce_mask & NEIGHTBL_ATTR_THRESH2)
498 nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);
499
500 if (tmpl->ce_mask & NEIGHTBL_ATTR_GC_INTERVAL)
501 nla_put_u64(m, NDTA_GC_INTERVAL,
502 tmpl->nt_gc_interval);
503
504 if (tmpl->ce_mask & NEIGHTBL_ATTR_PARMS) {
505 struct rtnl_neightbl_parms *p = &tmpl->nt_parms;
506 struct nl_msg *parms = nlmsg_alloc();
507
508 if (old->nt_parms.ntp_mask & NEIGHTBLPARM_ATTR_IFINDEX)
509 nla_put_u32(parms, NDTPA_IFINDEX,
510 old->nt_parms.ntp_ifindex);
511
512
513 if (p->ntp_mask & NEIGHTBLPARM_ATTR_QUEUE_LEN)
514 nla_put_u32(parms, NDTPA_QUEUE_LEN, p->ntp_queue_len);
515
516 if (p->ntp_mask & NEIGHTBLPARM_ATTR_APP_PROBES)
517 nla_put_u32(parms, NDTPA_APP_PROBES, p->ntp_app_probes);
518
519 if (p->ntp_mask & NEIGHTBLPARM_ATTR_UCAST_PROBES)
520 nla_put_u32(parms, NDTPA_UCAST_PROBES,
521 p->ntp_ucast_probes);
522
523 if (p->ntp_mask & NEIGHTBLPARM_ATTR_MCAST_PROBES)
524 nla_put_u32(parms, NDTPA_MCAST_PROBES,
525 p->ntp_mcast_probes);
526
527 if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_QLEN)
528 nla_put_u32(parms, NDTPA_PROXY_QLEN,
529 p->ntp_proxy_qlen);
530
531 if (p->ntp_mask & NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME)
532 nla_put_u64(parms, NDTPA_BASE_REACHABLE_TIME,
533 p->ntp_base_reachable_time);
534
535 if (p->ntp_mask & NEIGHTBLPARM_ATTR_RETRANS_TIME)
536 nla_put_u64(parms, NDTPA_RETRANS_TIME,
537 p->ntp_retrans_time);
538
539 if (p->ntp_mask & NEIGHTBLPARM_ATTR_GC_STALETIME)
540 nla_put_u64(parms, NDTPA_GC_STALETIME,
541 p->ntp_gc_stale_time);
542
543 if (p->ntp_mask & NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME)
544 nla_put_u64(parms, NDTPA_DELAY_PROBE_TIME,
545 p->ntp_proxy_delay);
546
547 if (p->ntp_mask & NEIGHTBLPARM_ATTR_ANYCAST_DELAY)
548 nla_put_u64(parms, NDTPA_ANYCAST_DELAY,
549 p->ntp_anycast_delay);
550
551 if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_DELAY)
552 nla_put_u64(parms, NDTPA_PROXY_DELAY,
553 p->ntp_proxy_delay);
554
555 if (p->ntp_mask & NEIGHTBLPARM_ATTR_LOCKTIME)
556 nla_put_u64(parms, NDTPA_LOCKTIME, p->ntp_locktime);
557
558 nla_put_nested(m, NDTA_PARMS, parms);
559 nlmsg_free(parms);
560 }
561
562 return m;
563}
int nla_put_u32(struct nl_msg *n, int attrtype, uint32_t value)
Add a u32 netlink attribute to a netlink message.
Definition: attr.c:569
int nla_put_string(struct nl_msg *n, int attrtype, const char *str)
Add a string netlink attribute to a netlink message.
Definition: attr.c:591
int nla_put_u64(struct nl_msg *n, int attrtype, uint64_t value)
Add a u64 netlink attribute to a netlink message.
Definition: attr.c:580
int nla_put_nested(struct nl_msg *n, int attrtype, struct nl_msg *nested)
Add a nested netlink attribute to a netlink message.
Definition: attr.c:535
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
Definition: msg.c:448
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
Definition: msg.c:656
struct nl_msg * nlmsg_alloc(void)
Allocate a new netlink message with the default maximum payload size.
Definition: msg.c:401
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
Definition: msg.c:549

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().

◆ rtnl_neightbl_change()

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.

580{
581 int err;
582 struct nl_msg *msg;
583
584 msg = rtnl_neightbl_build_change_request(old, tmpl);
585 err = nl_send_auto_complete(handle, msg);
586 nlmsg_free(msg);
587 if (err < 0)
588 return err;
589
590 return nl_wait_for_ack(handle);
591}
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.
Definition: neightbl.c:478
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
Definition: nl.c:373
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
Definition: nl.c:801

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

◆ rtnl_neightbl_set_family()

void rtnl_neightbl_set_family ( struct rtnl_neightbl *  ntbl,
int  family 
)

Definition at line 600 of file neightbl.c.

601{
602 ntbl->nt_family = family;
603 ntbl->ce_mask |= NEIGHTBL_ATTR_FAMILY;
604}

◆ rtnl_neightbl_set_gc_interval()

void rtnl_neightbl_set_gc_interval ( struct rtnl_neightbl *  ntbl,
uint64_t  ms 
)

Definition at line 606 of file neightbl.c.

607{
608 ntbl->nt_gc_interval = ms;
609 ntbl->ce_mask |= NEIGHTBL_ATTR_GC_INTERVAL;
610}

◆ rtnl_neightbl_set_gc_tresh1()

void rtnl_neightbl_set_gc_tresh1 ( struct rtnl_neightbl *  ntbl,
int  thresh 
)

Definition at line 612 of file neightbl.c.

613{
614 ntbl->nt_gc_thresh1 = thresh;
615 ntbl->ce_mask |= NEIGHTBL_ATTR_THRESH1;
616}

◆ rtnl_neightbl_set_gc_tresh2()

void rtnl_neightbl_set_gc_tresh2 ( struct rtnl_neightbl *  ntbl,
int  thresh 
)

Definition at line 618 of file neightbl.c.

619{
620 ntbl->nt_gc_thresh2 = thresh;
621 ntbl->ce_mask |= NEIGHTBL_ATTR_THRESH2;
622}

◆ rtnl_neightbl_set_gc_tresh3()

void rtnl_neightbl_set_gc_tresh3 ( struct rtnl_neightbl *  ntbl,
int  thresh 
)

Definition at line 624 of file neightbl.c.

625{
626 ntbl->nt_gc_thresh3 = thresh;
627 ntbl->ce_mask |= NEIGHTBL_ATTR_THRESH3;
628}

◆ rtnl_neightbl_set_name()

void rtnl_neightbl_set_name ( struct rtnl_neightbl *  ntbl,
const char *  name 
)

Definition at line 630 of file neightbl.c.

631{
632 strncpy(ntbl->nt_name, name, sizeof(ntbl->nt_name) - 1);
633 ntbl->ce_mask |= NEIGHTBL_ATTR_NAME;
634}

◆ rtnl_neightbl_set_dev()

void rtnl_neightbl_set_dev ( struct rtnl_neightbl *  ntbl,
int  ifindex 
)

Definition at line 636 of file neightbl.c.

637{
638 ntbl->nt_parms.ntp_ifindex = ifindex;
639 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_IFINDEX;
640 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
641}

◆ rtnl_neightbl_set_queue_len()

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.

649{
650 ntbl->nt_parms.ntp_queue_len = len;
651 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_QUEUE_LEN;
652 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
653}

◆ rtnl_neightbl_set_proxy_queue_len()

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.

661{
662 ntbl->nt_parms.ntp_proxy_qlen = len;
663 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_QLEN;
664 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
665}

◆ rtnl_neightbl_set_app_probes()

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.

673{
674 ntbl->nt_parms.ntp_app_probes = probes;
675 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_APP_PROBES;
676 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
677}

◆ rtnl_neightbl_set_ucast_probes()

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.

685{
686 ntbl->nt_parms.ntp_ucast_probes = probes;
687 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_UCAST_PROBES;
688 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
689}

◆ rtnl_neightbl_set_mcast_probes()

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.

697{
698 ntbl->nt_parms.ntp_mcast_probes = probes;
699 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_MCAST_PROBES;
700 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
701}

◆ rtnl_neightbl_set_base_reachable_time()

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.

710{
711 ntbl->nt_parms.ntp_base_reachable_time = ms;
712 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME;
713 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
714}

◆ rtnl_neightbl_set_retrans_time()

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.

722{
723 ntbl->nt_parms.ntp_retrans_time = ms;
724 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_RETRANS_TIME;
725 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
726}

◆ rtnl_neightbl_set_gc_stale_time()

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.

734{
735 ntbl->nt_parms.ntp_gc_stale_time = ms;
736 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_GC_STALETIME;
737 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
738}

◆ rtnl_neightbl_set_delay_probe_time()

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.

746{
747 ntbl->nt_parms.ntp_probe_delay = ms;
748 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME;
749 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
750}

◆ rtnl_neightbl_set_anycast_delay()

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.

758{
759 ntbl->nt_parms.ntp_anycast_delay = ms;
760 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_ANYCAST_DELAY;
761 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
762}

◆ rtnl_neightbl_set_proxy_delay()

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.

770{
771 ntbl->nt_parms.ntp_proxy_delay = ms;
772 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_DELAY;
773 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
774}

◆ rtnl_neightbl_set_locktime()

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.

782{
783 ntbl->nt_parms.ntp_locktime = ms;
784 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_LOCKTIME;
785 ntbl->ce_mask |= NEIGHTBL_ATTR_PARMS;
786}