1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2017 Jason King.
  14  * Copyright 2017 Joyent, Inc.
  15  */
  16 
  17 #ifndef _IKEV2_PKT_H
  18 #define _IKEV2_PKT_H
  19 
  20 #include <sys/types.h>
  21 
  22 #include "ikev2.h"
  23 #include "pkt.h"
  24 #include "buf.h"
  25 
  26 #ifdef __cplusplus
  27 extern "C" {
  28 #endif
  29 
  30 struct pkt;
  31 struct ikev2_sa;
  32 
  33 #define INBOUND_LOCAL_SPI(hdr) \
  34         (((hdr)->flags == IKEV2_FLAG_INITIATOR) ? \
  35             (hdr)->responder_spi : (hdr)->initiator_spi)
  36 
  37 #define INBOUND_REMOTE_SPI(hdr) \
  38         (((hdr)->flags == IKEV2_FLAG_INITIATOR) ? \
  39             (hdr)->initiator_spi : (hdr)->responder_spi)
  40 
  41 pkt_t *ikev2_pkt_new_inbound(uchar_t *, size_t);
  42 pkt_t *ikev2_pkt_new_initiator(struct ikev2_sa *, ikev2_exch_t);
  43 pkt_t *ikev2_pkt_new_response(const pkt_t *);
  44 void ikev2_pkt_free(pkt_t *);
  45 
  46 boolean_t ikev2_add_sa(pkt_t *);
  47 boolean_t ikev2_add_prop(pkt_t *, uint8_t, ikev2_spi_proto_t, uint64_t);
  48 boolean_t ikev2_add_xform(pkt_t *, ikev2_xf_type_t, int);
  49 boolean_t ikev2_add_xf_attr(pkt_t *, ikev2_xf_attr_type_t, uintptr_t);
  50 boolean_t ikev2_add_xf_encr(pkt_t *, ikev2_xf_encr_t, uint16_t, uint16_t);
  51 boolean_t ikev2_add_ke(pkt_t *restrict, uint_t, const uchar_t *restrict,
  52     size_t);
  53 boolean_t ikev2_add_id_i(pkt_t *restrict, ikev2_id_type_t, ...);
  54 boolean_t ikev2_add_id_r(pkt_t *restrict, ikev2_id_type_t, ...);
  55 boolean_t ikev2_add_cert(pkt_t *restrict, ikev2_cert_t,
  56     const uchar_t *restrict, size_t);
  57 boolean_t ikev2_add_certreq(pkt_t *restrict, ikev2_cert_t,
  58     const uchar_t *restrict, size_t);
  59 boolean_t ikev2_add_auth(pkt_t *restrict, ikev2_auth_type_t,
  60     const uchar_t *restrict, size_t);
  61 boolean_t ikev2_add_nonce(pkt_t *restrict, size_t);
  62 boolean_t ikev2_add_notify(pkt_t *restrict, ikev2_spi_proto_t, uint64_t,
  63     ikev2_notify_type_t, const void *restrict, size_t);
  64 
  65 boolean_t ikev2_add_delete(pkt_t *, ikev2_spi_proto_t);
  66 boolean_t ikev2_add_delete_spi(pkt_t *, uint64_t);
  67 
  68 boolean_t ikev2_add_vendor(pkt_t *restrict, const void *restrict, size_t);
  69 
  70 boolean_t ikev2_add_ts_i(pkt_t *);
  71 boolean_t ikev2_add_ts_r(pkt_t *);
  72 boolean_t ikev2_add_ts(pkt_t *restrict, ikev2_ts_type_t, uint8_t /* proto */,
  73     const sockaddr_u_t *restrict /* start */,
  74     const sockaddr_u_t *restrict /* end */);
  75 
  76 boolean_t ikev2_add_sk(pkt_t *);
  77 
  78 boolean_t ikev2_add_config(pkt_t *restrict, ikev2_cfg_type_t);
  79 boolean_t ikev2_add_config_attr(pkt_t *restrict, ikev2_cfg_attr_type_t,
  80     const void *restrict);
  81 
  82 boolean_t ikev2_pkt_decrypt(pkt_t *);
  83 
  84 #ifdef __cplusplus
  85 }
  86 #endif
  87 
  88 #endif /* _IKEV2_PKT_H */