103#include <netlink-private/netlink.h>
104#include <netlink/netlink.h>
105#include <netlink/route/rtnl.h>
106#include <netlink/route/addr.h>
107#include <netlink/route/route.h>
108#include <netlink/route/link.h>
109#include <netlink/utils.h>
112#define ADDR_ATTR_FAMILY 0x0001
113#define ADDR_ATTR_PREFIXLEN 0x0002
114#define ADDR_ATTR_FLAGS 0x0004
115#define ADDR_ATTR_SCOPE 0x0008
116#define ADDR_ATTR_IFINDEX 0x0010
117#define ADDR_ATTR_LABEL 0x0020
118#define ADDR_ATTR_CACHEINFO 0x0040
119#define ADDR_ATTR_PEER 0x0080
120#define ADDR_ATTR_LOCAL 0x0100
121#define ADDR_ATTR_BROADCAST 0x0200
122#define ADDR_ATTR_MULTICAST 0x0400
123#define ADDR_ATTR_ANYCAST 0x0800
125static struct nl_cache_ops rtnl_addr_ops;
126static struct nl_object_ops addr_obj_ops;
129static void addr_constructor(
struct nl_object *obj)
131 struct rtnl_addr *addr = nl_object_priv(obj);
133 addr->a_scope = RT_SCOPE_NOWHERE;
136static void addr_free_data(
struct nl_object *obj)
138 struct rtnl_addr *addr = nl_object_priv(obj);
151static int addr_clone(
struct nl_object *_dst,
struct nl_object *_src)
153 struct rtnl_addr *dst = nl_object_priv(_dst);
154 struct rtnl_addr *src = nl_object_priv(_src);
159 dst->a_anycast = NULL;
160 dst->a_multicast = NULL;
165 dst->a_link = src->a_link;
180 if (src->a_multicast)
191static struct nla_policy addr_policy[IFA_MAX+1] = {
193 .maxlen = IFNAMSIZ },
194 [IFA_CACHEINFO] = { .minlen =
sizeof(
struct ifa_cacheinfo) },
197static int addr_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
198 struct nlmsghdr *nlh,
struct nl_parser_param *pp)
200 struct rtnl_addr *addr;
201 struct ifaddrmsg *ifa;
202 struct nlattr *tb[IFA_MAX+1];
204 struct nl_cache *link_cache;
205 struct nl_addr *plen_addr = NULL;
207 addr = rtnl_addr_alloc();
211 addr->ce_msgtype = nlh->nlmsg_type;
213 err =
nlmsg_parse(nlh,
sizeof(*ifa), tb, IFA_MAX, addr_policy);
218 addr->a_family = family = ifa->ifa_family;
219 addr->a_prefixlen = ifa->ifa_prefixlen;
220 addr->a_scope = ifa->ifa_scope;
221 addr->a_flags = tb[IFA_FLAGS] ?
nla_get_u32(tb[IFA_FLAGS]) :
223 addr->a_ifindex = ifa->ifa_index;
225 addr->ce_mask = (ADDR_ATTR_FAMILY | ADDR_ATTR_PREFIXLEN |
226 ADDR_ATTR_FLAGS | ADDR_ATTR_SCOPE | ADDR_ATTR_IFINDEX);
229 nla_strlcpy(addr->a_label, tb[IFA_LABEL], IFNAMSIZ);
230 addr->ce_mask |= ADDR_ATTR_LABEL;
234 if (tb[IFA_CACHEINFO]) {
235 struct ifa_cacheinfo *ca;
238 addr->a_cacheinfo.aci_prefered = ca->ifa_prefered;
239 addr->a_cacheinfo.aci_valid = ca->ifa_valid;
240 addr->a_cacheinfo.aci_cstamp = ca->cstamp;
241 addr->a_cacheinfo.aci_tstamp = ca->tstamp;
242 addr->ce_mask |= ADDR_ATTR_CACHEINFO;
245 if (family == AF_INET) {
256 addr->ce_mask |= ADDR_ATTR_LOCAL;
275 addr->ce_mask |= ADDR_ATTR_PEER;
277 plen_addr = addr->a_local;
283 addr->ce_mask |= ADDR_ATTR_LOCAL;
284 plen_addr = addr->a_local;
287 if (tb[IFA_ADDRESS]) {
297 if (!tb[IFA_LOCAL] || !
nl_addr_cmp(a, addr->a_local)) {
300 addr->ce_mask |= ADDR_ATTR_LOCAL;
303 addr->ce_mask |= ADDR_ATTR_PEER;
314 if (tb[IFA_BROADCAST]) {
319 addr->ce_mask |= ADDR_ATTR_BROADCAST;
323 if (tb[IFA_MULTICAST]) {
326 if (!addr->a_multicast)
329 addr->ce_mask |= ADDR_ATTR_MULTICAST;
333 if (tb[IFA_ANYCAST]) {
336 if (!addr->a_anycast)
339 addr->ce_mask |= ADDR_ATTR_ANYCAST;
342 if ((link_cache = __nl_cache_mngt_require(
"route/link"))) {
346 rtnl_addr_set_link(addr, link);
353 err = pp->pp_cb((
struct nl_object *) addr, pp);
364static int addr_request_update(
struct nl_cache *cache,
struct nl_sock *sk)
369static void addr_dump_line(
struct nl_object *obj,
struct nl_dump_params *p)
371 struct rtnl_addr *addr = (
struct rtnl_addr *) obj;
372 struct nl_cache *link_cache;
377 if (addr->ce_mask & ADDR_ATTR_LOCAL)
378 nl_dump_line(p,
"%s",
381 nl_dump_line(p,
"none");
383 if (addr->ce_mask & ADDR_ATTR_PEER)
387 nl_dump(p,
" %s ", nl_af2str(addr->a_family, buf,
sizeof(buf)));
394 nl_dump(p,
"dev %d ", addr->a_ifindex);
397 rtnl_scope2str(addr->a_scope, buf,
sizeof(buf)));
399 rtnl_addr_flags2str(addr->a_flags, buf,
sizeof(buf));
406 nl_cache_put(link_cache);
409static void addr_dump_details(
struct nl_object *obj,
struct nl_dump_params *p)
411 struct rtnl_addr *addr = (
struct rtnl_addr *) obj;
414 addr_dump_line(obj, p);
416 if (addr->ce_mask & (ADDR_ATTR_LABEL | ADDR_ATTR_BROADCAST |
417 ADDR_ATTR_MULTICAST)) {
418 nl_dump_line(p,
" ");
420 if (addr->ce_mask & ADDR_ATTR_LABEL)
421 nl_dump(p,
" label %s", addr->a_label);
423 if (addr->ce_mask & ADDR_ATTR_BROADCAST)
427 if (addr->ce_mask & ADDR_ATTR_MULTICAST)
432 if (addr->ce_mask & ADDR_ATTR_ANYCAST)
440 if (addr->ce_mask & ADDR_ATTR_CACHEINFO) {
441 struct rtnl_addr_cacheinfo *ci = &addr->a_cacheinfo;
443 nl_dump_line(p,
" valid-lifetime %s",
444 ci->aci_valid == 0xFFFFFFFFU ?
"forever" :
448 nl_dump(p,
" preferred-lifetime %s\n",
449 ci->aci_prefered == 0xFFFFFFFFU ?
"forever" :
453 nl_dump_line(p,
" created boot-time+%s ",
457 nl_dump(p,
"last-updated boot-time+%s\n",
463static void addr_dump_stats(
struct nl_object *obj,
struct nl_dump_params *p)
465 addr_dump_details(obj, p);
468static uint32_t addr_id_attrs_get(
struct nl_object *obj)
470 struct rtnl_addr *addr = (
struct rtnl_addr *)obj;
473 switch (addr->a_family) {
475 rv = (ADDR_ATTR_FAMILY | ADDR_ATTR_IFINDEX |
476 ADDR_ATTR_LOCAL | ADDR_ATTR_PREFIXLEN);
478 rv |= ADDR_ATTR_PEER;
481 return (ADDR_ATTR_FAMILY | ADDR_ATTR_IFINDEX |
484 return (ADDR_ATTR_FAMILY | ADDR_ATTR_IFINDEX |
485 ADDR_ATTR_LOCAL | ADDR_ATTR_PREFIXLEN);
489static uint64_t addr_compare(
struct nl_object *_a,
struct nl_object *_b,
490 uint64_t attrs,
int flags)
492 struct rtnl_addr *a = (
struct rtnl_addr *) _a;
493 struct rtnl_addr *b = (
struct rtnl_addr *) _b;
496#define ADDR_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ADDR_ATTR_##ATTR, a, b, EXPR)
498 diff |= ADDR_DIFF(IFINDEX, a->a_ifindex != b->a_ifindex);
499 diff |= ADDR_DIFF(FAMILY, a->a_family != b->a_family);
500 diff |= ADDR_DIFF(SCOPE, a->a_scope != b->a_scope);
501 diff |= ADDR_DIFF(LABEL, strcmp(a->a_label, b->a_label));
502 if (attrs & ADDR_ATTR_PEER) {
503 if ( (flags & ID_COMPARISON)
504 && a->a_family == AF_INET
505 && b->a_family == AF_INET
508 && a->a_prefixlen == b->a_prefixlen) {
514 diff |= ADDR_DIFF(PEER,
nl_addr_cmp(a->a_peer, b->a_peer));
516 diff |= ADDR_DIFF(LOCAL,
nl_addr_cmp(a->a_local, b->a_local));
517 diff |= ADDR_DIFF(MULTICAST,
nl_addr_cmp(a->a_multicast,
519 diff |= ADDR_DIFF(BROADCAST,
nl_addr_cmp(a->a_bcast, b->a_bcast));
520 diff |= ADDR_DIFF(ANYCAST,
nl_addr_cmp(a->a_anycast, b->a_anycast));
521 diff |= ADDR_DIFF(CACHEINFO, memcmp(&a->a_cacheinfo, &b->a_cacheinfo,
522 sizeof (a->a_cacheinfo)));
524 if (flags & LOOSE_COMPARISON)
525 diff |= ADDR_DIFF(FLAGS,
526 (a->a_flags ^ b->a_flags) & b->a_flag_mask);
528 diff |= ADDR_DIFF(FLAGS, a->a_flags != b->a_flags);
535static const struct trans_tbl addr_attrs[] = {
536 __ADD(ADDR_ATTR_FAMILY, family),
537 __ADD(ADDR_ATTR_PREFIXLEN, prefixlen),
538 __ADD(ADDR_ATTR_FLAGS, flags),
539 __ADD(ADDR_ATTR_SCOPE, scope),
540 __ADD(ADDR_ATTR_IFINDEX, ifindex),
541 __ADD(ADDR_ATTR_LABEL, label),
542 __ADD(ADDR_ATTR_CACHEINFO, cacheinfo),
543 __ADD(ADDR_ATTR_PEER, peer),
544 __ADD(ADDR_ATTR_LOCAL, local),
545 __ADD(ADDR_ATTR_BROADCAST, broadcast),
546 __ADD(ADDR_ATTR_MULTICAST, multicast),
549static char *addr_attrs2str(
int attrs,
char *buf,
size_t len)
551 return __flags2str(attrs, buf, len, addr_attrs,
552 ARRAY_SIZE(addr_attrs));
560struct rtnl_addr *rtnl_addr_alloc(
void)
565void rtnl_addr_put(
struct rtnl_addr *addr)
577int rtnl_addr_alloc_cache(
struct nl_sock *sk,
struct nl_cache **result)
597 struct nl_addr *addr)
601 if (cache->c_ops != &rtnl_addr_ops)
604 nl_list_for_each_entry(a, &cache->c_items, ce_list) {
605 if (ifindex && a->a_ifindex != ifindex)
608 if (a->ce_mask & ADDR_ATTR_LOCAL &&
620static int build_addr_msg(
struct rtnl_addr *tmpl,
int cmd,
int flags,
621 struct nl_msg **result)
624 struct ifaddrmsg am = {
625 .ifa_family = tmpl->a_family,
626 .ifa_index = tmpl->a_ifindex,
627 .ifa_prefixlen = tmpl->a_prefixlen,
628 .ifa_flags = tmpl->a_flags,
631 if (tmpl->ce_mask & ADDR_ATTR_SCOPE)
632 am.ifa_scope = tmpl->a_scope;
635 if (tmpl->a_family == AF_INET &&
636 tmpl->ce_mask & ADDR_ATTR_LOCAL &&
638 am.ifa_scope = RT_SCOPE_HOST;
640 am.ifa_scope = RT_SCOPE_UNIVERSE;
647 if (
nlmsg_append(msg, &am,
sizeof(am), NLMSG_ALIGNTO) < 0)
648 goto nla_put_failure;
650 if (tmpl->ce_mask & ADDR_ATTR_LOCAL)
653 if (tmpl->ce_mask & ADDR_ATTR_PEER)
655 else if (tmpl->ce_mask & ADDR_ATTR_LOCAL)
658 if (tmpl->ce_mask & ADDR_ATTR_LABEL)
661 if (tmpl->ce_mask & ADDR_ATTR_BROADCAST)
664 if (tmpl->ce_mask & ADDR_ATTR_CACHEINFO) {
665 struct ifa_cacheinfo ca = {
666 .ifa_valid = tmpl->a_cacheinfo.aci_valid,
667 .ifa_prefered = tmpl->a_cacheinfo.aci_prefered,
670 NLA_PUT(msg, IFA_CACHEINFO,
sizeof(ca), &ca);
673 if (tmpl->a_flags & ~0xFF) {
723 struct nl_msg **result)
725 uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY |
726 ADDR_ATTR_PREFIXLEN | ADDR_ATTR_LOCAL;
728 if ((addr->ce_mask & required) != required)
729 return -NLE_MISSING_ATTR;
731 return build_addr_msg(addr, RTM_NEWADDR, NLM_F_CREATE | flags, result);
761 return wait_for_ack(sk);
796 struct nl_msg **result)
798 uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY;
800 if ((addr->ce_mask & required) != required)
801 return -NLE_MISSING_ATTR;
803 return build_addr_msg(addr, RTM_DELADDR, flags, result);
833 return wait_for_ack(sk);
843int rtnl_addr_set_label(
struct rtnl_addr *addr,
const char *label)
845 if (strlen(label) >
sizeof(addr->a_label) - 1)
848 strcpy(addr->a_label, label);
849 addr->ce_mask |= ADDR_ATTR_LABEL;
854char *rtnl_addr_get_label(
struct rtnl_addr *addr)
856 if (addr->ce_mask & ADDR_ATTR_LABEL)
857 return addr->a_label;
862void rtnl_addr_set_ifindex(
struct rtnl_addr *addr,
int ifindex)
864 addr->a_ifindex = ifindex;
865 addr->ce_mask |= ADDR_ATTR_IFINDEX;
868int rtnl_addr_get_ifindex(
struct rtnl_addr *addr)
870 return addr->a_ifindex;
873void rtnl_addr_set_link(
struct rtnl_addr *addr,
struct rtnl_link *link)
882 addr->a_ifindex = link->l_index;
883 addr->ce_mask |= ADDR_ATTR_IFINDEX;
886struct rtnl_link *rtnl_addr_get_link(
struct rtnl_addr *addr)
896void rtnl_addr_set_family(
struct rtnl_addr *addr,
int family)
898 addr->a_family = family;
899 addr->ce_mask |= ADDR_ATTR_FAMILY;
902int rtnl_addr_get_family(
struct rtnl_addr *addr)
904 return addr->a_family;
925 addr->a_prefixlen = prefixlen;
928 addr->ce_mask |= ADDR_ATTR_PREFIXLEN;
930 addr->ce_mask &= ~ADDR_ATTR_PREFIXLEN;
938 else if (addr->a_local)
942int rtnl_addr_get_prefixlen(
struct rtnl_addr *addr)
944 return addr->a_prefixlen;
947void rtnl_addr_set_scope(
struct rtnl_addr *addr,
int scope)
949 addr->a_scope = scope;
950 addr->ce_mask |= ADDR_ATTR_SCOPE;
953int rtnl_addr_get_scope(
struct rtnl_addr *addr)
955 return addr->a_scope;
958void rtnl_addr_set_flags(
struct rtnl_addr *addr,
unsigned int flags)
960 addr->a_flag_mask |= flags;
961 addr->a_flags |= flags;
962 addr->ce_mask |= ADDR_ATTR_FLAGS;
965void rtnl_addr_unset_flags(
struct rtnl_addr *addr,
unsigned int flags)
967 addr->a_flag_mask |= flags;
968 addr->a_flags &= ~flags;
969 addr->ce_mask |= ADDR_ATTR_FLAGS;
972unsigned int rtnl_addr_get_flags(
struct rtnl_addr *addr)
974 return addr->a_flags;
977static inline int __assign_addr(
struct rtnl_addr *addr,
struct nl_addr **pos,
978 struct nl_addr *
new,
int flag)
981 if (addr->ce_mask & ADDR_ATTR_FAMILY) {
982 if (new->a_family != addr->a_family)
983 return -NLE_AF_MISMATCH;
985 addr->a_family =
new->a_family;
991 addr->ce_mask |= (flag | ADDR_ATTR_FAMILY);
997 addr->ce_mask &= ~flag;
1003int rtnl_addr_set_local(
struct rtnl_addr *addr,
struct nl_addr *local)
1008 if ((addr->ce_mask & ADDR_ATTR_PEER) && local &&
1012 err = __assign_addr(addr, &addr->a_local, local, ADDR_ATTR_LOCAL);
1017 if (!(addr->ce_mask & ADDR_ATTR_PEER))
1023struct nl_addr *rtnl_addr_get_local(
struct rtnl_addr *addr)
1025 return addr->a_local;
1028int rtnl_addr_set_peer(
struct rtnl_addr *addr,
struct nl_addr *peer)
1032 if (peer && peer->a_family != AF_INET)
1033 return -NLE_AF_NOSUPPORT;
1035 err = __assign_addr(addr, &addr->a_peer, peer, ADDR_ATTR_PEER);
1044struct nl_addr *rtnl_addr_get_peer(
struct rtnl_addr *addr)
1046 return addr->a_peer;
1049int rtnl_addr_set_broadcast(
struct rtnl_addr *addr,
struct nl_addr *bcast)
1051 if (bcast && bcast->a_family != AF_INET)
1052 return -NLE_AF_NOSUPPORT;
1054 return __assign_addr(addr, &addr->a_bcast, bcast, ADDR_ATTR_BROADCAST);
1057struct nl_addr *rtnl_addr_get_broadcast(
struct rtnl_addr *addr)
1059 return addr->a_bcast;
1062int rtnl_addr_set_multicast(
struct rtnl_addr *addr,
struct nl_addr *multicast)
1064 if (multicast && multicast->a_family != AF_INET6)
1065 return -NLE_AF_NOSUPPORT;
1067 return __assign_addr(addr, &addr->a_multicast, multicast,
1068 ADDR_ATTR_MULTICAST);
1071struct nl_addr *rtnl_addr_get_multicast(
struct rtnl_addr *addr)
1073 return addr->a_multicast;
1076int rtnl_addr_set_anycast(
struct rtnl_addr *addr,
struct nl_addr *anycast)
1078 if (anycast && anycast->a_family != AF_INET6)
1079 return -NLE_AF_NOSUPPORT;
1081 return __assign_addr(addr, &addr->a_anycast, anycast,
1085struct nl_addr *rtnl_addr_get_anycast(
struct rtnl_addr *addr)
1087 return addr->a_anycast;
1090uint32_t rtnl_addr_get_valid_lifetime(
struct rtnl_addr *addr)
1092 if (addr->ce_mask & ADDR_ATTR_CACHEINFO)
1093 return addr->a_cacheinfo.aci_valid;
1098void rtnl_addr_set_valid_lifetime(
struct rtnl_addr *addr, uint32_t lifetime)
1100 addr->a_cacheinfo.aci_valid = lifetime;
1101 addr->ce_mask |= ADDR_ATTR_CACHEINFO;
1104uint32_t rtnl_addr_get_preferred_lifetime(
struct rtnl_addr *addr)
1106 if (addr->ce_mask & ADDR_ATTR_CACHEINFO)
1107 return addr->a_cacheinfo.aci_prefered;
1112void rtnl_addr_set_preferred_lifetime(
struct rtnl_addr *addr, uint32_t lifetime)
1114 addr->a_cacheinfo.aci_prefered = lifetime;
1115 addr->ce_mask |= ADDR_ATTR_CACHEINFO;
1118uint32_t rtnl_addr_get_create_time(
struct rtnl_addr *addr)
1120 return addr->a_cacheinfo.aci_cstamp;
1123uint32_t rtnl_addr_get_last_update_time(
struct rtnl_addr *addr)
1125 return addr->a_cacheinfo.aci_tstamp;
1135static const struct trans_tbl addr_flags[] = {
1136 __ADD(IFA_F_SECONDARY, secondary),
1137 __ADD(IFA_F_NODAD, nodad),
1138 __ADD(IFA_F_OPTIMISTIC, optimistic),
1139 __ADD(IFA_F_DADFAILED, dadfailed),
1140 __ADD(IFA_F_HOMEADDRESS, homeaddress),
1141 __ADD(IFA_F_DEPRECATED, deprecated),
1142 __ADD(IFA_F_TENTATIVE, tentative),
1143 __ADD(IFA_F_PERMANENT, permanent),
1144 __ADD(IFA_F_MANAGETEMPADDR, mngtmpaddr),
1145 __ADD(IFA_F_NOPREFIXROUTE, noprefixroute),
1148char *rtnl_addr_flags2str(
int flags,
char *buf,
size_t size)
1150 return __flags2str(flags, buf, size, addr_flags,
1151 ARRAY_SIZE(addr_flags));
1154int rtnl_addr_str2flags(
const char *name)
1156 return __str2flags(name, addr_flags, ARRAY_SIZE(addr_flags));
1161static struct nl_object_ops addr_obj_ops = {
1162 .oo_name =
"route/addr",
1163 .oo_size =
sizeof(
struct rtnl_addr),
1164 .oo_constructor = addr_constructor,
1165 .oo_free_data = addr_free_data,
1166 .oo_clone = addr_clone,
1172 .oo_compare = addr_compare,
1173 .oo_attrs2str = addr_attrs2str,
1174 .oo_id_attrs_get = addr_id_attrs_get,
1175 .oo_id_attrs = (ADDR_ATTR_FAMILY | ADDR_ATTR_IFINDEX |
1176 ADDR_ATTR_LOCAL | ADDR_ATTR_PREFIXLEN),
1179static struct nl_af_group addr_groups[] = {
1180 { AF_INET, RTNLGRP_IPV4_IFADDR },
1181 { AF_INET6, RTNLGRP_IPV6_IFADDR },
1182 { END_OF_GROUP_LIST },
1185static struct nl_cache_ops rtnl_addr_ops = {
1186 .co_name =
"route/addr",
1187 .co_hdrsize =
sizeof(
struct ifaddrmsg),
1189 { RTM_NEWADDR, NL_ACT_NEW,
"new" },
1190 { RTM_DELADDR, NL_ACT_DEL,
"del" },
1191 { RTM_GETADDR, NL_ACT_GET,
"get" },
1192 END_OF_MSGTYPES_LIST,
1194 .co_protocol = NETLINK_ROUTE,
1195 .co_groups = addr_groups,
1196 .co_request_update = addr_request_update,
1197 .co_msg_parser = addr_msg_parser,
1198 .co_obj_ops = &addr_obj_ops,
1201static void __init addr_init(
void)
1206static void __exit addr_exit(
void)
void nl_addr_set_prefixlen(struct nl_addr *addr, int prefixlen)
Set the prefix length of an abstract address.
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
struct nl_addr * nl_addr_build(int family, const void *buf, size_t size)
Allocate abstract address based on a binary 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_cmp_prefix(const struct nl_addr *a, const struct nl_addr *b)
Compare the prefix of two abstract addresses.
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_prefixlen(const struct nl_addr *addr)
Return prefix length of abstract address object.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
#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(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
Copy string attribute payload to a buffer.
#define NLA_PUT_STRING(msg, attrtype, value)
Add string attribute to netlink message.
@ NLA_STRING
NUL terminated character string.
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_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)
Return 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.
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 rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags, struct nl_msg **result)
Build a netlink request message to request deletion of an address.
int rtnl_addr_delete(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request deletion of an address.
struct rtnl_addr * rtnl_addr_get(struct nl_cache *cache, int ifindex, struct nl_addr *addr)
Search address in cache.
int rtnl_addr_add(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request addition of new address.
int rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags, struct nl_msg **result)
Build netlink request message to request addition of new address.
void rtnl_addr_set_prefixlen(struct rtnl_addr *addr, int prefixlen)
Set the prefix length / netmask.
int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
Send routing netlink request message.
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
Convert milliseconds to a 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 type
Type of attribute or NLA_UNSPEC.