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 2015 Jason King.  All rights reserved.
  14  */
  15 
  16 #include <stddef.h>
  17 #include <assert.h>
  18 #include <umem.h>
  19 #include <string.h>
  20 #include <errno.h>
  21 #include <sys/types.h>
  22 #include <sys/byteorder.h>
  23 #include <ipsec_util.h>
  24 #include <locale.h>
  25 #include <netinet/in.h>
  26 #include <security/cryptoki.h>
  27 #include <errno.h>
  28 #include <sys/socket.h>
  29 #include <pthread.h>
  30 #include <sys/debug.h>
  31 #include <note.h>
  32 #include "ikev2.h"
  33 #include "ikev2_sa.h"
  34 #include "pkt.h"
  35 #include "pkt_impl.h"
  36 #include "pkcs11.h"
  37 
  38 static void
  39 ikev1_add_payload(pkt_t *pkt, ikev1_pay_t type)
  40 {
  41         ASSERT(IKEV1_VALID_PAYLOAD(type));
  42         ASSERT(IKE_GET_MAJORV(pkt->header.version) == IKEV1_VERSION);
  43         pkt_add_payload(pkt, type, 0);
  44 }
  45 
  46 
  47 void
  48 ikev1_add_sa(pkt_t *pkt, uint32_t doi, uint32_t sit)
  49 {
  50         ikev1_add_payload(pkt, IKEV1_PAYLOAD_SA);
  51         buf_put32(&pkt->buf, doi);
  52         buf_put32(&pkt->buf, sit);
  53 }
  54 
  55 void
  56 ikev1_add_prop(pkt_t *pkt, uint8_t propnum, ikev1_spi_proto_t spitype,
  57     uint64_t spi)
  58 {
  59         size_t spilen;
  60 
  61         switch (spitype) {
  62         case IKEV1_SPI_PROTO_ISAKMP:
  63                 spilen = sizeof (uint64_t);
  64                 break;
  65         case IKEV1_SPI_PROTO_IPSEC_AH:
  66         case IKEV1_SPI_PROTO_IPSEC_ESP:
  67         case IKEV1_SPI_PROTO_IPCOMP:
  68                 spilen = sizeof (uint32_t);
  69                 break;
  70         default:
  71                 INVALID(spitype);
  72         }
  73 
  74         pkt_add_prop(pkt, propnum, spitype, spi);
  75 }
  76 
  77 
  78 /* TODO */