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