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/sa.h>
47#include <netlink/xfrm/selector.h>
48#include <netlink/xfrm/lifetime.h>
51#include "netlink-private/utils.h"
54#define XFRM_SA_ATTR_SEL 0x01
55#define XFRM_SA_ATTR_DADDR 0x02
56#define XFRM_SA_ATTR_SPI 0x04
57#define XFRM_SA_ATTR_PROTO 0x08
58#define XFRM_SA_ATTR_SADDR 0x10
59#define XFRM_SA_ATTR_LTIME_CFG 0x20
60#define XFRM_SA_ATTR_LTIME_CUR 0x40
61#define XFRM_SA_ATTR_STATS 0x80
62#define XFRM_SA_ATTR_SEQ 0x100
63#define XFRM_SA_ATTR_REQID 0x200
64#define XFRM_SA_ATTR_FAMILY 0x400
65#define XFRM_SA_ATTR_MODE 0x800
66#define XFRM_SA_ATTR_REPLAY_WIN 0x1000
67#define XFRM_SA_ATTR_FLAGS 0x2000
68#define XFRM_SA_ATTR_ALG_AEAD 0x4000
69#define XFRM_SA_ATTR_ALG_AUTH 0x8000
70#define XFRM_SA_ATTR_ALG_CRYPT 0x10000
71#define XFRM_SA_ATTR_ALG_COMP 0x20000
72#define XFRM_SA_ATTR_ENCAP 0x40000
73#define XFRM_SA_ATTR_TFCPAD 0x80000
74#define XFRM_SA_ATTR_COADDR 0x100000
75#define XFRM_SA_ATTR_MARK 0x200000
76#define XFRM_SA_ATTR_SECCTX 0x400000
77#define XFRM_SA_ATTR_REPLAY_MAXAGE 0x800000
78#define XFRM_SA_ATTR_REPLAY_MAXDIFF 0x1000000
79#define XFRM_SA_ATTR_REPLAY_STATE 0x2000000
80#define XFRM_SA_ATTR_EXPIRE 0x4000000
81#define XFRM_SA_ATTR_OFFLOAD_DEV 0x8000000
83static struct nl_cache_ops xfrmnl_sa_ops;
84static struct nl_object_ops xfrm_sa_obj_ops;
87static void xfrm_sa_alloc_data(
struct nl_object *c)
89 struct xfrmnl_sa* sa = nl_object_priv (c);
98static void xfrm_sa_free_data(
struct nl_object *c)
100 struct xfrmnl_sa* sa = nl_object_priv (c);
105 xfrmnl_sel_put (sa->sel);
106 xfrmnl_ltime_cfg_put (sa->lft);
119 if (sa->encap->encap_oa)
127 if (sa->replay_state_esn)
128 free (sa->replay_state_esn);
129 if (sa->user_offload)
130 free(sa->user_offload);
133static int xfrm_sa_clone(
struct nl_object *_dst,
struct nl_object *_src)
135 struct xfrmnl_sa* dst = nl_object_priv(_dst);
136 struct xfrmnl_sa* src = nl_object_priv(_src);
140 dst->id.daddr = NULL;
150 dst->replay_state_esn = NULL;
151 dst->user_offload = NULL;
170 len =
sizeof (
struct xfrmnl_algo_aead) + ((src->aead->alg_key_len + 7) / 8);
171 if ((dst->aead = calloc (1, len)) == NULL)
173 memcpy ((
void *)dst->aead, (
void *)src->aead, len);
177 len =
sizeof (
struct xfrmnl_algo_auth) + ((src->auth->alg_key_len + 7) / 8);
178 if ((dst->auth = calloc (1, len)) == NULL)
180 memcpy ((
void *)dst->auth, (
void *)src->auth, len);
184 len =
sizeof (
struct xfrmnl_algo) + ((src->crypt->alg_key_len + 7) / 8);
185 if ((dst->crypt = calloc (1, len)) == NULL)
187 memcpy ((
void *)dst->crypt, (
void *)src->crypt, len);
191 len =
sizeof (
struct xfrmnl_algo) + ((src->comp->alg_key_len + 7) / 8);
192 if ((dst->comp = calloc (1, len)) == NULL)
194 memcpy ((
void *)dst->comp, (
void *)src->comp, len);
198 len =
sizeof (
struct xfrmnl_encap_tmpl);
199 if ((dst->encap = calloc (1, len)) == NULL)
201 memcpy ((
void *)dst->encap, (
void *)src->encap, len);
209 len =
sizeof (*src->sec_ctx) + src->sec_ctx->ctx_len;
210 if ((dst->sec_ctx = calloc (1, len)) == NULL)
212 memcpy ((
void *)dst->sec_ctx, (
void *)src->sec_ctx, len);
215 if (src->replay_state_esn) {
216 len =
sizeof (
struct xfrmnl_replay_state_esn) + (src->replay_state_esn->bmp_len *
sizeof (uint32_t));
217 if ((dst->replay_state_esn = calloc (1, len)) == NULL)
219 memcpy ((
void *)dst->replay_state_esn, (
void *)src->replay_state_esn, len);
222 if (src->user_offload) {
223 dst->user_offload = _nl_memdup_ptr(src->user_offload);
224 if (!dst->user_offload)
231static uint64_t xfrm_sa_compare(
struct nl_object *_a,
struct nl_object *_b,
232 uint64_t attrs,
int flags)
234 struct xfrmnl_sa* a = (
struct xfrmnl_sa *) _a;
235 struct xfrmnl_sa* b = (
struct xfrmnl_sa *) _b;
239#define XFRM_SA_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, XFRM_SA_ATTR_##ATTR, a, b, EXPR)
241 diff |= XFRM_SA_DIFF(DADDR,
nl_addr_cmp(a->id.daddr, b->id.daddr));
242 diff |= XFRM_SA_DIFF(SPI, a->id.spi != b->id.spi);
243 diff |= XFRM_SA_DIFF(PROTO, a->id.proto != b->id.proto);
244 diff |= XFRM_SA_DIFF(SADDR,
nl_addr_cmp(a->saddr, b->saddr));
246 diff |= XFRM_SA_DIFF(REQID, a->reqid != b->reqid);
247 diff |= XFRM_SA_DIFF(FAMILY,a->family != b->family);
248 diff |= XFRM_SA_DIFF(MODE,a->mode != b->mode);
249 diff |= XFRM_SA_DIFF(REPLAY_WIN,a->replay_window != b->replay_window);
250 diff |= XFRM_SA_DIFF(FLAGS,a->flags != b->flags);
251 diff |= XFRM_SA_DIFF(ALG_AEAD,(strcmp(a->aead->alg_name, b->aead->alg_name) ||
252 (a->aead->alg_key_len != b->aead->alg_key_len) ||
253 (a->aead->alg_icv_len != b->aead->alg_icv_len) ||
254 memcmp(a->aead->alg_key, b->aead->alg_key,
255 ((a->aead->alg_key_len + 7)/8))));
256 diff |= XFRM_SA_DIFF(ALG_AUTH,(strcmp(a->auth->alg_name, b->auth->alg_name) ||
257 (a->auth->alg_key_len != b->auth->alg_key_len) ||
258 (a->auth->alg_trunc_len != b->auth->alg_trunc_len) ||
259 memcmp(a->auth->alg_key, b->auth->alg_key,
260 ((a->auth->alg_key_len + 7)/8))));
261 diff |= XFRM_SA_DIFF(ALG_CRYPT,(strcmp(a->crypt->alg_name, b->crypt->alg_name) ||
262 (a->crypt->alg_key_len != b->crypt->alg_key_len) ||
263 memcmp(a->crypt->alg_key, b->crypt->alg_key,
264 ((a->crypt->alg_key_len + 7)/8))));
265 diff |= XFRM_SA_DIFF(ALG_COMP,(strcmp(a->comp->alg_name, b->comp->alg_name) ||
266 (a->comp->alg_key_len != b->comp->alg_key_len) ||
267 memcmp(a->comp->alg_key, b->comp->alg_key,
268 ((a->comp->alg_key_len + 7)/8))));
269 diff |= XFRM_SA_DIFF(ENCAP,((a->encap->encap_type != b->encap->encap_type) ||
270 (a->encap->encap_sport != b->encap->encap_sport) ||
271 (a->encap->encap_dport != b->encap->encap_dport) ||
272 nl_addr_cmp(a->encap->encap_oa, b->encap->encap_oa)));
273 diff |= XFRM_SA_DIFF(TFCPAD,a->tfcpad != b->tfcpad);
274 diff |= XFRM_SA_DIFF(COADDR,
nl_addr_cmp(a->coaddr, b->coaddr));
275 diff |= XFRM_SA_DIFF(MARK,(a->mark.m != b->mark.m) ||
276 (a->mark.v != b->mark.v));
277 diff |= XFRM_SA_DIFF(SECCTX,((a->sec_ctx->ctx_doi != b->sec_ctx->ctx_doi) ||
278 (a->sec_ctx->ctx_alg != b->sec_ctx->ctx_alg) ||
279 (a->sec_ctx->ctx_len != b->sec_ctx->ctx_len) ||
280 strcmp(a->sec_ctx->ctx, b->sec_ctx->ctx)));
281 diff |= XFRM_SA_DIFF(REPLAY_MAXAGE,a->replay_maxage != b->replay_maxage);
282 diff |= XFRM_SA_DIFF(REPLAY_MAXDIFF,a->replay_maxdiff != b->replay_maxdiff);
283 diff |= XFRM_SA_DIFF(EXPIRE,a->hard != b->hard);
286 found = AVAILABLE_MISMATCH (a, b, XFRM_SA_ATTR_REPLAY_STATE);
289 if (((a->replay_state_esn != NULL) && (b->replay_state_esn == NULL)) ||
290 ((a->replay_state_esn == NULL) && (b->replay_state_esn != NULL)))
295 if (a->replay_state_esn)
297 if (a->replay_state_esn->bmp_len != b->replay_state_esn->bmp_len)
301 uint32_t len =
sizeof (
struct xfrmnl_replay_state_esn) +
302 (a->replay_state_esn->bmp_len *
sizeof (uint32_t));
303 diff |= memcmp (a->replay_state_esn, b->replay_state_esn, len);
308 if ((a->replay_state.oseq != b->replay_state.oseq) ||
309 (a->replay_state.seq != b->replay_state.seq) ||
310 (a->replay_state.bitmap != b->replay_state.bitmap))
324static const struct trans_tbl sa_attrs[] = {
325 __ADD(XFRM_SA_ATTR_SEL, selector),
326 __ADD(XFRM_SA_ATTR_DADDR, daddr),
327 __ADD(XFRM_SA_ATTR_SPI, spi),
328 __ADD(XFRM_SA_ATTR_PROTO, proto),
329 __ADD(XFRM_SA_ATTR_SADDR, saddr),
330 __ADD(XFRM_SA_ATTR_LTIME_CFG, lifetime_cfg),
331 __ADD(XFRM_SA_ATTR_LTIME_CUR, lifetime_cur),
332 __ADD(XFRM_SA_ATTR_STATS, stats),
333 __ADD(XFRM_SA_ATTR_SEQ, seqnum),
334 __ADD(XFRM_SA_ATTR_REQID, reqid),
335 __ADD(XFRM_SA_ATTR_FAMILY, family),
336 __ADD(XFRM_SA_ATTR_MODE, mode),
337 __ADD(XFRM_SA_ATTR_REPLAY_WIN, replay_window),
338 __ADD(XFRM_SA_ATTR_FLAGS, flags),
339 __ADD(XFRM_SA_ATTR_ALG_AEAD, alg_aead),
340 __ADD(XFRM_SA_ATTR_ALG_AUTH, alg_auth),
341 __ADD(XFRM_SA_ATTR_ALG_CRYPT, alg_crypto),
342 __ADD(XFRM_SA_ATTR_ALG_COMP, alg_comp),
343 __ADD(XFRM_SA_ATTR_ENCAP, encap),
344 __ADD(XFRM_SA_ATTR_TFCPAD, tfcpad),
345 __ADD(XFRM_SA_ATTR_COADDR, coaddr),
346 __ADD(XFRM_SA_ATTR_MARK, mark),
347 __ADD(XFRM_SA_ATTR_SECCTX, sec_ctx),
348 __ADD(XFRM_SA_ATTR_REPLAY_MAXAGE, replay_maxage),
349 __ADD(XFRM_SA_ATTR_REPLAY_MAXDIFF, replay_maxdiff),
350 __ADD(XFRM_SA_ATTR_REPLAY_STATE, replay_state),
351 __ADD(XFRM_SA_ATTR_EXPIRE, expire),
352 __ADD(XFRM_SA_ATTR_OFFLOAD_DEV, user_offload),
355static char* xfrm_sa_attrs2str(
int attrs,
char *buf,
size_t len)
357 return __flags2str (attrs, buf, len, sa_attrs, ARRAY_SIZE(sa_attrs));
365static const struct trans_tbl sa_flags[] = {
366 __ADD(XFRM_STATE_NOECN, no ecn),
367 __ADD(XFRM_STATE_DECAP_DSCP, decap dscp),
368 __ADD(XFRM_STATE_NOPMTUDISC, no pmtu discovery),
369 __ADD(XFRM_STATE_WILDRECV, wild receive),
370 __ADD(XFRM_STATE_ICMP, icmp),
371 __ADD(XFRM_STATE_AF_UNSPEC, unspecified),
372 __ADD(XFRM_STATE_ALIGN4, align4),
373 __ADD(XFRM_STATE_ESN, esn),
376char* xfrmnl_sa_flags2str(
int flags,
char *buf,
size_t len)
378 return __flags2str (flags, buf, len, sa_flags, ARRAY_SIZE(sa_flags));
381int xfrmnl_sa_str2flag(
const char *name)
383 return __str2flags (name, sa_flags, ARRAY_SIZE(sa_flags));
391static const struct trans_tbl sa_modes[] = {
392 __ADD(XFRM_MODE_TRANSPORT, transport),
393 __ADD(XFRM_MODE_TUNNEL, tunnel),
394 __ADD(XFRM_MODE_ROUTEOPTIMIZATION, route optimization),
395 __ADD(XFRM_MODE_IN_TRIGGER, in trigger),
396 __ADD(XFRM_MODE_BEET, beet),
399char* xfrmnl_sa_mode2str(
int mode,
char *buf,
size_t len)
401 return __type2str (mode, buf, len, sa_modes, ARRAY_SIZE(sa_modes));
404int xfrmnl_sa_str2mode(
const char *name)
406 return __str2type (name, sa_modes, ARRAY_SIZE(sa_modes));
411static void xfrm_sa_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
413 char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
414 struct xfrmnl_sa* sa = (
struct xfrmnl_sa *) a;
415 char flags[128], mode[128];
416 time_t add_time, use_time;
417 struct tm *add_time_tm, *use_time_tm;
419 nl_dump_line(p,
"src %s dst %s family: %s\n",
nl_addr2str(sa->saddr, src,
sizeof(src)),
421 nl_af2str (sa->family, flags, sizeof (flags)));
423 nl_dump_line(p,
"\tproto %s spi 0x%x reqid %u\n",
424 nl_ip_proto2str (sa->id.proto, flags,
sizeof(flags)),
425 sa->id.spi, sa->reqid);
427 xfrmnl_sa_flags2str(sa->flags, flags, sizeof (flags));
428 xfrmnl_sa_mode2str(sa->mode, mode, sizeof (mode));
429 nl_dump_line(p,
"\tmode: %s flags: %s (0x%x) seq: %u replay window: %u\n",
430 mode, flags, sa->flags, sa->seq, sa->replay_window);
432 nl_dump_line(p,
"\tlifetime configuration: \n");
433 if (sa->lft->soft_byte_limit == XFRM_INF)
434 sprintf (flags,
"INF");
436 sprintf (flags,
"%" PRIu64, sa->lft->soft_byte_limit);
437 if (sa->lft->soft_packet_limit == XFRM_INF)
438 sprintf (mode,
"INF");
440 sprintf (mode,
"%" PRIu64, sa->lft->soft_packet_limit);
441 nl_dump_line(p,
"\t\tsoft limit: %s (bytes), %s (packets)\n", flags, mode);
442 if (sa->lft->hard_byte_limit == XFRM_INF)
443 sprintf (flags,
"INF");
445 sprintf (flags,
"%" PRIu64, sa->lft->hard_byte_limit);
446 if (sa->lft->hard_packet_limit == XFRM_INF)
447 sprintf (mode,
"INF");
449 sprintf (mode,
"%" PRIu64, sa->lft->hard_packet_limit);
450 nl_dump_line(p,
"\t\thard limit: %s (bytes), %s (packets)\n", flags,
454 "\t\tsoft add_time: %llu (seconds), soft use_time: %llu (seconds) \n",
455 (
long long unsigned)sa->lft->soft_add_expires_seconds,
456 (
long long unsigned)sa->lft->soft_use_expires_seconds);
459 "\t\thard add_time: %llu (seconds), hard use_time: %llu (seconds) \n",
460 (
long long unsigned)sa->lft->hard_add_expires_seconds,
461 (
long long unsigned)sa->lft->hard_use_expires_seconds);
463 nl_dump_line(p,
"\tlifetime current: \n");
464 nl_dump_line(p,
"\t\t%llu bytes, %llu packets\n",
465 (
long long unsigned)sa->curlft.bytes,
466 (
long long unsigned)sa->curlft.packets);
467 if (sa->curlft.add_time != 0)
469 add_time = sa->curlft.add_time;
470 add_time_tm = gmtime (&add_time);
471 strftime (flags, 128,
"%Y-%m-%d %H-%M-%S", add_time_tm);
475 sprintf (flags,
"%s",
"-");
478 if (sa->curlft.use_time != 0)
480 use_time = sa->curlft.use_time;
481 use_time_tm = gmtime (&use_time);
482 strftime (mode, 128,
"%Y-%m-%d %H-%M-%S", use_time_tm);
486 sprintf (mode,
"%s",
"-");
488 nl_dump_line(p,
"\t\tadd_time: %s, use_time: %s\n", flags, mode);
492 nl_dump_line(p,
"\tAEAD Algo: \n");
493 nl_dump_line(p,
"\t\tName: %s Key len(bits): %u ICV Len(bits): %u\n",
494 sa->aead->alg_name, sa->aead->alg_key_len, sa->aead->alg_icv_len);
499 nl_dump_line(p,
"\tAuth Algo: \n");
500 nl_dump_line(p,
"\t\tName: %s Key len(bits): %u Trunc len(bits): %u\n",
501 sa->auth->alg_name, sa->auth->alg_key_len, sa->auth->alg_trunc_len);
506 nl_dump_line(p,
"\tEncryption Algo: \n");
507 nl_dump_line(p,
"\t\tName: %s Key len(bits): %u\n",
508 sa->crypt->alg_name, sa->crypt->alg_key_len);
513 nl_dump_line(p,
"\tCompression Algo: \n");
514 nl_dump_line(p,
"\t\tName: %s Key len(bits): %u\n",
515 sa->comp->alg_name, sa->comp->alg_key_len);
520 nl_dump_line(p,
"\tEncapsulation template: \n");
521 nl_dump_line(p,
"\t\tType: %d Src port: %d Dst port: %d Encap addr: %s\n",
522 sa->encap->encap_type, sa->encap->encap_sport, sa->encap->encap_dport,
523 nl_addr2str (sa->encap->encap_oa, dst, sizeof (dst)));
526 if (sa->ce_mask & XFRM_SA_ATTR_TFCPAD)
527 nl_dump_line(p,
"\tTFC Pad: %u\n", sa->tfcpad);
529 if (sa->ce_mask & XFRM_SA_ATTR_COADDR)
530 nl_dump_line(p,
"\tCO Address: %s\n",
nl_addr2str (sa->coaddr, dst, sizeof (dst)));
532 if (sa->ce_mask & XFRM_SA_ATTR_MARK)
533 nl_dump_line(p,
"\tMark mask: 0x%x Mark value: 0x%x\n", sa->mark.m, sa->mark.v);
535 if (sa->ce_mask & XFRM_SA_ATTR_SECCTX)
536 nl_dump_line(p,
"\tDOI: %d Algo: %d Len: %u ctx: %s\n", sa->sec_ctx->ctx_doi,
537 sa->sec_ctx->ctx_alg, sa->sec_ctx->ctx_len, sa->sec_ctx->ctx);
539 nl_dump_line(p,
"\treplay info: \n");
540 nl_dump_line(p,
"\t\tmax age %u max diff %u \n", sa->replay_maxage, sa->replay_maxdiff);
542 if (sa->ce_mask & XFRM_SA_ATTR_REPLAY_STATE)
544 nl_dump_line(p,
"\treplay state info: \n");
545 if (sa->replay_state_esn)
547 nl_dump_line(p,
"\t\toseq %u seq %u oseq_hi %u seq_hi %u replay window: %u \n",
548 sa->replay_state_esn->oseq, sa->replay_state_esn->seq,
549 sa->replay_state_esn->oseq_hi, sa->replay_state_esn->seq_hi,
550 sa->replay_state_esn->replay_window);
554 nl_dump_line(p,
"\t\toseq %u seq %u bitmap: %u \n", sa->replay_state.oseq,
555 sa->replay_state.seq, sa->replay_state.bitmap);
559 nl_dump_line(p,
"\tselector info: \n");
560 xfrmnl_sel_dump (sa->sel, p);
562 nl_dump_line(p,
"\tHard: %d\n", sa->hard);
567static void xfrm_sa_dump_stats(
struct nl_object *a,
struct nl_dump_params *p)
569 struct xfrmnl_sa* sa = (
struct xfrmnl_sa*)a;
571 nl_dump_line(p,
"\tstats: \n");
572 nl_dump_line(p,
"\t\treplay window: %u replay: %u integrity failed: %u \n",
573 sa->stats.replay_window, sa->stats.replay, sa->stats.integrity_failed);
578static void xfrm_sa_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
580 xfrm_sa_dump_line(a, p);
581 xfrm_sa_dump_stats (a, p);
589struct xfrmnl_sa* xfrmnl_sa_alloc(
void)
594void xfrmnl_sa_put(
struct xfrmnl_sa* sa)
616int xfrmnl_sa_alloc_cache(
struct nl_sock *sock,
struct nl_cache **result)
629struct xfrmnl_sa* xfrmnl_sa_get(
struct nl_cache* cache,
struct nl_addr* daddr,
630 unsigned int spi,
unsigned int proto)
632 struct xfrmnl_sa *sa;
639 if (sa->id.proto == proto &&
656static struct nla_policy xfrm_sa_policy[XFRMA_MAX+1] = {
657 [XFRMA_SA] = { .
minlen =
sizeof(
struct xfrm_usersa_info)},
658 [XFRMA_ALG_AUTH_TRUNC] = { .minlen =
sizeof(
struct xfrm_algo_auth)},
659 [XFRMA_ALG_AEAD] = { .minlen =
sizeof(
struct xfrm_algo_aead) },
660 [XFRMA_ALG_AUTH] = { .minlen =
sizeof(
struct xfrm_algo) },
661 [XFRMA_ALG_CRYPT] = { .minlen =
sizeof(
struct xfrm_algo) },
662 [XFRMA_ALG_COMP] = { .minlen =
sizeof(
struct xfrm_algo) },
663 [XFRMA_ENCAP] = { .minlen =
sizeof(
struct xfrm_encap_tmpl) },
664 [XFRMA_TMPL] = { .minlen =
sizeof(
struct xfrm_user_tmpl) },
665 [XFRMA_SEC_CTX] = { .minlen =
sizeof(
struct xfrm_sec_ctx) },
666 [XFRMA_LTIME_VAL] = { .minlen =
sizeof(
struct xfrm_lifetime_cur) },
667 [XFRMA_REPLAY_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state) },
668 [XFRMA_OFFLOAD_DEV] = { .minlen =
sizeof(
struct xfrm_user_offload) },
669 [XFRMA_REPLAY_THRESH] = { .type =
NLA_U32 },
670 [XFRMA_ETIMER_THRESH] = { .type =
NLA_U32 },
671 [XFRMA_SRCADDR] = { .minlen =
sizeof(xfrm_address_t) },
672 [XFRMA_COADDR] = { .minlen =
sizeof(xfrm_address_t) },
673 [XFRMA_MARK] = { .minlen =
sizeof(
struct xfrm_mark) },
674 [XFRMA_TFCPAD] = { .type =
NLA_U32 },
675 [XFRMA_REPLAY_ESN_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state_esn) },
678static int xfrm_sa_request_update(
struct nl_cache *c,
struct nl_sock *h)
683int xfrmnl_sa_parse(
struct nlmsghdr *n,
struct xfrmnl_sa **result)
685 struct xfrmnl_sa* sa;
686 struct nlattr *tb[XFRMA_MAX + 1];
687 struct xfrm_usersa_info* sa_info;
688 struct xfrm_user_expire* ue;
690 struct nl_addr* addr;
692 sa = xfrmnl_sa_alloc();
698 sa->ce_msgtype = n->nlmsg_type;
699 if (n->nlmsg_type == XFRM_MSG_EXPIRE)
702 sa_info = &ue->state;
704 sa->ce_mask |= XFRM_SA_ATTR_EXPIRE;
706 else if (n->nlmsg_type == XFRM_MSG_DELSA)
708 sa_info = (
struct xfrm_usersa_info*)((
char *)
nlmsg_data(n) +
sizeof (
struct xfrm_usersa_id) + NLA_HDRLEN);
715 err =
nlmsg_parse(n,
sizeof(
struct xfrm_usersa_info), tb, XFRMA_MAX, xfrm_sa_policy);
719 if (sa_info->sel.family == AF_INET)
720 addr =
nl_addr_build (sa_info->sel.family, &sa_info->sel.daddr.a4, sizeof (sa_info->sel.daddr.a4));
722 addr =
nl_addr_build (sa_info->sel.family, &sa_info->sel.daddr.a6, sizeof (sa_info->sel.daddr.a6));
724 xfrmnl_sel_set_daddr (sa->sel, addr);
727 xfrmnl_sel_set_prefixlen_d (sa->sel, sa_info->sel.prefixlen_d);
729 if (sa_info->sel.family == AF_INET)
730 addr =
nl_addr_build (sa_info->sel.family, &sa_info->sel.saddr.a4, sizeof (sa_info->sel.saddr.a4));
732 addr =
nl_addr_build (sa_info->sel.family, &sa_info->sel.saddr.a6, sizeof (sa_info->sel.saddr.a6));
734 xfrmnl_sel_set_saddr (sa->sel, addr);
737 xfrmnl_sel_set_prefixlen_s (sa->sel, sa_info->sel.prefixlen_s);
739 xfrmnl_sel_set_dport (sa->sel, ntohs(sa_info->sel.dport));
740 xfrmnl_sel_set_dportmask (sa->sel, ntohs(sa_info->sel.dport_mask));
741 xfrmnl_sel_set_sport (sa->sel, ntohs(sa_info->sel.sport));
742 xfrmnl_sel_set_sportmask (sa->sel, ntohs(sa_info->sel.sport_mask));
743 xfrmnl_sel_set_family (sa->sel, sa_info->sel.family);
744 xfrmnl_sel_set_proto (sa->sel, sa_info->sel.proto);
745 xfrmnl_sel_set_ifindex (sa->sel, sa_info->sel.ifindex);
746 xfrmnl_sel_set_userid (sa->sel, sa_info->sel.user);
747 sa->ce_mask |= XFRM_SA_ATTR_SEL;
749 if (sa_info->family == AF_INET)
750 sa->id.daddr =
nl_addr_build (sa_info->family, &sa_info->id.daddr.a4, sizeof (sa_info->id.daddr.a4));
752 sa->id.daddr =
nl_addr_build (sa_info->family, &sa_info->id.daddr.a6, sizeof (sa_info->id.daddr.a6));
753 sa->id.spi = ntohl(sa_info->id.spi);
754 sa->id.proto = sa_info->id.proto;
755 sa->ce_mask |= (XFRM_SA_ATTR_DADDR | XFRM_SA_ATTR_SPI | XFRM_SA_ATTR_PROTO);
757 if (sa_info->family == AF_INET)
758 sa->saddr =
nl_addr_build (sa_info->family, &sa_info->saddr.a4, sizeof (sa_info->saddr.a4));
760 sa->saddr =
nl_addr_build (sa_info->family, &sa_info->saddr.a6, sizeof (sa_info->saddr.a6));
761 sa->ce_mask |= XFRM_SA_ATTR_SADDR;
763 sa->lft->soft_byte_limit = sa_info->lft.soft_byte_limit;
764 sa->lft->hard_byte_limit = sa_info->lft.hard_byte_limit;
765 sa->lft->soft_packet_limit = sa_info->lft.soft_packet_limit;
766 sa->lft->hard_packet_limit = sa_info->lft.hard_packet_limit;
767 sa->lft->soft_add_expires_seconds = sa_info->lft.soft_add_expires_seconds;
768 sa->lft->hard_add_expires_seconds = sa_info->lft.hard_add_expires_seconds;
769 sa->lft->soft_use_expires_seconds = sa_info->lft.soft_use_expires_seconds;
770 sa->lft->hard_use_expires_seconds = sa_info->lft.hard_use_expires_seconds;
771 sa->ce_mask |= XFRM_SA_ATTR_LTIME_CFG;
773 sa->curlft.bytes = sa_info->curlft.bytes;
774 sa->curlft.packets = sa_info->curlft.packets;
775 sa->curlft.add_time = sa_info->curlft.add_time;
776 sa->curlft.use_time = sa_info->curlft.use_time;
777 sa->ce_mask |= XFRM_SA_ATTR_LTIME_CUR;
779 sa->stats.replay_window = sa_info->stats.replay_window;
780 sa->stats.replay = sa_info->stats.replay;
781 sa->stats.integrity_failed = sa_info->stats.integrity_failed;
782 sa->ce_mask |= XFRM_SA_ATTR_STATS;
784 sa->seq = sa_info->seq;
785 sa->reqid = sa_info->reqid;
786 sa->family = sa_info->family;
787 sa->mode = sa_info->mode;
788 sa->replay_window = sa_info->replay_window;
789 sa->flags = sa_info->flags;
790 sa->ce_mask |= (XFRM_SA_ATTR_SEQ | XFRM_SA_ATTR_REQID |
791 XFRM_SA_ATTR_FAMILY | XFRM_SA_ATTR_MODE |
792 XFRM_SA_ATTR_REPLAY_WIN | XFRM_SA_ATTR_FLAGS);
794 if (tb[XFRMA_ALG_AEAD]) {
795 struct xfrm_algo_aead* aead =
nla_data(tb[XFRMA_ALG_AEAD]);
796 len =
sizeof (
struct xfrmnl_algo_aead) + ((aead->alg_key_len + 7) / 8);
797 if ((sa->aead = calloc (1, len)) == NULL)
802 memcpy ((
void *)sa->aead, (
void *)aead, len);
803 sa->ce_mask |= XFRM_SA_ATTR_ALG_AEAD;
806 if (tb[XFRMA_ALG_AUTH_TRUNC]) {
807 struct xfrm_algo_auth* auth =
nla_data(tb[XFRMA_ALG_AUTH_TRUNC]);
808 len =
sizeof (
struct xfrmnl_algo_auth) + ((auth->alg_key_len + 7) / 8);
809 if ((sa->auth = calloc (1, len)) == NULL)
814 memcpy ((
void *)sa->auth, (
void *)auth, len);
815 sa->ce_mask |= XFRM_SA_ATTR_ALG_AUTH;
818 if (tb[XFRMA_ALG_AUTH] && !sa->auth) {
819 struct xfrm_algo* auth =
nla_data(tb[XFRMA_ALG_AUTH]);
820 len =
sizeof (
struct xfrmnl_algo_auth) + ((auth->alg_key_len + 7) / 8);
821 if ((sa->auth = calloc (1, len)) == NULL)
826 strcpy(sa->auth->alg_name, auth->alg_name);
827 memcpy(sa->auth->alg_key, auth->alg_key, (auth->alg_key_len + 7) / 8);
828 sa->auth->alg_key_len = auth->alg_key_len;
829 sa->ce_mask |= XFRM_SA_ATTR_ALG_AUTH;
832 if (tb[XFRMA_ALG_CRYPT]) {
833 struct xfrm_algo* crypt =
nla_data(tb[XFRMA_ALG_CRYPT]);
834 len =
sizeof (
struct xfrmnl_algo) + ((crypt->alg_key_len + 7) / 8);
835 if ((sa->crypt = calloc (1, len)) == NULL)
840 memcpy ((
void *)sa->crypt, (
void *)crypt, len);
841 sa->ce_mask |= XFRM_SA_ATTR_ALG_CRYPT;
844 if (tb[XFRMA_ALG_COMP]) {
845 struct xfrm_algo* comp =
nla_data(tb[XFRMA_ALG_COMP]);
846 len =
sizeof (
struct xfrmnl_algo) + ((comp->alg_key_len + 7) / 8);
847 if ((sa->comp = calloc (1, len)) == NULL)
852 memcpy ((
void *)sa->comp, (
void *)comp, len);
853 sa->ce_mask |= XFRM_SA_ATTR_ALG_COMP;
856 if (tb[XFRMA_ENCAP]) {
857 struct xfrm_encap_tmpl* encap =
nla_data(tb[XFRMA_ENCAP]);
858 len =
sizeof (
struct xfrmnl_encap_tmpl);
859 if ((sa->encap = calloc (1, len)) == NULL)
864 sa->encap->encap_type = encap->encap_type;
865 sa->encap->encap_sport = ntohs(encap->encap_sport);
866 sa->encap->encap_dport = ntohs(encap->encap_dport);
867 if (sa_info->family == AF_INET)
868 sa->encap->encap_oa =
nl_addr_build (sa_info->family, &encap->encap_oa.a4, sizeof (encap->encap_oa.a4));
870 sa->encap->encap_oa =
nl_addr_build (sa_info->family, &encap->encap_oa.a6, sizeof (encap->encap_oa.a6));
871 sa->ce_mask |= XFRM_SA_ATTR_ENCAP;
874 if (tb[XFRMA_TFCPAD]) {
875 sa->tfcpad = *(uint32_t*)
nla_data(tb[XFRMA_TFCPAD]);
876 sa->ce_mask |= XFRM_SA_ATTR_TFCPAD;
879 if (tb[XFRMA_COADDR]) {
880 if (sa_info->family == AF_INET)
888 sizeof (uint32_t) * 4);
890 sa->ce_mask |= XFRM_SA_ATTR_COADDR;
893 if (tb[XFRMA_MARK]) {
894 struct xfrm_mark* m =
nla_data(tb[XFRMA_MARK]);
897 sa->ce_mask |= XFRM_SA_ATTR_MARK;
900 if (tb[XFRMA_SEC_CTX]) {
901 struct xfrm_user_sec_ctx* sec_ctx =
nla_data(tb[XFRMA_SEC_CTX]);
902 len =
sizeof (
struct xfrmnl_user_sec_ctx) + sec_ctx->ctx_len;
903 if ((sa->sec_ctx = calloc (1, len)) == NULL)
908 memcpy (sa->sec_ctx, sec_ctx, len);
909 sa->ce_mask |= XFRM_SA_ATTR_SECCTX;
912 if (tb[XFRMA_ETIMER_THRESH]) {
913 sa->replay_maxage = *(uint32_t*)
nla_data(tb[XFRMA_ETIMER_THRESH]);
914 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_MAXAGE;
917 if (tb[XFRMA_REPLAY_THRESH]) {
918 sa->replay_maxdiff = *(uint32_t*)
nla_data(tb[XFRMA_REPLAY_THRESH]);
919 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_MAXDIFF;
922 if (tb[XFRMA_REPLAY_ESN_VAL]) {
923 struct xfrm_replay_state_esn* esn =
nla_data (tb[XFRMA_REPLAY_ESN_VAL]);
924 len =
sizeof (
struct xfrmnl_replay_state_esn) + (sizeof (uint32_t) * esn->bmp_len);
925 if ((sa->replay_state_esn = calloc (1, len)) == NULL)
930 memcpy ((
void *)sa->replay_state_esn, (
void *)esn, len);
931 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_STATE;
933 else if (tb[XFRMA_REPLAY_VAL])
935 struct xfrm_replay_state* replay_state =
nla_data (tb[XFRMA_REPLAY_VAL]);
936 sa->replay_state.oseq = replay_state->oseq;
937 sa->replay_state.seq = replay_state->seq;
938 sa->replay_state.bitmap = replay_state->bitmap;
939 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_STATE;
940 sa->replay_state_esn = NULL;
943 if (tb[XFRMA_OFFLOAD_DEV]) {
944 struct xfrm_user_offload *offload;
946 len =
sizeof(
struct xfrmnl_user_offload);
948 if ((sa->user_offload = calloc(1, len)) == NULL) {
953 offload =
nla_data(tb[XFRMA_OFFLOAD_DEV]);
954 sa->user_offload->ifindex = offload->ifindex;
955 sa->user_offload->flags = offload->flags;
956 sa->ce_mask |= XFRM_SA_ATTR_OFFLOAD_DEV;
967static int xfrm_sa_update_cache (
struct nl_cache *cache,
struct nl_object *obj,
968 change_func_t change_cb, change_func_v2_t change_cb_v2,
971 struct nl_object* old_sa;
972 struct xfrmnl_sa* sa = (
struct xfrmnl_sa*)obj;
1003 change_cb_v2(cache, NULL, obj, 0, NL_ACT_NEW, data);
1005 change_cb(cache, obj, NL_ACT_NEW, data);
1010 if (change_cb || change_cb_v2)
1017 change_cb_v2(cache, old_sa, obj, diff, NL_ACT_CHANGE, data);
1018 }
else if (change_cb)
1019 change_cb(cache, obj, NL_ACT_CHANGE, data);
1029 change_cb_v2(cache, obj, NULL, 0, NL_ACT_DEL, data);
1031 change_cb (cache, obj, NL_ACT_DEL, data);
1043 return nl_cache_include_v2(cache, obj, change_cb_v2, data);
1045 return nl_cache_include (cache, obj, change_cb, data);
1049static int xfrm_sa_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
1050 struct nlmsghdr *n,
struct nl_parser_param *pp)
1052 struct xfrmnl_sa* sa;
1055 if ((err = xfrmnl_sa_parse(n, &sa)) < 0)
1058 err = pp->pp_cb((
struct nl_object *) sa, pp);
1069int xfrmnl_sa_build_get_request(
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
unsigned int mark_v,
unsigned int mark_m,
struct nl_msg **result)
1072 struct xfrm_usersa_id sa_id;
1073 struct xfrm_mark mark;
1077 fprintf(stderr,
"APPLICATION BUG: %s:%d:%s: A valid destination address, spi must be specified\n",
1078 __FILE__, __LINE__, __func__);
1080 return -NLE_MISSING_ATTR;
1083 memset(&sa_id, 0,
sizeof(sa_id));
1086 sa_id.spi = htonl(spi);
1087 sa_id.proto = protocol;
1092 if (
nlmsg_append(msg, &sa_id,
sizeof(sa_id), NLMSG_ALIGNTO) < 0)
1093 goto nla_put_failure;
1095 if ((mark_m & mark_v) != 0)
1097 memset(&mark, 0,
sizeof(
struct xfrm_mark));
1101 NLA_PUT (msg, XFRMA_MARK,
sizeof (
struct xfrm_mark), &mark);
1109 return -NLE_MSGSIZE;
1112int xfrmnl_sa_get_kernel(
struct nl_sock* sock,
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
unsigned int mark_v,
unsigned int mark_m,
struct xfrmnl_sa** result)
1114 struct nl_msg *msg = NULL;
1115 struct nl_object *obj;
1118 if ((err = xfrmnl_sa_build_get_request(daddr, spi, protocol, mark_m, mark_v, &msg)) < 0)
1126 if ((err =
nl_pickup(sock, &xfrm_sa_msg_parser, &obj)) < 0)
1130 *result = (
struct xfrmnl_sa *) obj;
1133 if (err == 0 && obj)
1141static int build_xfrm_sa_message(
struct xfrmnl_sa *tmpl,
int cmd,
int flags,
struct nl_msg **result)
1144 struct xfrm_usersa_info sa_info;
1146 struct nl_addr* addr;
1148 if (!(tmpl->ce_mask & XFRM_SA_ATTR_DADDR) ||
1149 !(tmpl->ce_mask & XFRM_SA_ATTR_SPI) ||
1150 !(tmpl->ce_mask & XFRM_SA_ATTR_PROTO))
1151 return -NLE_MISSING_ATTR;
1153 memset ((
void*)&sa_info, 0,
sizeof (sa_info));
1154 if (tmpl->ce_mask & XFRM_SA_ATTR_SEL)
1156 addr = xfrmnl_sel_get_daddr (tmpl->sel);
1158 addr = xfrmnl_sel_get_saddr (tmpl->sel);
1160 sa_info.sel.dport = htons (xfrmnl_sel_get_dport (tmpl->sel));
1161 sa_info.sel.dport_mask = htons (xfrmnl_sel_get_dportmask (tmpl->sel));
1162 sa_info.sel.sport = htons (xfrmnl_sel_get_sport (tmpl->sel));
1163 sa_info.sel.sport_mask = htons (xfrmnl_sel_get_sportmask (tmpl->sel));
1164 sa_info.sel.family = xfrmnl_sel_get_family (tmpl->sel);
1165 sa_info.sel.prefixlen_d = xfrmnl_sel_get_prefixlen_d (tmpl->sel);
1166 sa_info.sel.prefixlen_s = xfrmnl_sel_get_prefixlen_s (tmpl->sel);
1167 sa_info.sel.proto = xfrmnl_sel_get_proto (tmpl->sel);
1168 sa_info.sel.ifindex = xfrmnl_sel_get_ifindex (tmpl->sel);
1169 sa_info.sel.user = xfrmnl_sel_get_userid (tmpl->sel);
1173 sa_info.id.spi = htonl(tmpl->id.spi);
1174 sa_info.id.proto = tmpl->id.proto;
1176 if (tmpl->ce_mask & XFRM_SA_ATTR_SADDR)
1179 if (tmpl->ce_mask & XFRM_SA_ATTR_LTIME_CFG)
1181 sa_info.lft.soft_byte_limit = xfrmnl_ltime_cfg_get_soft_bytelimit (tmpl->lft);
1182 sa_info.lft.hard_byte_limit = xfrmnl_ltime_cfg_get_hard_bytelimit (tmpl->lft);
1183 sa_info.lft.soft_packet_limit = xfrmnl_ltime_cfg_get_soft_packetlimit (tmpl->lft);
1184 sa_info.lft.hard_packet_limit = xfrmnl_ltime_cfg_get_hard_packetlimit (tmpl->lft);
1185 sa_info.lft.soft_add_expires_seconds = xfrmnl_ltime_cfg_get_soft_addexpires (tmpl->lft);
1186 sa_info.lft.hard_add_expires_seconds = xfrmnl_ltime_cfg_get_hard_addexpires (tmpl->lft);
1187 sa_info.lft.soft_use_expires_seconds = xfrmnl_ltime_cfg_get_soft_useexpires (tmpl->lft);
1188 sa_info.lft.hard_use_expires_seconds = xfrmnl_ltime_cfg_get_hard_useexpires (tmpl->lft);
1195 if (tmpl->ce_mask & XFRM_SA_ATTR_REQID)
1196 sa_info.reqid = tmpl->reqid;
1198 if (tmpl->ce_mask & XFRM_SA_ATTR_FAMILY)
1199 sa_info.family = tmpl->family;
1201 if (tmpl->ce_mask & XFRM_SA_ATTR_MODE)
1202 sa_info.mode = tmpl->mode;
1204 if (tmpl->ce_mask & XFRM_SA_ATTR_REPLAY_WIN)
1205 sa_info.replay_window = tmpl->replay_window;
1207 if (tmpl->ce_mask & XFRM_SA_ATTR_FLAGS)
1208 sa_info.flags = tmpl->flags;
1214 if (
nlmsg_append(msg, &sa_info,
sizeof(sa_info), NLMSG_ALIGNTO) < 0)
1215 goto nla_put_failure;
1217 if (tmpl->ce_mask & XFRM_SA_ATTR_ALG_AEAD) {
1218 len =
sizeof (
struct xfrm_algo_aead) + ((tmpl->aead->alg_key_len + 7) / 8);
1219 NLA_PUT (msg, XFRMA_ALG_AEAD, len, tmpl->aead);
1222 if (tmpl->ce_mask & XFRM_SA_ATTR_ALG_AUTH) {
1225 if (tmpl->auth->alg_trunc_len) {
1226 len =
sizeof (
struct xfrm_algo_auth) + ((tmpl->auth->alg_key_len + 7) / 8);
1227 NLA_PUT (msg, XFRMA_ALG_AUTH_TRUNC, len, tmpl->auth);
1229 struct xfrm_algo *auth;
1231 len =
sizeof (
struct xfrm_algo) + ((tmpl->auth->alg_key_len + 7) / 8);
1238 _nl_strncpy_assert(auth->alg_name, tmpl->auth->alg_name,
sizeof(auth->alg_name));
1239 auth->alg_key_len = tmpl->auth->alg_key_len;
1240 memcpy(auth->alg_key, tmpl->auth->alg_key, (tmpl->auth->alg_key_len + 7) / 8);
1241 if (
nla_put(msg, XFRMA_ALG_AUTH, len, auth) < 0) {
1243 goto nla_put_failure;
1249 if (tmpl->ce_mask & XFRM_SA_ATTR_ALG_CRYPT) {
1250 len =
sizeof (
struct xfrm_algo) + ((tmpl->crypt->alg_key_len + 7) / 8);
1251 NLA_PUT (msg, XFRMA_ALG_CRYPT, len, tmpl->crypt);
1254 if (tmpl->ce_mask & XFRM_SA_ATTR_ALG_COMP) {
1255 len =
sizeof (
struct xfrm_algo) + ((tmpl->comp->alg_key_len + 7) / 8);
1256 NLA_PUT (msg, XFRMA_ALG_COMP, len, tmpl->comp);
1259 if (tmpl->ce_mask & XFRM_SA_ATTR_ENCAP) {
1260 struct xfrm_encap_tmpl* encap_tmpl;
1261 struct nlattr* encap_attr;
1263 len =
sizeof (
struct xfrm_encap_tmpl);
1266 goto nla_put_failure;
1267 encap_tmpl =
nla_data (encap_attr);
1268 encap_tmpl->encap_type = tmpl->encap->encap_type;
1269 encap_tmpl->encap_sport = htons (tmpl->encap->encap_sport);
1270 encap_tmpl->encap_dport = htons (tmpl->encap->encap_dport);
1274 if (tmpl->ce_mask & XFRM_SA_ATTR_TFCPAD) {
1278 if (tmpl->ce_mask & XFRM_SA_ATTR_COADDR) {
1279 NLA_PUT (msg, XFRMA_COADDR,
sizeof (xfrm_address_t), tmpl->coaddr);
1282 if (tmpl->ce_mask & XFRM_SA_ATTR_MARK) {
1283 NLA_PUT (msg, XFRMA_MARK,
sizeof (
struct xfrm_mark), &tmpl->mark);
1286 if (tmpl->ce_mask & XFRM_SA_ATTR_SECCTX) {
1287 len =
sizeof (
struct xfrm_sec_ctx) + tmpl->sec_ctx->ctx_len;
1288 NLA_PUT (msg, XFRMA_SEC_CTX, len, tmpl->sec_ctx);
1291 if (tmpl->ce_mask & XFRM_SA_ATTR_REPLAY_MAXAGE) {
1292 NLA_PUT_U32 (msg, XFRMA_ETIMER_THRESH, tmpl->replay_maxage);
1295 if (tmpl->ce_mask & XFRM_SA_ATTR_REPLAY_MAXDIFF) {
1296 NLA_PUT_U32 (msg, XFRMA_REPLAY_THRESH, tmpl->replay_maxdiff);
1299 if (tmpl->ce_mask & XFRM_SA_ATTR_REPLAY_STATE) {
1300 if (tmpl->replay_state_esn) {
1301 len =
sizeof (
struct xfrm_replay_state_esn) + (sizeof (uint32_t) * tmpl->replay_state_esn->bmp_len);
1302 NLA_PUT (msg, XFRMA_REPLAY_ESN_VAL, len, tmpl->replay_state_esn);
1305 NLA_PUT (msg, XFRMA_REPLAY_VAL,
sizeof (
struct xfrm_replay_state), &tmpl->replay_state);
1309 if (tmpl->ce_mask & XFRM_SA_ATTR_OFFLOAD_DEV) {
1310 struct xfrm_user_offload *offload;
1311 struct nlattr *attr;
1313 len =
sizeof(
struct xfrm_user_offload);
1317 goto nla_put_failure;
1320 offload->ifindex = tmpl->user_offload->ifindex;
1321 offload->flags = tmpl->user_offload->flags;
1329 return -NLE_MSGSIZE;
1337int xfrmnl_sa_build_add_request(
struct xfrmnl_sa* tmpl,
int flags,
struct nl_msg **result)
1339 return build_xfrm_sa_message (tmpl, XFRM_MSG_NEWSA, flags, result);
1342int xfrmnl_sa_add(
struct nl_sock* sk,
struct xfrmnl_sa* tmpl,
int flags)
1347 if ((err = xfrmnl_sa_build_add_request(tmpl, flags, &msg)) < 0)
1363int xfrmnl_sa_build_update_request(
struct xfrmnl_sa* tmpl,
int flags,
struct nl_msg **result)
1365 return build_xfrm_sa_message (tmpl, XFRM_MSG_UPDSA, flags, result);
1368int xfrmnl_sa_update(
struct nl_sock* sk,
struct xfrmnl_sa* tmpl,
int flags)
1373 if ((err = xfrmnl_sa_build_update_request(tmpl, flags, &msg)) < 0)
1386static int build_xfrm_sa_delete_message(
struct xfrmnl_sa *tmpl,
int cmd,
int flags,
struct nl_msg **result)
1389 struct xfrm_usersa_id sa_id;
1391 if (!(tmpl->ce_mask & XFRM_SA_ATTR_DADDR) ||
1392 !(tmpl->ce_mask & XFRM_SA_ATTR_SPI) ||
1393 !(tmpl->ce_mask & XFRM_SA_ATTR_PROTO))
1394 return -NLE_MISSING_ATTR;
1396 memset(&sa_id, 0,
sizeof(
struct xfrm_usersa_id));
1400 sa_id.spi = htonl(tmpl->id.spi);
1401 sa_id.proto = tmpl->id.proto;
1407 if (
nlmsg_append(msg, &sa_id,
sizeof(sa_id), NLMSG_ALIGNTO) < 0)
1408 goto nla_put_failure;
1410 if (tmpl->ce_mask & XFRM_SA_ATTR_MARK) {
1411 NLA_PUT (msg, XFRMA_MARK,
sizeof (
struct xfrm_mark), &tmpl->mark);
1419 return -NLE_MSGSIZE;
1427int xfrmnl_sa_build_delete_request(
struct xfrmnl_sa* tmpl,
int flags,
struct nl_msg **result)
1429 return build_xfrm_sa_delete_message (tmpl, XFRM_MSG_DELSA, flags, result);
1432int xfrmnl_sa_delete(
struct nl_sock* sk,
struct xfrmnl_sa* tmpl,
int flags)
1437 if ((err = xfrmnl_sa_build_delete_request(tmpl, flags, &msg)) < 0)
1456struct xfrmnl_sel* xfrmnl_sa_get_sel (
struct xfrmnl_sa* sa)
1458 if (sa->ce_mask & XFRM_SA_ATTR_SEL)
1464int xfrmnl_sa_set_sel (
struct xfrmnl_sa* sa,
struct xfrmnl_sel* sel)
1468 xfrmnl_sel_put (sa->sel);
1471 xfrmnl_sel_get (sel);
1473 sa->ce_mask |= XFRM_SA_ATTR_SEL;
1478static inline int __assign_addr(
struct xfrmnl_sa* sa,
struct nl_addr **pos,
1479 struct nl_addr *
new,
int flag,
int nocheck)
1483 if (sa->ce_mask & XFRM_SA_ATTR_FAMILY)
1486 return -NLE_AF_MISMATCH;
1496 sa->ce_mask |= flag;
1502struct nl_addr* xfrmnl_sa_get_daddr (
struct xfrmnl_sa* sa)
1504 if (sa->ce_mask & XFRM_SA_ATTR_DADDR)
1505 return sa->id.daddr;
1510int xfrmnl_sa_set_daddr (
struct xfrmnl_sa* sa,
struct nl_addr* addr)
1512 return __assign_addr(sa, &sa->id.daddr, addr, XFRM_SA_ATTR_DADDR, 0);
1515int xfrmnl_sa_get_spi (
struct xfrmnl_sa* sa)
1517 if (sa->ce_mask & XFRM_SA_ATTR_SPI)
1523int xfrmnl_sa_set_spi (
struct xfrmnl_sa* sa,
unsigned int spi)
1526 sa->ce_mask |= XFRM_SA_ATTR_SPI;
1531int xfrmnl_sa_get_proto (
struct xfrmnl_sa* sa)
1533 if (sa->ce_mask & XFRM_SA_ATTR_PROTO)
1534 return sa->id.proto;
1539int xfrmnl_sa_set_proto (
struct xfrmnl_sa* sa,
unsigned int protocol)
1541 sa->id.proto = protocol;
1542 sa->ce_mask |= XFRM_SA_ATTR_PROTO;
1547struct nl_addr* xfrmnl_sa_get_saddr (
struct xfrmnl_sa* sa)
1549 if (sa->ce_mask & XFRM_SA_ATTR_SADDR)
1555int xfrmnl_sa_set_saddr (
struct xfrmnl_sa* sa,
struct nl_addr* addr)
1557 return __assign_addr(sa, &sa->saddr, addr, XFRM_SA_ATTR_SADDR, 1);
1560struct xfrmnl_ltime_cfg* xfrmnl_sa_get_lifetime_cfg (
struct xfrmnl_sa* sa)
1562 if (sa->ce_mask & XFRM_SA_ATTR_LTIME_CFG)
1568int xfrmnl_sa_set_lifetime_cfg (
struct xfrmnl_sa* sa,
struct xfrmnl_ltime_cfg* ltime)
1572 xfrmnl_ltime_cfg_put (sa->lft);
1575 xfrmnl_ltime_cfg_get (ltime);
1577 sa->ce_mask |= XFRM_SA_ATTR_LTIME_CFG;
1582int xfrmnl_sa_get_curlifetime (
struct xfrmnl_sa* sa,
unsigned long long int* curr_bytes,
1583 unsigned long long int* curr_packets,
unsigned long long int* curr_add_time,
unsigned long long int* curr_use_time)
1585 if (sa == NULL || curr_bytes == NULL || curr_packets == NULL || curr_add_time == NULL || curr_use_time == NULL)
1588 if (sa->ce_mask & XFRM_SA_ATTR_LTIME_CUR)
1590 *curr_bytes = sa->curlft.bytes;
1591 *curr_packets = sa->curlft.packets;
1592 *curr_add_time = sa->curlft.add_time;
1593 *curr_use_time = sa->curlft.use_time;
1601int xfrmnl_sa_get_stats (
struct xfrmnl_sa* sa,
unsigned long long int* replay_window,
1602 unsigned long long int* replay,
unsigned long long int* integrity_failed)
1604 if (sa == NULL || replay_window == NULL || replay == NULL || integrity_failed == NULL)
1607 if (sa->ce_mask & XFRM_SA_ATTR_STATS)
1609 *replay_window = sa->stats.replay_window;
1610 *replay = sa->stats.replay;
1611 *integrity_failed = sa->stats.integrity_failed;
1619int xfrmnl_sa_get_seq (
struct xfrmnl_sa* sa)
1621 if (sa->ce_mask & XFRM_SA_ATTR_SEQ)
1627int xfrmnl_sa_get_reqid (
struct xfrmnl_sa* sa)
1629 if (sa->ce_mask & XFRM_SA_ATTR_REQID)
1635int xfrmnl_sa_set_reqid (
struct xfrmnl_sa* sa,
unsigned int reqid)
1638 sa->ce_mask |= XFRM_SA_ATTR_REQID;
1643int xfrmnl_sa_get_family (
struct xfrmnl_sa* sa)
1645 if (sa->ce_mask & XFRM_SA_ATTR_FAMILY)
1651int xfrmnl_sa_set_family (
struct xfrmnl_sa* sa,
unsigned int family)
1653 sa->family = family;
1654 sa->ce_mask |= XFRM_SA_ATTR_FAMILY;
1659int xfrmnl_sa_get_mode (
struct xfrmnl_sa* sa)
1661 if (sa->ce_mask & XFRM_SA_ATTR_MODE)
1667int xfrmnl_sa_set_mode (
struct xfrmnl_sa* sa,
unsigned int mode)
1670 sa->ce_mask |= XFRM_SA_ATTR_MODE;
1675int xfrmnl_sa_get_replay_window (
struct xfrmnl_sa* sa)
1677 if (sa->ce_mask & XFRM_SA_ATTR_REPLAY_WIN)
1678 return sa->replay_window;
1683int xfrmnl_sa_set_replay_window (
struct xfrmnl_sa* sa,
unsigned int replay_window)
1685 sa->replay_window = replay_window;
1686 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_WIN;
1691int xfrmnl_sa_get_flags (
struct xfrmnl_sa* sa)
1693 if (sa->ce_mask & XFRM_SA_ATTR_FLAGS)
1699int xfrmnl_sa_set_flags (
struct xfrmnl_sa* sa,
unsigned int flags)
1702 sa->ce_mask |= XFRM_SA_ATTR_FLAGS;
1723int xfrmnl_sa_get_aead_params (
struct xfrmnl_sa* sa,
char* alg_name,
unsigned int* key_len,
unsigned int* icv_len,
char* key)
1725 if (sa->ce_mask & XFRM_SA_ATTR_ALG_AEAD)
1728 strcpy (alg_name, sa->aead->alg_name);
1730 *key_len = sa->aead->alg_key_len;
1732 *icv_len = sa->aead->alg_icv_len;
1734 memcpy (key, sa->aead->alg_key, ((sa->aead->alg_key_len + 7)/8));
1742int xfrmnl_sa_set_aead_params (
struct xfrmnl_sa* sa,
const char* alg_name,
unsigned int key_len,
unsigned int icv_len,
const char* key)
1744 _nl_auto_free
struct xfrmnl_algo_aead *b = NULL;
1745 size_t keysize =
sizeof (uint8_t) * ((key_len + 7)/8);
1746 uint32_t newlen =
sizeof (
struct xfrmnl_algo_aead) + keysize;
1749 if (strlen (alg_name) >=
sizeof (sa->aead->alg_name))
1751 if (!(b = calloc (1, newlen)))
1754 strcpy (b->alg_name, alg_name);
1755 b->alg_key_len = key_len;
1756 b->alg_icv_len = icv_len;
1757 memcpy (b->alg_key, key, keysize);
1760 sa->aead = _nl_steal_pointer (&b);
1761 sa->ce_mask |= XFRM_SA_ATTR_ALG_AEAD;
1781int xfrmnl_sa_get_auth_params (
struct xfrmnl_sa* sa,
char* alg_name,
unsigned int* key_len,
unsigned int* trunc_len,
char* key)
1783 if (sa->ce_mask & XFRM_SA_ATTR_ALG_AUTH)
1786 strcpy (alg_name, sa->auth->alg_name);
1788 *key_len = sa->auth->alg_key_len;
1790 *trunc_len = sa->auth->alg_trunc_len;
1792 memcpy (key, sa->auth->alg_key, (sa->auth->alg_key_len + 7)/8);
1800int xfrmnl_sa_set_auth_params (
struct xfrmnl_sa* sa,
const char* alg_name,
unsigned int key_len,
unsigned int trunc_len,
const char* key)
1802 _nl_auto_free
struct xfrmnl_algo_auth *b = NULL;
1803 size_t keysize =
sizeof (uint8_t) * ((key_len + 7)/8);
1804 uint32_t newlen =
sizeof (
struct xfrmnl_algo_auth) + keysize;
1806 if (strlen (alg_name) >=
sizeof (sa->auth->alg_name))
1808 if (!(b = calloc (1, newlen)))
1811 strcpy (b->alg_name, alg_name);
1812 b->alg_key_len = key_len;
1813 b->alg_trunc_len = trunc_len;
1814 memcpy (b->alg_key, key, keysize);
1817 sa->auth = _nl_steal_pointer (&b);
1818 sa->ce_mask |= XFRM_SA_ATTR_ALG_AUTH;
1837int xfrmnl_sa_get_crypto_params (
struct xfrmnl_sa* sa,
char* alg_name,
unsigned int* key_len,
char* key)
1839 if (sa->ce_mask & XFRM_SA_ATTR_ALG_CRYPT)
1842 strcpy (alg_name, sa->crypt->alg_name);
1844 *key_len = sa->crypt->alg_key_len;
1846 memcpy (key, sa->crypt->alg_key, ((sa->crypt->alg_key_len + 7)/8));
1854int xfrmnl_sa_set_crypto_params (
struct xfrmnl_sa* sa,
const char* alg_name,
unsigned int key_len,
const char* key)
1856 _nl_auto_free
struct xfrmnl_algo *b = NULL;
1857 size_t keysize =
sizeof (uint8_t) * ((key_len + 7)/8);
1858 uint32_t newlen =
sizeof (
struct xfrmnl_algo) + keysize;
1860 if (strlen (alg_name) >=
sizeof (sa->crypt->alg_name))
1862 if (!(b = calloc (1, newlen)))
1865 strcpy (b->alg_name, alg_name);
1866 b->alg_key_len = key_len;
1867 memcpy (b->alg_key, key, keysize);
1870 sa->crypt = _nl_steal_pointer(&b);
1871 sa->ce_mask |= XFRM_SA_ATTR_ALG_CRYPT;
1890int xfrmnl_sa_get_comp_params (
struct xfrmnl_sa* sa,
char* alg_name,
unsigned int* key_len,
char* key)
1892 if (sa->ce_mask & XFRM_SA_ATTR_ALG_COMP)
1895 strcpy (alg_name, sa->comp->alg_name);
1897 *key_len = sa->comp->alg_key_len;
1899 memcpy (key, sa->comp->alg_key, ((sa->comp->alg_key_len + 7)/8));
1907int xfrmnl_sa_set_comp_params (
struct xfrmnl_sa* sa,
const char* alg_name,
unsigned int key_len,
const char* key)
1909 _nl_auto_free
struct xfrmnl_algo *b = NULL;
1910 size_t keysize =
sizeof (uint8_t) * ((key_len + 7)/8);
1911 uint32_t newlen =
sizeof (
struct xfrmnl_algo) + keysize;
1913 if (strlen (alg_name) >=
sizeof (sa->comp->alg_name))
1915 if (!(b = calloc (1, newlen)))
1918 strcpy (b->alg_name, alg_name);
1919 b->alg_key_len = key_len;
1920 memcpy (b->alg_key, key, keysize);
1923 sa->comp = _nl_steal_pointer(&b);
1924 sa->ce_mask |= XFRM_SA_ATTR_ALG_COMP;
1928int xfrmnl_sa_get_encap_tmpl (
struct xfrmnl_sa* sa,
unsigned int* encap_type,
unsigned int* encap_sport,
unsigned int* encap_dport,
struct nl_addr** encap_oa)
1930 if (sa->ce_mask & XFRM_SA_ATTR_ENCAP)
1932 *encap_type = sa->encap->encap_type;
1933 *encap_sport = sa->encap->encap_sport;
1934 *encap_dport = sa->encap->encap_dport;
1943int xfrmnl_sa_set_encap_tmpl (
struct xfrmnl_sa* sa,
unsigned int encap_type,
unsigned int encap_sport,
unsigned int encap_dport,
struct nl_addr* encap_oa)
1947 if (sa->encap->encap_oa)
1949 memset(sa->encap, 0, sizeof (*sa->encap));
1950 }
else if ((sa->encap = calloc(1,
sizeof(*sa->encap))) == NULL)
1954 sa->encap->encap_type = encap_type;
1955 sa->encap->encap_sport = encap_sport;
1956 sa->encap->encap_dport = encap_dport;
1958 sa->encap->encap_oa = encap_oa;
1960 sa->ce_mask |= XFRM_SA_ATTR_ENCAP;
1965int xfrmnl_sa_get_tfcpad (
struct xfrmnl_sa* sa)
1967 if (sa->ce_mask & XFRM_SA_ATTR_TFCPAD)
1973int xfrmnl_sa_set_tfcpad (
struct xfrmnl_sa* sa,
unsigned int tfcpad)
1975 sa->tfcpad = tfcpad;
1976 sa->ce_mask |= XFRM_SA_ATTR_TFCPAD;
1981struct nl_addr* xfrmnl_sa_get_coaddr (
struct xfrmnl_sa* sa)
1983 if (sa->ce_mask & XFRM_SA_ATTR_COADDR)
1989int xfrmnl_sa_set_coaddr (
struct xfrmnl_sa* sa,
struct nl_addr* coaddr)
1997 sa->coaddr = coaddr;
1999 sa->ce_mask |= XFRM_SA_ATTR_COADDR;
2004int xfrmnl_sa_get_mark (
struct xfrmnl_sa* sa,
unsigned int* mark_mask,
unsigned int* mark_value)
2006 if (mark_mask == NULL || mark_value == NULL)
2009 if (sa->ce_mask & XFRM_SA_ATTR_MARK)
2011 *mark_mask = sa->mark.m;
2012 *mark_value = sa->mark.v;
2020int xfrmnl_sa_set_mark (
struct xfrmnl_sa* sa,
unsigned int value,
unsigned int mask)
2024 sa->ce_mask |= XFRM_SA_ATTR_MARK;
2048int xfrmnl_sa_get_sec_ctx (
struct xfrmnl_sa* sa,
unsigned int* doi,
unsigned int* alg,
2049 unsigned int* len,
unsigned int* sid,
char* ctx_str)
2051 if (sa->ce_mask & XFRM_SA_ATTR_SECCTX)
2054 *doi = sa->sec_ctx->ctx_doi;
2056 *alg = sa->sec_ctx->ctx_alg;
2058 *len = sa->sec_ctx->ctx_len;
2060 memcpy (ctx_str, sa->sec_ctx->ctx, sa->sec_ctx->ctx_len);
2081int xfrmnl_sa_set_sec_ctx (
struct xfrmnl_sa* sa,
unsigned int doi,
unsigned int alg,
unsigned int len,
2082 unsigned int sid,
const char* ctx_str)
2084 _nl_auto_free
struct xfrmnl_user_sec_ctx *b = NULL;
2086 if (!(b = calloc(1,
sizeof (
struct xfrmnl_user_sec_ctx) + 1 + len)))
2089 b->len =
sizeof(
struct xfrmnl_user_sec_ctx) + len;
2090 b->exttype = XFRMA_SEC_CTX;
2094 memcpy (b->ctx, ctx_str, len);
2098 sa->sec_ctx = _nl_steal_pointer(&b);
2099 sa->ce_mask |= XFRM_SA_ATTR_SECCTX;
2104int xfrmnl_sa_get_replay_maxage (
struct xfrmnl_sa* sa)
2106 if (sa->ce_mask & XFRM_SA_ATTR_REPLAY_MAXAGE)
2107 return sa->replay_maxage;
2112int xfrmnl_sa_set_replay_maxage (
struct xfrmnl_sa* sa,
unsigned int replay_maxage)
2114 sa->replay_maxage = replay_maxage;
2115 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_MAXAGE;
2120int xfrmnl_sa_get_replay_maxdiff (
struct xfrmnl_sa* sa)
2122 if (sa->ce_mask & XFRM_SA_ATTR_REPLAY_MAXDIFF)
2123 return sa->replay_maxdiff;
2128int xfrmnl_sa_set_replay_maxdiff (
struct xfrmnl_sa* sa,
unsigned int replay_maxdiff)
2130 sa->replay_maxdiff = replay_maxdiff;
2131 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_MAXDIFF;
2136int xfrmnl_sa_get_replay_state (
struct xfrmnl_sa* sa,
unsigned int* oseq,
unsigned int* seq,
unsigned int* bmp)
2138 if (sa->ce_mask & XFRM_SA_ATTR_REPLAY_STATE)
2140 if (sa->replay_state_esn == NULL)
2142 *oseq = sa->replay_state.oseq;
2143 *seq = sa->replay_state.seq;
2144 *bmp = sa->replay_state.bitmap;
2157int xfrmnl_sa_set_replay_state (
struct xfrmnl_sa* sa,
unsigned int oseq,
unsigned int seq,
unsigned int bitmap)
2159 sa->replay_state.oseq = oseq;
2160 sa->replay_state.seq = seq;
2161 sa->replay_state.bitmap = bitmap;
2162 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_STATE;
2167int xfrmnl_sa_get_replay_state_esn (
struct xfrmnl_sa* sa,
unsigned int* oseq,
unsigned int* seq,
unsigned int* oseq_hi,
2168 unsigned int* seq_hi,
unsigned int* replay_window,
unsigned int* bmp_len,
unsigned int* bmp)
2170 if (sa->ce_mask & XFRM_SA_ATTR_REPLAY_STATE)
2172 if (sa->replay_state_esn)
2174 *oseq = sa->replay_state_esn->oseq;
2175 *seq = sa->replay_state_esn->seq;
2176 *oseq_hi= sa->replay_state_esn->oseq_hi;
2177 *seq_hi = sa->replay_state_esn->seq_hi;
2178 *replay_window = sa->replay_state_esn->replay_window;
2179 *bmp_len = sa->replay_state_esn->bmp_len;
2180 memcpy (bmp, sa->replay_state_esn->bmp, sa->replay_state_esn->bmp_len * sizeof (uint32_t));
2193int xfrmnl_sa_set_replay_state_esn (
struct xfrmnl_sa* sa,
unsigned int oseq,
unsigned int seq,
2194 unsigned int oseq_hi,
unsigned int seq_hi,
unsigned int replay_window,
2195 unsigned int bmp_len,
unsigned int* bmp)
2197 _nl_auto_free
struct xfrmnl_replay_state_esn *b = NULL;
2199 if (!(b = calloc (1,
sizeof (
struct xfrmnl_replay_state_esn) + (
sizeof (uint32_t) * bmp_len))))
2204 b->oseq_hi = oseq_hi;
2206 b->replay_window = replay_window;
2207 b->bmp_len = bmp_len;
2208 memcpy (b->bmp, bmp, bmp_len * sizeof (uint32_t));
2210 free(sa->replay_state_esn);
2211 sa->replay_state_esn = _nl_steal_pointer(&b);
2212 sa->ce_mask |= XFRM_SA_ATTR_REPLAY_STATE;
2226int xfrmnl_sa_get_user_offload(
struct xfrmnl_sa *sa,
int *ifindex, uint8_t *flags)
2230 if (sa->ce_mask & XFRM_SA_ATTR_OFFLOAD_DEV && sa->user_offload) {
2232 *ifindex = sa->user_offload->ifindex;
2234 *flags = sa->user_offload->flags;
2251int xfrmnl_sa_set_user_offload(
struct xfrmnl_sa *sa,
int ifindex, uint8_t flags)
2253 _nl_auto_free
struct xfrmnl_user_offload *b = NULL;
2255 if (!(b = calloc(1,
sizeof(*b))))
2258 b->ifindex = ifindex;
2261 free(sa->user_offload);
2262 sa->user_offload = _nl_steal_pointer(&b);
2263 sa->ce_mask |= XFRM_SA_ATTR_OFFLOAD_DEV;
2268int xfrmnl_sa_is_hardexpiry_reached (
struct xfrmnl_sa* sa)
2270 if (sa->ce_mask & XFRM_SA_ATTR_EXPIRE)
2271 return (sa->hard > 0 ? 1: 0);
2276int xfrmnl_sa_is_expiry_reached (
struct xfrmnl_sa* sa)
2278 if (sa->ce_mask & XFRM_SA_ATTR_EXPIRE)
2286static struct nl_object_ops xfrm_sa_obj_ops = {
2287 .oo_name =
"xfrm/sa",
2288 .oo_size =
sizeof(
struct xfrmnl_sa),
2289 .oo_constructor = xfrm_sa_alloc_data,
2290 .oo_free_data = xfrm_sa_free_data,
2291 .oo_clone = xfrm_sa_clone,
2297 .oo_compare = xfrm_sa_compare,
2298 .oo_attrs2str = xfrm_sa_attrs2str,
2299 .oo_id_attrs = (XFRM_SA_ATTR_DADDR | XFRM_SA_ATTR_SPI | XFRM_SA_ATTR_PROTO),
2302static struct nl_af_group xfrm_sa_groups[] = {
2303 { AF_UNSPEC, XFRMNLGRP_SA },
2304 { AF_UNSPEC, XFRMNLGRP_EXPIRE },
2305 { END_OF_GROUP_LIST },
2308static struct nl_cache_ops xfrmnl_sa_ops = {
2309 .co_name =
"xfrm/sa",
2310 .co_hdrsize =
sizeof(
struct xfrm_usersa_info),
2312 { XFRM_MSG_NEWSA, NL_ACT_NEW,
"new" },
2313 { XFRM_MSG_DELSA, NL_ACT_DEL,
"del" },
2314 { XFRM_MSG_GETSA, NL_ACT_GET,
"get" },
2315 { XFRM_MSG_EXPIRE, NL_ACT_UNSPEC,
"expire"},
2316 { XFRM_MSG_UPDSA, NL_ACT_NEW,
"update"},
2317 END_OF_MSGTYPES_LIST,
2319 .co_protocol = NETLINK_XFRM,
2320 .co_groups = xfrm_sa_groups,
2321 .co_request_update = xfrm_sa_request_update,
2322 .co_msg_parser = xfrm_sa_msg_parser,
2323 .co_obj_ops = &xfrm_sa_obj_ops,
2324 .co_include_event = &xfrm_sa_update_cache
2332static void __attribute__ ((constructor)) xfrm_sa_init(
void)
2337static void __attribute__ ((destructor)) xfrm_sa_exit(
void)
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.
struct xfrmnl_sel * xfrmnl_sel_clone(struct xfrmnl_sel *sel)
Clone existing selector 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_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.
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 * 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.
int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
Add a unspecific attribute to netlink message.
struct nlattr * nla_reserve(struct nl_msg *msg, int attrtype, int attrlen)
Reserve space for a attribute.
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_search(struct nl_cache *cache, struct nl_object *needle)
Search object in cache.
struct nl_object * nl_cache_get_next(struct nl_object *obj)
Return the next element in the cache.
void nl_cache_remove(struct nl_object *obj)
Remove object from 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.
int nl_cache_move(struct nl_cache *cache, struct nl_object *obj)
Move object from one cache to another.
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 nl_object_get_msgtype(const struct nl_object *obj)
Return the netlink message type the object was derived from.
uint64_t nl_object_diff64(struct nl_object *a, struct nl_object *b)
Compute bitmask representing difference in attribute values.
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.