146#include "nl-default.h"
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>
157#include "nl-priv-dynamic-core/nl-core.h"
158#include "nl-priv-dynamic-core/cache-api.h"
161struct rtnl_ncacheinfo {
162 uint32_t nci_confirmed;
164 uint32_t nci_updated;
175 struct nl_addr *n_lladdr;
176 struct nl_addr *n_dst;
179 struct rtnl_ncacheinfo n_cacheinfo;
180 uint32_t n_state_mask;
181 uint32_t n_flag_mask;
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
199static struct nl_cache_ops rtnl_neigh_ops;
200static struct nl_object_ops neigh_obj_ops;
203static void neigh_free_data(
struct nl_object *c)
205 struct rtnl_neigh *neigh = nl_object_priv(c);
214static int neigh_clone(
struct nl_object *_dst,
struct nl_object *_src)
216 struct rtnl_neigh *dst = nl_object_priv(_dst);
217 struct rtnl_neigh *src = nl_object_priv(_src);
219 dst->n_lladdr = NULL;
233static void neigh_keygen(
struct nl_object *obj, uint32_t *hashkey,
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 {
246 char buf[INET6_ADDRSTRLEN+5];
249 if (neigh->n_family == AF_BRIDGE) {
251 addr = neigh->n_lladdr;
252 }
else if (neigh->n_dst) {
256 nkey_sz =
sizeof(*nkey);
260 nkey = calloc(1, nkey_sz);
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;
271 nkey->n_ifindex = neigh->n_master;
273 nkey->n_ifindex = neigh->n_ifindex;
280 *hashkey = nl_hash(nkey, nkey_sz, 0) % table_sz;
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,
292static uint64_t neigh_compare(
struct nl_object *_a,
struct nl_object *_b,
293 uint64_t attrs,
int flags)
295 struct rtnl_neigh *a = (
struct rtnl_neigh *) _a;
296 struct rtnl_neigh *b = (
struct rtnl_neigh *) _b;
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);
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);
315 diff |= _DIFF(NEIGH_ATTR_STATE, a->n_state != b->n_state);
316 diff |= _DIFF(NEIGH_ATTR_FLAGS, a->n_flags != b->n_flags);
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),
338static char *neigh_attrs2str(
int attrs,
char *buf,
size_t len)
340 return __flags2str(attrs, buf, len, neigh_attrs,
341 ARRAY_SIZE(neigh_attrs));
344static uint32_t neigh_id_attrs_get(
struct nl_object *obj)
346 struct rtnl_neigh *neigh = (
struct rtnl_neigh *)obj;
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));
355 return (NEIGH_ATTR_LLADDR | NEIGH_ATTR_FAMILY | NEIGH_ATTR_MASTER | NEIGH_ATTR_VLAN);
357 return neigh_obj_ops.oo_id_attrs;
360static struct nla_policy neigh_policy[NDA_MAX+1] = {
361 [NDA_CACHEINFO] = { .
minlen =
sizeof(
struct nda_cacheinfo) },
362 [NDA_PROBES] = { .type =
NLA_U32 },
365static int neigh_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
366 struct nlmsghdr *n,
struct nl_parser_param *pp)
368 struct rtnl_neigh *neigh;
371 if ((err = rtnl_neigh_parse(n, &neigh)) < 0)
374 err = pp->pp_cb((
struct nl_object *) neigh, pp);
376 rtnl_neigh_put(neigh);
381int rtnl_neigh_parse(
struct nlmsghdr *n,
struct rtnl_neigh **result)
383 struct rtnl_neigh *neigh;
384 struct nlattr *tb[NDA_MAX + 1];
388 neigh = rtnl_neigh_alloc();
394 neigh->ce_msgtype = n->nlmsg_type;
397 err =
nlmsg_parse(n,
sizeof(*nm), tb, NDA_MAX, neigh_policy);
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;
407 neigh->ce_mask |= (NEIGH_ATTR_FAMILY | NEIGH_ATTR_IFINDEX |
408 NEIGH_ATTR_STATE | NEIGH_ATTR_FLAGS |
411 if (tb[NDA_LLADDR]) {
413 if (!neigh->n_lladdr) {
419 neigh->ce_mask |= NEIGH_ATTR_LLADDR;
430 neigh->ce_mask |= NEIGH_ATTR_DST;
433 if (tb[NDA_CACHEINFO]) {
434 struct nda_cacheinfo *ci =
nla_data(tb[NDA_CACHEINFO]);
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;
441 neigh->ce_mask |= NEIGH_ATTR_CACHEINFO;
444 if (tb[NDA_PROBES]) {
446 neigh->ce_mask |= NEIGH_ATTR_PROBES;
451 neigh->ce_mask |= NEIGH_ATTR_VLAN;
456 neigh->ce_mask |= NEIGH_ATTR_NHID;
462 if (neigh->n_family == AF_BRIDGE) {
463 if (tb[NDA_MASTER]) {
465 neigh->ce_mask |= NEIGH_ATTR_MASTER;
472 neigh->n_master = link->l_master;
474 neigh->ce_mask |= NEIGH_ATTR_MASTER;
476 nl_cache_put(lcache);
485 rtnl_neigh_put(neigh);
489static int neigh_request_update(
struct nl_cache *c,
struct nl_sock *h)
491 int family = c->c_iarg1;
493 if (family == AF_UNSPEC) {
495 }
else if (family == AF_BRIDGE) {
496 struct ifinfomsg hdr = {.ifi_family = family};
505 if (
nlmsg_append(msg, &hdr,
sizeof(hdr), NLMSG_ALIGNTO) < 0)
506 goto nla_put_failure;
521static void neigh_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
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];
531 if (n->n_family != AF_UNSPEC)
532 nl_dump_line(p,
"%s ", nl_af2str(n->n_family, buf,
sizeof(buf)));
534 if (n->ce_mask & NEIGH_ATTR_DST)
535 nl_dump_line(p,
"%s ",
nl_addr2str(n->n_dst, dst,
sizeof(dst)));
540 state,
sizeof(state)));
542 nl_dump(p,
"dev %d ", n->n_ifindex);
544 if (n->ce_mask & NEIGH_ATTR_LLADDR)
548 if (n->ce_mask & NEIGH_ATTR_VLAN)
549 nl_dump(p,
"vlan %d ", n->n_vlan);
551 if (n->ce_mask & NEIGH_ATTR_NHID)
552 nl_dump(p,
"nhid %u ", n->n_nhid);
554 if (n->ce_mask & NEIGH_ATTR_MASTER) {
557 state,
sizeof(state)));
559 nl_dump(p,
"%d ", n->n_master);
562 rtnl_neigh_state2str(n->n_state, state,
sizeof(state));
563 rtnl_neigh_flags2str(n->n_flags, flags,
sizeof(flags));
568 nl_dump(p,
"%s%s", state[0] ?
"," :
"<", flags);
569 if (state[0] || flags[0])
574 nl_cache_put(link_cache);
577static void neigh_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
580 struct rtnl_neigh *n = (
struct rtnl_neigh *) a;
583 neigh_dump_line(a, p);
585 nl_dump_line(p,
" refcnt %u type %s confirmed %u used "
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);
593static void neigh_dump_stats(
struct nl_object *a,
struct nl_dump_params *p)
595 neigh_dump_details(a, p);
603struct rtnl_neigh *rtnl_neigh_alloc(
void)
608void rtnl_neigh_put(
struct rtnl_neigh *neigh)
649 struct nl_cache * cache;
678 struct rtnl_neigh *neigh;
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 &&
702 struct nl_addr *lladdr,
int vlan)
704 struct rtnl_neigh *neigh;
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)) {
725static int build_neigh_msg(
struct rtnl_neigh *tmpl,
int cmd,
int flags,
726 struct nl_msg **result)
729 struct ndmsg nhdr = {
730 .ndm_ifindex = tmpl->n_ifindex,
731 .ndm_state = NUD_PERMANENT,
734 if (tmpl->n_family != AF_BRIDGE) {
735 if (!(tmpl->ce_mask & NEIGH_ATTR_DST))
736 return -NLE_MISSING_ATTR;
740 nhdr.ndm_family = AF_BRIDGE;
742 if (tmpl->ce_mask & NEIGH_ATTR_FLAGS)
743 nhdr.ndm_flags = tmpl->n_flags;
745 if (tmpl->ce_mask & NEIGH_ATTR_STATE)
746 nhdr.ndm_state = tmpl->n_state;
752 if (
nlmsg_append(msg, &nhdr,
sizeof(nhdr), NLMSG_ALIGNTO) < 0)
753 goto nla_put_failure;
755 if (tmpl->ce_mask & NEIGH_ATTR_DST)
758 if (tmpl->ce_mask & NEIGH_ATTR_LLADDR)
761 if (tmpl->ce_mask & NEIGH_ATTR_VLAN)
764 if (tmpl->ce_mask & NEIGH_ATTR_NHID)
796 struct nl_msg **result)
798 return build_neigh_msg(tmpl, RTM_NEWNEIGH, flags, result);
832 return wait_for_ack(sk);
857 struct nl_msg **result)
859 return build_neigh_msg(neigh, RTM_DELNEIGH, flags, result);
888 return wait_for_ack(sk);
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),
911 __ADD(NUD_NOARP, norarp),
914char * rtnl_neigh_state2str(
int state,
char *buf,
size_t len)
916 return __flags2str(state, buf, len, neigh_states,
917 ARRAY_SIZE(neigh_states) - 1);
920int rtnl_neigh_str2state(
const char *name)
922 return __str2type(name, neigh_states, ARRAY_SIZE(neigh_states));
932static const struct trans_tbl neigh_flags[] = {
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),
942char * rtnl_neigh_flags2str(
int flags,
char *buf,
size_t len)
944 return __flags2str(flags, buf, len, neigh_flags,
945 ARRAY_SIZE(neigh_flags));
948int rtnl_neigh_str2flag(
const char *name)
950 return __str2type(name, neigh_flags, ARRAY_SIZE(neigh_flags));
960void rtnl_neigh_set_state(
struct rtnl_neigh *neigh,
int state)
962 neigh->n_state_mask |= state;
963 neigh->n_state |= state;
964 neigh->ce_mask |= NEIGH_ATTR_STATE;
967int rtnl_neigh_get_state(
struct rtnl_neigh *neigh)
969 if (neigh->ce_mask & NEIGH_ATTR_STATE)
970 return neigh->n_state;
975void rtnl_neigh_unset_state(
struct rtnl_neigh *neigh,
int state)
977 neigh->n_state_mask |= state;
978 neigh->n_state &= ~state;
979 neigh->ce_mask |= NEIGH_ATTR_STATE;
982void rtnl_neigh_set_flags(
struct rtnl_neigh *neigh,
unsigned int flags)
984 neigh->n_flag_mask |= flags;
985 neigh->n_flags |= flags;
986 neigh->ce_mask |= NEIGH_ATTR_FLAGS;
989unsigned int rtnl_neigh_get_flags(
struct rtnl_neigh *neigh)
991 return neigh->n_flags;
994void rtnl_neigh_unset_flags(
struct rtnl_neigh *neigh,
unsigned int flags)
996 neigh->n_flag_mask |= flags;
997 neigh->n_flags &= ~flags;
998 neigh->ce_mask |= NEIGH_ATTR_FLAGS;
1001void rtnl_neigh_set_ifindex(
struct rtnl_neigh *neigh,
int ifindex)
1003 neigh->n_ifindex = ifindex;
1004 neigh->ce_mask |= NEIGH_ATTR_IFINDEX;
1007int rtnl_neigh_get_ifindex(
struct rtnl_neigh *neigh)
1009 return neigh->n_ifindex;
1012static inline int __assign_addr(
struct rtnl_neigh *neigh,
struct nl_addr **pos,
1013 struct nl_addr *
new,
int flag,
int nocheck)
1016 if (neigh->ce_mask & NEIGH_ATTR_FAMILY) {
1017 if (new->a_family != neigh->n_family)
1018 return -NLE_AF_MISMATCH;
1020 neigh->n_family =
new->a_family;
1021 neigh->ce_mask |= NEIGH_ATTR_FAMILY;
1031 neigh->ce_mask |= flag;
1036void rtnl_neigh_set_lladdr(
struct rtnl_neigh *neigh,
struct nl_addr *addr)
1038 __assign_addr(neigh, &neigh->n_lladdr, addr, NEIGH_ATTR_LLADDR, 1);
1041struct nl_addr *rtnl_neigh_get_lladdr(
struct rtnl_neigh *neigh)
1043 if (neigh->ce_mask & NEIGH_ATTR_LLADDR)
1044 return neigh->n_lladdr;
1049int rtnl_neigh_set_dst(
struct rtnl_neigh *neigh,
struct nl_addr *addr)
1051 return __assign_addr(neigh, &neigh->n_dst, addr,
1055struct nl_addr *rtnl_neigh_get_dst(
struct rtnl_neigh *neigh)
1057 if (neigh->ce_mask & NEIGH_ATTR_DST)
1058 return neigh->n_dst;
1063void rtnl_neigh_set_family(
struct rtnl_neigh *neigh,
int family)
1065 neigh->n_family = family;
1066 neigh->ce_mask |= NEIGH_ATTR_FAMILY;
1069int rtnl_neigh_get_family(
struct rtnl_neigh *neigh)
1071 return neigh->n_family;
1074void rtnl_neigh_set_type(
struct rtnl_neigh *neigh,
int type)
1076 neigh->n_type = type;
1077 neigh->ce_mask = NEIGH_ATTR_TYPE;
1080int rtnl_neigh_get_type(
struct rtnl_neigh *neigh)
1082 if (neigh->ce_mask & NEIGH_ATTR_TYPE)
1083 return neigh->n_type;
1088void rtnl_neigh_set_vlan(
struct rtnl_neigh *neigh,
int vlan)
1090 neigh->n_vlan = vlan;
1091 neigh->ce_mask |= NEIGH_ATTR_VLAN;
1094int rtnl_neigh_get_vlan(
struct rtnl_neigh *neigh)
1096 if (neigh->ce_mask & NEIGH_ATTR_VLAN)
1097 return neigh->n_vlan;
1102void rtnl_neigh_set_master(
struct rtnl_neigh *neigh,
int ifindex)
1104 neigh->n_master = ifindex;
1105 neigh->ce_mask |= NEIGH_ATTR_MASTER;
1108int rtnl_neigh_get_master(
struct rtnl_neigh *neigh) {
1109 return neigh->n_master;
1112void rtnl_neigh_set_nhid(
struct rtnl_neigh *neigh, uint32_t nhid)
1114 neigh->n_nhid = nhid;
1115 neigh->ce_mask |= NEIGH_ATTR_NHID;
1118int rtnl_neigh_get_nhid(
struct rtnl_neigh *neigh, uint32_t *out_val) {
1119 if (!(neigh->ce_mask & NEIGH_ATTR_NHID))
1122 *out_val = neigh->n_nhid;
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,
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
1145static struct nl_af_group neigh_groups[] = {
1146 { AF_UNSPEC, RTNLGRP_NEIGH },
1147 { AF_BRIDGE, RTNLGRP_NEIGH },
1148 { END_OF_GROUP_LIST },
1151static struct nl_cache_ops rtnl_neigh_ops = {
1152 .co_name =
"route/neigh",
1153 .co_hdrsize =
sizeof(
struct ndmsg),
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,
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,
1167static void _nl_init neigh_init(
void)
1172static void _nl_exit neigh_exit(
void)
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
struct nl_addr * nl_addr_alloc_attr(const struct nlattr *nla, int family)
Allocate abstract address based on Netlink attribute.
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
Compare abstract addresses.
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
int nl_addr_get_family(const struct nl_addr *addr)
Return address family.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
unsigned int nl_addr_get_len(const struct nl_addr *addr)
Get length of binary address of abstract address object.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
void nl_addr_set_family(struct nl_addr *addr, int family)
Set address family.
int nl_addr_guess_family(const struct nl_addr *addr)
Guess address family of abstract address based on address size.
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
uint16_t nla_get_u16(const struct nlattr *nla)
Return payload of 16 bit integer attribute.
#define NLA_PUT_U16(msg, attrtype, value)
Add 16 bit integer attribute to netlink message.
#define NLA_PUT_ADDR(msg, attrtype, addr)
Add address attribute to netlink message.
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
int nl_cache_mngt_unregister(struct nl_cache_ops *ops)
Unregister a set of cache operations.
int nl_cache_mngt_register(struct nl_cache_ops *ops)
Register a set of cache operations.
struct nl_cache * nl_cache_mngt_require_safe(const char *name)
Return cache previously provided via nl_cache_mngt_provide()
int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
void nl_cache_set_flags(struct nl_cache *cache, unsigned int flags)
Set cache flags.
void nl_cache_free(struct nl_cache *cache)
Free a cache.
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate new cache.
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.
struct rtnl_link * rtnl_link_get(struct nl_cache *cache, int ifindex)
Lookup link in cache by interface index.
char * rtnl_link_i2name(struct nl_cache *cache, int ifindex, char *dst, size_t len)
Translate interface index to corresponding link name.
void rtnl_link_put(struct rtnl_link *link)
Release a link object reference.
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
void * nlmsg_data(const struct nlmsghdr *nlh)
Return pointer to message payload.
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, const struct nla_policy *policy)
parse attributes of a netlink message
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
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.
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.
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.
int rtnl_neigh_add(struct nl_sock *sk, struct rtnl_neigh *tmpl, int flags)
Add a new neighbour.
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.
int rtnl_neigh_delete(struct nl_sock *sk, struct rtnl_neigh *neigh, int flags)
Delete a neighbour.
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.
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.
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
Send routing netlink request message.
int nl_send_auto(struct nl_sock *sk, struct nl_msg *msg)
Finalize and transmit Netlink message.
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
int nl_get_user_hz(void)
Return the value of HZ.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t minlen
Minimal length of payload required.