42#include <netlink-private/netlink.h>
43#include <netlink/netlink.h>
44#include <netlink/cache.h>
45#include <netlink/object.h>
46#include <netlink/xfrm/selector.h>
47#include <netlink/xfrm/lifetime.h>
48#include <netlink/xfrm/template.h>
49#include <netlink/xfrm/sp.h>
52#define XFRM_SP_ATTR_SEL 0x01
53#define XFRM_SP_ATTR_LTIME_CFG 0x02
54#define XFRM_SP_ATTR_LTIME_CUR 0x04
55#define XFRM_SP_ATTR_PRIO 0x08
56#define XFRM_SP_ATTR_INDEX 0x10
57#define XFRM_SP_ATTR_DIR 0x20
58#define XFRM_SP_ATTR_ACTION 0x40
59#define XFRM_SP_ATTR_FLAGS 0x80
60#define XFRM_SP_ATTR_SHARE 0x100
61#define XFRM_SP_ATTR_POLTYPE 0x200
62#define XFRM_SP_ATTR_SECCTX 0x400
63#define XFRM_SP_ATTR_TMPL 0x800
64#define XFRM_SP_ATTR_MARK 0x1000
66static struct nl_cache_ops xfrmnl_sp_ops;
67static struct nl_object_ops xfrm_sp_obj_ops;
70static void xfrm_sp_alloc_data(
struct nl_object *c)
72 struct xfrmnl_sp* sp = nl_object_priv (c);
80 nl_init_list_head(&sp->usertmpl_list);
85static void xfrm_sp_free_data(
struct nl_object *c)
87 struct xfrmnl_sp* sp = nl_object_priv (c);
88 struct xfrmnl_user_tmpl *utmpl, *tmp;
93 xfrmnl_sel_put (sp->sel);
94 xfrmnl_ltime_cfg_put (sp->lft);
100 nl_list_for_each_entry_safe(utmpl, tmp, &sp->usertmpl_list, utmpl_list) {
101 xfrmnl_sp_remove_usertemplate (sp, utmpl);
102 xfrmnl_user_tmpl_free (utmpl);
106static int xfrm_sp_clone(
struct nl_object *_dst,
struct nl_object *_src)
108 struct xfrmnl_sp* dst = nl_object_priv(_dst);
109 struct xfrmnl_sp* src = nl_object_priv(_src);
110 struct xfrmnl_user_tmpl *utmpl;
111 struct xfrmnl_user_tmpl *
new;
116 nl_init_list_head(&dst->usertmpl_list);
129 uint32_t len =
sizeof (
struct xfrmnl_user_sec_ctx) + src->sec_ctx->ctx_len;
131 if ((dst->sec_ctx = malloc (len)) == NULL)
133 memcpy(dst->sec_ctx, src->sec_ctx, len);
136 nl_list_for_each_entry(utmpl, &src->usertmpl_list, utmpl_list) {
140 xfrmnl_sp_add_usertemplate(dst,
new);
146static uint64_t xfrm_sp_compare(
struct nl_object *_a,
struct nl_object *_b,
147 uint64_t attrs,
int flags)
149 struct xfrmnl_sp* a = (
struct xfrmnl_sp *) _a;
150 struct xfrmnl_sp* b = (
struct xfrmnl_sp *) _b;
151 struct xfrmnl_user_tmpl *tmpl_a, *tmpl_b;
154#define XFRM_SP_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, XFRM_SP_ATTR_##ATTR, a, b, EXPR)
157 diff |= XFRM_SP_DIFF(PRIO, a->priority != b->priority);
158 diff |= XFRM_SP_DIFF(INDEX, a->index != b->index);
159 diff |= XFRM_SP_DIFF(DIR, a->dir != b->dir);
160 diff |= XFRM_SP_DIFF(ACTION, a->action != b->action);
161 diff |= XFRM_SP_DIFF(FLAGS, a->flags != b->flags);
162 diff |= XFRM_SP_DIFF(SHARE, a->share != b->share);
163 diff |= XFRM_SP_DIFF(SECCTX,((a->sec_ctx->len != b->sec_ctx->len) ||
164 (a->sec_ctx->exttype != b->sec_ctx->exttype) ||
165 (a->sec_ctx->ctx_alg != b->sec_ctx->ctx_alg) ||
166 (a->sec_ctx->ctx_doi != b->sec_ctx->ctx_doi) ||
167 (a->sec_ctx->ctx_len != b->sec_ctx->ctx_len) ||
168 strcmp(a->sec_ctx->ctx, b->sec_ctx->ctx)));
169 diff |= XFRM_SP_DIFF(POLTYPE,(a->uptype.type != b->uptype.type));
170 diff |= XFRM_SP_DIFF(TMPL,(a->nr_user_tmpl != b->nr_user_tmpl));
171 diff |= XFRM_SP_DIFF(MARK,(a->mark.m != b->mark.m) ||
172 (a->mark.v != b->mark.v));
175 nl_list_for_each_entry(tmpl_b, &b->usertmpl_list, utmpl_list)
176 nl_list_for_each_entry(tmpl_a, &a->usertmpl_list, utmpl_list)
187static const struct trans_tbl sp_attrs[] = {
188 __ADD(XFRM_SP_ATTR_SEL, selector),
189 __ADD(XFRM_SP_ATTR_LTIME_CFG, lifetime_cfg),
190 __ADD(XFRM_SP_ATTR_LTIME_CUR, lifetime_cur),
191 __ADD(XFRM_SP_ATTR_PRIO, priority),
192 __ADD(XFRM_SP_ATTR_INDEX, index),
193 __ADD(XFRM_SP_ATTR_DIR, direction),
194 __ADD(XFRM_SP_ATTR_ACTION, action),
195 __ADD(XFRM_SP_ATTR_FLAGS, flags),
196 __ADD(XFRM_SP_ATTR_SHARE, share),
197 __ADD(XFRM_SP_ATTR_POLTYPE, policy_type),
198 __ADD(XFRM_SP_ATTR_SECCTX, security_context),
199 __ADD(XFRM_SP_ATTR_TMPL, user_template),
200 __ADD(XFRM_SP_ATTR_MARK, mark),
203static char* xfrm_sp_attrs2str(
int attrs,
char *buf,
size_t len)
205 return __flags2str (attrs, buf, len, sp_attrs, ARRAY_SIZE(sp_attrs));
213static const struct trans_tbl sa_actions[] = {
214 __ADD(XFRM_POLICY_ALLOW, allow),
215 __ADD(XFRM_POLICY_BLOCK, block),
218char* xfrmnl_sp_action2str(
int action,
char *buf,
size_t len)
220 return __type2str (action, buf, len, sa_actions, ARRAY_SIZE(sa_actions));
223int xfrmnl_sp_str2action(
const char *name)
225 return __str2type (name, sa_actions, ARRAY_SIZE(sa_actions));
233static const struct trans_tbl sp_flags[] = {
234 __ADD(XFRM_POLICY_LOCALOK, allow policy
override by user),
235 __ADD(XFRM_POLICY_ICMP,
auto include ICMP in policy),
238char* xfrmnl_sp_flags2str(
int flags,
char *buf,
size_t len)
240 return __flags2str (flags, buf, len, sp_flags, ARRAY_SIZE(sp_flags));
243int xfrmnl_sp_str2flag(
const char *name)
245 return __str2flags(name, sp_flags, ARRAY_SIZE(sp_flags));
253static const struct trans_tbl sp_types[] = {
254 __ADD(XFRM_POLICY_TYPE_MAIN, main),
255 __ADD(XFRM_POLICY_TYPE_SUB, sub),
256 __ADD(XFRM_POLICY_TYPE_MAX, max),
257 __ADD(XFRM_POLICY_TYPE_ANY, any),
260char* xfrmnl_sp_type2str(
int type,
char *buf,
size_t len)
262 return __type2str(type, buf, len, sp_types, ARRAY_SIZE(sp_types));
265int xfrmnl_sp_str2type(
const char *name)
267 return __str2type(name, sp_types, ARRAY_SIZE(sp_types));
275static const struct trans_tbl sp_dir[] = {
276 __ADD(XFRM_POLICY_IN, in),
277 __ADD(XFRM_POLICY_OUT, out),
278 __ADD(XFRM_POLICY_FWD, fwd),
279 __ADD(XFRM_POLICY_MASK, mask),
282char* xfrmnl_sp_dir2str(
int dir,
char *buf,
size_t len)
284 return __type2str (dir, buf, len, sp_dir, ARRAY_SIZE(sp_dir));
287int xfrmnl_sp_str2dir(
const char *name)
289 return __str2type (name, sp_dir, ARRAY_SIZE(sp_dir));
292int xfrmnl_sp_index2dir (
unsigned int index)
302static const struct trans_tbl sp_share[] = {
303 __ADD(XFRM_SHARE_ANY, any),
304 __ADD(XFRM_SHARE_SESSION, session),
305 __ADD(XFRM_SHARE_USER, user),
306 __ADD(XFRM_SHARE_UNIQUE, unique),
309char* xfrmnl_sp_share2str(
int share,
char *buf,
size_t len)
311 return __type2str (share, buf, len, sp_share, ARRAY_SIZE(sp_share));
314int xfrmnl_sp_str2share(
const char *name)
316 return __str2type (name, sp_share, ARRAY_SIZE(sp_share));
320static void xfrm_sp_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
322 struct xfrmnl_sp* sp = (
struct xfrmnl_sp *) a;
323 char dir[32], action[32], share[32], flags[32];
324 char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
325 time_t add_time, use_time;
326 struct tm *add_time_tm, *use_time_tm;
328 nl_addr2str(xfrmnl_sel_get_saddr (sp->sel), src,
sizeof(src));
329 nl_addr2str (xfrmnl_sel_get_daddr (sp->sel), dst, sizeof (dst));
330 nl_af2str (xfrmnl_sel_get_family (sp->sel), dir, 32);
331 nl_dump_line(p,
"src %s dst %s family: %s\n", src, dst, dir);
332 nl_dump_line (p,
"src port/mask: %d/%d dst port/mask: %d/%d\n",
333 xfrmnl_sel_get_dport (sp->sel), xfrmnl_sel_get_dportmask (sp->sel),
334 xfrmnl_sel_get_sport (sp->sel), xfrmnl_sel_get_sportmask (sp->sel));
335 nl_dump_line (p,
"protocol: %s ifindex: %u uid: %u\n",
336 nl_ip_proto2str (xfrmnl_sel_get_proto (sp->sel), dir,
sizeof(dir)),
337 xfrmnl_sel_get_ifindex (sp->sel),
338 xfrmnl_sel_get_userid (sp->sel));
340 xfrmnl_sp_dir2str (sp->dir, dir, 32);
341 xfrmnl_sp_action2str (sp->action, action, 32);
342 xfrmnl_sp_share2str (sp->share, share, 32);
343 xfrmnl_sp_flags2str (sp->flags, flags, 32);
344 nl_dump_line(p,
"\tdir: %s action: %s index: %u priority: %u share: %s flags: %s(0x%x) \n",
345 dir, action, sp->index, sp->priority, share, flags, sp->flags);
347 nl_dump_line(p,
"\tlifetime configuration: \n");
348 if (sp->lft->soft_byte_limit == XFRM_INF)
349 sprintf (dir,
"INF");
351 sprintf (dir,
"%" PRIu64, sp->lft->soft_byte_limit);
352 if (sp->lft->soft_packet_limit == XFRM_INF)
353 sprintf (action,
"INF");
355 sprintf (action,
"%" PRIu64, sp->lft->soft_packet_limit);
356 if (sp->lft->hard_byte_limit == XFRM_INF)
357 sprintf (flags,
"INF");
359 sprintf (flags,
"%" PRIu64, sp->lft->hard_byte_limit);
360 if (sp->lft->hard_packet_limit == XFRM_INF)
361 sprintf (share,
"INF");
363 sprintf (share,
"%" PRIu64, sp->lft->hard_packet_limit);
364 nl_dump_line(p,
"\t\tsoft limit: %s (bytes), %s (packets) \n", dir,
366 nl_dump_line(p,
"\t\thard limit: %s (bytes), %s (packets) \n", flags,
370 "\t\tsoft add_time: %llu (seconds), soft use_time: %llu (seconds) \n",
371 (
long long unsigned)sp->lft->soft_add_expires_seconds,
372 (
long long unsigned)sp->lft->soft_use_expires_seconds);
375 "\t\thard add_time: %llu (seconds), hard use_time: %llu (seconds) \n",
376 (
long long unsigned)sp->lft->hard_add_expires_seconds,
377 (
long long unsigned)sp->lft->hard_use_expires_seconds);
379 nl_dump_line(p,
"\tlifetime current: \n");
380 nl_dump_line(p,
"\t\t%llu bytes, %llu packets\n",
381 (
long long unsigned)sp->curlft.bytes,
382 (
long long unsigned)sp->curlft.packets);
384 if (sp->curlft.add_time != 0)
386 add_time = sp->curlft.add_time;
387 add_time_tm = gmtime (&add_time);
388 strftime (dst, INET6_ADDRSTRLEN+5,
"%Y-%m-%d %H-%M-%S", add_time_tm);
392 sprintf (dst,
"%s",
"-");
395 if (sp->curlft.use_time != 0)
397 use_time = sp->curlft.use_time;
398 use_time_tm = gmtime (&use_time);
399 strftime (src, INET6_ADDRSTRLEN+5,
"%Y-%m-%d %H-%M-%S", use_time_tm);
403 sprintf (src,
"%s",
"-");
405 nl_dump_line(p,
"\t\tadd_time: %s, use_time: %s\n", dst, src);
407 if (sp->ce_mask & XFRM_SP_ATTR_SECCTX)
409 nl_dump_line(p,
"\tUser security context: \n");
410 nl_dump_line(p,
"\t\tlen: %d exttype: %d Algo: %d DOI: %d ctxlen: %d\n",
411 sp->sec_ctx->len, sp->sec_ctx->exttype,
412 sp->sec_ctx->ctx_alg, sp->sec_ctx->ctx_doi, sp->sec_ctx->ctx_len);
413 nl_dump_line (p,
"\t\tctx: %s \n", sp->sec_ctx->ctx);
416 xfrmnl_sp_type2str (sp->uptype.type, flags, 32);
417 if (sp->ce_mask & XFRM_SP_ATTR_POLTYPE)
418 nl_dump_line(p,
"\tUser policy type: %s\n", flags);
420 if (sp->ce_mask & XFRM_SP_ATTR_TMPL)
422 struct xfrmnl_user_tmpl* utmpl;
424 nl_dump_line(p,
"\tUser template: \n");
426 nl_list_for_each_entry(utmpl, &sp->usertmpl_list, utmpl_list)
427 xfrmnl_user_tmpl_dump (utmpl, p);
430 if (sp->ce_mask & XFRM_SP_ATTR_MARK)
431 nl_dump_line(p,
"\tMark mask: 0x%x Mark value: 0x%x\n", sp->mark.m, sp->mark.v);
436static void xfrm_sp_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
438 xfrm_sp_dump_line(a, p);
441static void xfrm_sp_dump_stats(
struct nl_object *a,
struct nl_dump_params *p)
443 xfrm_sp_dump_details(a, p);
453struct xfrmnl_sp* xfrmnl_sp_alloc(
void)
458void xfrmnl_sp_put(
struct xfrmnl_sp* sp)
480int xfrmnl_sp_alloc_cache(
struct nl_sock *sock,
struct nl_cache **result)
492struct xfrmnl_sp* xfrmnl_sp_get(
struct nl_cache* cache,
unsigned int index,
unsigned int dir)
494 struct xfrmnl_sp *sp;
501 if (sp->index == index && sp->dir == dir)
515static struct nla_policy xfrm_sp_policy[XFRMA_MAX+1] = {
516 [XFRMA_POLICY] = { .
minlen =
sizeof(
struct xfrm_userpolicy_info)},
517 [XFRMA_SEC_CTX] = { .minlen =
sizeof(
struct xfrm_sec_ctx) },
518 [XFRMA_TMPL] = { .minlen =
sizeof(
struct xfrm_user_tmpl) },
519 [XFRMA_POLICY_TYPE] = { .minlen =
sizeof(
struct xfrm_userpolicy_type)},
520 [XFRMA_MARK] = { .minlen =
sizeof(
struct xfrm_mark) },
523static int xfrm_sp_request_update(
struct nl_cache *c,
struct nl_sock *h)
525 return nl_send_simple (h, XFRM_MSG_GETPOLICY, NLM_F_DUMP, NULL, 0);
528int xfrmnl_sp_parse(
struct nlmsghdr *n,
struct xfrmnl_sp **result)
530 struct xfrmnl_sp *sp;
531 struct nlattr *tb[XFRMA_MAX + 1];
532 struct xfrm_userpolicy_info *sp_info;
534 struct nl_addr* addr;
536 sp = xfrmnl_sp_alloc();
542 sp->ce_msgtype = n->nlmsg_type;
543 if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
545 sp_info = (
struct xfrm_userpolicy_info*)((
char *)
nlmsg_data(n) +
sizeof (
struct xfrm_userpolicy_id) + NLA_HDRLEN);
552 err =
nlmsg_parse(n,
sizeof(
struct xfrm_userpolicy_info), tb, XFRMA_MAX, xfrm_sp_policy);
555 printf (
"parse error: %d \n", err);
559 if (sp_info->sel.family == AF_INET)
560 addr =
nl_addr_build (sp_info->sel.family, &sp_info->sel.daddr.a4, sizeof (sp_info->sel.daddr.a4));
562 addr =
nl_addr_build (sp_info->sel.family, &sp_info->sel.daddr.a6, sizeof (sp_info->sel.daddr.a6));
564 xfrmnl_sel_set_daddr (sp->sel, addr);
565 xfrmnl_sel_set_prefixlen_d (sp->sel, sp_info->sel.prefixlen_d);
567 if (sp_info->sel.family == AF_INET)
568 addr =
nl_addr_build (sp_info->sel.family, &sp_info->sel.saddr.a4, sizeof (sp_info->sel.saddr.a4));
570 addr =
nl_addr_build (sp_info->sel.family, &sp_info->sel.saddr.a6, sizeof (sp_info->sel.saddr.a6));
572 xfrmnl_sel_set_saddr (sp->sel, addr);
573 xfrmnl_sel_set_prefixlen_s (sp->sel, sp_info->sel.prefixlen_s);
575 xfrmnl_sel_set_dport (sp->sel, ntohs (sp_info->sel.dport));
576 xfrmnl_sel_set_dportmask (sp->sel, ntohs (sp_info->sel.dport_mask));
577 xfrmnl_sel_set_sport (sp->sel, ntohs (sp_info->sel.sport));
578 xfrmnl_sel_set_sportmask (sp->sel, ntohs (sp_info->sel.sport_mask));
579 xfrmnl_sel_set_family (sp->sel, sp_info->sel.family);
580 xfrmnl_sel_set_proto (sp->sel, sp_info->sel.proto);
581 xfrmnl_sel_set_ifindex (sp->sel, sp_info->sel.ifindex);
582 xfrmnl_sel_set_userid (sp->sel, sp_info->sel.user);
583 sp->ce_mask |= XFRM_SP_ATTR_SEL;
585 sp->lft->soft_byte_limit = sp_info->lft.soft_byte_limit;
586 sp->lft->hard_byte_limit = sp_info->lft.hard_byte_limit;
587 sp->lft->soft_packet_limit = sp_info->lft.soft_packet_limit;
588 sp->lft->hard_packet_limit = sp_info->lft.hard_packet_limit;
589 sp->lft->soft_add_expires_seconds = sp_info->lft.soft_add_expires_seconds;
590 sp->lft->hard_add_expires_seconds = sp_info->lft.hard_add_expires_seconds;
591 sp->lft->soft_use_expires_seconds = sp_info->lft.soft_use_expires_seconds;
592 sp->lft->hard_use_expires_seconds = sp_info->lft.hard_use_expires_seconds;
593 sp->ce_mask |= XFRM_SP_ATTR_LTIME_CFG;
595 sp->curlft.bytes = sp_info->curlft.bytes;
596 sp->curlft.packets = sp_info->curlft.packets;
597 sp->curlft.add_time = sp_info->curlft.add_time;
598 sp->curlft.use_time = sp_info->curlft.use_time;
599 sp->ce_mask |= XFRM_SP_ATTR_LTIME_CUR;
601 sp->priority = sp_info->priority;
602 sp->index = sp_info->index;
603 sp->dir = sp_info->dir;
604 sp->action = sp_info->action;
605 sp->flags = sp_info->flags;
606 sp->share = sp_info->share;
607 sp->ce_mask |= (XFRM_SP_ATTR_PRIO | XFRM_SP_ATTR_INDEX |
608 XFRM_SP_ATTR_DIR | XFRM_SP_ATTR_ACTION |
609 XFRM_SP_ATTR_FLAGS | XFRM_SP_ATTR_SHARE);
611 if (tb[XFRMA_SEC_CTX]) {
612 struct xfrm_user_sec_ctx* ctx =
nla_data(tb[XFRMA_SEC_CTX]);
613 len =
sizeof (
struct xfrmnl_user_sec_ctx) + ctx->ctx_len;
614 if ((sp->sec_ctx = calloc (1, len)) == NULL)
619 memcpy ((
void *)sp->sec_ctx, (
void *)ctx, len);
620 sp->ce_mask |= XFRM_SP_ATTR_SECCTX;
623 if (tb[XFRMA_POLICY_TYPE]) {
624 struct xfrm_userpolicy_type* up =
nla_data(tb[XFRMA_POLICY_TYPE]);
625 memcpy ((
void *)&sp->uptype, (
void *)up, sizeof (
struct xfrm_userpolicy_type));
626 sp->ce_mask |= XFRM_SP_ATTR_POLTYPE;
629 if (tb[XFRMA_TMPL]) {
630 struct xfrm_user_tmpl* tmpl =
nla_data(tb[XFRMA_TMPL]);
631 struct xfrmnl_user_tmpl* sputmpl;
633 uint32_t num_tmpls =
nla_len(tb[XFRMA_TMPL]) /
sizeof (*tmpl);
634 struct nl_addr* addr;
636 for (i = 0; (i < num_tmpls) && (tmpl); i ++, tmpl++)
644 if (tmpl->family == AF_INET)
645 addr =
nl_addr_build(tmpl->family, &tmpl->id.daddr.a4, sizeof (tmpl->id.daddr.a4));
647 addr =
nl_addr_build(tmpl->family, &tmpl->id.daddr.a6, sizeof (tmpl->id.daddr.a6));
648 xfrmnl_user_tmpl_set_daddr (sputmpl, addr);
649 xfrmnl_user_tmpl_set_spi (sputmpl, ntohl(tmpl->id.spi));
650 xfrmnl_user_tmpl_set_proto (sputmpl, tmpl->id.proto);
651 xfrmnl_user_tmpl_set_family (sputmpl, tmpl->family);
653 if (tmpl->family == AF_INET)
654 addr =
nl_addr_build(tmpl->family, &tmpl->saddr.a4, sizeof (tmpl->saddr.a4));
656 addr =
nl_addr_build(tmpl->family, &tmpl->saddr.a6, sizeof (tmpl->saddr.a6));
657 xfrmnl_user_tmpl_set_saddr (sputmpl, addr);
659 xfrmnl_user_tmpl_set_reqid (sputmpl, tmpl->reqid);
660 xfrmnl_user_tmpl_set_mode (sputmpl, tmpl->mode);
661 xfrmnl_user_tmpl_set_share (sputmpl, tmpl->share);
662 xfrmnl_user_tmpl_set_optional (sputmpl, tmpl->optional);
663 xfrmnl_user_tmpl_set_aalgos (sputmpl, tmpl->aalgos);
664 xfrmnl_user_tmpl_set_ealgos (sputmpl, tmpl->ealgos);
665 xfrmnl_user_tmpl_set_calgos (sputmpl, tmpl->calgos);
666 xfrmnl_sp_add_usertemplate (sp, sputmpl);
668 sp->ce_mask |= XFRM_SP_ATTR_TMPL;
672 if (tb[XFRMA_MARK]) {
673 struct xfrm_mark* m =
nla_data(tb[XFRMA_MARK]);
676 sp->ce_mask |= XFRM_SP_ATTR_MARK;
687static int xfrm_sp_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
688 struct nlmsghdr *n,
struct nl_parser_param *pp)
690 struct xfrmnl_sp* sp;
693 if ((err = xfrmnl_sp_parse(n, &sp)) < 0)
695 printf (
"received error: %d \n", err);
699 err = pp->pp_cb((
struct nl_object *) sp, pp);
710int xfrmnl_sp_build_get_request(
unsigned int index,
unsigned int dir,
unsigned int mark_v,
unsigned int mark_m,
struct nl_msg **result)
713 struct xfrm_userpolicy_id spid;
714 struct xfrm_mark mark;
716 memset(&spid, 0,
sizeof(spid));
723 if (
nlmsg_append(msg, &spid,
sizeof(spid), NLMSG_ALIGNTO) < 0)
724 goto nla_put_failure;
726 if ((mark_m & mark_v) != 0)
728 memset(&mark, 0,
sizeof(
struct xfrm_mark));
732 NLA_PUT (msg, XFRMA_MARK,
sizeof (
struct xfrm_mark), &mark);
743int xfrmnl_sp_get_kernel(
struct nl_sock* sock,
unsigned int index,
unsigned int dir,
unsigned int mark_v,
unsigned int mark_m,
struct xfrmnl_sp** result)
745 struct nl_msg *msg = NULL;
746 struct nl_object *obj;
749 if ((err = xfrmnl_sp_build_get_request(index, dir, mark_m, mark_v, &msg)) < 0)
757 if ((err =
nl_pickup(sock, &xfrm_sp_msg_parser, &obj)) < 0)
761 *result = (
struct xfrmnl_sp *) obj;
772static int build_xfrm_sp_message(
struct xfrmnl_sp *tmpl,
int cmd,
int flags,
struct nl_msg **result)
775 struct xfrm_userpolicy_info sp_info;
777 struct nl_addr* addr;
779 if (!(tmpl->ce_mask & XFRM_SP_ATTR_DIR) ||
780 (!(tmpl->ce_mask & XFRM_SP_ATTR_INDEX) &&
781 !(tmpl->ce_mask & XFRM_SP_ATTR_SEL)))
782 return -NLE_MISSING_ATTR;
784 memset ((
void*)&sp_info, 0,
sizeof (sp_info));
785 if (tmpl->ce_mask & XFRM_SP_ATTR_SEL)
787 addr = xfrmnl_sel_get_daddr (tmpl->sel);
789 addr = xfrmnl_sel_get_saddr (tmpl->sel);
791 sp_info.sel.dport = htons (xfrmnl_sel_get_dport (tmpl->sel));
792 sp_info.sel.dport_mask = htons (xfrmnl_sel_get_dportmask (tmpl->sel));
793 sp_info.sel.sport = htons (xfrmnl_sel_get_sport (tmpl->sel));
794 sp_info.sel.sport_mask = htons (xfrmnl_sel_get_sportmask (tmpl->sel));
795 sp_info.sel.family = xfrmnl_sel_get_family (tmpl->sel);
796 sp_info.sel.prefixlen_d = xfrmnl_sel_get_prefixlen_d (tmpl->sel);
797 sp_info.sel.prefixlen_s = xfrmnl_sel_get_prefixlen_s (tmpl->sel);
798 sp_info.sel.proto = xfrmnl_sel_get_proto (tmpl->sel);
799 sp_info.sel.ifindex = xfrmnl_sel_get_ifindex (tmpl->sel);
800 sp_info.sel.user = xfrmnl_sel_get_userid (tmpl->sel);
803 if (tmpl->ce_mask & XFRM_SP_ATTR_LTIME_CFG)
805 sp_info.lft.soft_byte_limit = xfrmnl_ltime_cfg_get_soft_bytelimit (tmpl->lft);
806 sp_info.lft.hard_byte_limit = xfrmnl_ltime_cfg_get_hard_bytelimit (tmpl->lft);
807 sp_info.lft.soft_packet_limit = xfrmnl_ltime_cfg_get_soft_packetlimit (tmpl->lft);
808 sp_info.lft.hard_packet_limit = xfrmnl_ltime_cfg_get_hard_packetlimit (tmpl->lft);
809 sp_info.lft.soft_add_expires_seconds = xfrmnl_ltime_cfg_get_soft_addexpires (tmpl->lft);
810 sp_info.lft.hard_add_expires_seconds = xfrmnl_ltime_cfg_get_hard_addexpires (tmpl->lft);
811 sp_info.lft.soft_use_expires_seconds = xfrmnl_ltime_cfg_get_soft_useexpires (tmpl->lft);
812 sp_info.lft.hard_use_expires_seconds = xfrmnl_ltime_cfg_get_hard_useexpires (tmpl->lft);
817 if (tmpl->ce_mask & XFRM_SP_ATTR_PRIO)
818 sp_info.priority = tmpl->priority;
820 if (tmpl->ce_mask & XFRM_SP_ATTR_INDEX)
821 sp_info.index = tmpl->index;
823 if (tmpl->ce_mask & XFRM_SP_ATTR_DIR)
824 sp_info.dir = tmpl->dir;
826 if (tmpl->ce_mask & XFRM_SP_ATTR_ACTION)
827 sp_info.action = tmpl->action;
829 if (tmpl->ce_mask & XFRM_SP_ATTR_FLAGS)
830 sp_info.flags = tmpl->flags;
832 if (tmpl->ce_mask & XFRM_SP_ATTR_SHARE)
833 sp_info.share = tmpl->share;
839 if (
nlmsg_append(msg, &sp_info,
sizeof(sp_info), NLMSG_ALIGNTO) < 0)
840 goto nla_put_failure;
842 if (tmpl->ce_mask & XFRM_SP_ATTR_SECCTX) {
843 len = (
sizeof (
struct xfrm_user_sec_ctx)) + tmpl->sec_ctx->ctx_len;
844 NLA_PUT (msg, XFRMA_SEC_CTX, len, tmpl->sec_ctx);
847 if (tmpl->ce_mask & XFRM_SP_ATTR_POLTYPE) {
848 len =
sizeof (
struct xfrm_userpolicy_type);
849 NLA_PUT (msg, XFRMA_POLICY_TYPE, len, &tmpl->uptype);
852 if (tmpl->ce_mask & XFRM_SP_ATTR_TMPL) {
853 struct nlattr* tmpls;
854 struct xfrmnl_user_tmpl* utmpl;
855 struct nl_addr* addr;
858 goto nla_put_failure;
860 nl_list_for_each_entry(utmpl, &tmpl->usertmpl_list, utmpl_list) {
861 struct xfrm_user_tmpl* tmpl;
865 goto nla_put_failure;
866 addr = xfrmnl_user_tmpl_get_daddr (utmpl);
869 tmpl->id.spi = htonl(xfrmnl_user_tmpl_get_spi (utmpl));
870 tmpl->id.proto = xfrmnl_user_tmpl_get_proto (utmpl);
871 tmpl->family = xfrmnl_user_tmpl_get_family (utmpl);
872 addr = xfrmnl_user_tmpl_get_saddr (utmpl);
875 tmpl->reqid = xfrmnl_user_tmpl_get_reqid (utmpl);
876 tmpl->mode = xfrmnl_user_tmpl_get_mode (utmpl);
877 tmpl->share = xfrmnl_user_tmpl_get_share (utmpl);
878 tmpl->optional = xfrmnl_user_tmpl_get_optional (utmpl);
879 tmpl->aalgos = xfrmnl_user_tmpl_get_aalgos (utmpl);
880 tmpl->ealgos = xfrmnl_user_tmpl_get_ealgos (utmpl);
881 tmpl->calgos = xfrmnl_user_tmpl_get_calgos (utmpl);
886 if (tmpl->ce_mask & XFRM_SP_ATTR_MARK) {
887 NLA_PUT (msg, XFRMA_MARK,
sizeof (
struct xfrm_mark), &tmpl->mark);
903int xfrmnl_sp_build_add_request(
struct xfrmnl_sp* tmpl,
int flags,
struct nl_msg **result)
905 return build_xfrm_sp_message (tmpl, XFRM_MSG_NEWPOLICY, flags, result);
908int xfrmnl_sp_add(
struct nl_sock* sk,
struct xfrmnl_sp* tmpl,
int flags)
913 if ((err = xfrmnl_sp_build_add_request(tmpl, flags, &msg)) < 0)
929int xfrmnl_sp_build_update_request(
struct xfrmnl_sp* tmpl,
int flags,
struct nl_msg **result)
931 return build_xfrm_sp_message (tmpl, XFRM_MSG_UPDPOLICY, flags, result);
934int xfrmnl_sp_update(
struct nl_sock* sk,
struct xfrmnl_sp* tmpl,
int flags)
939 if ((err = xfrmnl_sp_build_update_request(tmpl, flags, &msg)) < 0)
965static int build_xfrm_sp_delete_message(
struct xfrmnl_sp *tmpl,
int cmd,
int flags,
struct nl_msg **result)
968 struct xfrm_userpolicy_id spid;
969 struct nl_addr* addr;
972 if (!(tmpl->ce_mask & XFRM_SP_ATTR_DIR) ||
973 (!(tmpl->ce_mask & XFRM_SP_ATTR_INDEX) &&
974 !(tmpl->ce_mask & XFRM_SP_ATTR_SEL)))
975 return -NLE_MISSING_ATTR;
977 memset(&spid, 0,
sizeof(spid));
978 spid.dir = tmpl->dir;
979 if(tmpl->ce_mask & XFRM_SP_ATTR_INDEX)
980 spid.index = tmpl->index;
982 if (tmpl->ce_mask & XFRM_SP_ATTR_SEL)
984 addr = xfrmnl_sel_get_daddr (tmpl->sel);
986 addr = xfrmnl_sel_get_saddr (tmpl->sel);
988 spid.sel.dport = htons (xfrmnl_sel_get_dport (tmpl->sel));
989 spid.sel.dport_mask = htons (xfrmnl_sel_get_dportmask (tmpl->sel));
990 spid.sel.sport = htons (xfrmnl_sel_get_sport (tmpl->sel));
991 spid.sel.sport_mask = htons (xfrmnl_sel_get_sportmask (tmpl->sel));
992 spid.sel.family = xfrmnl_sel_get_family (tmpl->sel);
993 spid.sel.prefixlen_d = xfrmnl_sel_get_prefixlen_d (tmpl->sel);
994 spid.sel.prefixlen_s = xfrmnl_sel_get_prefixlen_s (tmpl->sel);
995 spid.sel.proto = xfrmnl_sel_get_proto (tmpl->sel);
996 spid.sel.ifindex = xfrmnl_sel_get_ifindex (tmpl->sel);
997 spid.sel.user = xfrmnl_sel_get_userid (tmpl->sel);
1004 if (
nlmsg_append(msg, &spid,
sizeof(spid), NLMSG_ALIGNTO) < 0)
1005 goto nla_put_failure;
1007 if (tmpl->ce_mask & XFRM_SP_ATTR_SECCTX) {
1008 len = (
sizeof (
struct xfrm_user_sec_ctx)) + tmpl->sec_ctx->ctx_len;
1009 NLA_PUT (msg, XFRMA_SEC_CTX, len, tmpl->sec_ctx);
1012 if (tmpl->ce_mask & XFRM_SP_ATTR_MARK) {
1013 len =
sizeof (
struct xfrm_mark);
1014 NLA_PUT (msg, XFRMA_MARK, len, &tmpl->mark);
1022 return -NLE_MSGSIZE;
1030int xfrmnl_sp_build_delete_request(
struct xfrmnl_sp* tmpl,
int flags,
struct nl_msg **result)
1032 return build_xfrm_sp_delete_message (tmpl, XFRM_MSG_DELPOLICY, flags, result);
1035int xfrmnl_sp_delete(
struct nl_sock* sk,
struct xfrmnl_sp* tmpl,
int flags)
1040 if ((err = xfrmnl_sp_build_delete_request(tmpl, flags, &msg)) < 0)
1059struct xfrmnl_sel* xfrmnl_sp_get_sel (
struct xfrmnl_sp* sp)
1061 if (sp->ce_mask & XFRM_SP_ATTR_SEL)
1067int xfrmnl_sp_set_sel (
struct xfrmnl_sp* sp,
struct xfrmnl_sel* sel)
1071 xfrmnl_sel_put (sp->sel);
1074 xfrmnl_sel_get (sel);
1076 sp->ce_mask |= XFRM_SP_ATTR_SEL;
1081struct xfrmnl_ltime_cfg* xfrmnl_sp_get_lifetime_cfg (
struct xfrmnl_sp* sp)
1083 if (sp->ce_mask & XFRM_SP_ATTR_LTIME_CFG)
1089int xfrmnl_sp_set_lifetime_cfg (
struct xfrmnl_sp* sp,
struct xfrmnl_ltime_cfg* ltime)
1093 xfrmnl_ltime_cfg_put (sp->lft);
1096 xfrmnl_ltime_cfg_get (ltime);
1098 sp->ce_mask |= XFRM_SP_ATTR_LTIME_CFG;
1103int xfrmnl_sp_get_curlifetime (
struct xfrmnl_sp* sp,
unsigned long long int* curr_bytes,
1104 unsigned long long int* curr_packets,
unsigned long long int* curr_add_time,
unsigned long long int* curr_use_time)
1106 if (sp == NULL || curr_bytes == NULL || curr_packets == NULL || curr_add_time == NULL || curr_use_time == NULL)
1109 *curr_bytes = sp->curlft.bytes;
1110 *curr_packets = sp->curlft.packets;
1111 *curr_add_time = sp->curlft.add_time;
1112 *curr_use_time = sp->curlft.use_time;
1117int xfrmnl_sp_get_priority (
struct xfrmnl_sp* sp)
1119 if (sp->ce_mask & XFRM_SP_ATTR_PRIO)
1120 return sp->priority;
1125int xfrmnl_sp_set_priority (
struct xfrmnl_sp* sp,
unsigned int prio)
1127 sp->priority = prio;
1128 sp->ce_mask |= XFRM_SP_ATTR_PRIO;
1133int xfrmnl_sp_get_index (
struct xfrmnl_sp* sp)
1135 if (sp->ce_mask & XFRM_SP_ATTR_INDEX)
1141int xfrmnl_sp_set_index (
struct xfrmnl_sp* sp,
unsigned int index)
1144 sp->ce_mask |= XFRM_SP_ATTR_INDEX;
1149int xfrmnl_sp_get_dir (
struct xfrmnl_sp* sp)
1151 if (sp->ce_mask & XFRM_SP_ATTR_DIR)
1157int xfrmnl_sp_set_dir (
struct xfrmnl_sp* sp,
unsigned int dir)
1160 sp->ce_mask |= XFRM_SP_ATTR_DIR;
1165int xfrmnl_sp_get_action (
struct xfrmnl_sp* sp)
1167 if (sp->ce_mask & XFRM_SP_ATTR_ACTION)
1173int xfrmnl_sp_set_action (
struct xfrmnl_sp* sp,
unsigned int action)
1175 sp->action = action;
1176 sp->ce_mask |= XFRM_SP_ATTR_ACTION;
1181int xfrmnl_sp_get_flags (
struct xfrmnl_sp* sp)
1183 if (sp->ce_mask & XFRM_SP_ATTR_FLAGS)
1189int xfrmnl_sp_set_flags (
struct xfrmnl_sp* sp,
unsigned int flags)
1192 sp->ce_mask |= XFRM_SP_ATTR_FLAGS;
1197int xfrmnl_sp_get_share (
struct xfrmnl_sp* sp)
1199 if (sp->ce_mask & XFRM_SP_ATTR_SHARE)
1205int xfrmnl_sp_set_share (
struct xfrmnl_sp* sp,
unsigned int share)
1208 sp->ce_mask |= XFRM_SP_ATTR_SHARE;
1234int xfrmnl_sp_get_sec_ctx (
struct xfrmnl_sp* sp,
unsigned int* len,
unsigned int* exttype,
unsigned int* alg,
unsigned int* doi,
unsigned int* ctx_len,
char* ctx_str)
1236 if (sp->ce_mask & XFRM_SP_ATTR_SECCTX)
1239 *len =
sizeof (
struct xfrmnl_user_sec_ctx) + sp->sec_ctx->ctx_len;
1241 *exttype = sp->sec_ctx->exttype;
1243 *alg = sp->sec_ctx->ctx_alg;
1245 *doi = sp->sec_ctx->ctx_doi;
1247 *ctx_len = sp->sec_ctx->ctx_len;
1249 memcpy ((
void *)ctx_str, (
void *)sp->sec_ctx->ctx, sp->sec_ctx->ctx_len);
1269int xfrmnl_sp_set_sec_ctx (
struct xfrmnl_sp* sp,
unsigned int len __attribute__((unused)),
unsigned int exttype,
unsigned int alg,
unsigned int doi,
unsigned int ctx_len,
char* ctx_str)
1274 if ((sp->sec_ctx = calloc (1,
sizeof (
struct xfrmnl_user_sec_ctx) + 1 + ctx_len)) == NULL)
1278 sp->sec_ctx->len =
sizeof (
struct xfrmnl_user_sec_ctx) + ctx_len;
1279 sp->sec_ctx->exttype = exttype;
1280 sp->sec_ctx->ctx_alg = alg;
1281 sp->sec_ctx->ctx_doi = doi;
1282 sp->sec_ctx->ctx_len = ctx_len;
1283 memcpy ((
void *)sp->sec_ctx->ctx, (
void *)ctx_str, ctx_len);
1284 sp->sec_ctx->ctx[ctx_len] =
'\0';
1286 sp->ce_mask |= XFRM_SP_ATTR_SECCTX;
1291int xfrmnl_sp_get_userpolicy_type (
struct xfrmnl_sp* sp)
1293 if (sp->ce_mask & XFRM_SP_ATTR_POLTYPE)
1294 return sp->uptype.type;
1299int xfrmnl_sp_set_userpolicy_type (
struct xfrmnl_sp* sp,
unsigned int type)
1301 sp->uptype.type = type;
1302 sp->ce_mask |= XFRM_SP_ATTR_POLTYPE;
1307void xfrmnl_sp_add_usertemplate(
struct xfrmnl_sp *sp,
struct xfrmnl_user_tmpl *utmpl)
1309 nl_list_add_tail(&utmpl->utmpl_list, &sp->usertmpl_list);
1311 sp->ce_mask |= XFRM_SP_ATTR_TMPL;
1314void xfrmnl_sp_remove_usertemplate(
struct xfrmnl_sp *sp,
struct xfrmnl_user_tmpl *utmpl)
1316 if (sp->ce_mask & XFRM_SP_ATTR_TMPL) {
1318 nl_list_del(&utmpl->utmpl_list);
1322struct nl_list_head *xfrmnl_sp_get_usertemplates(
struct xfrmnl_sp *sp)
1324 if (sp->ce_mask & XFRM_SP_ATTR_TMPL)
1325 return &sp->usertmpl_list;
1330int xfrmnl_sp_get_nusertemplates(
struct xfrmnl_sp *sp)
1332 if (sp->ce_mask & XFRM_SP_ATTR_TMPL)
1333 return sp->nr_user_tmpl;
1338void xfrmnl_sp_foreach_usertemplate(
struct xfrmnl_sp *r,
1339 void (*cb)(
struct xfrmnl_user_tmpl *,
void *),
1342 struct xfrmnl_user_tmpl *utmpl;
1344 if (r->ce_mask & XFRM_SP_ATTR_TMPL) {
1345 nl_list_for_each_entry(utmpl, &r->usertmpl_list, utmpl_list) {
1351struct xfrmnl_user_tmpl *xfrmnl_sp_usertemplate_n(
struct xfrmnl_sp *r,
int n)
1353 struct xfrmnl_user_tmpl *utmpl;
1356 if (r->ce_mask & XFRM_SP_ATTR_TMPL && r->nr_user_tmpl > n) {
1358 nl_list_for_each_entry(utmpl, &r->usertmpl_list, utmpl_list) {
1359 if (i == n)
return utmpl;
1366int xfrmnl_sp_get_mark (
struct xfrmnl_sp* sp,
unsigned int* mark_mask,
unsigned int* mark_value)
1368 if (mark_mask == NULL || mark_value == NULL)
1371 if (sp->ce_mask & XFRM_SP_ATTR_MARK)
1373 *mark_mask = sp->mark.m;
1374 *mark_value = sp->mark.v;
1382int xfrmnl_sp_set_mark (
struct xfrmnl_sp* sp,
unsigned int value,
unsigned int mask)
1386 sp->ce_mask |= XFRM_SP_ATTR_MARK;
1393static struct nl_object_ops xfrm_sp_obj_ops = {
1394 .oo_name =
"xfrm/sp",
1395 .oo_size =
sizeof(
struct xfrmnl_sp),
1396 .oo_constructor = xfrm_sp_alloc_data,
1397 .oo_free_data = xfrm_sp_free_data,
1398 .oo_clone = xfrm_sp_clone,
1404 .oo_compare = xfrm_sp_compare,
1405 .oo_attrs2str = xfrm_sp_attrs2str,
1406 .oo_id_attrs = (XFRM_SP_ATTR_SEL | XFRM_SP_ATTR_INDEX | XFRM_SP_ATTR_DIR),
1409static struct nl_af_group xfrm_sp_groups[] = {
1410 { AF_UNSPEC, XFRMNLGRP_POLICY },
1411 { END_OF_GROUP_LIST },
1414static struct nl_cache_ops xfrmnl_sp_ops = {
1415 .co_name =
"xfrm/sp",
1416 .co_hdrsize =
sizeof(
struct xfrm_userpolicy_info),
1418 { XFRM_MSG_NEWPOLICY, NL_ACT_NEW,
"new" },
1419 { XFRM_MSG_DELPOLICY, NL_ACT_DEL,
"del" },
1420 { XFRM_MSG_GETPOLICY, NL_ACT_GET,
"get" },
1421 { XFRM_MSG_UPDPOLICY, NL_ACT_NEW,
"update" },
1422 END_OF_MSGTYPES_LIST,
1424 .co_protocol = NETLINK_XFRM,
1425 .co_groups = xfrm_sp_groups,
1426 .co_request_update = xfrm_sp_request_update,
1427 .co_msg_parser = xfrm_sp_msg_parser,
1428 .co_obj_ops = &xfrm_sp_obj_ops,
1436static void __attribute__ ((constructor)) xfrm_sp_init(
void)
1441static void __attribute__ ((destructor)) xfrm_sp_exit(
void)
struct xfrmnl_user_tmpl * xfrmnl_user_tmpl_clone(struct xfrmnl_user_tmpl *utmpl)
Clone existing user template object.
int xfrmnl_sel_cmp(struct xfrmnl_sel *a, struct xfrmnl_sel *b)
Compares two selector objects.
struct xfrmnl_ltime_cfg * xfrmnl_ltime_cfg_alloc()
Allocate new lifetime config object.
int xfrmnl_ltime_cfg_cmp(struct xfrmnl_ltime_cfg *a, struct xfrmnl_ltime_cfg *b)
Compares two lifetime config objects.
struct xfrmnl_ltime_cfg * xfrmnl_ltime_cfg_clone(struct xfrmnl_ltime_cfg *ltime)
Clone existing lifetime config object.
struct xfrmnl_sel * xfrmnl_sel_alloc()
Allocate new selector object.
int xfrmnl_user_tmpl_cmp(struct xfrmnl_user_tmpl *a, struct xfrmnl_user_tmpl *b)
Compares two user template objects.
struct xfrmnl_sel * xfrmnl_sel_clone(struct xfrmnl_sel *sel)
Clone existing selector object.
struct xfrmnl_user_tmpl * xfrmnl_user_tmpl_alloc()
Allocate new user template object.
void nl_addr_set_prefixlen(struct nl_addr *addr, int prefixlen)
Set the prefix length 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.
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
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 * 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.
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
int nla_len(const struct nlattr *nla)
Return length of the payload .
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
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_object * nl_cache_get_next(struct nl_object *obj)
Return the next element in the 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 nl_object * nl_cache_get_first(struct nl_cache *cache)
Return the first element in the cache.
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_reserve(struct nl_msg *n, size_t len, int pad)
Reserve room for additional data in a netlink message.
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 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_pickup(struct nl_sock *sk, int(*parser)(struct nl_cache_ops *, struct sockaddr_nl *, struct nlmsghdr *, struct nl_parser_param *), struct nl_object **result)
Pickup netlink answer, parse is and return object.
int nl_wait_for_ack(struct nl_sock *sk)
Wait for ACK.
int nl_send_simple(struct nl_sock *sk, int type, int flags, void *buf, size_t size)
Construct and transmit a Netlink message.
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.