tagged release 0.3.2
[vpnc.git] / isakmp-pkt.h
blob5cedcb8b89dd64d66566976ac87028c6e1baf69c
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 #ifndef __ISAKMP_PKT_H__
20 #define __ISAKMP_PKT_H__
21 #if defined(__linux__)
22 #include <stdint.h>
23 #endif
24 #include <sys/types.h>
26 #include "isakmp.h"
28 struct isakmp_attribute {
29 struct isakmp_attribute *next;
30 uint16_t type;
31 enum {
32 isakmp_attr_lots,
33 isakmp_attr_16,
34 isakmp_attr_2x8
35 } af;
36 union {
37 uint16_t attr_16;
38 uint8_t attr_2x8[2];
39 struct {
40 uint16_t length;
41 uint8_t *data;
42 } lots;
43 } u;
46 struct isakmp_payload {
47 struct isakmp_payload *next;
48 enum isakmp_payload_enum type;
49 union {
50 struct {
51 uint32_t doi;
52 uint32_t situation;
53 struct isakmp_payload *proposals;
54 } sa;
55 struct {
56 uint8_t number;
57 uint8_t prot_id;
58 uint8_t spi_size;
59 uint8_t *spi;
60 struct isakmp_payload *transforms;
61 } p;
62 struct {
63 uint8_t number;
64 uint8_t id;
65 struct isakmp_attribute *attributes;
66 } t;
67 struct {
68 uint16_t length;
69 uint8_t *data;
70 } ke, hash, sig, nonce, vid, natd;
71 struct {
72 uint8_t type;
73 uint8_t protocol;
74 uint16_t port;
75 uint16_t length;
76 uint8_t *data;
77 } id;
78 struct {
79 uint8_t encoding;
80 uint16_t length;
81 uint8_t *data;
82 } cert, cr;
83 struct {
84 uint32_t doi;
85 uint8_t protocol;
86 uint8_t spi_length;
87 uint8_t *spi;
88 uint16_t type;
89 uint16_t data_length;
90 uint8_t *data;
91 } n;
92 struct {
93 uint32_t doi;
94 uint8_t protocol;
95 uint8_t spi_length;
96 uint16_t num_spi;
97 uint8_t **spi;
98 } d;
99 struct {
100 uint8_t type;
101 uint16_t id;
102 struct isakmp_attribute *attributes;
103 } modecfg;
104 } u;
107 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 *new_isakmp_data_payload(uint8_t type, const void *data,
121 size_t data_length);
122 extern struct isakmp_attribute *new_isakmp_attribute(uint16_t, struct isakmp_attribute *);
123 extern struct isakmp_attribute *new_isakmp_attribute_16(uint16_t type, uint16_t data,
124 struct isakmp_attribute *next);
125 extern void free_isakmp_packet(struct isakmp_packet *p);
126 extern void flatten_isakmp_payload(struct isakmp_payload *p, uint8_t ** result, size_t * size);
127 extern void flatten_isakmp_packet(struct isakmp_packet *p,
128 uint8_t ** result, size_t * size, size_t blksz);
129 extern struct isakmp_packet *parse_isakmp_packet(const uint8_t * data,
130 size_t data_len, int * reject);
131 extern const char *isakmp_notify_to_error(uint16_t notify);
132 extern void test_pack_unpack(void);
134 #endif