import of 0.2-rm+zomb.1
[vpnc.git] / isakmp-pkt.h
blob2d82fd57880d90288d913e887d43691389ef57f8
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
46 struct isakmp_payload *next;
47 enum isakmp_payload_enum type;
48 union {
49 struct {
50 uint32_t doi;
51 uint32_t situation;
52 struct isakmp_payload *proposals;
53 } sa;
54 struct {
55 uint8_t number;
56 uint8_t prot_id;
57 uint8_t spi_size;
58 uint8_t *spi;
59 struct isakmp_payload *transforms;
60 } p;
61 struct {
62 uint8_t number;
63 uint8_t id;
64 struct isakmp_attribute *attributes;
65 } t;
66 struct {
67 uint16_t length;
68 uint8_t *data;
69 } ke, hash, sig, nonce, vid;
70 struct {
71 uint8_t type;
72 uint8_t protocol;
73 uint16_t port;
74 uint16_t length;
75 uint8_t *data;
76 } id;
77 struct {
78 uint8_t encoding;
79 uint16_t length;
80 uint8_t *data;
81 } cert, cr;
82 struct {
83 uint32_t doi;
84 uint8_t protocol;
85 uint8_t spi_length;
86 uint8_t *spi;
87 uint16_t type;
88 uint16_t data_length;
89 uint8_t *data;
90 } n;
91 struct {
92 uint32_t doi;
93 uint8_t protocol;
94 uint8_t spi_length;
95 uint16_t num_spi;
96 uint8_t **spi;
97 } d;
98 struct {
99 uint8_t type;
100 uint16_t id;
101 struct isakmp_attribute *attributes;
102 } modecfg;
103 } u;
106 struct isakmp_packet
108 uint8_t i_cookie[ISAKMP_COOKIE_LENGTH];
109 uint8_t r_cookie[ISAKMP_COOKIE_LENGTH];
110 uint8_t isakmp_version;
111 uint8_t exchange_type;
112 uint8_t flags;
113 uint32_t message_id;
114 struct isakmp_payload *payload;
117 extern void * xallocc (size_t x);
118 extern struct isakmp_packet * new_isakmp_packet(void);
119 extern struct isakmp_payload * new_isakmp_payload(uint8_t);
120 extern struct isakmp_payload *
121 new_isakmp_data_payload(uint8_t type, const void *data, size_t data_length);
122 extern struct isakmp_attribute *
123 new_isakmp_attribute(uint16_t, struct isakmp_attribute *);
124 extern struct isakmp_attribute *
125 new_isakmp_attribute_16 (uint16_t type, uint16_t data,
126 struct isakmp_attribute *next);
127 extern void free_isakmp_packet(struct isakmp_packet *p);
128 extern void flatten_isakmp_payload (struct isakmp_payload *p,
129 uint8_t **result, size_t *size);
130 extern void flatten_isakmp_packet (struct isakmp_packet *p,
131 uint8_t **result, size_t *size, size_t blksz);
132 extern struct isakmp_packet * parse_isakmp_packet (const uint8_t *data,
133 size_t data_len,
134 uint16_t *reject);
135 extern const char * isakmp_notify_to_error (uint16_t notify);
136 extern void test_pack_unpack(void);