1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2014 Jason King.
  24  */
  25 
  26 #ifndef _IKE_H
  27 #define _IKE_H
  28 
  29 #include <sys/types.h>
  30 
  31 #ifdef __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 /* Stuff that is the same between IKEv1 and IKEv2 */
  36 
  37 #define IKE_GET_MAJORV(v)       (((v) & 0xf0) >> 4)
  38 #define IKE_GET_MINORV(v)       ((v) & 0x0f)
  39 #define IKE_VERSION(_maj, _min) (((_maj) & 0xf0 << 4) | (_min) & 0x0f)
  40 
  41 #ifndef __packed
  42 #define __packed __attribute__((packed))
  43 #endif
  44 
  45 struct ike_header {
  46         uint64_t        initiator_spi;
  47         uint64_t        responder_spi;
  48         uint8_t         next_payload;
  49         uint8_t         version;
  50         uint8_t         exch_type;
  51         uint8_t         flags;
  52         uint32_t        msgid;
  53         uint32_t        length;
  54 } __packed;
  55 typedef struct ike_header ike_header_t;
  56 #define IKE_HEADER_LEN  (sizeof (ike_header_t))
  57 
  58 struct ike_payload {
  59         uint8_t         pay_next;
  60         uint8_t         pay_reserved;
  61         uint16_t        pay_length;
  62 } __packed;
  63 typedef struct ike_payload ike_payload_t;
  64 
  65 #define IKE_PAYLOAD_NONE        0
  66 
  67 /* Of the IKEv1 and IKEv2 payloads we recognize, this is MAX of the two */
  68 #define IKE_NUM_PAYLOADS 17
  69 
  70 struct ike_prop {
  71         uint8_t         prop_more;
  72         uint8_t         prop_resv;
  73         uint16_t        prop_len;
  74         uint8_t         prop_num;
  75         uint8_t         prop_proto;
  76         uint8_t         prop_spilen;
  77         uint8_t         prop_numxform;
  78 } __packed;
  79 typedef struct ike_prop ike_prop_t;
  80 #define IKE_PROP_NONE   (0)
  81 #define IKE_PROP_MORE   (2)
  82 
  83 struct ike_xform {
  84         uint8_t         xf_more;
  85         uint8_t         xf_resv;
  86         uint16_t        xf_len;
  87         uint8_t         xf_type;
  88         uint8_t         xf_resv2;
  89         uint16_t        xf_id;
  90 } __packed;
  91 typedef struct ike_xform ike_xform_t;
  92 #define IKE_XFORM_NONE  (0)
  93 #define IKE_XFORM_MORE  (3)
  94 
  95 struct ike_xf_attr {
  96         uint16_t        attr_type;
  97         uint16_t        attr_len;
  98 };
  99 typedef struct ike_xf_attr ike_xf_attr_t;
 100 #define IKE_ATTR_TV                     (1)
 101 #define IKE_ATTR_TLV                    (0)
 102 #define IKE_ATTR_GET_TYPE(type)         ((type) & 0x7fff)
 103 #define IKE_ATTR_GET_FORMAT(type)       ((type) & 0x8000) >> 15)
 104 #define IKE_ATTR_TYPE(fmt, type) \
 105         (((fmt) << 15) | ((type) & 0x7fff))
 106 
 107 struct ike_ke {
 108         uint16_t        ke_group;
 109         uint16_t        ke_resv;
 110 };
 111 typedef struct ike_ke ike_ke_t;
 112 
 113 #ifdef __cplusplus
 114 }
 115 #endif
 116 
 117 #endif /* _IKE_H */