]> git.ipfire.org Git - thirdparty/dhcp.git/blob - includes/omapip/omapip_p.h
Revert last commit
[thirdparty/dhcp.git] / includes / omapip / omapip_p.h
1 /* omapip_p.h
2
3 Private master include file for the OMAPI library. */
4
5 /*
6 * Copyright (c) 2004-2019 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1996-2003 by Internet Software Consortium
8 *
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 * Internet Systems Consortium, Inc.
22 * 950 Charter Street
23 * Redwood City, CA 94063
24 * <info@isc.org>
25 * https://www.isc.org/
26 *
27 */
28
29 #ifndef __OMAPIP_OMAPIP_P_H__
30 #define __OMAPIP_OMAPIP_P_H__
31
32 #ifndef __CYGWIN32__
33 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <sys/socket.h>
36 #include <sys/un.h>
37 #include <arpa/inet.h>
38
39 #include <netdb.h>
40 #else
41 #define fd_set cygwin_fd_set
42 #include <sys/types.h>
43 #endif
44 #include <fcntl.h>
45 #include <stdio.h>
46 #include <unistd.h>
47 #include <string.h>
48 #include <memory.h>
49 #include <stdlib.h>
50 #include <sys/stat.h>
51 #include <ctype.h>
52 #include <time.h>
53
54 /*
55 * XXX: I'm not sure why these were here.
56 #include "cdefs.h"
57 #include "osdep.h"
58 */
59
60 #include <dst/dst.h>
61 #include "result.h"
62
63 #include <omapip/convert.h>
64 #include <omapip/hash.h>
65 #include <omapip/omapip.h>
66 #include <omapip/trace.h>
67
68 /* DST_API control flags */
69 /* These are used in functions dst_sign_data and dst_verify_data */
70 #define SIG_MODE_INIT 1 /* initalize digest */
71 #define SIG_MODE_UPDATE 2 /* add data to digest */
72 #define SIG_MODE_FINAL 4 /* generate/verify signature */
73 #define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
74
75 /* OMAPI protocol header, version 1.00 */
76 typedef struct {
77 u_int32_t authlen; /* Length of authenticator. */
78 u_int32_t authid; /* Authenticator object ID. */
79 u_int32_t op; /* Opcode. */
80 omapi_handle_t handle; /* Handle of object being operated on,
81 or zero. */
82 u_int32_t id; /* Transaction ID. */
83 u_int32_t rid; /* ID of transaction to which this is a response. */
84 } omapi_protocol_header_t;
85
86 #define OMAPI_PROTOCOL_VERSION 100
87
88 #define OMAPI_OP_OPEN 1
89 #define OMAPI_OP_REFRESH 2
90 #define OMAPI_OP_UPDATE 3
91 #define OMAPI_OP_NOTIFY 4
92 #define OMAPI_OP_STATUS 5
93 #define OMAPI_OP_DELETE 6
94
95 typedef enum {
96 omapi_connection_unconnected,
97 omapi_connection_connecting,
98 omapi_connection_connected,
99 omapi_connection_disconnecting,
100 omapi_connection_closed
101 } omapi_connection_state_t;
102
103 typedef enum {
104 omapi_protocol_intro_wait,
105 omapi_protocol_header_wait,
106 omapi_protocol_signature_wait,
107 omapi_protocol_name_wait,
108 omapi_protocol_name_length_wait,
109 omapi_protocol_value_wait,
110 omapi_protocol_value_length_wait
111 } omapi_protocol_state_t;
112
113 typedef struct __omapi_message_object {
114 OMAPI_OBJECT_PREAMBLE;
115 struct __omapi_message_object *next, *prev;
116 omapi_object_t *object;
117 omapi_object_t *notify_object;
118 struct __omapi_protocol_object *protocol_object;
119 u_int32_t authlen;
120 omapi_typed_data_t *authenticator;
121 u_int32_t authid;
122 omapi_object_t *id_object;
123 u_int32_t op;
124 u_int32_t h;
125 u_int32_t id;
126 u_int32_t rid;
127 } omapi_message_object_t;
128
129 typedef struct __omapi_remote_auth {
130 struct __omapi_remote_auth *next;
131 omapi_handle_t remote_handle;
132 omapi_object_t *a;
133 } omapi_remote_auth_t;
134
135 typedef struct __omapi_protocol_object {
136 OMAPI_OBJECT_PREAMBLE;
137 u_int32_t header_size;
138 u_int32_t protocol_version;
139 u_int32_t next_xid;
140
141 omapi_protocol_state_t state; /* Input state. */
142 int reading_message_values; /* True if reading message-specific
143 values. */
144 omapi_message_object_t *message; /* Incoming message. */
145 omapi_data_string_t *name; /* Incoming name. */
146 omapi_typed_data_t *value; /* Incoming value. */
147 isc_result_t verify_result;
148 omapi_remote_auth_t *default_auth; /* Default authinfo to use. */
149 omapi_remote_auth_t *remote_auth_list; /* Authenticators active on
150 this connection. */
151
152 isc_boolean_t insecure; /* Set to allow unauthenticated
153 messages. */
154
155 isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
156 } omapi_protocol_object_t;
157
158 typedef struct {
159 OMAPI_OBJECT_PREAMBLE;
160
161 isc_boolean_t insecure; /* Set to allow unauthenticated
162 messages. */
163
164 isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
165 } omapi_protocol_listener_object_t;
166
167 #include <omapip/buffer.h>
168
169 typedef struct __omapi_listener_object {
170 OMAPI_OBJECT_PREAMBLE;
171 int socket; /* Connection socket. */
172 int index;
173 struct sockaddr_in address;
174 isc_result_t (*verify_addr) (omapi_object_t *, omapi_addr_t *);
175 } omapi_listener_object_t;
176
177 typedef struct __omapi_connection_object {
178 OMAPI_OBJECT_PREAMBLE;
179 int socket; /* Connection socket. */
180 int32_t index;
181 omapi_connection_state_t state;
182 struct sockaddr_in remote_addr;
183 struct sockaddr_in local_addr;
184 omapi_addr_list_t *connect_list; /* List of addresses to which
185 to connect. */
186 int cptr; /* Current element we are connecting to. */
187 u_int32_t bytes_needed; /* Bytes of input needed before wakeup. */
188 u_int32_t in_bytes; /* Bytes of input already buffered. */
189 omapi_buffer_t *inbufs;
190 u_int32_t out_bytes; /* Bytes of output in buffers. */
191 omapi_buffer_t *outbufs;
192 omapi_listener_object_t *listener; /* Listener that accepted this
193 connection, if any. */
194 dst_key_t *in_key; /* Authenticator signing incoming
195 data. */
196 void *in_context; /* Input hash context. */
197 dst_key_t *out_key; /* Authenticator signing outgoing
198 data. */
199 void *out_context; /* Output hash context. */
200 } omapi_connection_object_t;
201
202 typedef struct __omapi_io_object {
203 OMAPI_OBJECT_PREAMBLE;
204 struct __omapi_io_object *next;
205 int (*readfd) (omapi_object_t *);
206 int (*writefd) (omapi_object_t *);
207 isc_result_t (*reader) (omapi_object_t *);
208 isc_result_t (*writer) (omapi_object_t *);
209 isc_result_t (*reaper) (omapi_object_t *);
210 isc_socket_t *fd;
211 isc_boolean_t closed; /* ISC_TRUE = closed, do not use */
212 } omapi_io_object_t;
213
214 typedef struct __omapi_generic_object {
215 OMAPI_OBJECT_PREAMBLE;
216 omapi_value_t **values;
217 u_int8_t *changed;
218 int nvalues, va_max;
219 } omapi_generic_object_t;
220
221 typedef struct __omapi_waiter_object {
222 OMAPI_OBJECT_PREAMBLE;
223 int ready;
224 isc_result_t waitstatus;
225 struct __omapi_waiter_object *next;
226 } omapi_waiter_object_t;
227
228 #define OMAPI_HANDLE_TABLE_SIZE 120
229
230 typedef struct __omapi_handle_table {
231 omapi_handle_t first, limit;
232 omapi_handle_t next;
233 int leafp;
234 union {
235 omapi_object_t *object;
236 struct __omapi_handle_table *table;
237 } children [OMAPI_HANDLE_TABLE_SIZE];
238 } omapi_handle_table_t;
239
240 #include <omapip/alloc.h>
241
242 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol, omapi_protocol_object_t,
243 omapi_type_protocol)
244 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol_listener,
245 omapi_protocol_listener_object_t,
246 omapi_type_protocol_listener)
247 OMAPI_OBJECT_ALLOC_DECL (omapi_connection,
248 omapi_connection_object_t, omapi_type_connection)
249 OMAPI_OBJECT_ALLOC_DECL (omapi_listener,
250 omapi_listener_object_t, omapi_type_listener)
251 OMAPI_OBJECT_ALLOC_DECL (omapi_io,
252 omapi_io_object_t, omapi_type_io_object)
253 OMAPI_OBJECT_ALLOC_DECL (omapi_waiter,
254 omapi_waiter_object_t, omapi_type_waiter)
255 OMAPI_OBJECT_ALLOC_DECL (omapi_generic,
256 omapi_generic_object_t, omapi_type_generic)
257 OMAPI_OBJECT_ALLOC_DECL (omapi_message,
258 omapi_message_object_t, omapi_type_message)
259
260 isc_result_t omapi_connection_sign_data (int mode,
261 dst_key_t *key,
262 void **context,
263 const unsigned char *data,
264 const unsigned len,
265 omapi_typed_data_t **result);
266 isc_result_t omapi_listener_connect (omapi_connection_object_t **obj,
267 omapi_listener_object_t *listener,
268 int socket,
269 struct sockaddr_in *remote_addr);
270 void omapi_listener_trace_setup (void);
271 void omapi_connection_trace_setup (void);
272 void omapi_buffer_trace_setup (void);
273 void omapi_connection_register (omapi_connection_object_t *,
274 const char *, int);
275 OMAPI_ARRAY_TYPE_DECL(omapi_listener, omapi_listener_object_t);
276 OMAPI_ARRAY_TYPE_DECL(omapi_connection, omapi_connection_object_t);
277
278 isc_result_t omapi_handle_clear(omapi_handle_t);
279
280 extern int log_perror;
281 extern void (*log_cleanup) (void);
282
283 void log_fatal (const char *, ...)
284 __attribute__((__format__(__printf__,1,2))) ISC_DHCP_NORETURN;
285 int log_error (const char *, ...)
286 __attribute__((__format__(__printf__,1,2)));
287 int log_info (const char *, ...)
288 __attribute__((__format__(__printf__,1,2)));
289 int log_debug (const char *, ...)
290 __attribute__((__format__(__printf__,1,2)));
291
292 void do_percentm (char *obuf, size_t obufsize, const char *ibuf);
293
294 isc_result_t uerr2isc (int);
295 isc_result_t ns_rcode_to_isc (int);
296
297 extern omapi_message_object_t *omapi_registered_messages;
298
299 #endif /* __OMAPIP_OMAPIP_P_H__ */