added vpnc.ps target (enscript ... vpnc.c)
[vpnc.git] / isakmp-pkt.h
blobeaa9952a68cdc0bde945fbe5cc3a12e811cce875
1 /* ISAKMP packing and unpacking routines.
2 Copyright (C) 2002 Geoffrey Keating
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #if defined(__linux__)
20 #include <stdint.h>
21 #endif
22 #include <sys/types.h>
24 #include "isakmp.h"
26 struct isakmp_attribute {
27 struct isakmp_attribute *next;
28 uint16_t type;
29 enum {
30 isakmp_attr_lots,
31 isakmp_attr_16,
32 isakmp_attr_2x8
33 } af;
34 union {
35 uint16_t attr_16;
36 uint8_t attr_2x8[2];
37 struct {
38 uint16_t length;
39 uint8_t *data;
40 } lots;
41 } u;
44 struct isakmp_payload {
45 struct isakmp_payload *next;
46 enum isakmp_payload_enum type;
47 union {
48 struct {
49 uint32_t doi;
50 uint32_t situation;
51 struct isakmp_payload *proposals;
52 } sa;
53 struct {
54 uint8_t number;
55 uint8_t prot_id;
56 uint8_t spi_size;
57 uint8_t *spi;
58 struct isakmp_payload *transforms;
59 } p;
60 struct {
61 uint8_t number;
62 uint8_t id;
63 struct isakmp_attribute *attributes;
64 } t;
65 struct {
66 uint16_t length;
67 uint8_t *data;
68 } ke, hash, sig, nonce, vid;
69 struct {
70 uint8_t type;
71 uint8_t protocol;
72 uint16_t port;
73 uint16_t length;
74 uint8_t *data;
75 } id;
76 struct {
77 uint8_t encoding;
78 uint16_t length;
79 uint8_t *data;
80 } cert, cr;
81 struct {
82 uint32_t doi;
83 uint8_t protocol;
84 uint8_t spi_length;
85 uint8_t *spi;
86 uint16_t type;
87 uint16_t data_length;
88 uint8_t *data;
89 } n;
90 struct {
91 uint32_t doi;
92 uint8_t protocol;
93 uint8_t spi_length;
94 uint16_t num_spi;
95 uint8_t **spi;
96 } d;
97 struct {
98 uint8_t type;
99 uint16_t id;
100 struct isakmp_attribute *attributes;
101 } modecfg;
102 } u;
105 struct isakmp_packet {
106 uint8_t i_cookie[ISAKMP_COOKIE_LENGTH];
107 uint8_t r_cookie[ISAKMP_COOKIE_LENGTH];
108 uint8_t isakmp_version;
109 uint8_t exchange_type;
110 uint8_t flags;
111 uint32_t message_id;
112 struct isakmp_payload *payload;
115 extern void *xallocc(size_t x);
116 extern struct isakmp_packet *new_isakmp_packet(void);
117 extern struct isakmp_payload *new_isakmp_payload(uint8_t);
118 extern struct isakmp_payload *new_isakmp_data_payload(uint8_t type, const void *data,
119 size_t data_length);
120 extern struct isakmp_attribute *new_isakmp_attribute(uint16_t, struct isakmp_attribute *);
121 extern struct isakmp_attribute *new_isakmp_attribute_16(uint16_t type, uint16_t data,
122 struct isakmp_attribute *next);
123 extern void free_isakmp_packet(struct isakmp_packet *p);
124 extern void flatten_isakmp_payload(struct isakmp_payload *p, uint8_t ** result, size_t * size);
125 extern void flatten_isakmp_packet(struct isakmp_packet *p,
126 uint8_t ** result, size_t * size, size_t blksz);
127 extern struct isakmp_packet *parse_isakmp_packet(const uint8_t * data,
128 size_t data_len, uint16_t * reject);
129 extern const char *isakmp_notify_to_error(uint16_t notify);
130 extern void test_pack_unpack(void);