includes/omapip/omapip_p.h

Go to the documentation of this file.
00001 /* omapip_p.h
00002 
00003    Private master include file for the OMAPI library. */
00004 
00005 /*
00006  * Copyright (c) 2009-2010,2014 by Internet Systems Consortium, Inc. ("ISC") 
00007  * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
00008  * Copyright (c) 1996-2003 by Internet Software Consortium
00009  *
00010  * Permission to use, copy, modify, and distribute this software for any
00011  * purpose with or without fee is hereby granted, provided that the above
00012  * copyright notice and this permission notice appear in all copies.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
00015  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00016  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
00017  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00018  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00019  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00020  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00021  *
00022  *   Internet Systems Consortium, Inc.
00023  *   950 Charter Street
00024  *   Redwood City, CA 94063
00025  *   <info@isc.org>
00026  *   https://www.isc.org/
00027  *
00028  */
00029 
00030 #ifndef __OMAPIP_OMAPIP_P_H__
00031 #define __OMAPIP_OMAPIP_P_H__
00032 
00033 #ifndef __CYGWIN32__
00034 #include <sys/types.h>
00035 #include <netinet/in.h>
00036 #include <sys/socket.h>
00037 #include <sys/un.h>
00038 #include <arpa/inet.h>
00039 
00040 #include <netdb.h>
00041 #else
00042 #define fd_set cygwin_fd_set
00043 #include <sys/types.h>
00044 #endif
00045 #include <fcntl.h>
00046 #include <stdio.h>
00047 #include <unistd.h>
00048 #include <string.h>
00049 #include <memory.h>
00050 #include <stdlib.h>
00051 #include <sys/stat.h>
00052 #include <ctype.h>
00053 #include <time.h>
00054 
00055 /*
00056  * XXX: I'm not sure why these were here.
00057 #include "cdefs.h"
00058 #include "osdep.h"
00059  */
00060 
00061 #include <dst/dst.h>
00062 #include "result.h"
00063 
00064 #include <omapip/convert.h>
00065 #include <omapip/hash.h>
00066 #include <omapip/omapip.h>
00067 #include <omapip/trace.h>
00068 
00069 /* DST_API control flags */
00070 /* These are used in functions dst_sign_data and dst_verify_data */
00071 #define SIG_MODE_INIT           1  /* initalize digest */
00072 #define SIG_MODE_UPDATE         2  /* add data to digest */
00073 #define SIG_MODE_FINAL          4  /* generate/verify signature */
00074 #define SIG_MODE_ALL            (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
00075 
00076 /* OMAPI protocol header, version 1.00 */
00077 typedef struct {
00078         u_int32_t authlen;      /* Length of authenticator. */
00079         u_int32_t authid;       /* Authenticator object ID. */
00080         u_int32_t op;           /* Opcode. */
00081         omapi_handle_t handle;  /* Handle of object being operated on,
00082                                    or zero. */
00083         u_int32_t id;           /* Transaction ID. */
00084         u_int32_t rid;  /* ID of transaction to which this is a response. */
00085 } omapi_protocol_header_t;
00086 
00087 #define OMAPI_PROTOCOL_VERSION  100
00088 
00089 #define OMAPI_OP_OPEN           1
00090 #define OMAPI_OP_REFRESH        2
00091 #define OMAPI_OP_UPDATE         3
00092 #define OMAPI_OP_NOTIFY         4
00093 #define OMAPI_OP_STATUS         5
00094 #define OMAPI_OP_DELETE         6
00095 
00096 typedef enum {
00097         omapi_connection_unconnected,
00098         omapi_connection_connecting,
00099         omapi_connection_connected,
00100         omapi_connection_disconnecting,
00101         omapi_connection_closed
00102 } omapi_connection_state_t;
00103 
00104 typedef enum {
00105         omapi_protocol_intro_wait,
00106         omapi_protocol_header_wait,
00107         omapi_protocol_signature_wait,
00108         omapi_protocol_name_wait,
00109         omapi_protocol_name_length_wait,
00110         omapi_protocol_value_wait,
00111         omapi_protocol_value_length_wait
00112 } omapi_protocol_state_t;
00113 
00114 typedef struct __omapi_message_object {
00115         OMAPI_OBJECT_PREAMBLE;
00116         struct __omapi_message_object *next, *prev;
00117         omapi_object_t *object;
00118         omapi_object_t *notify_object;
00119         struct __omapi_protocol_object *protocol_object;
00120         u_int32_t authlen;
00121         omapi_typed_data_t *authenticator;
00122         u_int32_t authid;
00123         omapi_object_t *id_object;
00124         u_int32_t op;
00125         u_int32_t h;
00126         u_int32_t id;
00127         u_int32_t rid;
00128 } omapi_message_object_t;
00129 
00130 typedef struct __omapi_remote_auth {
00131         struct __omapi_remote_auth *next;
00132         omapi_handle_t remote_handle;
00133         omapi_object_t *a;
00134 } omapi_remote_auth_t;
00135 
00136 typedef struct __omapi_protocol_object {
00137         OMAPI_OBJECT_PREAMBLE;
00138         u_int32_t header_size;          
00139         u_int32_t protocol_version;
00140         u_int32_t next_xid;
00141 
00142         omapi_protocol_state_t state;   /* Input state. */
00143         int reading_message_values;     /* True if reading message-specific
00144                                            values. */
00145         omapi_message_object_t *message;        /* Incoming message. */
00146         omapi_data_string_t *name;      /* Incoming name. */
00147         omapi_typed_data_t *value;      /* Incoming value. */
00148         isc_result_t verify_result;
00149         omapi_remote_auth_t *default_auth; /* Default authinfo to use. */
00150         omapi_remote_auth_t *remote_auth_list;  /* Authenticators active on
00151                                                    this connection. */
00152 
00153         isc_boolean_t insecure;         /* Set to allow unauthenticated
00154                                            messages. */
00155 
00156         isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
00157 } omapi_protocol_object_t;
00158 
00159 typedef struct {
00160         OMAPI_OBJECT_PREAMBLE;
00161 
00162         isc_boolean_t insecure;         /* Set to allow unauthenticated
00163                                            messages. */
00164 
00165         isc_result_t (*verify_auth) (omapi_object_t *, omapi_auth_key_t *);
00166 } omapi_protocol_listener_object_t;
00167 
00168 #include <omapip/buffer.h>
00169 
00170 typedef struct __omapi_listener_object {
00171         OMAPI_OBJECT_PREAMBLE;
00172         int socket;             /* Connection socket. */
00173         int index;
00174         struct sockaddr_in address;
00175         isc_result_t (*verify_addr) (omapi_object_t *, omapi_addr_t *);
00176 } omapi_listener_object_t;
00177 
00178 typedef struct __omapi_connection_object {
00179         OMAPI_OBJECT_PREAMBLE;
00180         int socket;             /* Connection socket. */
00181         int32_t index;
00182         omapi_connection_state_t state;
00183         struct sockaddr_in remote_addr;
00184         struct sockaddr_in local_addr;
00185         omapi_addr_list_t *connect_list;        /* List of addresses to which
00186                                                    to connect. */
00187         int cptr;               /* Current element we are connecting to. */
00188         u_int32_t bytes_needed; /* Bytes of input needed before wakeup. */
00189         u_int32_t in_bytes;     /* Bytes of input already buffered. */
00190         omapi_buffer_t *inbufs;
00191         u_int32_t out_bytes;    /* Bytes of output in buffers. */
00192         omapi_buffer_t *outbufs;
00193         omapi_listener_object_t *listener;      /* Listener that accepted this
00194                                                    connection, if any. */
00195         dst_key_t *in_key;      /* Authenticator signing incoming
00196                                    data. */
00197         void *in_context;       /* Input hash context. */
00198         dst_key_t *out_key;     /* Authenticator signing outgoing
00199                                    data. */
00200         void *out_context;      /* Output hash context. */
00201 } omapi_connection_object_t;
00202 
00203 typedef struct __omapi_io_object {
00204         OMAPI_OBJECT_PREAMBLE;
00205         struct __omapi_io_object *next;
00206         int (*readfd) (omapi_object_t *);
00207         int (*writefd) (omapi_object_t *);
00208         isc_result_t (*reader) (omapi_object_t *);
00209         isc_result_t (*writer) (omapi_object_t *);
00210         isc_result_t (*reaper) (omapi_object_t *);
00211         isc_socket_t *fd;
00212         isc_boolean_t closed; /* ISC_TRUE = closed, do not use */
00213 } omapi_io_object_t;
00214 
00215 typedef struct __omapi_generic_object {
00216         OMAPI_OBJECT_PREAMBLE;
00217         omapi_value_t **values;
00218         u_int8_t *changed;
00219         int nvalues, va_max;
00220 } omapi_generic_object_t;
00221 
00222 typedef struct __omapi_waiter_object {
00223         OMAPI_OBJECT_PREAMBLE;
00224         int ready;
00225         isc_result_t waitstatus;
00226         struct __omapi_waiter_object *next;
00227 } omapi_waiter_object_t;
00228 
00229 #define OMAPI_HANDLE_TABLE_SIZE 120
00230 
00231 typedef struct __omapi_handle_table {
00232         omapi_handle_t first, limit;
00233         omapi_handle_t next;
00234         int leafp;
00235         union {
00236                 omapi_object_t *object;
00237                 struct __omapi_handle_table *table;
00238         } children [OMAPI_HANDLE_TABLE_SIZE];
00239 } omapi_handle_table_t;
00240 
00241 #include <omapip/alloc.h>
00242 
00243 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol, omapi_protocol_object_t,
00244                          omapi_type_protocol)
00245 OMAPI_OBJECT_ALLOC_DECL (omapi_protocol_listener,
00246                          omapi_protocol_listener_object_t,
00247                          omapi_type_protocol_listener)
00248 OMAPI_OBJECT_ALLOC_DECL (omapi_connection,
00249                          omapi_connection_object_t, omapi_type_connection)
00250 OMAPI_OBJECT_ALLOC_DECL (omapi_listener,
00251                          omapi_listener_object_t, omapi_type_listener)
00252 OMAPI_OBJECT_ALLOC_DECL (omapi_io,
00253                          omapi_io_object_t, omapi_type_io_object)
00254 OMAPI_OBJECT_ALLOC_DECL (omapi_waiter,
00255                          omapi_waiter_object_t, omapi_type_waiter)
00256 OMAPI_OBJECT_ALLOC_DECL (omapi_generic,
00257                          omapi_generic_object_t, omapi_type_generic)
00258 OMAPI_OBJECT_ALLOC_DECL (omapi_message,
00259                          omapi_message_object_t, omapi_type_message)
00260 
00261 isc_result_t omapi_connection_sign_data (int mode,
00262                                          dst_key_t *key,
00263                                          void **context,
00264                                          const unsigned char *data,
00265                                          const unsigned len,
00266                                          omapi_typed_data_t **result);
00267 isc_result_t omapi_listener_connect (omapi_connection_object_t **obj,
00268                                      omapi_listener_object_t *listener,
00269                                      int socket,
00270                                      struct sockaddr_in *remote_addr);
00271 void omapi_listener_trace_setup (void);
00272 void omapi_connection_trace_setup (void);
00273 void omapi_buffer_trace_setup (void);
00274 void omapi_connection_register (omapi_connection_object_t *,
00275                                 const char *, int);
00276 OMAPI_ARRAY_TYPE_DECL(omapi_listener, omapi_listener_object_t);
00277 OMAPI_ARRAY_TYPE_DECL(omapi_connection, omapi_connection_object_t);
00278 
00279 isc_result_t omapi_handle_clear(omapi_handle_t);
00280 
00281 extern int log_priority;
00282 extern int log_perror;
00283 extern void (*log_cleanup) (void);
00284 
00285 void log_fatal (const char *, ...)
00286         __attribute__((__format__(__printf__,1,2))) ISC_DHCP_NORETURN;
00287 int log_error (const char *, ...)
00288         __attribute__((__format__(__printf__,1,2)));
00289 int log_info (const char *, ...)
00290         __attribute__((__format__(__printf__,1,2)));
00291 int log_debug (const char *, ...)
00292         __attribute__((__format__(__printf__,1,2)));
00293 void do_percentm (char *obuf, const char *ibuf);
00294 
00295 isc_result_t uerr2isc (int);
00296 isc_result_t ns_rcode_to_isc (int);
00297 
00298 extern omapi_message_object_t *omapi_registered_messages;
00299 
00300 #endif /* __OMAPIP_OMAPIP_P_H__ */

Generated on 5 Apr 2014 for ISC DHCP by  doxygen 1.6.1