1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 2001 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #ifndef _DHCP_SVC_PRIVATE_H 28 #define _DHCP_SVC_PRIVATE_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * Contains SMI-private interfaces to DHCP data service. DO NOT SHIP! 34 */ 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #include <sys/types.h> 41 #include <stddef.h> 42 #include <dhcp_svc_confopt.h> 43 #include <dhcp_svc_public.h> 44 45 #define DSVC_PRIVATE_VERSION 1 /* Version of private layer API */ 46 #define DSVC_MODULE_DIR "/usr/lib/inet/dhcp/svc" 47 #define DSVC_PUBLIC_PREFIX "ds" 48 49 /* 50 * Public (service provider) layer definitions at boundary with private layer. 51 */ 52 typedef int (*dsvc_splfuncp_t)(); 53 54 typedef struct { 55 dsvc_splfuncp_t status; 56 dsvc_splfuncp_t version; 57 dsvc_splfuncp_t mklocation; 58 dsvc_splfuncp_t list_dt; 59 dsvc_splfuncp_t open_dt; 60 dsvc_splfuncp_t close_dt; 61 dsvc_splfuncp_t remove_dt; 62 dsvc_splfuncp_t lookup_dt; 63 dsvc_splfuncp_t add_dt; 64 dsvc_splfuncp_t modify_dt; 65 dsvc_splfuncp_t delete_dt; 66 dsvc_splfuncp_t list_dn; 67 dsvc_splfuncp_t open_dn; 68 dsvc_splfuncp_t close_dn; 69 dsvc_splfuncp_t remove_dn; 70 dsvc_splfuncp_t lookup_dn; 71 dsvc_splfuncp_t add_dn; 72 dsvc_splfuncp_t modify_dn; 73 dsvc_splfuncp_t delete_dn; 74 } dsvc_splapi_t; 75 76 #define DSVC_NSPLFUNCS (sizeof (dsvc_splapi_t) / sizeof (dsvc_splfuncp_t)) 77 #define DSVC_CUR_CONVER (-1) /* magic "get the current version" token */ 78 79 typedef struct { 80 char *d_resource; /* datastore name; e.g. "SUNWfiles" */ 81 char *d_location; /* location of datastore containers */ 82 char *d_config; /* datastore-specific config data */ 83 int d_conver; /* container version */ 84 } dsvc_datastore_t; 85 86 /* 87 * Container types. 88 */ 89 typedef enum { 90 DSVC_DHCPTAB, 91 DSVC_DHCPNETWORK 92 } dsvc_contype_t; 93 94 /* 95 * Container ID: so far just the network and netmask for DSVC_DHCPNETWORK 96 * containers, but may include more information in the future. 97 */ 98 typedef struct { 99 struct in_addr c_net; /* network number */ 100 struct in_addr c_mask; /* netmask */ 101 } dsvc_conid_t; 102 103 struct dsvc_synch_ops; /* forward declaration */ 104 105 /* 106 * Per-handle synchronization information, used when modules require 107 * private-layer synchronization. 108 */ 109 typedef struct { 110 dsvc_datastore_t *s_datastore; /* datastore backpointer */ 111 char s_loctoken[MAXPATHLEN]; 112 char *s_conname; /* container name */ 113 boolean_t s_nonblock; /* container opened NONBLOCK */ 114 struct dsvc_synch_ops *s_ops; /* pointer to ops vector */ 115 void *s_data; /* synch-layer private data */ 116 } dsvc_synch_t; 117 118 /* 119 * Synchronization operations; each synchronization strategy must implement 120 * these operations. Right now, we only have one synchronization strategy, 121 * but this may change someday. 122 */ 123 typedef struct dsvc_synch_ops { 124 int (*synch_init)(dsvc_synch_t *, unsigned int); 125 void (*synch_fini)(dsvc_synch_t *); 126 int (*synch_rdlock)(dsvc_synch_t *, void **); 127 int (*synch_wrlock)(dsvc_synch_t *, void **); 128 int (*synch_unlock)(dsvc_synch_t *, void *); 129 } dsvc_synch_ops_t; 130 131 #define DSVC_SYNCH_INIT(sp, flags) ((sp)->s_ops->synch_init((sp), (flags))) 132 #define DSVC_SYNCH_FINI(sp) ((sp)->s_ops->synch_fini((sp))) 133 #define DSVC_SYNCH_RDLOCK(sp, cp) ((sp)->s_ops->synch_rdlock((sp), (cp))) 134 #define DSVC_SYNCH_WRLOCK(sp, cp) ((sp)->s_ops->synch_wrlock((sp), (cp))) 135 #define DSVC_SYNCH_UNLOCK(sp, c) ((sp)->s_ops->synch_unlock((sp), (c))) 136 137 /* 138 * We divide the dsvc_synchtype_t up into two parts: a strategy part and a 139 * flags part. Right now, the only flag tells private layer to request 140 * cross-host synchronization. This is here instead of <dhcp_svc_public.h> 141 * since it's not a public interface and there's nowhere better to put it. 142 */ 143 #define DSVC_SYNCH_FLAGMASK 0xffff0000 144 #define DSVC_SYNCH_STRATMASK 0x0000ffff 145 #define DSVC_SYNCH_CROSSHOST 0x00010000 146 147 /* 148 * Private layer handle, one per open instance of a container. 149 * Allocated by open_dd(), destroyed by close_dd(). 150 */ 151 typedef struct dsvc_handle { 152 dsvc_datastore_t d_desc; /* datastore descriptor */ 153 void *d_instance; /* dlopen() instance */ 154 dsvc_contype_t d_type; /* container type */ 155 dsvc_conid_t d_conid; /* container id */ 156 void *d_hand; /* public module handle */ 157 dsvc_synch_t *d_synch; /* synchronization state */ 158 dsvc_splapi_t d_api; /* service provider layer API */ 159 } *dsvc_handle_t; 160 161 /* 162 * Quick-n-dirty check for an invalid dsvc_handle_t. 163 */ 164 #define DSVC_HANDLE_INVAL(h) ((h) == NULL || (h)->d_instance == NULL || \ 165 (h)->d_hand == NULL) 166 167 extern int enumerate_dd(char ***, int *); 168 extern int list_dd(dsvc_datastore_t *, dsvc_contype_t, char ***, uint_t *); 169 extern int status_dd(dsvc_datastore_t *); 170 extern int mklocation_dd(dsvc_datastore_t *); 171 extern int add_dd_entry(dsvc_handle_t, void *); 172 extern int modify_dd_entry(dsvc_handle_t, const void *, void *); 173 extern int delete_dd_entry(dsvc_handle_t, void *); 174 extern int close_dd(dsvc_handle_t *); 175 extern int remove_dd(dsvc_datastore_t *, dsvc_contype_t, const char *); 176 extern int open_dd(dsvc_handle_t *, dsvc_datastore_t *, dsvc_contype_t, 177 const char *, uint_t); 178 extern int lookup_dd(dsvc_handle_t, boolean_t, uint_t, int, const void *, 179 void **, uint_t *); 180 extern void free_dd(dsvc_handle_t, void *); 181 extern void free_dd_list(dsvc_handle_t, void *); 182 extern int confopt_to_datastore(dhcp_confopt_t *, dsvc_datastore_t *); 183 extern int module_synchtype(dsvc_datastore_t *, dsvc_synchtype_t *); 184 185 /* 186 * Under DEBUG, the DHCP_CONFOPT_ROOT environment variable can be set to 187 * the path of a directory for the DHCP server to use an alternate root 188 * for its configuration information and datastores. 189 */ 190 #ifdef DEBUG 191 #define DHCP_CONFOPT_ROOT ((getenv("DHCP_CONFOPT_ROOT") != NULL) ? \ 192 getenv("DHCP_CONFOPT_ROOT") : "") 193 #else 194 #define DHCP_CONFOPT_ROOT "" 195 #endif 196 197 #ifdef __cplusplus 198 } 199 #endif 200 201 #endif /* !_DHCP_SVC_PRIVATE_H */