Alexey Sopov <suntechnic@gmail.com>
[vpnc.git] / isakmp-pkt.h
blobbd292dbe1e620fb8841883f9bc909357ebc25a7e
1 /* ISAKMP packing and unpacking routines.
2 Copyright (C) 2002 Geoffrey Keating
3 Copyright (C) 2003-2005 Maurice Massar
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 $Id$
22 #ifndef __ISAKMP_PKT_H__
23 #define __ISAKMP_PKT_H__
24 #if defined(__linux__)
25 #include <stdint.h>
26 #endif
27 #include <sys/types.h>
29 #include "isakmp.h"
31 struct isakmp_attribute {
32 struct isakmp_attribute *next;
33 uint16_t type;
34 enum {
35 isakmp_attr_lots,
36 isakmp_attr_16,
37 isakmp_attr_2x8,
38 isakmp_attr_acl
39 } af;
40 union {
41 uint16_t attr_16;
42 uint8_t attr_2x8[2];
43 struct {
44 uint16_t length;
45 uint8_t *data;
46 } lots;
47 struct {
48 uint16_t count;
49 struct acl_ent_s {
50 struct in_addr addr, mask;
51 uint16_t protocol, sport, dport;
52 } *acl_ent;
53 } acl;
54 } u;
57 struct isakmp_payload {
58 struct isakmp_payload *next;
59 enum isakmp_payload_enum type;
60 union {
61 struct {
62 uint32_t doi;
63 uint32_t situation;
64 struct isakmp_payload *proposals;
65 } sa;
66 struct {
67 uint8_t number;
68 uint8_t prot_id;
69 uint8_t spi_size;
70 uint8_t *spi;
71 struct isakmp_payload *transforms;
72 } p;
73 struct {
74 uint8_t number;
75 uint8_t id;
76 struct isakmp_attribute *attributes;
77 } t;
78 struct {
79 uint16_t length;
80 uint8_t *data;
81 } ke, hash, sig, nonce, vid, natd;
82 struct {
83 uint8_t type;
84 uint8_t protocol;
85 uint16_t port;
86 uint16_t length;
87 uint8_t *data;
88 } id;
89 struct {
90 uint8_t encoding;
91 uint16_t length;
92 uint8_t *data;
93 } cert, cr;
94 struct {
95 uint32_t doi;
96 uint8_t protocol;
97 uint8_t spi_length;
98 uint8_t *spi;
99 uint16_t type;
100 uint16_t data_length;
101 uint8_t *data;
102 struct isakmp_attribute *attributes; /* sometimes, data is an attributes array */
103 } n;
104 struct {
105 uint32_t doi;
106 uint8_t protocol;
107 uint8_t spi_length;
108 uint16_t num_spi;
109 uint8_t **spi;
110 } d;
111 struct {
112 uint8_t type;
113 uint16_t id;
114 struct isakmp_attribute *attributes;
115 } modecfg;
116 } u;
119 struct isakmp_packet {
120 uint8_t i_cookie[ISAKMP_COOKIE_LENGTH];
121 uint8_t r_cookie[ISAKMP_COOKIE_LENGTH];
122 uint8_t isakmp_version;
123 uint8_t exchange_type;
124 uint8_t flags;
125 uint32_t message_id;
126 struct isakmp_payload *payload;
129 extern void *xallocc(size_t x);
130 extern struct isakmp_packet *new_isakmp_packet(void);
131 extern struct isakmp_payload *new_isakmp_payload(uint8_t);
132 extern struct isakmp_payload *new_isakmp_data_payload(uint8_t type, const void *data,
133 size_t data_length);
134 extern struct isakmp_attribute *new_isakmp_attribute(uint16_t, struct isakmp_attribute *);
135 extern struct isakmp_attribute *new_isakmp_attribute_16(uint16_t type, uint16_t data,
136 struct isakmp_attribute *next);
137 extern void free_isakmp_packet(struct isakmp_packet *p);
138 extern void flatten_isakmp_payloads(struct isakmp_payload *p, uint8_t ** result, size_t * size);
139 extern void flatten_isakmp_payload(struct isakmp_payload *p, uint8_t ** result, size_t * size);
140 extern void flatten_isakmp_packet(struct isakmp_packet *p,
141 uint8_t ** result, size_t * size, size_t blksz);
142 extern struct isakmp_packet *parse_isakmp_packet(const uint8_t * data,
143 size_t data_len, int * reject);
144 extern void test_pack_unpack(void);
146 #endif