123#include "nl-default.h"
126#include <linux/xfrm.h>
128#include <netlink/netlink.h>
129#include <netlink/cache.h>
130#include <netlink/object.h>
131#include <netlink/xfrm/ae.h>
134#include "nl-priv-dynamic-core/object-api.h"
135#include "nl-priv-dynamic-core/nl-core.h"
136#include "nl-priv-dynamic-core/cache-api.h"
137#include "nl-aux-core/nl-core.h"
138#include "nl-aux-xfrm/nl-xfrm.h"
143 struct nl_addr* daddr;
152 struct xfrmnl_sa_id sa_id;
153 struct nl_addr* saddr;
158 uint32_t replay_maxage;
159 uint32_t replay_maxdiff;
164#define XFRM_AE_ATTR_DADDR 0x01
165#define XFRM_AE_ATTR_SPI 0x02
166#define XFRM_AE_ATTR_PROTO 0x04
167#define XFRM_AE_ATTR_SADDR 0x08
168#define XFRM_AE_ATTR_FLAGS 0x10
169#define XFRM_AE_ATTR_REQID 0x20
170#define XFRM_AE_ATTR_MARK 0x40
171#define XFRM_AE_ATTR_LIFETIME 0x80
172#define XFRM_AE_ATTR_REPLAY_MAXAGE 0x100
173#define XFRM_AE_ATTR_REPLAY_MAXDIFF 0x200
174#define XFRM_AE_ATTR_REPLAY_STATE 0x400
175#define XFRM_AE_ATTR_FAMILY 0x800
177static struct nl_object_ops xfrm_ae_obj_ops;
181static void xfrm_ae_free_data(
struct nl_object *c)
183 struct xfrmnl_ae* ae = nl_object_priv (c);
191 if (ae->replay_state_esn)
192 free (ae->replay_state_esn);
195static int xfrm_ae_clone(
struct nl_object *_dst,
struct nl_object *_src)
197 struct xfrmnl_ae* dst = nl_object_priv(_dst);
198 struct xfrmnl_ae* src = nl_object_priv(_src);
200 dst->sa_id.daddr = NULL;
202 dst->replay_state_esn = NULL;
204 if (src->sa_id.daddr) {
205 if ((dst->sa_id.daddr =
nl_addr_clone (src->sa_id.daddr)) == NULL)
214 if (src->replay_state_esn) {
217 if ((dst->replay_state_esn = malloc (len)) == NULL)
219 memcpy (dst->replay_state_esn, src->replay_state_esn, len);
225static uint64_t xfrm_ae_compare(
struct nl_object *_a,
struct nl_object *_b,
226 uint64_t attrs,
int flags)
228 struct xfrmnl_ae* a = (
struct xfrmnl_ae *) _a;
229 struct xfrmnl_ae* b = (
struct xfrmnl_ae *) _b;
233#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ATTR, a, b, EXPR)
234 diff |= _DIFF(XFRM_AE_ATTR_DADDR,
236 diff |= _DIFF(XFRM_AE_ATTR_SPI, a->sa_id.spi != b->sa_id.spi);
237 diff |= _DIFF(XFRM_AE_ATTR_PROTO, a->sa_id.proto != b->sa_id.proto);
238 diff |= _DIFF(XFRM_AE_ATTR_SADDR,
nl_addr_cmp(a->saddr, b->saddr));
239 diff |= _DIFF(XFRM_AE_ATTR_FLAGS, a->flags != b->flags);
240 diff |= _DIFF(XFRM_AE_ATTR_REQID, a->reqid != b->reqid);
241 diff |= _DIFF(XFRM_AE_ATTR_MARK,
242 (a->mark.v & a->mark.m) != (b->mark.v & b->mark.m));
243 diff |= _DIFF(XFRM_AE_ATTR_REPLAY_MAXAGE,
244 a->replay_maxage != b->replay_maxage);
245 diff |= _DIFF(XFRM_AE_ATTR_REPLAY_MAXDIFF,
246 a->replay_maxdiff != b->replay_maxdiff);
249 found = AVAILABLE_MISMATCH (a, b, XFRM_AE_ATTR_REPLAY_STATE);
252 if (((a->replay_state_esn != NULL) && (b->replay_state_esn == NULL)) ||
253 ((a->replay_state_esn == NULL) && (b->replay_state_esn != NULL)))
258 if (a->replay_state_esn)
260 if (a->replay_state_esn->bmp_len != b->replay_state_esn->bmp_len)
265 diff |= memcmp (a->replay_state_esn, b->replay_state_esn, len);
270 if ((a->replay_state.oseq != b->replay_state.oseq) ||
271 (a->replay_state.seq != b->replay_state.seq) ||
272 (a->replay_state.bitmap != b->replay_state.bitmap))
286static const struct trans_tbl ae_attrs[] =
288 __ADD(XFRM_AE_ATTR_DADDR, daddr),
289 __ADD(XFRM_AE_ATTR_SPI, spi),
290 __ADD(XFRM_AE_ATTR_PROTO, protocol),
291 __ADD(XFRM_AE_ATTR_SADDR, saddr),
292 __ADD(XFRM_AE_ATTR_FLAGS, flags),
293 __ADD(XFRM_AE_ATTR_REQID, reqid),
294 __ADD(XFRM_AE_ATTR_MARK, mark),
295 __ADD(XFRM_AE_ATTR_LIFETIME, cur_lifetime),
296 __ADD(XFRM_AE_ATTR_REPLAY_MAXAGE, replay_maxage),
297 __ADD(XFRM_AE_ATTR_REPLAY_MAXDIFF, replay_maxdiff),
298 __ADD(XFRM_AE_ATTR_REPLAY_STATE, replay_state),
301static char* xfrm_ae_attrs2str (
int attrs,
char *buf,
size_t len)
303 return __flags2str(attrs, buf, len, ae_attrs, ARRAY_SIZE(ae_attrs));
312static const struct trans_tbl ae_flags[] = {
313 __ADD(XFRM_AE_UNSPEC, unspecified),
314 __ADD(XFRM_AE_RTHR, replay threshold),
315 __ADD(XFRM_AE_RVAL, replay value),
316 __ADD(XFRM_AE_LVAL, lifetime value),
317 __ADD(XFRM_AE_ETHR, expiry time threshold),
318 __ADD(XFRM_AE_CR, replay update event),
319 __ADD(XFRM_AE_CE, timer expiry event),
320 __ADD(XFRM_AE_CU, policy update event),
323char* xfrmnl_ae_flags2str(
int flags,
char *buf,
size_t len)
325 return __flags2str (flags, buf, len, ae_flags, ARRAY_SIZE(ae_flags));
328int xfrmnl_ae_str2flag(
const char *name)
330 return __str2flags(name, ae_flags, ARRAY_SIZE(ae_flags));
334static void xfrm_ae_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
336 char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
337 struct xfrmnl_ae* ae = (
struct xfrmnl_ae *) a;
338 char flags[128], buf[128];
339 time_t add_time, use_time;
340 struct tm *add_time_tm, *use_time_tm;
343 nl_dump_line(p,
"src %s dst %s \n",
nl_addr2str(ae->saddr, src,
sizeof(src)),
346 nl_dump_line(p,
"\tproto %s spi 0x%x reqid %u ",
347 nl_ip_proto2str (ae->sa_id.proto, buf, sizeof (buf)),
348 ae->sa_id.spi, ae->reqid);
350 xfrmnl_ae_flags2str(ae->flags, flags, sizeof (flags));
351 nl_dump_line(p,
"flags %s(0x%x) mark mask/value 0x%x/0x%x \n", flags,
352 ae->flags, ae->mark.m, ae->mark.v);
354 nl_dump_line(p,
"\tlifetime current: \n");
355 nl_dump_line(p,
"\t\tbytes %llu packets %llu \n",
356 (
long long unsigned)ae->lifetime_cur.bytes,
357 (
long long unsigned)ae->lifetime_cur.packets);
358 if (ae->lifetime_cur.add_time != 0)
360 add_time = ae->lifetime_cur.add_time;
361 add_time_tm = gmtime_r (&add_time, &tm_buf);
362 strftime (flags, 128,
"%Y-%m-%d %H-%M-%S", add_time_tm);
366 sprintf (flags,
"%s",
"-");
369 if (ae->lifetime_cur.use_time != 0)
371 use_time = ae->lifetime_cur.use_time;
372 use_time_tm = gmtime_r (&use_time, &tm_buf);
373 strftime (buf, 128,
"%Y-%m-%d %H-%M-%S", use_time_tm);
377 sprintf (buf,
"%s",
"-");
379 nl_dump_line(p,
"\t\tadd_time: %s, use_time: %s\n", flags, buf);
381 nl_dump_line(p,
"\treplay info: \n");
382 nl_dump_line(p,
"\t\tmax age %u max diff %u \n", ae->replay_maxage, ae->replay_maxdiff);
384 nl_dump_line(p,
"\treplay state info: \n");
385 if (ae->replay_state_esn)
387 nl_dump_line(p,
"\t\toseq %u seq %u oseq_hi %u seq_hi %u replay window: %u \n",
388 ae->replay_state_esn->oseq, ae->replay_state_esn->seq,
389 ae->replay_state_esn->oseq_hi, ae->replay_state_esn->seq_hi,
390 ae->replay_state_esn->replay_window);
394 nl_dump_line(p,
"\t\toseq %u seq %u bitmap: %u \n", ae->replay_state.oseq,
395 ae->replay_state.seq, ae->replay_state.bitmap);
401static void xfrm_ae_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
403 xfrm_ae_dump_line(a, p);
406static void xfrm_ae_dump_stats(
struct nl_object *a,
struct nl_dump_params *p)
408 xfrm_ae_dump_details(a, p);
412static int build_xfrm_ae_message(
struct xfrmnl_ae *tmpl,
int cmd,
int flags,
413 struct nl_msg **result)
416 struct xfrm_aevent_id ae_id;
418 if (!(tmpl->ce_mask & XFRM_AE_ATTR_DADDR) ||
419 !(tmpl->ce_mask & XFRM_AE_ATTR_SPI) ||
420 !(tmpl->ce_mask & XFRM_AE_ATTR_PROTO))
421 return -NLE_MISSING_ATTR;
423 memset(&ae_id, 0,
sizeof(ae_id));
426 ae_id.sa_id.spi = htonl(tmpl->sa_id.spi);
427 ae_id.sa_id.family = tmpl->sa_id.family;
428 ae_id.sa_id.proto = tmpl->sa_id.proto;
430 if (tmpl->ce_mask & XFRM_AE_ATTR_SADDR)
433 if (tmpl->ce_mask & XFRM_AE_ATTR_FLAGS)
434 ae_id.flags = tmpl->flags;
436 if (tmpl->ce_mask & XFRM_AE_ATTR_REQID)
437 ae_id.reqid = tmpl->reqid;
443 if (
nlmsg_append(msg, &ae_id,
sizeof(ae_id), NLMSG_ALIGNTO) < 0)
444 goto nla_put_failure;
446 if (tmpl->ce_mask & XFRM_AE_ATTR_MARK)
449 if (tmpl->ce_mask & XFRM_AE_ATTR_LIFETIME)
452 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_MAXAGE)
453 NLA_PUT_U32 (msg, XFRMA_ETIMER_THRESH, tmpl->replay_maxage);
455 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_MAXDIFF)
456 NLA_PUT_U32 (msg, XFRMA_REPLAY_THRESH, tmpl->replay_maxdiff);
458 if (tmpl->ce_mask & XFRM_AE_ATTR_REPLAY_STATE) {
459 if (tmpl->replay_state_esn) {
460 uint32_t len =
sizeof (
struct xfrm_replay_state_esn) + (sizeof (uint32_t) * tmpl->replay_state_esn->bmp_len);
461 NLA_PUT (msg, XFRMA_REPLAY_ESN_VAL, len, tmpl->replay_state_esn);
481int xfrmnl_ae_set(
struct nl_sock* sk,
struct xfrmnl_ae* ae,
int flags)
486 if ((err = build_xfrm_ae_message(ae, XFRM_MSG_NEWAE, flags|NLM_F_REPLACE, &msg)) < 0)
504struct xfrmnl_ae* xfrmnl_ae_alloc(
void)
509void xfrmnl_ae_put(
struct xfrmnl_ae* ae)
518 [XFRMA_REPLAY_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state) },
519 [XFRMA_REPLAY_THRESH] = { .type =
NLA_U32 },
520 [XFRMA_ETIMER_THRESH] = { .type =
NLA_U32 },
521 [XFRMA_SRCADDR] = { .minlen =
sizeof(xfrm_address_t) },
522 [XFRMA_MARK] = { .minlen =
sizeof(
struct xfrm_mark) },
523 [XFRMA_REPLAY_ESN_VAL] = { .minlen =
sizeof(
struct xfrm_replay_state_esn) },
526int xfrmnl_ae_parse(
struct nlmsghdr *n,
struct xfrmnl_ae **result)
528 _nl_auto_xfrmnl_ae
struct xfrmnl_ae *ae = NULL;
529 struct nlattr *tb[XFRMA_MAX + 1];
530 struct xfrm_aevent_id* ae_id;
533 ae = xfrmnl_ae_alloc();
537 ae->ce_msgtype = n->nlmsg_type;
540 err =
nlmsg_parse(n,
sizeof(
struct xfrm_aevent_id), tb, XFRMA_MAX, xfrm_ae_policy);
544 if (!(ae->sa_id.daddr =
545 _nl_addr_build(ae_id->sa_id.family, &ae_id->sa_id.daddr)))
547 ae->sa_id.family= ae_id->sa_id.family;
548 ae->sa_id.spi = ntohl(ae_id->sa_id.spi);
549 ae->sa_id.proto = ae_id->sa_id.proto;
550 if (!(ae->saddr = _nl_addr_build(ae_id->sa_id.family, &ae_id->saddr)))
552 ae->reqid = ae_id->reqid;
553 ae->flags = ae_id->flags;
554 ae->ce_mask |= (XFRM_AE_ATTR_DADDR | XFRM_AE_ATTR_FAMILY | XFRM_AE_ATTR_SPI |
555 XFRM_AE_ATTR_PROTO | XFRM_AE_ATTR_SADDR | XFRM_AE_ATTR_REQID |
558 if (tb[XFRMA_MARK]) {
559 struct xfrm_mark* m =
nla_data(tb[XFRMA_MARK]);
562 ae->ce_mask |= XFRM_AE_ATTR_MARK;
565 if (tb[XFRMA_LTIME_VAL]) {
566 struct xfrm_lifetime_cur* cur =
nla_data(tb[XFRMA_LTIME_VAL]);
568 ae->lifetime_cur.bytes = cur->bytes;
569 ae->lifetime_cur.packets = cur->packets;
570 ae->lifetime_cur.add_time = cur->add_time;
571 ae->lifetime_cur.use_time = cur->use_time;
572 ae->ce_mask |= XFRM_AE_ATTR_LIFETIME;
575 if (tb[XFRM_AE_ETHR]) {
576 ae->replay_maxage = *(uint32_t*)
nla_data(tb[XFRM_AE_ETHR]);
577 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXAGE;
580 if (tb[XFRM_AE_RTHR]) {
581 ae->replay_maxdiff = *(uint32_t*)
nla_data(tb[XFRM_AE_RTHR]);
582 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXDIFF;
585 if (tb[XFRMA_REPLAY_ESN_VAL]) {
586 struct xfrm_replay_state_esn* esn =
nla_data (tb[XFRMA_REPLAY_ESN_VAL]);
589 if ((ae->replay_state_esn = calloc (1, len)) == NULL)
591 ae->replay_state_esn->oseq = esn->oseq;
592 ae->replay_state_esn->seq = esn->seq;
593 ae->replay_state_esn->oseq_hi = esn->oseq_hi;
594 ae->replay_state_esn->seq_hi = esn->seq_hi;
595 ae->replay_state_esn->replay_window = esn->replay_window;
596 ae->replay_state_esn->bmp_len = esn->bmp_len;
597 memcpy (ae->replay_state_esn->bmp, esn->bmp, sizeof (uint32_t) * esn->bmp_len);
598 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
602 struct xfrm_replay_state* replay_state =
nla_data (tb[XFRMA_REPLAY_VAL]);
603 ae->replay_state.oseq = replay_state->oseq;
604 ae->replay_state.seq = replay_state->seq;
605 ae->replay_state.bitmap = replay_state->bitmap;
606 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
608 ae->replay_state_esn = NULL;
611 *result = _nl_steal_pointer(&ae);
615static int xfrm_ae_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
616 struct nlmsghdr *n,
struct nl_parser_param *pp)
618 struct xfrmnl_ae* ae;
621 if ((err = xfrmnl_ae_parse(n, &ae)) < 0)
624 err = pp->pp_cb((
struct nl_object *) ae, pp);
635int xfrmnl_ae_build_get_request(
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
636 unsigned int mark_mask,
unsigned int mark_value,
struct nl_msg **result)
639 struct xfrm_aevent_id ae_id;
644 fprintf(stderr,
"APPLICATION BUG: %s:%d:%s: A valid destination address, spi must be specified\n",
645 __FILE__, __LINE__, __func__);
647 return -NLE_MISSING_ATTR;
650 memset(&ae_id, 0,
sizeof(ae_id));
652 ae_id.sa_id.spi = htonl(spi);
654 ae_id.sa_id.proto = protocol;
659 if (
nlmsg_append(msg, &ae_id,
sizeof(ae_id), NLMSG_ALIGNTO) < 0)
660 goto nla_put_failure;
674int xfrmnl_ae_get_kernel(
struct nl_sock* sock,
struct nl_addr* daddr,
unsigned int spi,
unsigned int protocol,
675 unsigned int mark_mask,
unsigned int mark_value,
struct xfrmnl_ae** result)
677 struct nl_msg *msg = NULL;
678 struct nl_object *obj;
681 if ((err = xfrmnl_ae_build_get_request(daddr, spi, protocol, mark_mask, mark_value, &msg)) < 0)
689 if ((err =
nl_pickup(sock, &xfrm_ae_msg_parser, &obj)) < 0)
693 *result = (
struct xfrmnl_ae *) obj;
709static inline int __assign_addr(
struct xfrmnl_ae* ae,
struct nl_addr **pos,
710 struct nl_addr *
new,
int flag,
int nocheck)
713 if (ae->ce_mask & XFRM_AE_ATTR_FAMILY) {
715 return -NLE_AF_MISMATCH;
718 ae->ce_mask |= XFRM_AE_ATTR_FAMILY;
734struct nl_addr* xfrmnl_ae_get_daddr (
struct xfrmnl_ae* ae)
736 if (ae->ce_mask & XFRM_AE_ATTR_DADDR)
737 return ae->sa_id.daddr;
742int xfrmnl_ae_set_daddr (
struct xfrmnl_ae* ae,
struct nl_addr* addr)
744 return __assign_addr(ae, &ae->sa_id.daddr, addr, XFRM_AE_ATTR_DADDR, 0);
747int xfrmnl_ae_get_spi (
struct xfrmnl_ae* ae)
749 if (ae->ce_mask & XFRM_AE_ATTR_SPI)
750 return ae->sa_id.spi;
755int xfrmnl_ae_set_spi (
struct xfrmnl_ae* ae,
unsigned int spi)
758 ae->ce_mask |= XFRM_AE_ATTR_SPI;
763int xfrmnl_ae_get_family (
struct xfrmnl_ae* ae)
765 if (ae->ce_mask & XFRM_AE_ATTR_FAMILY)
766 return ae->sa_id.family;
771int xfrmnl_ae_set_family (
struct xfrmnl_ae* ae,
unsigned int family)
773 ae->sa_id.family = family;
774 ae->ce_mask |= XFRM_AE_ATTR_FAMILY;
779int xfrmnl_ae_get_proto (
struct xfrmnl_ae* ae)
781 if (ae->ce_mask & XFRM_AE_ATTR_PROTO)
782 return ae->sa_id.proto;
787int xfrmnl_ae_set_proto (
struct xfrmnl_ae* ae,
unsigned int protocol)
789 ae->sa_id.proto = protocol;
790 ae->ce_mask |= XFRM_AE_ATTR_PROTO;
795struct nl_addr* xfrmnl_ae_get_saddr (
struct xfrmnl_ae* ae)
797 if (ae->ce_mask & XFRM_AE_ATTR_SADDR)
803int xfrmnl_ae_set_saddr (
struct xfrmnl_ae* ae,
struct nl_addr* addr)
805 return __assign_addr(ae, &ae->saddr, addr, XFRM_AE_ATTR_SADDR, 1);
808int xfrmnl_ae_get_flags (
struct xfrmnl_ae* ae)
810 if (ae->ce_mask & XFRM_AE_ATTR_FLAGS)
816int xfrmnl_ae_set_flags (
struct xfrmnl_ae* ae,
unsigned int flags)
819 ae->ce_mask |= XFRM_AE_ATTR_FLAGS;
824int xfrmnl_ae_get_reqid (
struct xfrmnl_ae* ae)
826 if (ae->ce_mask & XFRM_AE_ATTR_REQID)
832int xfrmnl_ae_set_reqid (
struct xfrmnl_ae* ae,
unsigned int reqid)
835 ae->ce_mask |= XFRM_AE_ATTR_REQID;
840int xfrmnl_ae_get_mark (
struct xfrmnl_ae* ae,
unsigned int* mark_mask,
unsigned int* mark_value)
842 if (mark_mask == NULL || mark_value == NULL)
845 if (ae->ce_mask & XFRM_AE_ATTR_MARK)
847 *mark_mask = ae->mark.m;
848 *mark_value = ae->mark.v;
856int xfrmnl_ae_set_mark (
struct xfrmnl_ae* ae,
unsigned int value,
unsigned int mask)
860 ae->ce_mask |= XFRM_AE_ATTR_MARK;
865int xfrmnl_ae_get_curlifetime (
struct xfrmnl_ae* ae,
unsigned long long int* curr_bytes,
866 unsigned long long int* curr_packets,
unsigned long long int* curr_add_time,
867 unsigned long long int* curr_use_time)
869 if (curr_bytes == NULL || curr_packets == NULL || curr_add_time == NULL || curr_use_time == NULL)
872 if (ae->ce_mask & XFRM_AE_ATTR_LIFETIME)
874 *curr_bytes = ae->lifetime_cur.bytes;
875 *curr_packets = ae->lifetime_cur.packets;
876 *curr_add_time = ae->lifetime_cur.add_time;
877 *curr_use_time = ae->lifetime_cur.use_time;
885int xfrmnl_ae_set_curlifetime (
struct xfrmnl_ae* ae,
unsigned long long int curr_bytes,
886 unsigned long long int curr_packets,
unsigned long long int curr_add_time,
887 unsigned long long int curr_use_time)
889 ae->lifetime_cur.bytes = curr_bytes;
890 ae->lifetime_cur.packets = curr_packets;
891 ae->lifetime_cur.add_time = curr_add_time;
892 ae->lifetime_cur.use_time = curr_use_time;
893 ae->ce_mask |= XFRM_AE_ATTR_LIFETIME;
898int xfrmnl_ae_get_replay_maxage (
struct xfrmnl_ae* ae)
900 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_MAXAGE)
901 return ae->replay_maxage;
906int xfrmnl_ae_set_replay_maxage (
struct xfrmnl_ae* ae,
unsigned int replay_maxage)
908 ae->replay_maxage = replay_maxage;
909 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXAGE;
914int xfrmnl_ae_get_replay_maxdiff (
struct xfrmnl_ae* ae)
916 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_MAXDIFF)
917 return ae->replay_maxdiff;
922int xfrmnl_ae_set_replay_maxdiff (
struct xfrmnl_ae* ae,
unsigned int replay_maxdiff)
924 ae->replay_maxdiff = replay_maxdiff;
925 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_MAXDIFF;
930int xfrmnl_ae_get_replay_state (
struct xfrmnl_ae* ae,
unsigned int* oseq,
unsigned int* seq,
unsigned int* bmp)
932 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_STATE)
934 if (ae->replay_state_esn == NULL)
936 *oseq = ae->replay_state.oseq;
937 *seq = ae->replay_state.seq;
938 *bmp = ae->replay_state.bitmap;
951int xfrmnl_ae_set_replay_state (
struct xfrmnl_ae* ae,
unsigned int oseq,
unsigned int seq,
unsigned int bitmap)
953 ae->replay_state.oseq = oseq;
954 ae->replay_state.seq = seq;
955 ae->replay_state.bitmap = bitmap;
956 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
961int xfrmnl_ae_get_replay_state_esn(
struct xfrmnl_ae* ae,
unsigned int* oseq,
unsigned int* seq,
unsigned int* oseq_hi,
962 unsigned int* seq_hi,
unsigned int* replay_window,
unsigned int* bmp_len,
unsigned int* bmp)
964 if (ae->ce_mask & XFRM_AE_ATTR_REPLAY_STATE)
966 if (ae->replay_state_esn)
968 *oseq = ae->replay_state_esn->oseq;
969 *seq = ae->replay_state_esn->seq;
970 *oseq_hi= ae->replay_state_esn->oseq_hi;
971 *seq_hi = ae->replay_state_esn->seq_hi;
972 *replay_window = ae->replay_state_esn->replay_window;
973 *bmp_len = ae->replay_state_esn->bmp_len;
974 memcpy (bmp, ae->replay_state_esn->bmp, ae->replay_state_esn->bmp_len * sizeof (uint32_t));
987int xfrmnl_ae_set_replay_state_esn(
struct xfrmnl_ae* ae,
unsigned int oseq,
unsigned int seq,
988 unsigned int oseq_hi,
unsigned int seq_hi,
unsigned int replay_window,
989 unsigned int bmp_len,
unsigned int* bmp)
992 if (ae->replay_state_esn)
993 free (ae->replay_state_esn);
995 if ((ae->replay_state_esn = calloc (1,
sizeof (
struct xfrmnl_replay_state_esn) +
sizeof (uint32_t) * bmp_len)) == NULL)
998 ae->replay_state_esn->oseq = oseq;
999 ae->replay_state_esn->seq = seq;
1000 ae->replay_state_esn->oseq_hi = oseq_hi;
1001 ae->replay_state_esn->seq_hi = seq_hi;
1002 ae->replay_state_esn->replay_window = replay_window;
1003 ae->replay_state_esn->bmp_len = bmp_len;
1004 memcpy (ae->replay_state_esn->bmp, bmp, bmp_len * sizeof (uint32_t));
1005 ae->ce_mask |= XFRM_AE_ATTR_REPLAY_STATE;
1012static struct nl_object_ops xfrm_ae_obj_ops = {
1013 .oo_name =
"xfrm/ae",
1014 .oo_size =
sizeof(
struct xfrmnl_ae),
1015 .oo_free_data = xfrm_ae_free_data,
1016 .oo_clone = xfrm_ae_clone,
1022 .oo_compare = xfrm_ae_compare,
1023 .oo_attrs2str = xfrm_ae_attrs2str,
1024 .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.
uint16_t type
Type of attribute or NLA_UNSPEC.