resetting manifest requested domain to floor
[platform/upstream/vpnc.git] / isakmp-pkt.h
1 /* ISAKMP packing and unpacking routines.
2    Copyright (C) 2002  Geoffrey Keating
3    Copyright (C) 2003-2005 Maurice Massar
4
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.
9
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.
14
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
18
19    $Id: isakmp-pkt.h 377 2008-11-26 08:03:43Z Joerg Mayer $
20 */
21
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>
28
29 #include "isakmp.h"
30
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;
55 };
56
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;
117 };
118
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;
127         uint16_t extra_data_length;
128         uint8_t *extra_data;
129 };
130
131 extern void *xallocc(size_t x);
132 extern void *dup_data(const void *data, size_t x);
133 extern struct isakmp_packet *new_isakmp_packet(void);
134 extern struct isakmp_payload *new_isakmp_payload(uint8_t);
135 extern struct isakmp_payload *new_isakmp_data_payload(uint8_t type, const void *data,
136         size_t data_length);
137 extern struct isakmp_payload *dup_isakmp_payload(struct isakmp_payload *p);
138 //extern void free_isakmp_payload(struct isakmp_payload *p);
139 extern struct isakmp_attribute *new_isakmp_attribute(uint16_t, struct isakmp_attribute *);
140 extern struct isakmp_attribute *new_isakmp_attribute_16(uint16_t type, uint16_t data,
141         struct isakmp_attribute *next);
142 extern struct isakmp_attribute *dup_isakmp_attributes(struct isakmp_attribute *);
143 extern void free_isakmp_attributes(struct isakmp_attribute *);
144 extern void free_isakmp_packet(struct isakmp_packet *p);
145 extern void flatten_isakmp_payloads(struct isakmp_payload *p, uint8_t ** result, size_t * size);
146 extern void flatten_isakmp_payload(struct isakmp_payload *p, uint8_t ** result, size_t * size);
147 extern void flatten_isakmp_packet(struct isakmp_packet *p,
148         uint8_t ** result, size_t * size, size_t blksz);
149 extern struct isakmp_packet *parse_isakmp_packet(const uint8_t * data,
150         size_t data_len, int * reject);
151 extern void test_pack_unpack(void);
152
153 #endif