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