Annotation of embedaddon/strongswan/src/libcharon/encoding/payloads/vendor_id_payload.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2005-2010 Martin Willi
3: * Copyright (C) 2010 revosec AG
4: * Copyright (C) 2005 Jan Hutter
5: * HSR Hochschule fuer Technik Rapperswil
6: *
7: * This program is free software; you can redistribute it and/or modify it
8: * under the terms of the GNU General Public License as published by the
9: * Free Software Foundation; either version 2 of the License, or (at your
10: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11: *
12: * This program is distributed in the hope that it will be useful, but
13: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: */
17:
18: #include <stddef.h>
19:
20: #include "vendor_id_payload.h"
21:
22: typedef struct private_vendor_id_payload_t private_vendor_id_payload_t;
23:
24: /**
25: * Private data of an vendor_id_payload_t object.
26: */
27: struct private_vendor_id_payload_t {
28:
29: /**
30: * Public vendor_id_payload_t interface.
31: */
32: vendor_id_payload_t public;
33:
34: /**
35: * Next payload type.
36: */
37: uint8_t next_payload;
38:
39: /**
40: * Critical flag.
41: */
42: bool critical;
43:
44: /**
45: * Reserved bits
46: */
47: bool reserved[7];
48:
49: /**
50: * Length of this payload.
51: */
52: uint16_t payload_length;
53:
54: /**
55: * The contained data.
56: */
57: chunk_t data;
58:
59: /**
60: * Either a IKEv1 or a IKEv2 vendor ID payload
61: */
62: payload_type_t type;
63: };
64:
65: /**
66: * Encoding rules to parse or generate a VENDOR ID payload
67: *
68: * The defined offsets are the positions in a object of type
69: * private_vendor_id_payload_t.
70: */
71: static encoding_rule_t encodings[] = {
72: /* 1 Byte next payload type, stored in the field next_payload */
73: { U_INT_8, offsetof(private_vendor_id_payload_t, next_payload) },
74: /* the critical bit */
75: { FLAG, offsetof(private_vendor_id_payload_t, critical) },
76: /* 7 Bit reserved bits, nowhere stored */
77: { RESERVED_BIT, offsetof(private_vendor_id_payload_t, reserved[0]) },
78: { RESERVED_BIT, offsetof(private_vendor_id_payload_t, reserved[1]) },
79: { RESERVED_BIT, offsetof(private_vendor_id_payload_t, reserved[2]) },
80: { RESERVED_BIT, offsetof(private_vendor_id_payload_t, reserved[3]) },
81: { RESERVED_BIT, offsetof(private_vendor_id_payload_t, reserved[4]) },
82: { RESERVED_BIT, offsetof(private_vendor_id_payload_t, reserved[5]) },
83: { RESERVED_BIT, offsetof(private_vendor_id_payload_t, reserved[6]) },
84: /* Length of the whole payload*/
85: { PAYLOAD_LENGTH, offsetof(private_vendor_id_payload_t, payload_length)},
86: /* some vendor_id data bytes, length is defined in PAYLOAD_LENGTH */
87: { CHUNK_DATA, offsetof(private_vendor_id_payload_t, data) }
88: };
89:
90: /*
91: 1 2 3
92: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
93: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94: ! Next Payload !C! RESERVED ! Payload Length !
95: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96: + !
97: ~ VID Data ~
98: ! !
99: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100: */
101:
102: METHOD(payload_t, verify, status_t,
103: private_vendor_id_payload_t *this)
104: {
105: return SUCCESS;
106: }
107:
108: METHOD(payload_t, get_encoding_rules, int,
109: private_vendor_id_payload_t *this, encoding_rule_t **rules)
110: {
111: *rules = encodings;
112: return countof(encodings);
113: }
114:
115: METHOD(payload_t, get_header_length, int,
116: private_vendor_id_payload_t *this)
117: {
118: return 4;
119: }
120:
121: METHOD(payload_t, get_type, payload_type_t,
122: private_vendor_id_payload_t *this)
123: {
124: return this->type;
125: }
126:
127: METHOD(payload_t, get_next_type, payload_type_t,
128: private_vendor_id_payload_t *this)
129: {
130: return this->next_payload;
131: }
132:
133: METHOD(payload_t, set_next_type, void,
134: private_vendor_id_payload_t *this, payload_type_t type)
135: {
136: this->next_payload = type;
137: }
138:
139: METHOD(payload_t, get_length, size_t,
140: private_vendor_id_payload_t *this)
141: {
142: return this->payload_length;
143: }
144:
145: METHOD(vendor_id_payload_t, get_data, chunk_t,
146: private_vendor_id_payload_t *this)
147: {
148: return this->data;
149: }
150:
151: METHOD2(payload_t, vendor_id_payload_t, destroy, void,
152: private_vendor_id_payload_t *this)
153: {
154: free(this->data.ptr);
155: free(this);
156: }
157:
158: /*
159: * Described in header
160: */
161: vendor_id_payload_t *vendor_id_payload_create_data(payload_type_t type,
162: chunk_t data)
163: {
164: private_vendor_id_payload_t *this;
165:
166: INIT(this,
167: .public = {
168: .payload_interface = {
169: .verify = _verify,
170: .get_encoding_rules = _get_encoding_rules,
171: .get_header_length = _get_header_length,
172: .get_length = _get_length,
173: .get_next_type = _get_next_type,
174: .set_next_type = _set_next_type,
175: .get_type = _get_type,
176: .destroy = _destroy,
177: },
178: .get_data = _get_data,
179: .destroy = _destroy,
180: },
181: .next_payload = PL_NONE,
182: .payload_length = get_header_length(this) + data.len,
183: .data = data,
184: .type = type,
185: );
186: return &this->public;
187: }
188:
189: /*
190: * Described in header
191: */
192: vendor_id_payload_t *vendor_id_payload_create(payload_type_t type)
193: {
194: return vendor_id_payload_create_data(type, chunk_empty);
195: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>