123#include "nl-default.h"
125#include <linux/xfrm.h>
127#include <netlink/netlink.h>
128#include <netlink/cache.h>
129#include <netlink/object.h>
130#include <netlink/xfrm/ae.h>
133#include "nl-priv-dynamic-core/object-api.h"
134#include "nl-priv-dynamic-core/nl-core.h"
135#include "nl-priv-dynamic-core/cache-api.h"
140 struct nl_addr* daddr;
149 struct xfrmnl_sa_id sa_id;
150 struct nl_addr* saddr;
155 uint32_t replay_maxage;
156 uint32_t replay_maxdiff;
161#define XFRM_AE_ATTR_DADDR 0x01
162#define XFRM_AE_ATTR_SPI 0x02
163#define XFRM_AE_ATTR_PROTO 0x04
164#define XFRM_AE_ATTR_SADDR 0x08
165#define XFRM_AE_ATTR_FLAGS 0x10
166#define XFRM_AE_ATTR_REQID 0x20
167#define XFRM_AE_ATTR_MARK 0x40
168#define XFRM_AE_ATTR_LIFETIME 0x80
169#define XFRM_AE_ATTR_REPLAY_MAXAGE 0x100
170#define XFRM_AE_ATTR_REPLAY_MAXDIFF 0x200
171#define XFRM_AE_ATTR_REPLAY_STATE 0x400
172#define XFRM_AE_ATTR_FAMILY 0x800
174static struct nl_object_ops xfrm_ae_obj_ops;
178static void xfrm_ae_free_data(
struct nl_object *c)
180 struct xfrmnl_ae* ae = nl_object_priv (c);
188 if (ae->replay_state_esn)
189 free (ae->replay_state_esn);
192static int xfrm_ae_clone(
struct nl_object *_dst,
struct nl_object *_src)
194 struct xfrmnl_ae* dst = nl_object_priv(_dst);
195 struct xfrmnl_ae* src = nl_object_priv(_src);
197 dst->sa_id.daddr = NULL;
199 dst->replay_state_esn = NULL;
201 if (src->sa_id.daddr) {
202 if ((dst->sa_id.daddr =
nl_addr_clone (src->sa_id.daddr)) == NULL)
211 if (src->replay_state_esn) {
214 if ((dst->replay_state_esn = malloc (len)) == NULL)
216 memcpy (dst->replay_state_esn, src->replay_state_esn, len);
222static uint64_t xfrm_ae_compare(
struct nl_object *_a,
struct nl_object *_b,
223 uint64_t attrs,
int flags)
225 struct xfrmnl_ae* a = (
struct xfrmnl_ae *) _a;
226 struct xfrmnl_ae* b = (
struct xfrmnl_ae *) _b;
230#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
231 diff |= _DIFF(XFRM_AE_ATTR_DADDR,
233 diff |= _DIFF(XFRM_AE_ATTR_SPI, a->sa_id.spi != b->sa_id.spi);
234 diff |= _DIFF(XFRM_AE_ATTR_PROTO, a->sa_id.proto != b->sa_id.proto);
235 diff |= _DIFF(XFRM_AE_ATTR_SADDR,
nl_addr_cmp(a->saddr, b->saddr));
236 diff |= _DIFF(XFRM_AE_ATTR_FLAGS, a->flags != b->flags);
237 diff |= _DIFF(XFRM_AE_ATTR_REQID, a->reqid != b->reqid);
238 diff |= _DIFF(XFRM_AE_ATTR_MARK,
239 (a->mark.v & a->mark.m) != (b->mark.v & b->mark.m));
240 diff |= _DIFF(XFRM_AE_ATTR_REPLAY_MAXAGE,
241 a->replay_maxage != b->replay_maxage);
242 diff |= _DIFF(XFRM_AE_ATTR_REPLAY_MAXDIFF,
243 a->replay_maxdiff != b->replay_maxdiff);
246 found = AVAILABLE_MISMATCH (a, b, XFRM_AE_ATTR_REPLAY_STATE);
249 if (((a->replay_state_esn != NULL) && (b->replay_state_esn == NULL)) ||
250 ((a->replay_state_esn == NULL) && (b->replay_state_esn != NULL)))
255 if (a->replay_state_esn)
257 if (a->replay_state_esn->bmp_len != b->replay_state_esn->bmp_len)
262 diff |= memcmp (a->replay_state_esn, b->replay_state_esn, len);
267 if ((a->replay_state.oseq != b->replay_state.oseq) ||
268 (a->replay_state.seq != b->replay_state.seq) ||
269 (a->replay_state.bitmap != b->replay_state.bitmap))
283static const struct trans_tbl ae_attrs[] =
285 __ADD(XFRM_AE_ATTR_DADDR, daddr),
286 __ADD(XFRM_AE_ATTR_SPI, spi),
287 __ADD(XFRM_AE_ATTR_PROTO, protocol),
288 __ADD(XFRM_AE_ATTR_SADDR, saddr),
289 __ADD(XFRM_AE_ATTR_FLAGS, flags),
290 __ADD(XFRM_AE_ATTR_REQID, reqid),
291 __ADD(XFRM_AE_ATTR_MARK, mark),
292 __ADD(XFRM_AE_ATTR_LIFETIME, cur_lifetime),
293 __ADD(XFRM_AE_ATTR_REPLAY_MAXAGE, replay_maxage),
294 __ADD(XFRM_AE_ATTR_REPLAY_MAXDIFF, replay_maxdiff),
295 __ADD(XFRM_AE_ATTR_REPLAY_STATE, replay_state),
298static char* xfrm_ae_attrs2str (
int attrs,
char *buf,
size_t len)
300 return __flags2str(attrs, buf, len, ae_attrs, ARRAY_SIZE(ae_attrs));
309static const struct trans_tbl ae_flags[] = {
310 __ADD(XFRM_AE_UNSPEC, unspecified),
311 __ADD(XFRM_AE_RTHR, replay threshold),
312 __ADD(XFRM_AE_RVAL, replay value),
313 __ADD(XFRM_AE_LVAL, lifetime value),
314 __ADD(XFRM_AE_ETHR, expiry time threshold),
315 __ADD(XFRM_AE_CR, replay update event),
316 __ADD(XFRM_AE_CE, timer expiry event),
317 __ADD(XFRM_AE_CU, policy update event),
320char* xfrmnl_ae_flags2str(
int flags,
char *buf,
size_t len)
322 return __flags2str (flags, buf, len, ae_flags, ARRAY_SIZE(ae_flags));
325int xfrmnl_ae_str2flag(
const char *name)
327 return __str2flags(name, ae_flags, ARRAY_SIZE(ae_flags));
331static void xfrm_ae_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
333 char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
334 struct xfrmnl_ae* ae = (
struct xfrmnl_ae *) a;
335 char flags[128], buf[128];
336 time_t add_time, use_time;
337 struct tm *add_time_tm, *use_time_tm;
340 nl_dump_line(p,
"src %s dst %s \n",
nl_addr2str(ae->saddr, src,
sizeof(src)),
343 nl_dump_line(p,
"\tproto %s spi 0x%x reqid %u ",
344 nl_ip_proto2str (ae->sa_id.proto, buf, sizeof (buf)),
345 ae->sa_id.spi, ae->reqid);
347 xfrmnl_ae_flags2str(ae->flags, flags, sizeof (flags));
348 nl_dump_line(p,
"flags %s(0x%x) mark mask/value 0x%x/0x%x \n", flags,
349 ae->flags, ae->mark.m, ae->mark.v);
351 nl_dump_line(p,
"\tlifetime current: \n");
352 nl_dump_line(p,
"\t\tbytes %llu packets %llu \n",
353 (
long long unsigned)ae->lifetime_cur.bytes,
354 (
long long unsigned)ae->lifetime_cur.packets);
355 if (ae->lifetime_cur.add_time != 0)
357 add_time = ae->lifetime_cur.add_time;
358 add_time_tm = gmtime_r (&add_time, &tm_buf);
359 strftime (flags, 128,
"%Y-%m-%d %H-%M-%S", add_time_tm);
363 sprintf (flags,
"%s",
"-");
366 if (ae->lifetime_cur.use_time != 0)
368 use_time = ae->lifetime_cur.use_time;
369 use_time_tm = gmtime_r (&use_time, &tm_buf);
370 strftime (buf, 128,
"%Y-%m-%d %H-%M-%S", use_time_tm);
374 sprintf (buf,
"%s",
"-");
376 nl_dump_line(p,
"\t\tadd_time: %s, use_time: %s\n", flags, buf);
378 nl_dump_line(p,
"\treplay info: \n");
379 nl_dump_line(p,
"\t\tmax age %u max diff %u \n", ae->replay_maxage, ae->replay_maxdiff);
381 nl_dump_line(p,
"\treplay state info: \n");
382 if (ae->replay_state_esn)
384 nl_dump_line(p,
"\t\toseq %u seq %u oseq_hi %u seq_hi %u replay window: %u \n",
385 ae->replay_state_esn->oseq, ae->replay_state_esn->seq,
386 ae->replay_state_esn->oseq_hi, ae->replay_state_esn->seq_hi,
387 ae->replay_state_esn->replay_window);
391 nl_dump_line(p,
"\t\toseq %u seq %u bitmap: %u \n", ae->replay_state.oseq,
392 ae->replay_state.seq, ae->replay_state.bitmap);
398static void xfrm_ae_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
400 xfrm_ae_dump_line(a, p);
403static void xfrm_ae_dump_stats(
struct nl_object *a,
struct nl_dump_params *p)
405 xfrm_ae_dump_details(a, p);
409static int build_xfrm_ae_message(
struct xfrmnl_ae *tmpl,
int cmd,
int flags,
410 struct nl_msg **result)
413 struct xfrm_aevent_id ae_id;
415 if (!(tmpl->ce_mask & XFRM_AE_ATTR_DADDR) ||
416 !(tmpl->ce_mask & XFRM_AE_ATTR_SPI) ||
417 !(tmpl->ce_mask & XFRM_AE_ATTR_PROTO))
418 return -NLE_MISSING_ATTR;
420 memset(&ae_id, 0,
sizeof(ae_id));
423 ae_id.sa_id.spi = htonl(tmpl->sa_id.spi);
424 ae_id.sa_id.family = tmpl->sa_id.family;
425 ae_id.sa_id.proto = tmpl->sa_id.proto;
427 if (tmpl->ce_mask & XFRM_AE_ATTR_SADDR)
430 if (tmpl->ce_mask & XFRM_AE_ATTR_FLAGS)
431 ae_id.flags = tmpl->flags;
433 if (tmpl->ce_mask & XFRM_AE_ATTR_REQID)
434 ae_id.reqid = tmpl->reqid;
440 if (
nlmsg_append(msg, &ae_id,
sizeof(ae_id), NLMSG_ALIGNTO) < 0)
441 goto nla_put_failure;
443 if (tmpl->ce_mask & XFRM_AE_ATTR_MARK)
446 if (tmpl->ce_mask & XFRM_AE_ATTR_LIFETIME)
449 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_MAXAGE)
450 NLA_PUT_U32 (msg, XFRMA_ETIMER_THRESH, tmpl->replay_maxage);
452 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_MAXDIFF)
453 NLA_PUT_U32 (msg, XFRMA_REPLAY_THRESH, tmpl->replay_maxdiff);
455 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_STATE) {
456 if (tmpl->replay_state_esn) {
457 uint32_t len =
sizeof (
struct xfrm_replay_state_esn) + (sizeof (uint32_t) * tmpl->replay_state_esn->bmp_len);
458 NLA_PUT (msg, XFRMA_REPLAY_ESN_VAL, len, tmpl->replay_state_esn);
478int xfrmnl_ae_set(
struct nl_sock* sk,
struct xfrmnl_ae* ae,
int flags)
483 if ((err = build_xfrm_ae_message(ae, XFRM_MSG_NEWAE, flags|NLM_F_REPLACE, &msg)) < 0)
501struct xfrmnl_ae* xfrmnl_ae_alloc(
void)
506void xfrmnl_ae_put(
struct xfrmnl_ae* ae)
513static struct nla_policy xfrm_ae_policy[XFRMA_MAX+1] = {
514 [XFRMA_LTIME_VAL] = { .
minlen =
sizeof(
struct xfrm_lifetime_cur) },
515 [XFRMA_REPLAY_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state) },
516 [XFRMA_REPLAY_THRESH] = { .type =
NLA_U32 },
517 [XFRMA_ETIMER_THRESH] = { .type =
NLA_U32 },
518 [XFRMA_SRCADDR] = { .minlen =
sizeof(xfrm_address_t) },
519 [XFRMA_MARK] = { .minlen =
sizeof(
struct xfrm_mark) },
520 [XFRMA_REPLAY_ESN_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state_esn) },
523int xfrmnl_ae_parse(
struct nlmsghdr *n,
struct xfrmnl_ae **result)
525 struct xfrmnl_ae* ae;
526 struct nlattr *tb[XFRMA_MAX + 1];
527 struct xfrm_aevent_id* ae_id;
530 ae = xfrmnl_ae_alloc();
536 ae->ce_msgtype = n->nlmsg_type;
539 err =
nlmsg_parse(n,
sizeof(
struct xfrm_aevent_id), tb, XFRMA_MAX, xfrm_ae_policy);
543 ae->sa_id.daddr =
nl_addr_build(ae_id->sa_id.family, &ae_id->sa_id.daddr, sizeof (ae_id->sa_id.daddr));
544 ae->sa_id.family= ae_id->sa_id.family;
545 ae->sa_id.spi = ntohl(ae_id->sa_id.spi);
546 ae->sa_id.proto = ae_id->sa_id.proto;
547 ae->saddr =
nl_addr_build(ae_id->sa_id.family, &ae_id->saddr, sizeof (ae_id->saddr));
548 ae->reqid = ae_id->reqid;
549 ae->flags = ae_id->flags;
550 ae->ce_mask |= (XFRM_AE_ATTR_DADDR | XFRM_AE_ATTR_FAMILY | XFRM_AE_ATTR_SPI |
551 XFRM_AE_ATTR_PROTO | XFRM_AE_ATTR_SADDR | XFRM_AE_ATTR_REQID |
554 if (tb[XFRMA_MARK]) {
555 struct xfrm_mark* m =
nla_data(tb[XFRMA_MARK]);
558 ae->ce_mask |= XFRM_AE_ATTR_MARK;
561 if (tb[XFRMA_LTIME_VAL]) {
562 struct xfrm_lifetime_cur* cur =
nla_data(tb[XFRMA_LTIME_VAL]);
563 ae->lifetime_cur.bytes = cur->bytes;
564 ae->lifetime_cur.packets = cur->packets;
565 ae->lifetime_cur.add_time = cur->add_time;
566 ae->lifetime_cur.use_time = cur->use_time;
567 ae->ce_mask |= XFRM_AE_ATTR_LIFETIME;
570 if (tb[XFRM_AE_ETHR]) {
571 ae->replay_maxage = *(uint32_t*)
nla_data(tb[XFRM_AE_ETHR]);
572 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXAGE;
575 if (tb[XFRM_AE_RTHR]) {
576 ae->replay_maxdiff = *(uint32_t*)
nla_data(tb[XFRM_AE_RTHR]);
577 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXDIFF;
580 if (tb[XFRMA_REPLAY_ESN_VAL]) {
581 struct xfrm_replay_state_esn* esn =
nla_data (tb[XFRMA_REPLAY_ESN_VAL]);
584 if ((ae->replay_state_esn = calloc (1, len)) == NULL) {
588 ae->replay_state_esn->oseq = esn->oseq;
589 ae->replay_state_esn->seq = esn->seq;
590 ae->replay_state_esn->oseq_hi = esn->oseq_hi;
591 ae->replay_state_esn->seq_hi = esn->seq_hi;
592 ae->replay_state_esn->replay_window = esn->replay_window;
593 ae->replay_state_esn->bmp_len = esn->bmp_len;
594 memcpy (ae->replay_state_esn->bmp, esn->bmp, sizeof (uint32_t) * esn->bmp_len);
595 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
599 struct xfrm_replay_state* replay_state =
nla_data (tb[XFRMA_REPLAY_VAL]);
600 ae->replay_state.oseq = replay_state->oseq;
601 ae->replay_state.seq = replay_state->seq;
602 ae->replay_state.bitmap = replay_state->bitmap;
603 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
605 ae->replay_state_esn = NULL;
616static int xfrm_ae_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
617 struct nlmsghdr *n,
struct nl_parser_param *pp)
619 struct xfrmnl_ae* ae;
622 if ((err = xfrmnl_ae_parse(n, &ae)) < 0)
625 err = pp->pp_cb((
struct nl_object *) ae, pp);
636int xfrmnl_ae_build_get_request(
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
637 unsigned int mark_mask,
unsigned int mark_value,
struct nl_msg **result)
640 struct xfrm_aevent_id ae_id;
645 fprintf(stderr,
"APPLICATION BUG: %s:%d:%s: A valid destination address, spi must be specified\n",
646 __FILE__, __LINE__, __func__);
648 return -NLE_MISSING_ATTR;
651 memset(&ae_id, 0,
sizeof(ae_id));
653 ae_id.sa_id.spi = htonl(spi);
655 ae_id.sa_id.proto = protocol;
660 if (
nlmsg_append(msg, &ae_id,
sizeof(ae_id), NLMSG_ALIGNTO) < 0)
661 goto nla_put_failure;
675int xfrmnl_ae_get_kernel(
struct nl_sock* sock,
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
676 unsigned int mark_mask,
unsigned int mark_value,
struct xfrmnl_ae** result)
678 struct nl_msg *msg = NULL;
679 struct nl_object *obj;
682 if ((err = xfrmnl_ae_build_get_request(daddr, spi, protocol, mark_mask, mark_value, &msg)) < 0)
690 if ((err =
nl_pickup(sock, &xfrm_ae_msg_parser, &obj)) < 0)
694 *result = (
struct xfrmnl_ae *) obj;
710static inline int __assign_addr(
struct xfrmnl_ae* ae,
struct nl_addr **pos,
711 struct nl_addr *
new,
int flag,
int nocheck)
714 if (ae->ce_mask & XFRM_AE_ATTR_FAMILY) {
716 return -NLE_AF_MISMATCH;
719 ae->ce_mask |= XFRM_AE_ATTR_FAMILY;
735struct nl_addr* xfrmnl_ae_get_daddr (
struct xfrmnl_ae* ae)
737 if (ae->ce_mask & XFRM_AE_ATTR_DADDR)
738 return ae->sa_id.daddr;
743int xfrmnl_ae_set_daddr (
struct xfrmnl_ae* ae,
struct nl_addr* addr)
745 return __assign_addr(ae, &ae->sa_id.daddr, addr, XFRM_AE_ATTR_DADDR, 0);
748int xfrmnl_ae_get_spi (
struct xfrmnl_ae* ae)
750 if (ae->ce_mask & XFRM_AE_ATTR_SPI)
751 return ae->sa_id.spi;
756int xfrmnl_ae_set_spi (
struct xfrmnl_ae* ae,
unsigned int spi)
759 ae->ce_mask |= XFRM_AE_ATTR_SPI;
764int xfrmnl_ae_get_family (
struct xfrmnl_ae* ae)
766 if (ae->ce_mask & XFRM_AE_ATTR_FAMILY)
767 return ae->sa_id.family;
772int xfrmnl_ae_set_family (
struct xfrmnl_ae* ae,
unsigned int family)
774 ae->sa_id.family = family;
775 ae->ce_mask |= XFRM_AE_ATTR_FAMILY;
780int xfrmnl_ae_get_proto (
struct xfrmnl_ae* ae)
782 if (ae->ce_mask & XFRM_AE_ATTR_PROTO)
783 return ae->sa_id.proto;
788int xfrmnl_ae_set_proto (
struct xfrmnl_ae* ae,
unsigned int protocol)
790 ae->sa_id.proto = protocol;
791 ae->ce_mask |= XFRM_AE_ATTR_PROTO;
796struct nl_addr* xfrmnl_ae_get_saddr (
struct xfrmnl_ae* ae)
798 if (ae->ce_mask & XFRM_AE_ATTR_SADDR)
804int xfrmnl_ae_set_saddr (
struct xfrmnl_ae* ae,
struct nl_addr* addr)
806 return __assign_addr(ae, &ae->saddr, addr, XFRM_AE_ATTR_SADDR, 1);
809int xfrmnl_ae_get_flags (
struct xfrmnl_ae* ae)
811 if (ae->ce_mask & XFRM_AE_ATTR_FLAGS)
817int xfrmnl_ae_set_flags (
struct xfrmnl_ae* ae,
unsigned int flags)
820 ae->ce_mask |= XFRM_AE_ATTR_FLAGS;
825int xfrmnl_ae_get_reqid (
struct xfrmnl_ae* ae)
827 if (ae->ce_mask & XFRM_AE_ATTR_REQID)
833int xfrmnl_ae_set_reqid (
struct xfrmnl_ae* ae,
unsigned int reqid)
836 ae->ce_mask |= XFRM_AE_ATTR_REQID;
841int xfrmnl_ae_get_mark (
struct xfrmnl_ae* ae,
unsigned int* mark_mask,
unsigned int* mark_value)
843 if (mark_mask == NULL || mark_value == NULL)
846 if (ae->ce_mask & XFRM_AE_ATTR_MARK)
848 *mark_mask = ae->mark.m;
849 *mark_value = ae->mark.v;
857int xfrmnl_ae_set_mark (
struct xfrmnl_ae* ae,
unsigned int value,
unsigned int mask)
861 ae->ce_mask |= XFRM_AE_ATTR_MARK;
866int xfrmnl_ae_get_curlifetime (
struct xfrmnl_ae* ae,
unsigned long long int* curr_bytes,
867 unsigned long long int* curr_packets,
unsigned long long int* curr_add_time,
868 unsigned long long int* curr_use_time)
870 if (curr_bytes == NULL || curr_packets == NULL || curr_add_time == NULL || curr_use_time == NULL)
873 if (ae->ce_mask & XFRM_AE_ATTR_LIFETIME)
875 *curr_bytes = ae->lifetime_cur.bytes;
876 *curr_packets = ae->lifetime_cur.packets;
877 *curr_add_time = ae->lifetime_cur.add_time;
878 *curr_use_time = ae->lifetime_cur.use_time;
886int xfrmnl_ae_set_curlifetime (
struct xfrmnl_ae* ae,
unsigned long long int curr_bytes,
887 unsigned long long int curr_packets,
unsigned long long int curr_add_time,
888 unsigned long long int curr_use_time)
890 ae->lifetime_cur.bytes = curr_bytes;
891 ae->lifetime_cur.packets = curr_packets;
892 ae->lifetime_cur.add_time = curr_add_time;
893 ae->lifetime_cur.use_time = curr_use_time;
894 ae->ce_mask |= XFRM_AE_ATTR_LIFETIME;
899int xfrmnl_ae_get_replay_maxage (
struct xfrmnl_ae* ae)
901 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_MAXAGE)
902 return ae->replay_maxage;
907int xfrmnl_ae_set_replay_maxage (
struct xfrmnl_ae* ae,
unsigned int replay_maxage)
909 ae->replay_maxage = replay_maxage;
910 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXAGE;
915int xfrmnl_ae_get_replay_maxdiff (
struct xfrmnl_ae* ae)
917 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_MAXDIFF)
918 return ae->replay_maxdiff;
923int xfrmnl_ae_set_replay_maxdiff (
struct xfrmnl_ae* ae,
unsigned int replay_maxdiff)
925 ae->replay_maxdiff = replay_maxdiff;
926 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXDIFF;
931int xfrmnl_ae_get_replay_state (
struct xfrmnl_ae* ae,
unsigned int* oseq,
unsigned int* seq,
unsigned int* bmp)
933 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_STATE)
935 if (ae->replay_state_esn == NULL)
937 *oseq = ae->replay_state.oseq;
938 *seq = ae->replay_state.seq;
939 *bmp = ae->replay_state.bitmap;
952int xfrmnl_ae_set_replay_state (
struct xfrmnl_ae* ae,
unsigned int oseq,
unsigned int seq,
unsigned int bitmap)
954 ae->replay_state.oseq = oseq;
955 ae->replay_state.seq = seq;
956 ae->replay_state.bitmap = bitmap;
957 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
962int xfrmnl_ae_get_replay_state_esn(
struct xfrmnl_ae* ae,
unsigned int* oseq,
unsigned int* seq,
unsigned int* oseq_hi,
963 unsigned int* seq_hi,
unsigned int* replay_window,
unsigned int* bmp_len,
unsigned int* bmp)
965 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_STATE)
967 if (ae->replay_state_esn)
969 *oseq = ae->replay_state_esn->oseq;
970 *seq = ae->replay_state_esn->seq;
971 *oseq_hi= ae->replay_state_esn->oseq_hi;
972 *seq_hi = ae->replay_state_esn->seq_hi;
973 *replay_window = ae->replay_state_esn->replay_window;
974 *bmp_len = ae->replay_state_esn->bmp_len;
975 memcpy (bmp, ae->replay_state_esn->bmp, ae->replay_state_esn->bmp_len * sizeof (uint32_t));
988int xfrmnl_ae_set_replay_state_esn(
struct xfrmnl_ae* ae,
unsigned int oseq,
unsigned int seq,
989 unsigned int oseq_hi,
unsigned int seq_hi,
unsigned int replay_window,
990 unsigned int bmp_len,
unsigned int* bmp)
993 if (ae->replay_state_esn)
994 free (ae->replay_state_esn);
996 if ((ae->replay_state_esn = calloc (1,
sizeof (
struct xfrmnl_replay_state_esn) +
sizeof (uint32_t) * bmp_len)) == NULL)
999 ae->replay_state_esn->oseq = oseq;
1000 ae->replay_state_esn->seq = seq;
1001 ae->replay_state_esn->oseq_hi = oseq_hi;
1002 ae->replay_state_esn->seq_hi = seq_hi;
1003 ae->replay_state_esn->replay_window = replay_window;
1004 ae->replay_state_esn->bmp_len = bmp_len;
1005 memcpy (ae->replay_state_esn->bmp, bmp, bmp_len * sizeof (uint32_t));
1006 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
1013static struct nl_object_ops xfrm_ae_obj_ops = {
1014 .oo_name =
"xfrm/ae",
1015 .oo_size =
sizeof(
struct xfrmnl_ae),
1016 .oo_free_data = xfrm_ae_free_data,
1017 .oo_clone = xfrm_ae_clone,
1023 .oo_compare = xfrm_ae_compare,
1024 .oo_attrs2str = xfrm_ae_attrs2str,
1025 .oo_id_attrs = (XFRM_AE_ATTR_DADDR | XFRM_AE_ATTR_SPI | XFRM_AE_ATTR_PROTO),
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.
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.
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.
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.