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"
136#include "nl-aux-core/nl-core.h"
137#include "nl-aux-xfrm/nl-xfrm.h"
142 struct nl_addr* daddr;
151 struct xfrmnl_sa_id sa_id;
152 struct nl_addr* saddr;
157 uint32_t replay_maxage;
158 uint32_t replay_maxdiff;
163#define XFRM_AE_ATTR_DADDR 0x01
164#define XFRM_AE_ATTR_SPI 0x02
165#define XFRM_AE_ATTR_PROTO 0x04
166#define XFRM_AE_ATTR_SADDR 0x08
167#define XFRM_AE_ATTR_FLAGS 0x10
168#define XFRM_AE_ATTR_REQID 0x20
169#define XFRM_AE_ATTR_MARK 0x40
170#define XFRM_AE_ATTR_LIFETIME 0x80
171#define XFRM_AE_ATTR_REPLAY_MAXAGE 0x100
172#define XFRM_AE_ATTR_REPLAY_MAXDIFF 0x200
173#define XFRM_AE_ATTR_REPLAY_STATE 0x400
174#define XFRM_AE_ATTR_FAMILY 0x800
176static struct nl_object_ops xfrm_ae_obj_ops;
180static void xfrm_ae_free_data(
struct nl_object *c)
182 struct xfrmnl_ae* ae = nl_object_priv (c);
190 if (ae->replay_state_esn)
191 free (ae->replay_state_esn);
194static int xfrm_ae_clone(
struct nl_object *_dst,
struct nl_object *_src)
196 struct xfrmnl_ae* dst = nl_object_priv(_dst);
197 struct xfrmnl_ae* src = nl_object_priv(_src);
199 dst->sa_id.daddr = NULL;
201 dst->replay_state_esn = NULL;
203 if (src->sa_id.daddr) {
204 if ((dst->sa_id.daddr =
nl_addr_clone (src->sa_id.daddr)) == NULL)
213 if (src->replay_state_esn) {
216 if ((dst->replay_state_esn = malloc (len)) == NULL)
218 memcpy (dst->replay_state_esn, src->replay_state_esn, len);
224static uint64_t xfrm_ae_compare(
struct nl_object *_a,
struct nl_object *_b,
225 uint64_t attrs,
int flags)
227 struct xfrmnl_ae* a = (
struct xfrmnl_ae *) _a;
228 struct xfrmnl_ae* b = (
struct xfrmnl_ae *) _b;
232#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
233 diff |= _DIFF(XFRM_AE_ATTR_DADDR,
235 diff |= _DIFF(XFRM_AE_ATTR_SPI, a->sa_id.spi != b->sa_id.spi);
236 diff |= _DIFF(XFRM_AE_ATTR_PROTO, a->sa_id.proto != b->sa_id.proto);
237 diff |= _DIFF(XFRM_AE_ATTR_SADDR,
nl_addr_cmp(a->saddr, b->saddr));
238 diff |= _DIFF(XFRM_AE_ATTR_FLAGS, a->flags != b->flags);
239 diff |= _DIFF(XFRM_AE_ATTR_REQID, a->reqid != b->reqid);
240 diff |= _DIFF(XFRM_AE_ATTR_MARK,
241 (a->mark.v & a->mark.m) != (b->mark.v & b->mark.m));
242 diff |= _DIFF(XFRM_AE_ATTR_REPLAY_MAXAGE,
243 a->replay_maxage != b->replay_maxage);
244 diff |= _DIFF(XFRM_AE_ATTR_REPLAY_MAXDIFF,
245 a->replay_maxdiff != b->replay_maxdiff);
248 found = AVAILABLE_MISMATCH (a, b, XFRM_AE_ATTR_REPLAY_STATE);
251 if (((a->replay_state_esn != NULL) && (b->replay_state_esn == NULL)) ||
252 ((a->replay_state_esn == NULL) && (b->replay_state_esn != NULL)))
257 if (a->replay_state_esn)
259 if (a->replay_state_esn->bmp_len != b->replay_state_esn->bmp_len)
264 diff |= memcmp (a->replay_state_esn, b->replay_state_esn, len);
269 if ((a->replay_state.oseq != b->replay_state.oseq) ||
270 (a->replay_state.seq != b->replay_state.seq) ||
271 (a->replay_state.bitmap != b->replay_state.bitmap))
285static const struct trans_tbl ae_attrs[] =
287 __ADD(XFRM_AE_ATTR_DADDR, daddr),
288 __ADD(XFRM_AE_ATTR_SPI, spi),
289 __ADD(XFRM_AE_ATTR_PROTO, protocol),
290 __ADD(XFRM_AE_ATTR_SADDR, saddr),
291 __ADD(XFRM_AE_ATTR_FLAGS, flags),
292 __ADD(XFRM_AE_ATTR_REQID, reqid),
293 __ADD(XFRM_AE_ATTR_MARK, mark),
294 __ADD(XFRM_AE_ATTR_LIFETIME, cur_lifetime),
295 __ADD(XFRM_AE_ATTR_REPLAY_MAXAGE, replay_maxage),
296 __ADD(XFRM_AE_ATTR_REPLAY_MAXDIFF, replay_maxdiff),
297 __ADD(XFRM_AE_ATTR_REPLAY_STATE, replay_state),
300static char* xfrm_ae_attrs2str (
int attrs,
char *buf,
size_t len)
302 return __flags2str(attrs, buf, len, ae_attrs, ARRAY_SIZE(ae_attrs));
311static const struct trans_tbl ae_flags[] = {
312 __ADD(XFRM_AE_UNSPEC, unspecified),
313 __ADD(XFRM_AE_RTHR, replay threshold),
314 __ADD(XFRM_AE_RVAL, replay value),
315 __ADD(XFRM_AE_LVAL, lifetime value),
316 __ADD(XFRM_AE_ETHR, expiry time threshold),
317 __ADD(XFRM_AE_CR, replay update event),
318 __ADD(XFRM_AE_CE, timer expiry event),
319 __ADD(XFRM_AE_CU, policy update event),
322char* xfrmnl_ae_flags2str(
int flags,
char *buf,
size_t len)
324 return __flags2str (flags, buf, len, ae_flags, ARRAY_SIZE(ae_flags));
327int xfrmnl_ae_str2flag(
const char *name)
329 return __str2flags(name, ae_flags, ARRAY_SIZE(ae_flags));
333static void xfrm_ae_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
335 char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
336 struct xfrmnl_ae* ae = (
struct xfrmnl_ae *) a;
337 char flags[128], buf[128];
338 time_t add_time, use_time;
339 struct tm *add_time_tm, *use_time_tm;
342 nl_dump_line(p,
"src %s dst %s \n",
nl_addr2str(ae->saddr, src,
sizeof(src)),
345 nl_dump_line(p,
"\tproto %s spi 0x%x reqid %u ",
346 nl_ip_proto2str (ae->sa_id.proto, buf, sizeof (buf)),
347 ae->sa_id.spi, ae->reqid);
349 xfrmnl_ae_flags2str(ae->flags, flags, sizeof (flags));
350 nl_dump_line(p,
"flags %s(0x%x) mark mask/value 0x%x/0x%x \n", flags,
351 ae->flags, ae->mark.m, ae->mark.v);
353 nl_dump_line(p,
"\tlifetime current: \n");
354 nl_dump_line(p,
"\t\tbytes %llu packets %llu \n",
355 (
long long unsigned)ae->lifetime_cur.bytes,
356 (
long long unsigned)ae->lifetime_cur.packets);
357 if (ae->lifetime_cur.add_time != 0)
359 add_time = ae->lifetime_cur.add_time;
360 add_time_tm = gmtime_r (&add_time, &tm_buf);
361 strftime (flags, 128,
"%Y-%m-%d %H-%M-%S", add_time_tm);
365 sprintf (flags,
"%s",
"-");
368 if (ae->lifetime_cur.use_time != 0)
370 use_time = ae->lifetime_cur.use_time;
371 use_time_tm = gmtime_r (&use_time, &tm_buf);
372 strftime (buf, 128,
"%Y-%m-%d %H-%M-%S", use_time_tm);
376 sprintf (buf,
"%s",
"-");
378 nl_dump_line(p,
"\t\tadd_time: %s, use_time: %s\n", flags, buf);
380 nl_dump_line(p,
"\treplay info: \n");
381 nl_dump_line(p,
"\t\tmax age %u max diff %u \n", ae->replay_maxage, ae->replay_maxdiff);
383 nl_dump_line(p,
"\treplay state info: \n");
384 if (ae->replay_state_esn)
386 nl_dump_line(p,
"\t\toseq %u seq %u oseq_hi %u seq_hi %u replay window: %u \n",
387 ae->replay_state_esn->oseq, ae->replay_state_esn->seq,
388 ae->replay_state_esn->oseq_hi, ae->replay_state_esn->seq_hi,
389 ae->replay_state_esn->replay_window);
393 nl_dump_line(p,
"\t\toseq %u seq %u bitmap: %u \n", ae->replay_state.oseq,
394 ae->replay_state.seq, ae->replay_state.bitmap);
400static void xfrm_ae_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
402 xfrm_ae_dump_line(a, p);
405static void xfrm_ae_dump_stats(
struct nl_object *a,
struct nl_dump_params *p)
407 xfrm_ae_dump_details(a, p);
411static int build_xfrm_ae_message(
struct xfrmnl_ae *tmpl,
int cmd,
int flags,
412 struct nl_msg **result)
415 struct xfrm_aevent_id ae_id;
417 if (!(tmpl->ce_mask & XFRM_AE_ATTR_DADDR) ||
418 !(tmpl->ce_mask & XFRM_AE_ATTR_SPI) ||
419 !(tmpl->ce_mask & XFRM_AE_ATTR_PROTO))
420 return -NLE_MISSING_ATTR;
422 memset(&ae_id, 0,
sizeof(ae_id));
425 ae_id.sa_id.spi = htonl(tmpl->sa_id.spi);
426 ae_id.sa_id.family = tmpl->sa_id.family;
427 ae_id.sa_id.proto = tmpl->sa_id.proto;
429 if (tmpl->ce_mask & XFRM_AE_ATTR_SADDR)
432 if (tmpl->ce_mask & XFRM_AE_ATTR_FLAGS)
433 ae_id.flags = tmpl->flags;
435 if (tmpl->ce_mask & XFRM_AE_ATTR_REQID)
436 ae_id.reqid = tmpl->reqid;
442 if (
nlmsg_append(msg, &ae_id,
sizeof(ae_id), NLMSG_ALIGNTO) < 0)
443 goto nla_put_failure;
445 if (tmpl->ce_mask & XFRM_AE_ATTR_MARK)
448 if (tmpl->ce_mask & XFRM_AE_ATTR_LIFETIME)
451 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_MAXAGE)
452 NLA_PUT_U32 (msg, XFRMA_ETIMER_THRESH, tmpl->replay_maxage);
454 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_MAXDIFF)
455 NLA_PUT_U32 (msg, XFRMA_REPLAY_THRESH, tmpl->replay_maxdiff);
457 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_STATE) {
458 if (tmpl->replay_state_esn) {
459 uint32_t len =
sizeof (
struct xfrm_replay_state_esn) + (sizeof (uint32_t) * tmpl->replay_state_esn->bmp_len);
460 NLA_PUT (msg, XFRMA_REPLAY_ESN_VAL, len, tmpl->replay_state_esn);
480int xfrmnl_ae_set(
struct nl_sock* sk,
struct xfrmnl_ae* ae,
int flags)
485 if ((err = build_xfrm_ae_message(ae, XFRM_MSG_NEWAE, flags|NLM_F_REPLACE, &msg)) < 0)
503struct xfrmnl_ae* xfrmnl_ae_alloc(
void)
508void xfrmnl_ae_put(
struct xfrmnl_ae* ae)
515static struct nla_policy xfrm_ae_policy[XFRMA_MAX+1] = {
516 [XFRMA_LTIME_VAL] = { .
minlen =
sizeof(
struct xfrm_lifetime_cur) },
517 [XFRMA_REPLAY_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state) },
518 [XFRMA_REPLAY_THRESH] = { .type =
NLA_U32 },
519 [XFRMA_ETIMER_THRESH] = { .type =
NLA_U32 },
520 [XFRMA_SRCADDR] = { .minlen =
sizeof(xfrm_address_t) },
521 [XFRMA_MARK] = { .minlen =
sizeof(
struct xfrm_mark) },
522 [XFRMA_REPLAY_ESN_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state_esn) },
525int xfrmnl_ae_parse(
struct nlmsghdr *n,
struct xfrmnl_ae **result)
527 _nl_auto_xfrmnl_ae
struct xfrmnl_ae *ae = NULL;
528 struct nlattr *tb[XFRMA_MAX + 1];
529 struct xfrm_aevent_id* ae_id;
532 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 if (!(ae->sa_id.daddr =
544 _nl_addr_build(ae_id->sa_id.family, &ae_id->sa_id.daddr)))
546 ae->sa_id.family= ae_id->sa_id.family;
547 ae->sa_id.spi = ntohl(ae_id->sa_id.spi);
548 ae->sa_id.proto = ae_id->sa_id.proto;
549 if (!(ae->saddr = _nl_addr_build(ae_id->sa_id.family, &ae_id->saddr)))
551 ae->reqid = ae_id->reqid;
552 ae->flags = ae_id->flags;
553 ae->ce_mask |= (XFRM_AE_ATTR_DADDR | XFRM_AE_ATTR_FAMILY | XFRM_AE_ATTR_SPI |
554 XFRM_AE_ATTR_PROTO | XFRM_AE_ATTR_SADDR | XFRM_AE_ATTR_REQID |
557 if (tb[XFRMA_MARK]) {
558 struct xfrm_mark* m =
nla_data(tb[XFRMA_MARK]);
561 ae->ce_mask |= XFRM_AE_ATTR_MARK;
564 if (tb[XFRMA_LTIME_VAL]) {
565 struct xfrm_lifetime_cur* cur =
nla_data(tb[XFRMA_LTIME_VAL]);
567 ae->lifetime_cur.bytes = cur->bytes;
568 ae->lifetime_cur.packets = cur->packets;
569 ae->lifetime_cur.add_time = cur->add_time;
570 ae->lifetime_cur.use_time = cur->use_time;
571 ae->ce_mask |= XFRM_AE_ATTR_LIFETIME;
574 if (tb[XFRM_AE_ETHR]) {
575 ae->replay_maxage = *(uint32_t*)
nla_data(tb[XFRM_AE_ETHR]);
576 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXAGE;
579 if (tb[XFRM_AE_RTHR]) {
580 ae->replay_maxdiff = *(uint32_t*)
nla_data(tb[XFRM_AE_RTHR]);
581 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXDIFF;
584 if (tb[XFRMA_REPLAY_ESN_VAL]) {
585 struct xfrm_replay_state_esn* esn =
nla_data (tb[XFRMA_REPLAY_ESN_VAL]);
588 if ((ae->replay_state_esn = calloc (1, len)) == NULL)
590 ae->replay_state_esn->oseq = esn->oseq;
591 ae->replay_state_esn->seq = esn->seq;
592 ae->replay_state_esn->oseq_hi = esn->oseq_hi;
593 ae->replay_state_esn->seq_hi = esn->seq_hi;
594 ae->replay_state_esn->replay_window = esn->replay_window;
595 ae->replay_state_esn->bmp_len = esn->bmp_len;
596 memcpy (ae->replay_state_esn->bmp, esn->bmp, sizeof (uint32_t) * esn->bmp_len);
597 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
601 struct xfrm_replay_state* replay_state =
nla_data (tb[XFRMA_REPLAY_VAL]);
602 ae->replay_state.oseq = replay_state->oseq;
603 ae->replay_state.seq = replay_state->seq;
604 ae->replay_state.bitmap = replay_state->bitmap;
605 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
607 ae->replay_state_esn = NULL;
610 *result = _nl_steal_pointer(&ae);
614static int xfrm_ae_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
615 struct nlmsghdr *n,
struct nl_parser_param *pp)
617 struct xfrmnl_ae* ae;
620 if ((err = xfrmnl_ae_parse(n, &ae)) < 0)
623 err = pp->pp_cb((
struct nl_object *) ae, pp);
634int xfrmnl_ae_build_get_request(
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
635 unsigned int mark_mask,
unsigned int mark_value,
struct nl_msg **result)
638 struct xfrm_aevent_id ae_id;
643 fprintf(stderr,
"APPLICATION BUG: %s:%d:%s: A valid destination address, spi must be specified\n",
644 __FILE__, __LINE__, __func__);
646 return -NLE_MISSING_ATTR;
649 memset(&ae_id, 0,
sizeof(ae_id));
651 ae_id.sa_id.spi = htonl(spi);
653 ae_id.sa_id.proto = protocol;
658 if (
nlmsg_append(msg, &ae_id,
sizeof(ae_id), NLMSG_ALIGNTO) < 0)
659 goto nla_put_failure;
673int xfrmnl_ae_get_kernel(
struct nl_sock* sock,
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
674 unsigned int mark_mask,
unsigned int mark_value,
struct xfrmnl_ae** result)
676 struct nl_msg *msg = NULL;
677 struct nl_object *obj;
680 if ((err = xfrmnl_ae_build_get_request(daddr, spi, protocol, mark_mask, mark_value, &msg)) < 0)
688 if ((err =
nl_pickup(sock, &xfrm_ae_msg_parser, &obj)) < 0)
692 *result = (
struct xfrmnl_ae *) obj;
708static inline int __assign_addr(
struct xfrmnl_ae* ae,
struct nl_addr **pos,
709 struct nl_addr *
new,
int flag,
int nocheck)
712 if (ae->ce_mask & XFRM_AE_ATTR_FAMILY) {
714 return -NLE_AF_MISMATCH;
717 ae->ce_mask |= XFRM_AE_ATTR_FAMILY;
733struct nl_addr* xfrmnl_ae_get_daddr (
struct xfrmnl_ae* ae)
735 if (ae->ce_mask & XFRM_AE_ATTR_DADDR)
736 return ae->sa_id.daddr;
741int xfrmnl_ae_set_daddr (
struct xfrmnl_ae* ae,
struct nl_addr* addr)
743 return __assign_addr(ae, &ae->sa_id.daddr, addr, XFRM_AE_ATTR_DADDR, 0);
746int xfrmnl_ae_get_spi (
struct xfrmnl_ae* ae)
748 if (ae->ce_mask & XFRM_AE_ATTR_SPI)
749 return ae->sa_id.spi;
754int xfrmnl_ae_set_spi (
struct xfrmnl_ae* ae,
unsigned int spi)
757 ae->ce_mask |= XFRM_AE_ATTR_SPI;
762int xfrmnl_ae_get_family (
struct xfrmnl_ae* ae)
764 if (ae->ce_mask & XFRM_AE_ATTR_FAMILY)
765 return ae->sa_id.family;
770int xfrmnl_ae_set_family (
struct xfrmnl_ae* ae,
unsigned int family)
772 ae->sa_id.family = family;
773 ae->ce_mask |= XFRM_AE_ATTR_FAMILY;
778int xfrmnl_ae_get_proto (
struct xfrmnl_ae* ae)
780 if (ae->ce_mask & XFRM_AE_ATTR_PROTO)
781 return ae->sa_id.proto;
786int xfrmnl_ae_set_proto (
struct xfrmnl_ae* ae,
unsigned int protocol)
788 ae->sa_id.proto = protocol;
789 ae->ce_mask |= XFRM_AE_ATTR_PROTO;
794struct nl_addr* xfrmnl_ae_get_saddr (
struct xfrmnl_ae* ae)
796 if (ae->ce_mask & XFRM_AE_ATTR_SADDR)
802int xfrmnl_ae_set_saddr (
struct xfrmnl_ae* ae,
struct nl_addr* addr)
804 return __assign_addr(ae, &ae->saddr, addr, XFRM_AE_ATTR_SADDR, 1);
807int xfrmnl_ae_get_flags (
struct xfrmnl_ae* ae)
809 if (ae->ce_mask & XFRM_AE_ATTR_FLAGS)
815int xfrmnl_ae_set_flags (
struct xfrmnl_ae* ae,
unsigned int flags)
818 ae->ce_mask |= XFRM_AE_ATTR_FLAGS;
823int xfrmnl_ae_get_reqid (
struct xfrmnl_ae* ae)
825 if (ae->ce_mask & XFRM_AE_ATTR_REQID)
831int xfrmnl_ae_set_reqid (
struct xfrmnl_ae* ae,
unsigned int reqid)
834 ae->ce_mask |= XFRM_AE_ATTR_REQID;
839int xfrmnl_ae_get_mark (
struct xfrmnl_ae* ae,
unsigned int* mark_mask,
unsigned int* mark_value)
841 if (mark_mask == NULL || mark_value == NULL)
844 if (ae->ce_mask & XFRM_AE_ATTR_MARK)
846 *mark_mask = ae->mark.m;
847 *mark_value = ae->mark.v;
855int xfrmnl_ae_set_mark (
struct xfrmnl_ae* ae,
unsigned int value,
unsigned int mask)
859 ae->ce_mask |= XFRM_AE_ATTR_MARK;
864int xfrmnl_ae_get_curlifetime (
struct xfrmnl_ae* ae,
unsigned long long int* curr_bytes,
865 unsigned long long int* curr_packets,
unsigned long long int* curr_add_time,
866 unsigned long long int* curr_use_time)
868 if (curr_bytes == NULL || curr_packets == NULL || curr_add_time == NULL || curr_use_time == NULL)
871 if (ae->ce_mask & XFRM_AE_ATTR_LIFETIME)
873 *curr_bytes = ae->lifetime_cur.bytes;
874 *curr_packets = ae->lifetime_cur.packets;
875 *curr_add_time = ae->lifetime_cur.add_time;
876 *curr_use_time = ae->lifetime_cur.use_time;
884int xfrmnl_ae_set_curlifetime (
struct xfrmnl_ae* ae,
unsigned long long int curr_bytes,
885 unsigned long long int curr_packets,
unsigned long long int curr_add_time,
886 unsigned long long int curr_use_time)
888 ae->lifetime_cur.bytes = curr_bytes;
889 ae->lifetime_cur.packets = curr_packets;
890 ae->lifetime_cur.add_time = curr_add_time;
891 ae->lifetime_cur.use_time = curr_use_time;
892 ae->ce_mask |= XFRM_AE_ATTR_LIFETIME;
897int xfrmnl_ae_get_replay_maxage (
struct xfrmnl_ae* ae)
899 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_MAXAGE)
900 return ae->replay_maxage;
905int xfrmnl_ae_set_replay_maxage (
struct xfrmnl_ae* ae,
unsigned int replay_maxage)
907 ae->replay_maxage = replay_maxage;
908 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXAGE;
913int xfrmnl_ae_get_replay_maxdiff (
struct xfrmnl_ae* ae)
915 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_MAXDIFF)
916 return ae->replay_maxdiff;
921int xfrmnl_ae_set_replay_maxdiff (
struct xfrmnl_ae* ae,
unsigned int replay_maxdiff)
923 ae->replay_maxdiff = replay_maxdiff;
924 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXDIFF;
929int xfrmnl_ae_get_replay_state (
struct xfrmnl_ae* ae,
unsigned int* oseq,
unsigned int* seq,
unsigned int* bmp)
931 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_STATE)
933 if (ae->replay_state_esn == NULL)
935 *oseq = ae->replay_state.oseq;
936 *seq = ae->replay_state.seq;
937 *bmp = ae->replay_state.bitmap;
950int xfrmnl_ae_set_replay_state (
struct xfrmnl_ae* ae,
unsigned int oseq,
unsigned int seq,
unsigned int bitmap)
952 ae->replay_state.oseq = oseq;
953 ae->replay_state.seq = seq;
954 ae->replay_state.bitmap = bitmap;
955 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
960int xfrmnl_ae_get_replay_state_esn(
struct xfrmnl_ae* ae,
unsigned int* oseq,
unsigned int* seq,
unsigned int* oseq_hi,
961 unsigned int* seq_hi,
unsigned int* replay_window,
unsigned int* bmp_len,
unsigned int* bmp)
963 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_STATE)
965 if (ae->replay_state_esn)
967 *oseq = ae->replay_state_esn->oseq;
968 *seq = ae->replay_state_esn->seq;
969 *oseq_hi= ae->replay_state_esn->oseq_hi;
970 *seq_hi = ae->replay_state_esn->seq_hi;
971 *replay_window = ae->replay_state_esn->replay_window;
972 *bmp_len = ae->replay_state_esn->bmp_len;
973 memcpy (bmp, ae->replay_state_esn->bmp, ae->replay_state_esn->bmp_len * sizeof (uint32_t));
986int xfrmnl_ae_set_replay_state_esn(
struct xfrmnl_ae* ae,
unsigned int oseq,
unsigned int seq,
987 unsigned int oseq_hi,
unsigned int seq_hi,
unsigned int replay_window,
988 unsigned int bmp_len,
unsigned int* bmp)
991 if (ae->replay_state_esn)
992 free (ae->replay_state_esn);
994 if ((ae->replay_state_esn = calloc (1,
sizeof (
struct xfrmnl_replay_state_esn) +
sizeof (uint32_t) * bmp_len)) == NULL)
997 ae->replay_state_esn->oseq = oseq;
998 ae->replay_state_esn->seq = seq;
999 ae->replay_state_esn->oseq_hi = oseq_hi;
1000 ae->replay_state_esn->seq_hi = seq_hi;
1001 ae->replay_state_esn->replay_window = replay_window;
1002 ae->replay_state_esn->bmp_len = bmp_len;
1003 memcpy (ae->replay_state_esn->bmp, bmp, bmp_len * sizeof (uint32_t));
1004 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
1011static struct nl_object_ops xfrm_ae_obj_ops = {
1012 .oo_name =
"xfrm/ae",
1013 .oo_size =
sizeof(
struct xfrmnl_ae),
1014 .oo_free_data = xfrm_ae_free_data,
1015 .oo_clone = xfrm_ae_clone,
1021 .oo_compare = xfrm_ae_compare,
1022 .oo_attrs2str = xfrm_ae_attrs2str,
1023 .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.
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.