libnl 3.9.0
neigh.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
4 */
5
6/**
7 * @ingroup rtnl
8 * @defgroup neigh Neighbours
9 * @brief
10 *
11 * The neighbour table establishes bindings between protocol addresses and
12 * link layer addresses for hosts sharing the same physical link. This
13 * module allows you to access and manipulate the content of these tables.
14 *
15 * @par Neighbour States
16 * @code
17 * NUD_INCOMPLETE
18 * NUD_REACHABLE
19 * NUD_STALE
20 * NUD_DELAY
21 * NUD_PROBE
22 * NUD_FAILED
23 * NUD_NOARP
24 * NUD_PERMANENT
25 * @endcode
26 *
27 * @par Neighbour Flags
28 * @code
29 * NTF_USE
30 * NTF_PROXY
31 * NTF_ROUTER
32 * NTF_SELF
33 * @endcode
34 *
35 * @par Neighbour Identification
36 * A neighbour is uniquely identified by the attributes listed below, whenever
37 * you refer to an existing neighbour all of the attributes must be set.
38 * Neighbours from caches automatically have all required attributes set.
39 * - interface index (rtnl_neigh_set_ifindex())
40 * - destination address (rtnl_neigh_set_dst())
41 *
42 * @par Changeable Attributes
43 * \anchor neigh_changeable
44 * - state (rtnl_neigh_set_state())
45 * - link layer address (rtnl_neigh_set_lladdr())
46 *
47 * @par Required Caches for Dumping
48 * In order to dump neighbour attributes you must provide the following
49 * caches via nl_cache_provide()
50 * - link cache holding all links
51 *
52 * @par TODO
53 * - Document proxy settings
54 * - Document states and their influence
55 *
56 * @par 1) Retrieving information about configured neighbours
57 * @code
58 * // The first step is to retrieve a list of all available neighbour within
59 * // the kernel and put them into a cache.
60 * struct nl_cache *cache = rtnl_neigh_alloc_cache(sk);
61 *
62 * // Neighbours can then be looked up by the interface and destination
63 * // address:
64 * struct rtnl_neigh *neigh = rtnl_neigh_get(cache, ifindex, dst_addr);
65 *
66 * // After successful usage, the object must be given back to the cache
67 * rtnl_neigh_put(neigh);
68 * @endcode
69 *
70 * @par 2) Adding new neighbours
71 * @code
72 * // Allocate an empty neighbour handle to be filled out with the attributes
73 * // of the new neighbour.
74 * struct rtnl_neigh *neigh = rtnl_neigh_alloc();
75 *
76 * // Fill out the attributes of the new neighbour
77 * rtnl_neigh_set_ifindex(neigh, ifindex);
78 * rtnl_neigh_set_dst(neigh, dst_addr);
79 * rtnl_neigh_set_state(neigh, rtnl_neigh_str2state("permanent"));
80 *
81 * // Build the netlink message and send it to the kernel, the operation will
82 * // block until the operation has been completed. Alternatively the required
83 * // netlink message can be built using rtnl_neigh_build_add_request()
84 * // to be sent out using nl_send_auto_complete().
85 * rtnl_neigh_add(sk, neigh, NLM_F_CREATE);
86 *
87 * // Free the memory
88 * rtnl_neigh_put(neigh);
89 * @endcode
90 *
91 * @par 3) Deleting an existing neighbour
92 * @code
93 * // Allocate an empty neighbour object to be filled out with the attributes
94 * // matching the neighbour to be deleted. Alternatively a fully equipped
95 * // neighbour object out of a cache can be used instead.
96 * struct rtnl_neigh *neigh = rtnl_neigh_alloc();
97 *
98 * // Neighbours are uniquely identified by their interface index and
99 * // destination address, you may fill out other attributes but they
100 * // will have no influence.
101 * rtnl_neigh_set_ifindex(neigh, ifindex);
102 * rtnl_neigh_set_dst(neigh, dst_addr);
103 *
104 * // Build the netlink message and send it to the kernel, the operation will
105 * // block until the operation has been completed. Alternatively the required
106 * // netlink message can be built using rtnl_neigh_build_delete_request()
107 * // to be sent out using nl_send_auto_complete().
108 * rtnl_neigh_delete(sk, neigh, 0);
109 *
110 * // Free the memory
111 * rtnl_neigh_put(neigh);
112 * @endcode
113 *
114 * @par 4) Changing neighbour attributes
115 * @code
116 * // Allocate an empty neighbour object to be filled out with the attributes
117 * // matching the neighbour to be changed and the new parameters. Alternatively
118 * // a fully equipped modified neighbour object out of a cache can be used.
119 * struct rtnl_neigh *neigh = rtnl_neigh_alloc();
120 *
121 * // Identify the neighbour to be changed by its interface index and
122 * // destination address
123 * rtnl_neigh_set_ifindex(neigh, ifindex);
124 * rtnl_neigh_set_dst(neigh, dst_addr);
125 *
126 * // The link layer address may be modified, if so it is wise to change
127 * // its state to "permanent" in order to avoid having it overwritten.
128 * rtnl_neigh_set_lladdr(neigh, lladdr);
129 *
130 * // Secondly the state can be modified allowing normal neighbours to be
131 * // converted into permanent entries or to manually confirm a neighbour.
132 * rtnl_neigh_set_state(neigh, state);
133 *
134 * // Build the netlink message and send it to the kernel, the operation will
135 * // block until the operation has been completed. Alternatively the required
136 * // netlink message can be built using rtnl_neigh_build_change_request()
137 * // to be sent out using nl_send_auto_complete().
138 * rtnl_neigh_add(sk, neigh, NLM_F_REPLACE);
139 *
140 * // Free the memory
141 * rtnl_neigh_put(neigh);
142 * @endcode
143 * @{
144 */
145
146#include "nl-default.h"
147
148#include <netlink/netlink.h>
149#include <netlink/utils.h>
150#include <netlink/hashtable.h>
151#include <netlink/route/rtnl.h>
152#include <netlink/route/neighbour.h>
153#include <netlink/route/link.h>
154#include <netlink/hashtable.h>
155
156#include "nl-route.h"
157#include "nl-priv-dynamic-core/nl-core.h"
158#include "nl-priv-dynamic-core/cache-api.h"
159
160/** @cond SKIP */
161struct rtnl_ncacheinfo {
162 uint32_t nci_confirmed; /**< Time since neighbour validty was last confirmed */
163 uint32_t nci_used; /**< Time since neighbour entry was last ued */
164 uint32_t nci_updated; /**< Time since last update */
165 uint32_t nci_refcnt; /**< Reference counter */
166};
167
168struct rtnl_neigh {
169 NLHDR_COMMON
170 uint32_t n_family;
171 uint32_t n_ifindex;
172 uint16_t n_state;
173 uint8_t n_flags;
174 uint8_t n_type;
175 struct nl_addr *n_lladdr;
176 struct nl_addr *n_dst;
177 uint32_t n_nhid;
178 uint32_t n_probes;
179 struct rtnl_ncacheinfo n_cacheinfo;
180 uint32_t n_state_mask;
181 uint32_t n_flag_mask;
182 uint32_t n_master;
183 uint16_t n_vlan;
184};
185
186#define NEIGH_ATTR_FLAGS 0x01
187#define NEIGH_ATTR_STATE 0x02
188#define NEIGH_ATTR_LLADDR 0x04
189#define NEIGH_ATTR_DST 0x08
190#define NEIGH_ATTR_CACHEINFO 0x10
191#define NEIGH_ATTR_IFINDEX 0x20
192#define NEIGH_ATTR_FAMILY 0x40
193#define NEIGH_ATTR_TYPE 0x80
194#define NEIGH_ATTR_PROBES 0x100
195#define NEIGH_ATTR_MASTER 0x200
196#define NEIGH_ATTR_VLAN 0x400
197#define NEIGH_ATTR_NHID 0x800
198
199static struct nl_cache_ops rtnl_neigh_ops;
200static struct nl_object_ops neigh_obj_ops;
201/** @endcond */
202
203static void neigh_free_data(struct nl_object *c)
204{
205 struct rtnl_neigh *neigh = nl_object_priv(c);
206
207 if (!neigh)
208 return;
209
210 nl_addr_put(neigh->n_lladdr);
211 nl_addr_put(neigh->n_dst);
212}
213
214static int neigh_clone(struct nl_object *_dst, struct nl_object *_src)
215{
216 struct rtnl_neigh *dst = nl_object_priv(_dst);
217 struct rtnl_neigh *src = nl_object_priv(_src);
218
219 dst->n_lladdr = NULL;
220 dst->n_dst = NULL;
221
222 if (src->n_lladdr)
223 if (!(dst->n_lladdr = nl_addr_clone(src->n_lladdr)))
224 return -NLE_NOMEM;
225
226 if (src->n_dst)
227 if (!(dst->n_dst = nl_addr_clone(src->n_dst)))
228 return -NLE_NOMEM;
229
230 return 0;
231}
232
233static void neigh_keygen(struct nl_object *obj, uint32_t *hashkey,
234 uint32_t table_sz)
235{
236 struct rtnl_neigh *neigh = (struct rtnl_neigh *) obj;
237 unsigned int nkey_sz;
238 struct nl_addr *addr = NULL;
239 struct neigh_hash_key {
240 uint32_t n_family;
241 uint32_t n_ifindex;
242 uint16_t n_vlan;
243 char n_addr[0];
244 } _nl_packed *nkey;
245#ifdef NL_DEBUG
246 char buf[INET6_ADDRSTRLEN+5];
247#endif
248
249 if (neigh->n_family == AF_BRIDGE) {
250 if (neigh->n_lladdr)
251 addr = neigh->n_lladdr;
252 } else if (neigh->n_dst) {
253 addr = neigh->n_dst;
254 }
255
256 nkey_sz = sizeof(*nkey);
257 if (addr)
258 nkey_sz += nl_addr_get_len(addr);
259
260 nkey = calloc(1, nkey_sz);
261 if (!nkey) {
262 *hashkey = 0;
263 return;
264 }
265 nkey->n_family = neigh->n_family;
266 if (neigh->n_family == AF_BRIDGE) {
267 nkey->n_vlan = neigh->n_vlan;
268 if (neigh->n_flags & NTF_SELF)
269 nkey->n_ifindex = neigh->n_ifindex;
270 else
271 nkey->n_ifindex = neigh->n_master;
272 } else
273 nkey->n_ifindex = neigh->n_ifindex;
274
275 if (addr)
276 memcpy(nkey->n_addr,
278 nl_addr_get_len(addr));
279
280 *hashkey = nl_hash(nkey, nkey_sz, 0) % table_sz;
281
282 NL_DBG(5, "neigh %p key (fam %d dev %d addr %s) keysz %d hash 0x%x\n",
283 neigh, nkey->n_family, nkey->n_ifindex,
284 nl_addr2str(addr, buf, sizeof(buf)),
285 nkey_sz, *hashkey);
286
287 free(nkey);
288
289 return;
290}
291
292static uint64_t neigh_compare(struct nl_object *_a, struct nl_object *_b,
293 uint64_t attrs, int flags)
294{
295 struct rtnl_neigh *a = (struct rtnl_neigh *) _a;
296 struct rtnl_neigh *b = (struct rtnl_neigh *) _b;
297 uint64_t diff = 0;
298
299#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
300 diff |= _DIFF(NEIGH_ATTR_IFINDEX, a->n_ifindex != b->n_ifindex);
301 diff |= _DIFF(NEIGH_ATTR_FAMILY, a->n_family != b->n_family);
302 diff |= _DIFF(NEIGH_ATTR_TYPE, a->n_type != b->n_type);
303 diff |= _DIFF(NEIGH_ATTR_LLADDR, nl_addr_cmp(a->n_lladdr, b->n_lladdr));
304 diff |= _DIFF(NEIGH_ATTR_DST, nl_addr_cmp(a->n_dst, b->n_dst));
305 diff |= _DIFF(NEIGH_ATTR_MASTER, a->n_master != b->n_master);
306 diff |= _DIFF(NEIGH_ATTR_VLAN, a->n_vlan != b->n_vlan);
307 diff |= _DIFF(NEIGH_ATTR_NHID, a->n_nhid != b->n_nhid);
308
309 if (flags & LOOSE_COMPARISON) {
310 diff |= _DIFF(NEIGH_ATTR_STATE,
311 (a->n_state ^ b->n_state) & b->n_state_mask);
312 diff |= _DIFF(NEIGH_ATTR_FLAGS,
313 (a->n_flags ^ b->n_flags) & b->n_flag_mask);
314 } else {
315 diff |= _DIFF(NEIGH_ATTR_STATE, a->n_state != b->n_state);
316 diff |= _DIFF(NEIGH_ATTR_FLAGS, a->n_flags != b->n_flags);
317 }
318#undef _DIFF
319
320 return diff;
321}
322
323static const struct trans_tbl neigh_attrs[] = {
324 __ADD(NEIGH_ATTR_FLAGS, flags),
325 __ADD(NEIGH_ATTR_STATE, state),
326 __ADD(NEIGH_ATTR_LLADDR, lladdr),
327 __ADD(NEIGH_ATTR_DST, dst),
328 __ADD(NEIGH_ATTR_CACHEINFO, cacheinfo),
329 __ADD(NEIGH_ATTR_IFINDEX, ifindex),
330 __ADD(NEIGH_ATTR_FAMILY, family),
331 __ADD(NEIGH_ATTR_TYPE, type),
332 __ADD(NEIGH_ATTR_PROBES, probes),
333 __ADD(NEIGH_ATTR_MASTER, master),
334 __ADD(NEIGH_ATTR_VLAN, vlan),
335 __ADD(NEIGH_ATTR_NHID, nhid),
336};
337
338static char *neigh_attrs2str(int attrs, char *buf, size_t len)
339{
340 return __flags2str(attrs, buf, len, neigh_attrs,
341 ARRAY_SIZE(neigh_attrs));
342}
343
344static uint32_t neigh_id_attrs_get(struct nl_object *obj)
345{
346 struct rtnl_neigh *neigh = (struct rtnl_neigh *)obj;
347
348 if (neigh->n_family == AF_BRIDGE) {
349 if (neigh->n_flags & NTF_SELF)
350 return (NEIGH_ATTR_LLADDR | NEIGH_ATTR_FAMILY | NEIGH_ATTR_IFINDEX |
351 ((neigh->ce_mask & NEIGH_ATTR_DST) ? NEIGH_ATTR_DST: 0) |
352 ((neigh->ce_mask & NEIGH_ATTR_NHID) ? NEIGH_ATTR_NHID: 0) |
353 ((neigh->ce_mask & NEIGH_ATTR_VLAN) ? NEIGH_ATTR_VLAN : 0));
354 else
355 return (NEIGH_ATTR_LLADDR | NEIGH_ATTR_FAMILY | NEIGH_ATTR_MASTER | NEIGH_ATTR_VLAN);
356 } else
357 return neigh_obj_ops.oo_id_attrs;
358}
359
360static struct nla_policy neigh_policy[NDA_MAX+1] = {
361 [NDA_CACHEINFO] = { .minlen = sizeof(struct nda_cacheinfo) },
362 [NDA_PROBES] = { .type = NLA_U32 },
363};
364
365static int neigh_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
366 struct nlmsghdr *n, struct nl_parser_param *pp)
367{
368 struct rtnl_neigh *neigh;
369 int err;
370
371 if ((err = rtnl_neigh_parse(n, &neigh)) < 0)
372 return err;
373
374 err = pp->pp_cb((struct nl_object *) neigh, pp);
375
376 rtnl_neigh_put(neigh);
377 return err;
378}
379
380
381int rtnl_neigh_parse(struct nlmsghdr *n, struct rtnl_neigh **result)
382{
383 struct rtnl_neigh *neigh;
384 struct nlattr *tb[NDA_MAX + 1];
385 struct ndmsg *nm;
386 int err;
387
388 neigh = rtnl_neigh_alloc();
389 if (!neigh) {
390 err = -NLE_NOMEM;
391 goto errout;
392 }
393
394 neigh->ce_msgtype = n->nlmsg_type;
395 nm = nlmsg_data(n);
396
397 err = nlmsg_parse(n, sizeof(*nm), tb, NDA_MAX, neigh_policy);
398 if (err < 0)
399 goto errout;
400
401 neigh->n_family = nm->ndm_family;
402 neigh->n_ifindex = nm->ndm_ifindex;
403 neigh->n_state = nm->ndm_state;
404 neigh->n_flags = nm->ndm_flags;
405 neigh->n_type = nm->ndm_type;
406
407 neigh->ce_mask |= (NEIGH_ATTR_FAMILY | NEIGH_ATTR_IFINDEX |
408 NEIGH_ATTR_STATE | NEIGH_ATTR_FLAGS |
409 NEIGH_ATTR_TYPE);
410
411 if (tb[NDA_LLADDR]) {
412 neigh->n_lladdr = nl_addr_alloc_attr(tb[NDA_LLADDR], AF_UNSPEC);
413 if (!neigh->n_lladdr) {
414 err = -NLE_NOMEM;
415 goto errout;
416 }
417 nl_addr_set_family(neigh->n_lladdr,
418 nl_addr_guess_family(neigh->n_lladdr));
419 neigh->ce_mask |= NEIGH_ATTR_LLADDR;
420 }
421
422 if (tb[NDA_DST]) {
423 neigh->n_dst = nl_addr_alloc_attr(tb[NDA_DST], AF_UNSPEC);
424 if (!neigh->n_dst) {
425 err = -NLE_NOMEM;
426 goto errout;
427 }
428 nl_addr_set_family(neigh->n_dst,
429 nl_addr_guess_family(neigh->n_dst));
430 neigh->ce_mask |= NEIGH_ATTR_DST;
431 }
432
433 if (tb[NDA_CACHEINFO]) {
434 struct nda_cacheinfo *ci = nla_data(tb[NDA_CACHEINFO]);
435
436 neigh->n_cacheinfo.nci_confirmed = ci->ndm_confirmed;
437 neigh->n_cacheinfo.nci_used = ci->ndm_used;
438 neigh->n_cacheinfo.nci_updated = ci->ndm_updated;
439 neigh->n_cacheinfo.nci_refcnt = ci->ndm_refcnt;
440
441 neigh->ce_mask |= NEIGH_ATTR_CACHEINFO;
442 }
443
444 if (tb[NDA_PROBES]) {
445 neigh->n_probes = nla_get_u32(tb[NDA_PROBES]);
446 neigh->ce_mask |= NEIGH_ATTR_PROBES;
447 }
448
449 if (tb[NDA_VLAN]) {
450 neigh->n_vlan = nla_get_u16(tb[NDA_VLAN]);
451 neigh->ce_mask |= NEIGH_ATTR_VLAN;
452 }
453
454 if (tb[NDA_NH_ID]) {
455 neigh->n_nhid = nla_get_u32(tb[NDA_NH_ID]);
456 neigh->ce_mask |= NEIGH_ATTR_NHID;
457 }
458
459 /*
460 * Get the bridge index for AF_BRIDGE family entries
461 */
462 if (neigh->n_family == AF_BRIDGE) {
463 if (tb[NDA_MASTER]) {
464 neigh->n_master = nla_get_u32(tb[NDA_MASTER]);
465 neigh->ce_mask |= NEIGH_ATTR_MASTER;
466 } else {
467 struct nl_cache *lcache = nl_cache_mngt_require_safe("route/link");
468 if (lcache ) {
469 struct rtnl_link *link = rtnl_link_get(lcache,
470 neigh->n_ifindex);
471 if (link) {
472 neigh->n_master = link->l_master;
473 rtnl_link_put(link);
474 neigh->ce_mask |= NEIGH_ATTR_MASTER;
475 }
476 nl_cache_put(lcache);
477 }
478 }
479 }
480
481 *result = neigh;
482 return 0;
483
484errout:
485 rtnl_neigh_put(neigh);
486 return err;
487}
488
489static int neigh_request_update(struct nl_cache *c, struct nl_sock *h)
490{
491 int family = c->c_iarg1;
492
493 if (family == AF_UNSPEC) {
494 return nl_rtgen_request(h, RTM_GETNEIGH, family, NLM_F_DUMP);
495 } else if (family == AF_BRIDGE) {
496 struct ifinfomsg hdr = {.ifi_family = family};
497 struct nl_msg *msg;
498 int err;
499
500 msg = nlmsg_alloc_simple(RTM_GETNEIGH, NLM_F_REQUEST | NLM_F_DUMP);
501 if (!msg)
502 return -NLE_NOMEM;
503
504 err = -NLE_MSGSIZE;
505 if (nlmsg_append(msg, &hdr, sizeof(hdr), NLMSG_ALIGNTO) < 0)
506 goto nla_put_failure;
507
508 err = nl_send_auto(h, msg);
509 if (err > 0)
510 err = 0;
511
512 nla_put_failure:
513 nlmsg_free(msg);
514 return err;
515 }
516
517 return -NLE_INVAL;
518}
519
520
521static void neigh_dump_line(struct nl_object *a, struct nl_dump_params *p)
522{
523 char dst[INET6_ADDRSTRLEN+5], lladdr[INET6_ADDRSTRLEN+5];
524 struct rtnl_neigh *n = (struct rtnl_neigh *) a;
525 struct nl_cache *link_cache;
526 char state[128], flags[64];
527 char buf[128];
528
529 link_cache = nl_cache_mngt_require_safe("route/link");
530
531 if (n->n_family != AF_UNSPEC)
532 nl_dump_line(p, "%s ", nl_af2str(n->n_family, buf, sizeof(buf)));
533
534 if (n->ce_mask & NEIGH_ATTR_DST)
535 nl_dump_line(p, "%s ", nl_addr2str(n->n_dst, dst, sizeof(dst)));
536
537 if (link_cache)
538 nl_dump(p, "dev %s ",
539 rtnl_link_i2name(link_cache, n->n_ifindex,
540 state, sizeof(state)));
541 else
542 nl_dump(p, "dev %d ", n->n_ifindex);
543
544 if (n->ce_mask & NEIGH_ATTR_LLADDR)
545 nl_dump(p, "lladdr %s ",
546 nl_addr2str(n->n_lladdr, lladdr, sizeof(lladdr)));
547
548 if (n->ce_mask & NEIGH_ATTR_VLAN)
549 nl_dump(p, "vlan %d ", n->n_vlan);
550
551 if (n->ce_mask & NEIGH_ATTR_NHID)
552 nl_dump(p, "nhid %u ", n->n_nhid);
553
554 if (n->ce_mask & NEIGH_ATTR_MASTER) {
555 if (link_cache)
556 nl_dump(p, "%s ", rtnl_link_i2name(link_cache, n->n_master,
557 state, sizeof(state)));
558 else
559 nl_dump(p, "%d ", n->n_master);
560 }
561
562 rtnl_neigh_state2str(n->n_state, state, sizeof(state));
563 rtnl_neigh_flags2str(n->n_flags, flags, sizeof(flags));
564
565 if (state[0])
566 nl_dump(p, "<%s", state);
567 if (flags[0])
568 nl_dump(p, "%s%s", state[0] ? "," : "<", flags);
569 if (state[0] || flags[0])
570 nl_dump(p, ">");
571 nl_dump(p, "\n");
572
573 if (link_cache)
574 nl_cache_put(link_cache);
575}
576
577static void neigh_dump_details(struct nl_object *a, struct nl_dump_params *p)
578{
579 char rtn_type[32];
580 struct rtnl_neigh *n = (struct rtnl_neigh *) a;
581 int hz = nl_get_user_hz();
582
583 neigh_dump_line(a, p);
584
585 nl_dump_line(p, " refcnt %u type %s confirmed %u used "
586 "%u updated %u\n",
587 n->n_cacheinfo.nci_refcnt,
588 nl_rtntype2str(n->n_type, rtn_type, sizeof(rtn_type)),
589 n->n_cacheinfo.nci_confirmed/hz,
590 n->n_cacheinfo.nci_used/hz, n->n_cacheinfo.nci_updated/hz);
591}
592
593static void neigh_dump_stats(struct nl_object *a, struct nl_dump_params *p)
594{
595 neigh_dump_details(a, p);
596}
597
598/**
599 * @name Neighbour Object Allocation/Freeage
600 * @{
601 */
602
603struct rtnl_neigh *rtnl_neigh_alloc(void)
604{
605 return (struct rtnl_neigh *) nl_object_alloc(&neigh_obj_ops);
606}
607
608void rtnl_neigh_put(struct rtnl_neigh *neigh)
609{
610 nl_object_put((struct nl_object *) neigh);
611}
612
613/** @} */
614
615/**
616 * @name Neighbour Cache Managament
617 * @{
618 */
619
620/**
621 * Build a neighbour cache including all neighbours currently configured in the kernel.
622 * @arg sock Netlink socket.
623 * @arg result Pointer to store resulting cache.
624 *
625 * Allocates a new neighbour cache, initializes it properly and updates it
626 * to include all neighbours currently configured in the kernel.
627 *
628 * @return 0 on success or a negative error code.
629 */
630int rtnl_neigh_alloc_cache(struct nl_sock *sock, struct nl_cache **result)
631{
632 return nl_cache_alloc_and_fill(&rtnl_neigh_ops, sock, result);
633}
634
635/**
636 * Build a neighbour cache including all neighbours currently configured in the kernel.
637 * @arg sock Netlink socket.
638 * @arg result Pointer to store resulting cache.
639 * @arg flags Flags to apply to cache before filling
640 *
641 * Allocates a new neighbour cache, initializes it properly and updates it
642 * to include all neighbours currently configured in the kernel.
643 *
644 * @return 0 on success or a negative error code.
645 */
646int rtnl_neigh_alloc_cache_flags(struct nl_sock *sock, struct nl_cache **result,
647 unsigned int flags)
648{
649 struct nl_cache * cache;
650 int err;
651
652 cache = nl_cache_alloc(&rtnl_neigh_ops);
653 if (!cache)
654 return -NLE_NOMEM;
655
656 nl_cache_set_flags(cache, flags);
657
658 if (sock && (err = nl_cache_refill(sock, cache)) < 0) {
659 nl_cache_free(cache);
660 return err;
661 }
662
663 *result = cache;
664 return 0;
665}
666
667/**
668 * Look up a neighbour by interface index and destination address
669 * @arg cache neighbour cache
670 * @arg ifindex interface index the neighbour is on
671 * @arg dst destination address of the neighbour
672 *
673 * @return neighbour handle or NULL if no match was found.
674 */
675struct rtnl_neigh * rtnl_neigh_get(struct nl_cache *cache, int ifindex,
676 struct nl_addr *dst)
677{
678 struct rtnl_neigh *neigh;
679
680 nl_list_for_each_entry(neigh, &cache->c_items, ce_list) {
681 if (neigh->n_ifindex == ifindex &&
682 neigh->n_family == dst->a_family &&
683 !nl_addr_cmp(neigh->n_dst, dst)) {
684 nl_object_get((struct nl_object *) neigh);
685 return neigh;
686 }
687 }
688
689 return NULL;
690}
691
692/**
693 * Look up a neighbour by interface index, link layer address and vlan id
694 * @arg cache neighbour cache
695 * @arg ifindex interface index the neighbour is on
696 * @arg lladdr link layer address of the neighbour
697 * @arg vlan vlan id of the neighbour
698 *
699 * @return neighbour handle or NULL if no match was found.
700 */
701struct rtnl_neigh * rtnl_neigh_get_by_vlan(struct nl_cache *cache, int ifindex,
702 struct nl_addr *lladdr, int vlan)
703{
704 struct rtnl_neigh *neigh;
705
706 nl_list_for_each_entry(neigh, &cache->c_items, ce_list) {
707 if (neigh->n_ifindex == ifindex &&
708 neigh->n_vlan == vlan &&
709 neigh->n_lladdr && !nl_addr_cmp(neigh->n_lladdr, lladdr)) {
710 nl_object_get((struct nl_object *) neigh);
711 return neigh;
712 }
713 }
714
715 return NULL;
716}
717
718/** @} */
719
720/**
721 * @name Neighbour Addition
722 * @{
723 */
724
725static int build_neigh_msg(struct rtnl_neigh *tmpl, int cmd, int flags,
726 struct nl_msg **result)
727{
728 struct nl_msg *msg;
729 struct ndmsg nhdr = {
730 .ndm_ifindex = tmpl->n_ifindex,
731 .ndm_state = NUD_PERMANENT,
732 };
733
734 if (tmpl->n_family != AF_BRIDGE) {
735 if (!(tmpl->ce_mask & NEIGH_ATTR_DST))
736 return -NLE_MISSING_ATTR;
737 nhdr.ndm_family = nl_addr_get_family(tmpl->n_dst);
738 }
739 else
740 nhdr.ndm_family = AF_BRIDGE;
741
742 if (tmpl->ce_mask & NEIGH_ATTR_FLAGS)
743 nhdr.ndm_flags = tmpl->n_flags;
744
745 if (tmpl->ce_mask & NEIGH_ATTR_STATE)
746 nhdr.ndm_state = tmpl->n_state;
747
748 msg = nlmsg_alloc_simple(cmd, flags);
749 if (!msg)
750 return -NLE_NOMEM;
751
752 if (nlmsg_append(msg, &nhdr, sizeof(nhdr), NLMSG_ALIGNTO) < 0)
753 goto nla_put_failure;
754
755 if (tmpl->ce_mask & NEIGH_ATTR_DST)
756 NLA_PUT_ADDR(msg, NDA_DST, tmpl->n_dst);
757
758 if (tmpl->ce_mask & NEIGH_ATTR_LLADDR)
759 NLA_PUT_ADDR(msg, NDA_LLADDR, tmpl->n_lladdr);
760
761 if (tmpl->ce_mask & NEIGH_ATTR_VLAN)
762 NLA_PUT_U16(msg, NDA_VLAN, tmpl->n_vlan);
763
764 if (tmpl->ce_mask & NEIGH_ATTR_NHID)
765 NLA_PUT_U32(msg, NDA_NH_ID, tmpl->n_nhid);
766
767 *result = msg;
768 return 0;
769
770nla_put_failure:
771 nlmsg_free(msg);
772 return -NLE_MSGSIZE;
773}
774
775/**
776 * Build netlink request message to add a new neighbour
777 * @arg tmpl template with data of new neighbour
778 * @arg flags additional netlink message flags
779 * @arg result Pointer to store resulting message.
780 *
781 * Builds a new netlink message requesting a addition of a new
782 * neighbour. The netlink message header isn't fully equipped with
783 * all relevant fields and must thus be sent out via nl_send_auto_complete()
784 * or supplemented as needed. \a tmpl must contain the attributes of the new
785 * neighbour set via \c rtnl_neigh_set_* functions.
786 *
787 * The following attributes must be set in the template:
788 * - Interface index (rtnl_neigh_set_ifindex())
789 * - State (rtnl_neigh_set_state())
790 * - Destination address (rtnl_neigh_set_dst())
791 * - Link layer address (rtnl_neigh_set_lladdr())
792 *
793 * @return 0 on success or a negative error code.
794 */
795int rtnl_neigh_build_add_request(struct rtnl_neigh *tmpl, int flags,
796 struct nl_msg **result)
797{
798 return build_neigh_msg(tmpl, RTM_NEWNEIGH, flags, result);
799}
800
801/**
802 * Add a new neighbour
803 * @arg sk Netlink socket.
804 * @arg tmpl template with requested changes
805 * @arg flags additional netlink message flags
806 *
807 * Builds a netlink message by calling rtnl_neigh_build_add_request(),
808 * sends the request to the kernel and waits for the next ACK to be
809 * received and thus blocks until the request has been fullfilled.
810 *
811 * The following attributes must be set in the template:
812 * - Interface index (rtnl_neigh_set_ifindex())
813 * - State (rtnl_neigh_set_state())
814 * - Destination address (rtnl_neigh_set_dst())
815 * - Link layer address (rtnl_neigh_set_lladdr())
816 *
817 * @return 0 on success or a negative error if an error occured.
818 */
819int rtnl_neigh_add(struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
820{
821 int err;
822 struct nl_msg *msg;
823
824 if ((err = rtnl_neigh_build_add_request(tmpl, flags, &msg)) < 0)
825 return err;
826
827 err = nl_send_auto_complete(sk, msg);
828 nlmsg_free(msg);
829 if (err < 0)
830 return err;
831
832 return wait_for_ack(sk);
833}
834
835/** @} */
836
837/**
838 * @name Neighbour Deletion
839 * @{
840 */
841
842/**
843 * Build a netlink request message to delete a neighbour
844 * @arg neigh neighbour to delete
845 * @arg flags additional netlink message flags
846 * @arg result Pointer to store resulting message.
847 *
848 * Builds a new netlink message requesting a deletion of a neighbour.
849 * The netlink message header isn't fully equipped with all relevant
850 * fields and must thus be sent out via nl_send_auto_complete()
851 * or supplemented as needed. \a neigh must point to an existing
852 * neighbour.
853 *
854 * @return 0 on success or a negative error code.
855 */
856int rtnl_neigh_build_delete_request(struct rtnl_neigh *neigh, int flags,
857 struct nl_msg **result)
858{
859 return build_neigh_msg(neigh, RTM_DELNEIGH, flags, result);
860}
861
862/**
863 * Delete a neighbour
864 * @arg sk Netlink socket.
865 * @arg neigh neighbour to delete
866 * @arg flags additional netlink message flags
867 *
868 * Builds a netlink message by calling rtnl_neigh_build_delete_request(),
869 * sends the request to the kernel and waits for the next ACK to be
870 * received and thus blocks until the request has been fullfilled.
871 *
872 * @return 0 on success or a negative error if an error occured.
873 */
874int rtnl_neigh_delete(struct nl_sock *sk, struct rtnl_neigh *neigh,
875 int flags)
876{
877 struct nl_msg *msg;
878 int err;
879
880 if ((err = rtnl_neigh_build_delete_request(neigh, flags, &msg)) < 0)
881 return err;
882
883 err = nl_send_auto_complete(sk, msg);
884 nlmsg_free(msg);
885 if (err < 0)
886 return err;
887
888 return wait_for_ack(sk);
889}
890
891/** @} */
892
893/**
894 * @name Neighbour States Translations
895 * @{
896 */
897
898static const struct trans_tbl neigh_states[] = {
899 __ADD(NUD_INCOMPLETE, incomplete),
900 __ADD(NUD_REACHABLE, reachable),
901 __ADD(NUD_STALE, stale),
902 __ADD(NUD_DELAY, delay),
903 __ADD(NUD_PROBE, probe),
904 __ADD(NUD_FAILED, failed),
905 __ADD(NUD_NOARP, noarp),
906 __ADD(NUD_PERMANENT, permanent),
907
908 /* Accept this value for backward compatibility. Originally
909 * there was a typo in the string value. This was fixed later,
910 * but we still want to successfully parse "norarp". */
911 __ADD(NUD_NOARP, norarp),
912};
913
914char * rtnl_neigh_state2str(int state, char *buf, size_t len)
915{
916 return __flags2str(state, buf, len, neigh_states,
917 ARRAY_SIZE(neigh_states) - 1);
918}
919
920int rtnl_neigh_str2state(const char *name)
921{
922 return __str2type(name, neigh_states, ARRAY_SIZE(neigh_states));
923}
924
925/** @} */
926
927/**
928 * @name Neighbour Flags Translations
929 * @{
930 */
931
932static const struct trans_tbl neigh_flags[] = {
933 __ADD(NTF_USE, use),
934 __ADD(NTF_PROXY, proxy),
935 __ADD(NTF_ROUTER, router),
936 __ADD(NTF_SELF, self),
937 __ADD(NTF_MASTER, master),
938 __ADD(NTF_EXT_LEARNED, ext_learned),
939 __ADD(NTF_OFFLOADED, offloaded),
940};
941
942char * rtnl_neigh_flags2str(int flags, char *buf, size_t len)
943{
944 return __flags2str(flags, buf, len, neigh_flags,
945 ARRAY_SIZE(neigh_flags));
946}
947
948int rtnl_neigh_str2flag(const char *name)
949{
950 return __str2type(name, neigh_flags, ARRAY_SIZE(neigh_flags));
951}
952
953/** @} */
954
955/**
956 * @name Attributes
957 * @{
958 */
959
960void rtnl_neigh_set_state(struct rtnl_neigh *neigh, int state)
961{
962 neigh->n_state_mask |= state;
963 neigh->n_state |= state;
964 neigh->ce_mask |= NEIGH_ATTR_STATE;
965}
966
967int rtnl_neigh_get_state(struct rtnl_neigh *neigh)
968{
969 if (neigh->ce_mask & NEIGH_ATTR_STATE)
970 return neigh->n_state;
971 else
972 return -1;
973}
974
975void rtnl_neigh_unset_state(struct rtnl_neigh *neigh, int state)
976{
977 neigh->n_state_mask |= state;
978 neigh->n_state &= ~state;
979 neigh->ce_mask |= NEIGH_ATTR_STATE;
980}
981
982void rtnl_neigh_set_flags(struct rtnl_neigh *neigh, unsigned int flags)
983{
984 neigh->n_flag_mask |= flags;
985 neigh->n_flags |= flags;
986 neigh->ce_mask |= NEIGH_ATTR_FLAGS;
987}
988
989unsigned int rtnl_neigh_get_flags(struct rtnl_neigh *neigh)
990{
991 return neigh->n_flags;
992}
993
994void rtnl_neigh_unset_flags(struct rtnl_neigh *neigh, unsigned int flags)
995{
996 neigh->n_flag_mask |= flags;
997 neigh->n_flags &= ~flags;
998 neigh->ce_mask |= NEIGH_ATTR_FLAGS;
999}
1000
1001void rtnl_neigh_set_ifindex(struct rtnl_neigh *neigh, int ifindex)
1002{
1003 neigh->n_ifindex = ifindex;
1004 neigh->ce_mask |= NEIGH_ATTR_IFINDEX;
1005}
1006
1007int rtnl_neigh_get_ifindex(struct rtnl_neigh *neigh)
1008{
1009 return neigh->n_ifindex;
1010}
1011
1012static inline int __assign_addr(struct rtnl_neigh *neigh, struct nl_addr **pos,
1013 struct nl_addr *new, int flag, int nocheck)
1014{
1015 if (!nocheck) {
1016 if (neigh->ce_mask & NEIGH_ATTR_FAMILY) {
1017 if (new->a_family != neigh->n_family)
1018 return -NLE_AF_MISMATCH;
1019 } else {
1020 neigh->n_family = new->a_family;
1021 neigh->ce_mask |= NEIGH_ATTR_FAMILY;
1022 }
1023 }
1024
1025 if (*pos)
1026 nl_addr_put(*pos);
1027
1028 nl_addr_get(new);
1029 *pos = new;
1030
1031 neigh->ce_mask |= flag;
1032
1033 return 0;
1034}
1035
1036void rtnl_neigh_set_lladdr(struct rtnl_neigh *neigh, struct nl_addr *addr)
1037{
1038 __assign_addr(neigh, &neigh->n_lladdr, addr, NEIGH_ATTR_LLADDR, 1);
1039}
1040
1041struct nl_addr *rtnl_neigh_get_lladdr(struct rtnl_neigh *neigh)
1042{
1043 if (neigh->ce_mask & NEIGH_ATTR_LLADDR)
1044 return neigh->n_lladdr;
1045 else
1046 return NULL;
1047}
1048
1049int rtnl_neigh_set_dst(struct rtnl_neigh *neigh, struct nl_addr *addr)
1050{
1051 return __assign_addr(neigh, &neigh->n_dst, addr,
1052 NEIGH_ATTR_DST, 0);
1053}
1054
1055struct nl_addr *rtnl_neigh_get_dst(struct rtnl_neigh *neigh)
1056{
1057 if (neigh->ce_mask & NEIGH_ATTR_DST)
1058 return neigh->n_dst;
1059 else
1060 return NULL;
1061}
1062
1063void rtnl_neigh_set_family(struct rtnl_neigh *neigh, int family)
1064{
1065 neigh->n_family = family;
1066 neigh->ce_mask |= NEIGH_ATTR_FAMILY;
1067}
1068
1069int rtnl_neigh_get_family(struct rtnl_neigh *neigh)
1070{
1071 return neigh->n_family;
1072}
1073
1074void rtnl_neigh_set_type(struct rtnl_neigh *neigh, int type)
1075{
1076 neigh->n_type = type;
1077 neigh->ce_mask = NEIGH_ATTR_TYPE;
1078}
1079
1080int rtnl_neigh_get_type(struct rtnl_neigh *neigh)
1081{
1082 if (neigh->ce_mask & NEIGH_ATTR_TYPE)
1083 return neigh->n_type;
1084 else
1085 return -1;
1086}
1087
1088void rtnl_neigh_set_vlan(struct rtnl_neigh *neigh, int vlan)
1089{
1090 neigh->n_vlan = vlan;
1091 neigh->ce_mask |= NEIGH_ATTR_VLAN;
1092}
1093
1094int rtnl_neigh_get_vlan(struct rtnl_neigh *neigh)
1095{
1096 if (neigh->ce_mask & NEIGH_ATTR_VLAN)
1097 return neigh->n_vlan;
1098 else
1099 return -1;
1100}
1101
1102void rtnl_neigh_set_master(struct rtnl_neigh *neigh, int ifindex)
1103{
1104 neigh->n_master = ifindex;
1105 neigh->ce_mask |= NEIGH_ATTR_MASTER;
1106}
1107
1108int rtnl_neigh_get_master(struct rtnl_neigh *neigh) {
1109 return neigh->n_master;
1110}
1111
1112void rtnl_neigh_set_nhid(struct rtnl_neigh *neigh, uint32_t nhid)
1113{
1114 neigh->n_nhid = nhid;
1115 neigh->ce_mask |= NEIGH_ATTR_NHID;
1116}
1117
1118int rtnl_neigh_get_nhid(struct rtnl_neigh *neigh, uint32_t *out_val) {
1119 if (!(neigh->ce_mask & NEIGH_ATTR_NHID))
1120 return -NLE_NOATTR;
1121
1122 *out_val = neigh->n_nhid;
1123 return NLE_SUCCESS;
1124}
1125
1126/** @} */
1127
1128static struct nl_object_ops neigh_obj_ops = {
1129 .oo_name = "route/neigh",
1130 .oo_size = sizeof(struct rtnl_neigh),
1131 .oo_free_data = neigh_free_data,
1132 .oo_clone = neigh_clone,
1133 .oo_dump = {
1134 [NL_DUMP_LINE] = neigh_dump_line,
1135 [NL_DUMP_DETAILS] = neigh_dump_details,
1136 [NL_DUMP_STATS] = neigh_dump_stats,
1137 },
1138 .oo_compare = neigh_compare,
1139 .oo_keygen = neigh_keygen,
1140 .oo_attrs2str = neigh_attrs2str,
1141 .oo_id_attrs = (NEIGH_ATTR_IFINDEX | NEIGH_ATTR_DST | NEIGH_ATTR_FAMILY),
1142 .oo_id_attrs_get = neigh_id_attrs_get
1143};
1144
1145static struct nl_af_group neigh_groups[] = {
1146 { AF_UNSPEC, RTNLGRP_NEIGH },
1147 { AF_BRIDGE, RTNLGRP_NEIGH },
1148 { END_OF_GROUP_LIST },
1149};
1150
1151static struct nl_cache_ops rtnl_neigh_ops = {
1152 .co_name = "route/neigh",
1153 .co_hdrsize = sizeof(struct ndmsg),
1154 .co_msgtypes = {
1155 { RTM_NEWNEIGH, NL_ACT_NEW, "new" },
1156 { RTM_DELNEIGH, NL_ACT_DEL, "del" },
1157 { RTM_GETNEIGH, NL_ACT_GET, "get" },
1158 END_OF_MSGTYPES_LIST,
1159 },
1160 .co_protocol = NETLINK_ROUTE,
1161 .co_groups = neigh_groups,
1162 .co_request_update = neigh_request_update,
1163 .co_msg_parser = neigh_msg_parser,
1164 .co_obj_ops = &neigh_obj_ops,
1165};
1166
1167static void _nl_init neigh_init(void)
1168{
1169 nl_cache_mngt_register(&rtnl_neigh_ops);
1170}
1171
1172static void _nl_exit neigh_exit(void)
1173{
1174 nl_cache_mngt_unregister(&rtnl_neigh_ops);
1175}
1176
1177/** @} */
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
Definition addr.c:525
struct nl_addr * nl_addr_alloc_attr(const struct nlattr *nla, int family)
Allocate abstract address based on Netlink attribute.
Definition addr.c:261
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
Definition addr.c:943
int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
Compare abstract addresses.
Definition addr.c:587
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
Definition addr.c:495
int nl_addr_get_family(const struct nl_addr *addr)
Return address family.
Definition addr.c:895
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
Definition addr.c:1001
unsigned int nl_addr_get_len(const struct nl_addr *addr)
Get length of binary address of abstract address object.
Definition addr.c:955
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
Definition addr.c:541
void nl_addr_set_family(struct nl_addr *addr, int family)
Set address family.
Definition addr.c:882
int nl_addr_guess_family(const struct nl_addr *addr)
Guess address family of abstract address based on address size.
Definition addr.c:711
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
Definition attr.c:710
uint16_t nla_get_u16(const struct nlattr *nla)
Return payload of 16 bit integer attribute.
Definition attr.c:660
#define NLA_PUT_U16(msg, attrtype, value)
Add 16 bit integer attribute to netlink message.
Definition attr.h:212
#define NLA_PUT_ADDR(msg, attrtype, addr)
Add address attribute to netlink message.
Definition attr.h:283
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
Definition attr.c:119
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
Definition attr.h:230
@ NLA_U32
32 bit integer
Definition attr.h:37
int nl_cache_mngt_unregister(struct nl_cache_ops *ops)
Unregister a set of cache operations.
Definition cache_mngt.c:287
int nl_cache_mngt_register(struct nl_cache_ops *ops)
Register a set of cache operations.
Definition cache_mngt.c:252
struct nl_cache * nl_cache_mngt_require_safe(const char *name)
Return cache previously provided via nl_cache_mngt_provide()
Definition cache_mngt.c:430
int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
Definition cache.c:1041
void nl_cache_set_flags(struct nl_cache *cache, unsigned int flags)
Set cache flags.
Definition cache.c:614
void nl_cache_free(struct nl_cache *cache)
Free a cache.
Definition cache.c:409
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate new cache.
Definition cache.c:184
int nl_cache_alloc_and_fill(struct nl_cache_ops *ops, struct nl_sock *sock, struct nl_cache **result)
Allocate new cache and fill it.
Definition cache.c:234
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
Definition msg.c:349
void * nlmsg_data(const struct nlmsghdr *nlh)
Return pointer to message payload.
Definition msg.c:108
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
Definition msg.c:566
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, const struct nla_policy *policy)
parse attributes of a netlink message
Definition msg.c:216
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:450
int rtnl_neigh_build_delete_request(struct rtnl_neigh *neigh, int flags, struct nl_msg **result)
Build a netlink request message to delete a neighbour.
Definition neigh.c:856
int rtnl_neigh_build_add_request(struct rtnl_neigh *tmpl, int flags, struct nl_msg **result)
Build netlink request message to add a new neighbour.
Definition neigh.c:795
int rtnl_neigh_alloc_cache(struct nl_sock *sock, struct nl_cache **result)
Build a neighbour cache including all neighbours currently configured in the kernel.
Definition neigh.c:630
int rtnl_neigh_add(struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
Add a new neighbour.
Definition neigh.c:819
struct rtnl_neigh * rtnl_neigh_get_by_vlan(struct nl_cache *cache, int ifindex, struct nl_addr *lladdr, int vlan)
Look up a neighbour by interface index, link layer address and vlan id.
Definition neigh.c:701
int rtnl_neigh_delete(struct nl_sock *sk, struct rtnl_neigh *neigh, int flags)
Delete a neighbour.
Definition neigh.c:874
struct rtnl_neigh * rtnl_neigh_get(struct nl_cache *cache, int ifindex, struct nl_addr *dst)
Look up a neighbour by interface index and destination address.
Definition neigh.c:675
int rtnl_neigh_alloc_cache_flags(struct nl_sock *sock, struct nl_cache **result, unsigned int flags)
Build a neighbour cache including all neighbours currently configured in the kernel.
Definition neigh.c:646
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition object.c:221
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition object.c:210
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:55
int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
Send routing netlink request message.
Definition rtnl.c:38
int nl_send_auto(struct nl_sock *sk, struct nl_msg *msg)
Finalize and transmit Netlink message.
Definition nl.c:515
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
Definition nl.c:1246
int nl_get_user_hz(void)
Return the value of HZ.
Definition utils.c:564
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Definition utils.c:1017
@ NL_DUMP_STATS
Dump all attributes including statistics.
Definition types.h:22
@ NL_DUMP_LINE
Dump object briefly on one line.
Definition types.h:20
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Definition types.h:21
Dumping parameters.
Definition types.h:32
Attribute validation policy.
Definition attr.h:63
uint16_t minlen
Minimal length of payload required.
Definition attr.h:68