2 * lib/route/neightbl.c neighbour tables
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
14 * @defgroup neightbl Neighbour Tables
19 #include <netlink-local.h>
20 #include <netlink/netlink.h>
21 #include <netlink/utils.h>
22 #include <netlink/route/rtnl.h>
23 #include <netlink/route/neightbl.h>
24 #include <netlink/route/link.h>
27 #define NEIGHTBL_ATTR_FAMILY 0x001
28 #define NEIGHTBL_ATTR_STATS 0x002
29 #define NEIGHTBL_ATTR_NAME 0x004
30 #define NEIGHTBL_ATTR_THRESH1 0x008
31 #define NEIGHTBL_ATTR_THRESH2 0x010
32 #define NEIGHTBL_ATTR_THRESH3 0x020
33 #define NEIGHTBL_ATTR_CONFIG 0x040
34 #define NEIGHTBL_ATTR_PARMS 0x080
35 #define NEIGHTBL_ATTR_GC_INTERVAL 0x100
37 #define NEIGHTBLPARM_ATTR_IFINDEX 0x0001
38 #define NEIGHTBLPARM_ATTR_REFCNT 0x0002
39 #define NEIGHTBLPARM_ATTR_QUEUE_LEN 0x0004
40 #define NEIGHTBLPARM_ATTR_APP_PROBES 0x0008
41 #define NEIGHTBLPARM_ATTR_UCAST_PROBES 0x0010
42 #define NEIGHTBLPARM_ATTR_MCAST_PROBES 0x0020
43 #define NEIGHTBLPARM_ATTR_PROXY_QLEN 0x0040
44 #define NEIGHTBLPARM_ATTR_REACHABLE_TIME 0x0080
45 #define NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME 0x0100
46 #define NEIGHTBLPARM_ATTR_RETRANS_TIME 0x0200
47 #define NEIGHTBLPARM_ATTR_GC_STALETIME 0x0400
48 #define NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME 0x0800
49 #define NEIGHTBLPARM_ATTR_ANYCAST_DELAY 0x1000
50 #define NEIGHTBLPARM_ATTR_PROXY_DELAY 0x2000
51 #define NEIGHTBLPARM_ATTR_LOCKTIME 0x4000
53 static struct nl_cache_ops rtnl_neightbl_ops;
56 static int neightbl_filter(struct nl_object *obj, struct nl_object *filter)
58 struct rtnl_neightbl *o = (struct rtnl_neightbl *) obj;
59 struct rtnl_neightbl *f = (struct rtnl_neightbl *) filter;
60 struct rtnl_neightbl_parms *op = &o->nt_parms;
61 struct rtnl_neightbl_parms *fp = &f->nt_parms;
63 #define REQ(F) (f->nt_mask & NEIGHTBL_ATTR_##F)
64 #define AVAIL(F) (o->nt_mask & NEIGHTBL_ATTR_##F)
65 #define _O(F, EXPR) (REQ(F) && (!AVAIL(F) || (EXPR)))
66 #define _C(F, N) (REQ(F) && (!AVAIL(F) || (o->N != f->N)))
68 if (_C(FAMILY, nt_family) ||
69 _O(NAME, strcmp(o->nt_name, f->nt_name)) ||
70 _C(THRESH1, nt_gc_thresh1) ||
71 _C(THRESH2, nt_gc_thresh2) ||
72 _C(THRESH3, nt_gc_thresh3) ||
73 _C(GC_INTERVAL, nt_gc_interval))
80 if (!(f->nt_mask & NEIGHTBL_ATTR_PARMS) &&
81 !(o->nt_mask & NEIGHTBL_ATTR_PARMS))
84 #define REQ(F) (fp->ntp_mask & NEIGHTBLPARM_ATTR_##F)
85 #define AVAIL(F) (op->ntp_mask & NEIGHTBLPARM_ATTR_##F)
86 #define _C(F, N) (REQ(F) && (!AVAIL(F) || (op->N != fp->N)))
87 if (_C(IFINDEX, ntp_ifindex) ||
88 _C(QUEUE_LEN, ntp_queue_len) ||
89 _C(APP_PROBES, ntp_app_probes) ||
90 _C(UCAST_PROBES, ntp_ucast_probes) ||
91 _C(MCAST_PROBES, ntp_mcast_probes) ||
92 _C(PROXY_QLEN, ntp_proxy_qlen) ||
93 _C(LOCKTIME, ntp_locktime) ||
94 _C(RETRANS_TIME, ntp_retrans_time) ||
95 _C(BASE_REACHABLE_TIME, ntp_base_reachable_time) ||
96 _C(GC_STALETIME, ntp_gc_stale_time) ||
97 _C(DELAY_PROBE_TIME, ntp_probe_delay) ||
98 _C(ANYCAST_DELAY, ntp_anycast_delay) ||
99 _C(PROXY_DELAY, ntp_proxy_delay))
108 static struct nla_policy neightbl_policy[NDTA_MAX+1] = {
109 [NDTA_NAME] = { .type = NLA_STRING,
110 .maxlen = NTBLNAMSIZ },
111 [NDTA_THRESH1] = { .type = NLA_U32 },
112 [NDTA_THRESH2] = { .type = NLA_U32 },
113 [NDTA_THRESH3] = { .type = NLA_U32 },
114 [NDTA_GC_INTERVAL] = { .type = NLA_U32 },
115 [NDTA_CONFIG] = { .minlen = sizeof(struct ndt_config) },
116 [NDTA_STATS] = { .minlen = sizeof(struct ndt_stats) },
117 [NDTA_PARMS] = { .type = NLA_NESTED },
120 static int neightbl_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *n,
123 struct rtnl_neightbl *ntbl;
124 struct nlattr *tb[NDTA_MAX + 1];
125 struct nl_parser_param *pp = arg;
126 struct rtgenmsg *rtmsg;
129 ntbl = rtnl_neightbl_alloc();
131 err = nl_errno(ENOMEM);
135 ntbl->ce_msgtype = n->nlmsg_type;
136 rtmsg = nlmsg_data(n);
138 err = nlmsg_parse(n, sizeof(*rtmsg), tb, NDTA_MAX, neightbl_policy);
142 ntbl->nt_family = rtmsg->rtgen_family;
144 if (tb[NDTA_NAME] == NULL) {
145 err = nl_error(EINVAL, "NDTA_NAME is missing");
149 nla_strlcpy(ntbl->nt_name, tb[NDTA_NAME], NTBLNAMSIZ);
150 ntbl->nt_mask |= NEIGHTBL_ATTR_NAME;
152 if (tb[NDTA_THRESH1]) {
153 ntbl->nt_gc_thresh1 = nla_get_u32(tb[NDTA_THRESH1]);
154 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH1;
157 if (tb[NDTA_THRESH2]) {
158 ntbl->nt_gc_thresh2 = nla_get_u32(tb[NDTA_THRESH2]);
159 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH2;
162 if (tb[NDTA_THRESH3]) {
163 ntbl->nt_gc_thresh3 = nla_get_u32(tb[NDTA_THRESH3]);
164 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH3;
167 if (tb[NDTA_GC_INTERVAL]) {
168 ntbl->nt_gc_interval = nla_get_u32(tb[NDTA_GC_INTERVAL]);
169 ntbl->nt_mask |= NEIGHTBL_ATTR_GC_INTERVAL;
172 if (tb[NDTA_CONFIG]) {
173 nla_memcpy(&ntbl->nt_config, tb[NDTA_CONFIG],
174 sizeof(ntbl->nt_config));
175 ntbl->nt_mask |= NEIGHTBL_ATTR_CONFIG;
178 if (tb[NDTA_STATS]) {
179 nla_memcpy(&ntbl->nt_stats, tb[NDTA_STATS],
180 sizeof(ntbl->nt_stats));
181 ntbl->nt_mask |= NEIGHTBL_ATTR_STATS;
184 if (tb[NDTA_PARMS]) {
185 struct nlattr *tbp[NDTPA_MAX + 1];
186 struct rtnl_neightbl_parms *p = &ntbl->nt_parms;
188 err = nla_parse_nested(tbp, NDTPA_MAX, tb[NDTA_PARMS], NULL);
192 #define COPY_ENTRY(name, var) \
193 if (tbp[NDTPA_ ##name]) { \
194 p->ntp_ ##var = nla_get_u32(tbp[NDTPA_ ##name]); \
195 p->ntp_mask |= NEIGHTBLPARM_ATTR_ ##name; \
198 COPY_ENTRY(IFINDEX, ifindex);
199 COPY_ENTRY(REFCNT, refcnt);
200 COPY_ENTRY(QUEUE_LEN, queue_len);
201 COPY_ENTRY(APP_PROBES, app_probes);
202 COPY_ENTRY(UCAST_PROBES, ucast_probes);
203 COPY_ENTRY(MCAST_PROBES, mcast_probes);
204 COPY_ENTRY(PROXY_QLEN, proxy_qlen);
205 COPY_ENTRY(PROXY_DELAY, proxy_delay);
206 COPY_ENTRY(ANYCAST_DELAY, anycast_delay);
207 COPY_ENTRY(LOCKTIME, locktime);
208 COPY_ENTRY(REACHABLE_TIME, reachable_time);
209 COPY_ENTRY(BASE_REACHABLE_TIME, base_reachable_time);
210 COPY_ENTRY(RETRANS_TIME, retrans_time);
211 COPY_ENTRY(GC_STALETIME, gc_stale_time);
212 COPY_ENTRY(DELAY_PROBE_TIME, probe_delay);
215 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
218 err = pp->pp_cb((struct nl_object *) ntbl, pp);
224 rtnl_neightbl_put(ntbl);
228 static int neightbl_request_update(struct nl_cache *c, struct nl_handle *h)
230 return nl_rtgen_request(h, RTM_GETNEIGHTBL, AF_UNSPEC, NLM_F_DUMP);
234 static int neightbl_dump_brief(struct nl_object *arg, struct nl_dump_params *p)
237 struct rtnl_neightbl *ntbl = (struct rtnl_neightbl *) arg;
239 dp_dump(p, "%s", ntbl->nt_name);
241 if (ntbl->nt_parms.ntp_mask & NEIGHTBLPARM_ATTR_IFINDEX) {
242 struct nl_cache *link_cache;
244 link_cache = nl_cache_mngt_require("route/link");
249 rtnl_link_i2name(link_cache,
250 ntbl->nt_parms.ntp_ifindex,
253 dp_dump(p, "<%u> ", ntbl->nt_parms.ntp_ifindex);
257 if (ntbl->nt_mask & NEIGHTBL_ATTR_CONFIG)
258 dp_dump(p, "entries %u ", ntbl->nt_config.ndtc_entries);
260 if (ntbl->nt_mask & NEIGHTBL_ATTR_PARMS) {
261 char rt[32], rt2[32];
262 struct rtnl_neightbl_parms *pa = &ntbl->nt_parms;
264 dp_dump(p, "reachable-time %s retransmit-time %s",
265 nl_msec2str(pa->ntp_reachable_time, rt, sizeof(rt)),
266 nl_msec2str(pa->ntp_retrans_time, rt2, sizeof(rt2)));
274 static int neightbl_dump_full(struct nl_object *arg, struct nl_dump_params *p)
276 char x[32], y[32], z[32];
277 struct rtnl_neightbl *ntbl = (struct rtnl_neightbl *) arg;
279 int line = neightbl_dump_brief(arg, p);
281 if (ntbl->nt_mask & NEIGHTBL_ATTR_CONFIG) {
282 dp_new_line(p, line++);
283 dp_dump(p, " key-len %u entry-size %u last-flush %s\n",
284 ntbl->nt_config.ndtc_key_len,
285 ntbl->nt_config.ndtc_entry_size,
286 nl_msec2str(ntbl->nt_config.ndtc_last_flush,
289 dp_new_line(p, line++);
290 dp_dump(p, " gc threshold %u/%u/%u interval %s " \
291 "chain-position %u\n",
292 ntbl->nt_gc_thresh1, ntbl->nt_gc_thresh2,
294 nl_msec2str(ntbl->nt_gc_interval, x, sizeof(x)),
295 ntbl->nt_config.ndtc_hash_chain_gc);
297 dp_new_line(p, line++);
298 dp_dump(p, " hash-rand 0x%08X/0x%08X last-rand %s\n",
299 ntbl->nt_config.ndtc_hash_rnd,
300 ntbl->nt_config.ndtc_hash_mask,
301 nl_msec2str(ntbl->nt_config.ndtc_last_rand,
305 if (ntbl->nt_mask & NEIGHTBL_ATTR_PARMS) {
306 struct rtnl_neightbl_parms *pa = &ntbl->nt_parms;
308 dp_new_line(p, line++);
309 dp_dump(p, " refcnt %u pending-queue-limit %u " \
310 "proxy-delayed-queue-limit %u\n",
315 dp_new_line(p, line++);
316 dp_dump(p, " num-userspace-probes %u num-unicast-probes " \
317 "%u num-multicast-probes %u\n",
319 pa->ntp_ucast_probes,
320 pa->ntp_mcast_probes);
322 dp_new_line(p, line++);
323 dp_dump(p, " min-age %s base-reachable-time %s " \
324 "stale-check-interval %s\n",
325 nl_msec2str(pa->ntp_locktime, x, sizeof(x)),
326 nl_msec2str(pa->ntp_base_reachable_time,
328 nl_msec2str(pa->ntp_gc_stale_time, z, sizeof(z)));
330 dp_new_line(p, line++);
331 dp_dump(p, " initial-probe-delay %s answer-delay %s " \
332 "proxy-answer-delay %s\n",
333 nl_msec2str(pa->ntp_probe_delay, x, sizeof(x)),
334 nl_msec2str(pa->ntp_anycast_delay, y, sizeof(y)),
335 nl_msec2str(pa->ntp_proxy_delay, z, sizeof(z)));
341 static int neightbl_dump_stats(struct nl_object *arg, struct nl_dump_params *p)
343 struct rtnl_neightbl *ntbl = (struct rtnl_neightbl *) arg;
344 int line = neightbl_dump_full(arg, p);
346 if (!(ntbl->nt_mask & NEIGHTBL_ATTR_STATS))
349 dp_new_line(p, line++);
350 dp_dump(p, " lookups %lld hits %lld failed %lld " \
351 "allocations %lld destroys %lld\n",
352 ntbl->nt_stats.ndts_lookups,
353 ntbl->nt_stats.ndts_hits,
354 ntbl->nt_stats.ndts_res_failed,
355 ntbl->nt_stats.ndts_allocs,
356 ntbl->nt_stats.ndts_destroys);
358 dp_new_line(p, line++);
359 dp_dump(p, " hash-grows %lld forced-gc-runs %lld " \
360 "periodic-gc-runs %lld\n",
361 ntbl->nt_stats.ndts_hash_grows,
362 ntbl->nt_stats.ndts_forced_gc_runs,
363 ntbl->nt_stats.ndts_periodic_gc_runs);
365 dp_dump(p, " rcv-unicast-probes %lld rcv-multicast-probes %lld\n",
366 ntbl->nt_stats.ndts_rcv_probes_ucast,
367 ntbl->nt_stats.ndts_rcv_probes_mcast);
373 * @name Neighbour Table Object Allocation/Freeage
378 * Allocate a new neighbour table object
379 * @return New neighbour table object
381 struct rtnl_neightbl *rtnl_neightbl_alloc(void)
383 return (struct rtnl_neightbl *)
384 nl_object_alloc_from_ops(&rtnl_neightbl_ops);
388 * Give back reference on neighbour table object.
389 * @arg neightbl Neighbour table object to be given back.
391 * Decrements the reference counter and frees the object if the
392 * last reference has been released.
394 void rtnl_neightbl_put(struct rtnl_neightbl *neightbl)
396 nl_object_put((struct nl_object *) neightbl);
399 * Free neighbour table object.
400 * @arg neightbl Neighbour table object to be freed.
402 * @note Always use rtnl_neightbl_put() unless you're absolutely sure
403 * that no other user may have a reference on this object.
405 void rtnl_neightbl_free(struct rtnl_neightbl *neightbl)
407 nl_object_free((struct nl_object *) neightbl);
413 * @name Neighbour Table Cache Management
418 * Build a neighbour table cache including all neighbour tables currently configured in the kernel.
419 * @arg handle netlink handle
421 * Allocates a new neighbour table cache, initializes it properly and
422 * updates it to include all neighbour tables currently configured in
425 * @note The caller is responsible for destroying and freeing the
426 * cache after using it.
427 * @return The new cache or NULL if an error occured.
429 struct nl_cache * rtnl_neightbl_alloc_cache(struct nl_handle *handle)
431 struct nl_cache * cache;
433 cache = nl_cache_alloc_from_ops(&rtnl_neightbl_ops);
437 if (nl_cache_update(handle, cache) < 0) {
438 nl_cache_free(cache);
446 * Lookup neighbour table by name and optional interface index
447 * @arg cache neighbour table cache
448 * @arg name name of table
449 * @arg ifindex optional interface index
451 * Looks up the neighbour table matching the specified name and
452 * optionally the specified ifindex to retrieve device specific
455 * @return ptr to neighbour table inside the cache or NULL if no
458 struct rtnl_neightbl *rtnl_neightbl_get(struct nl_cache *cache,
459 const char *name, int ifindex)
461 struct rtnl_neightbl *nt;
463 if (cache->c_ops != &rtnl_neightbl_ops)
466 nl_list_for_each_entry(nt, &cache->c_items, ce_list) {
467 if (!strcasecmp(nt->nt_name, name) &&
468 ((!ifindex && !nt->nt_parms.ntp_ifindex) ||
469 (ifindex && ifindex == nt->nt_parms.ntp_ifindex))) {
470 nl_object_get((struct nl_object *) nt);
481 * @name Neighbour Table Modifications
486 * Builds a netlink change request message to change neighbour table attributes
487 * @arg old neighbour table to change
488 * @arg tmpl template with requested changes
490 * Builds a new netlink message requesting a change of neighbour table
491 * attributes. The netlink message header isn't fully equipped with all
492 * relevant fields and must be sent out via nl_send_auto_complete() or
493 * supplemented as needed.
494 * \a old must point to a neighbour table currently configured in the
495 * kernel and \a tmpl must contain the attributes to be changed set via
496 * \c rtnl_neightbl_set_* functions.
498 * @return New netlink message
500 struct nl_msg * rtnl_neightbl_build_change_request(struct rtnl_neightbl *old,
501 struct rtnl_neightbl *tmpl)
504 struct ndtmsg ndt = {
505 .ndtm_family = old->nt_family,
508 m = nlmsg_build_simple(RTM_SETNEIGHTBL, 0);
509 nlmsg_append(m, &ndt, sizeof(ndt), 1);
511 nla_put_string(m, NDTA_NAME, old->nt_name);
513 if (tmpl->nt_mask & NEIGHTBL_ATTR_THRESH1)
514 nla_put_u32(m, NDTA_THRESH1, tmpl->nt_gc_thresh1);
516 if (tmpl->nt_mask & NEIGHTBL_ATTR_THRESH2)
517 nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);
519 if (tmpl->nt_mask & NEIGHTBL_ATTR_THRESH2)
520 nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);
522 if (tmpl->nt_mask & NEIGHTBL_ATTR_GC_INTERVAL)
523 nla_put_u64(m, NDTA_GC_INTERVAL,
524 tmpl->nt_gc_interval);
526 if (tmpl->nt_mask & NEIGHTBL_ATTR_PARMS) {
527 struct rtnl_neightbl_parms *p = &tmpl->nt_parms;
528 struct nl_msg *parms = nlmsg_build(NULL);
530 if (old->nt_parms.ntp_mask & NEIGHTBLPARM_ATTR_IFINDEX)
531 nla_put_u32(parms, NDTPA_IFINDEX,
532 old->nt_parms.ntp_ifindex);
535 if (p->ntp_mask & NEIGHTBLPARM_ATTR_QUEUE_LEN)
536 nla_put_u32(parms, NDTPA_QUEUE_LEN, p->ntp_queue_len);
538 if (p->ntp_mask & NEIGHTBLPARM_ATTR_APP_PROBES)
539 nla_put_u32(parms, NDTPA_APP_PROBES, p->ntp_app_probes);
541 if (p->ntp_mask & NEIGHTBLPARM_ATTR_UCAST_PROBES)
542 nla_put_u32(parms, NDTPA_UCAST_PROBES,
543 p->ntp_ucast_probes);
545 if (p->ntp_mask & NEIGHTBLPARM_ATTR_MCAST_PROBES)
546 nla_put_u32(parms, NDTPA_MCAST_PROBES,
547 p->ntp_mcast_probes);
549 if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_QLEN)
550 nla_put_u32(parms, NDTPA_PROXY_QLEN,
553 if (p->ntp_mask & NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME)
554 nla_put_u64(parms, NDTPA_BASE_REACHABLE_TIME,
555 p->ntp_base_reachable_time);
557 if (p->ntp_mask & NEIGHTBLPARM_ATTR_RETRANS_TIME)
558 nla_put_u64(parms, NDTPA_RETRANS_TIME,
559 p->ntp_retrans_time);
561 if (p->ntp_mask & NEIGHTBLPARM_ATTR_GC_STALETIME)
562 nla_put_u64(parms, NDTPA_GC_STALETIME,
563 p->ntp_gc_stale_time);
565 if (p->ntp_mask & NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME)
566 nla_put_u64(parms, NDTPA_DELAY_PROBE_TIME,
569 if (p->ntp_mask & NEIGHTBLPARM_ATTR_ANYCAST_DELAY)
570 nla_put_u64(parms, NDTPA_ANYCAST_DELAY,
571 p->ntp_anycast_delay);
573 if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_DELAY)
574 nla_put_u64(parms, NDTPA_PROXY_DELAY,
577 if (p->ntp_mask & NEIGHTBLPARM_ATTR_LOCKTIME)
578 nla_put_u64(parms, NDTPA_LOCKTIME, p->ntp_locktime);
580 nla_put_nested(m, NDTA_PARMS, parms);
588 * Change neighbour table attributes
589 * @arg handle netlink handle
590 * @arg old neighbour table to be changed
591 * @arg tmpl template with requested changes
593 * Builds a new netlink message by calling
594 * rtnl_neightbl_build_change_request(), sends the request to the
595 * kernel and waits for the next ACK to be received, i.e. blocks
596 * until the request has been processed.
598 * @return 0 on success or a negative error code
600 int rtnl_neightbl_change(struct nl_handle *handle, struct rtnl_neightbl *old,
601 struct rtnl_neightbl *tmpl)
606 msg = rtnl_neightbl_build_change_request(old, tmpl);
607 err = nl_send_auto_complete(handle, msg);
612 return nl_wait_for_ack(handle);
618 * @name Attribute Modification
623 * Set the address family of a neighbour table to the specified value
624 * @arg ntbl neighbour table to change
625 * @arg family new address family
627 void rtnl_neightbl_set_family(struct rtnl_neightbl *ntbl, int family)
629 ntbl->nt_family = family;
630 ntbl->nt_mask |= NEIGHTBL_ATTR_FAMILY;
634 * Set the gc interval of a neighbour table to the specified value
635 * @arg ntbl neighbour table to change
636 * @arg ms new interval in milliseconds
638 void rtnl_neightbl_set_gc_interval(struct rtnl_neightbl *ntbl, uint64_t ms)
640 ntbl->nt_gc_interval = ms;
641 ntbl->nt_mask |= NEIGHTBL_ATTR_GC_INTERVAL;
645 * Set the gc threshold 1 of a neighbour table to the specified value
646 * @arg ntbl neighbour table to change
647 * @arg thresh new gc threshold
649 void rtnl_neightbl_set_gc_tresh1(struct rtnl_neightbl *ntbl, int thresh)
651 ntbl->nt_gc_thresh1 = thresh;
652 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH1;
656 * Set the gc threshold 2 of a neighbour table to the specified value
657 * @arg ntbl neighbour table to change
658 * @arg thresh new gc threshold
660 void rtnl_neightbl_set_gc_tresh2(struct rtnl_neightbl *ntbl, int thresh)
662 ntbl->nt_gc_thresh2 = thresh;
663 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH2;
667 * Set the gc threshold 3 of a neighbour table to the specified value
668 * @arg ntbl neighbour table to change
669 * @arg thresh new gc threshold
671 void rtnl_neightbl_set_gc_tresh3(struct rtnl_neightbl *ntbl, int thresh)
673 ntbl->nt_gc_thresh3 = thresh;
674 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH3;
678 * Set the table name of a neighbour table to the specified value
679 * @arg ntbl neighbour table to change
680 * @arg name new table name
682 void rtnl_neightbl_set_name(struct rtnl_neightbl *ntbl, const char *name)
684 strncpy(ntbl->nt_name, name, sizeof(ntbl->nt_name) - 1);
685 ntbl->nt_mask |= NEIGHTBL_ATTR_NAME;
689 * Set the device of a neighbour table to the specified value
690 * @arg ntbl neighbour table to change
691 * @arg ifindex interface index of the device
693 void rtnl_neightbl_set_dev(struct rtnl_neightbl *ntbl, int ifindex)
695 ntbl->nt_parms.ntp_ifindex = ifindex;
696 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_IFINDEX;
697 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
701 * Set the queue length for pending requests of a neighbour table to the specified value
702 * @arg ntbl neighbour table to change
703 * @arg len new queue len
705 void rtnl_neightbl_set_queue_len(struct rtnl_neightbl *ntbl, int len)
707 ntbl->nt_parms.ntp_queue_len = len;
708 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_QUEUE_LEN;
709 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
713 * Set the queue length for delay proxy arp requests of a neighbour table to the specified value
714 * @arg ntbl neighbour table to change
715 * @arg len new queue len
717 void rtnl_neightbl_set_proxy_queue_len(struct rtnl_neightbl *ntbl, int len)
719 ntbl->nt_parms.ntp_proxy_qlen = len;
720 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_QLEN;
721 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
725 * Set the number of application probes of a neighbour table to the specified value
726 * @arg ntbl neighbour table to change
727 * @arg probes new probes value
729 void rtnl_neightbl_set_app_probes(struct rtnl_neightbl *ntbl, int probes)
731 ntbl->nt_parms.ntp_app_probes = probes;
732 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_APP_PROBES;
733 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
737 * Set the number of unicast probes of a neighbour table to the specified value
738 * @arg ntbl neighbour table to change
739 * @arg probes new probes value
741 void rtnl_neightbl_set_ucast_probes(struct rtnl_neightbl *ntbl, int probes)
743 ntbl->nt_parms.ntp_ucast_probes = probes;
744 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_UCAST_PROBES;
745 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
749 * Set the number of multicast probes of a neighbour table to the specified value
750 * @arg ntbl neighbour table to change
751 * @arg probes new probes value
753 void rtnl_neightbl_set_mcast_probes(struct rtnl_neightbl *ntbl, int probes)
755 ntbl->nt_parms.ntp_mcast_probes = probes;
756 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_MCAST_PROBES;
757 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
761 * Set the base reachable time of a neighbour table to the specified value
762 * @arg ntbl neighbour table to change
763 * @arg ms new base reachable time in milliseconds
765 void rtnl_neightbl_set_base_reachable_time(struct rtnl_neightbl *ntbl,
768 ntbl->nt_parms.ntp_base_reachable_time = ms;
769 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME;
770 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
774 * Set the retransmit time of a neighbour table to the specified value
775 * @arg ntbl neighbour table to change
776 * @arg ms new retransmit time
778 void rtnl_neightbl_set_retrans_time(struct rtnl_neightbl *ntbl, uint64_t ms)
780 ntbl->nt_parms.ntp_retrans_time = ms;
781 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_RETRANS_TIME;
782 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
786 * Set the gc stale time of a neighbour table to the specified value
787 * @arg ntbl neighbour table to change
788 * @arg ms new gc stale time in milliseconds
790 void rtnl_neightbl_set_gc_stale_time(struct rtnl_neightbl *ntbl, uint64_t ms)
792 ntbl->nt_parms.ntp_gc_stale_time = ms;
793 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_GC_STALETIME;
794 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
798 * Set the first probe delay time of a neighbour table to the specified value
799 * @arg ntbl neighbour table to change
800 * @arg ms new first probe delay time in milliseconds
802 void rtnl_neightbl_set_delay_probe_time(struct rtnl_neightbl *ntbl, uint64_t ms)
804 ntbl->nt_parms.ntp_probe_delay = ms;
805 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME;
806 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
810 * Set the anycast delay of a neighbour table to the specified value
811 * @arg ntbl neighbour table to change
812 * @arg ms new anycast delay in milliseconds
814 void rtnl_neightbl_set_anycast_delay(struct rtnl_neightbl *ntbl, uint64_t ms)
816 ntbl->nt_parms.ntp_anycast_delay = ms;
817 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_ANYCAST_DELAY;
818 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
822 * Set the proxy delay of a neighbour table to the specified value
823 * @arg ntbl neighbour table to change
824 * @arg ms new proxy delay in milliseconds
826 void rtnl_neightbl_set_proxy_delay(struct rtnl_neightbl *ntbl, uint64_t ms)
828 ntbl->nt_parms.ntp_proxy_delay = ms;
829 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_DELAY;
830 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
834 * Set the locktime of a neighbour table to the specified value
835 * @arg ntbl neighbour table to change
836 * @arg ms new locktime in milliseconds
838 void rtnl_neightbl_set_locktime(struct rtnl_neightbl *ntbl, uint64_t ms)
840 ntbl->nt_parms.ntp_locktime = ms;
841 ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_LOCKTIME;
842 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
847 static struct nl_cache_ops rtnl_neightbl_ops = {
848 .co_name = "route/neightbl",
849 .co_size = sizeof(struct rtnl_neightbl),
850 .co_hdrsize = sizeof(struct rtgenmsg),
852 { RTM_NEWNEIGHTBL, "new" },
853 { RTM_SETNEIGHTBL, "set" },
854 { RTM_GETNEIGHTBL, "get" },
857 .co_protocol = NETLINK_ROUTE,
858 .co_request_update = &neightbl_request_update,
859 .co_msg_parser = &neightbl_msg_parser,
860 .co_dump[NL_DUMP_BRIEF] = &neightbl_dump_brief,
861 .co_dump[NL_DUMP_FULL] = &neightbl_dump_full,
862 .co_dump[NL_DUMP_STATS] = &neightbl_dump_stats,
863 .co_filter = &neightbl_filter,
866 static void __init neightbl_init(void)
868 nl_cache_mngt_register(&rtnl_neightbl_ops);
871 static void __exit neightbl_exit(void)
873 nl_cache_mngt_unregister(&rtnl_neightbl_ops);