summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdhcpsvc/head/dhcp_svc_private.h
blob: 1a3555e36728133a572edb689ee735e5afbd1f7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2001 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#ifndef _DHCP_SVC_PRIVATE_H
#define	_DHCP_SVC_PRIVATE_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

/*
 * Contains SMI-private interfaces to DHCP data service.  DO NOT SHIP!
 */

#ifdef	__cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <stddef.h>
#include <dhcp_svc_confopt.h>
#include <dhcp_svc_public.h>

#define	DSVC_PRIVATE_VERSION	1	/* Version of private layer API */
#define	DSVC_MODULE_DIR		"/usr/lib/inet/dhcp/svc"
#define	DSVC_PUBLIC_PREFIX	"ds"

/*
 * Public (service provider) layer definitions at boundary with private layer.
 */
typedef	int (*dsvc_splfuncp_t)();

typedef struct {
	dsvc_splfuncp_t	status;
	dsvc_splfuncp_t	version;
	dsvc_splfuncp_t	mklocation;
	dsvc_splfuncp_t	list_dt;
	dsvc_splfuncp_t	open_dt;
	dsvc_splfuncp_t	close_dt;
	dsvc_splfuncp_t	remove_dt;
	dsvc_splfuncp_t	lookup_dt;
	dsvc_splfuncp_t	add_dt;
	dsvc_splfuncp_t	modify_dt;
	dsvc_splfuncp_t	delete_dt;
	dsvc_splfuncp_t	list_dn;
	dsvc_splfuncp_t	open_dn;
	dsvc_splfuncp_t	close_dn;
	dsvc_splfuncp_t	remove_dn;
	dsvc_splfuncp_t	lookup_dn;
	dsvc_splfuncp_t	add_dn;
	dsvc_splfuncp_t	modify_dn;
	dsvc_splfuncp_t	delete_dn;
} dsvc_splapi_t;

#define	DSVC_NSPLFUNCS	(sizeof (dsvc_splapi_t) / sizeof (dsvc_splfuncp_t))
#define	DSVC_CUR_CONVER	(-1)	/* magic "get the current version" token */

typedef struct {
	char		*d_resource;	/* datastore name; e.g. "SUNWfiles" */
	char		*d_location;	/* location of datastore containers */
	char		*d_config;	/* datastore-specific config data */
	int		d_conver;	/* container version */
} dsvc_datastore_t;

/*
 * Container types.
 */
typedef enum {
	DSVC_DHCPTAB,
	DSVC_DHCPNETWORK
} dsvc_contype_t;

/*
 * Container ID: so far just the network and netmask for DSVC_DHCPNETWORK
 * containers, but may include more information in the future.
 */
typedef struct {
	struct in_addr		c_net; 		/* network number */
	struct in_addr		c_mask;		/* netmask */
} dsvc_conid_t;

struct dsvc_synch_ops;				/* forward declaration */

/*
 * Per-handle synchronization information, used when modules require
 * private-layer synchronization.
 */
typedef struct {
	dsvc_datastore_t	*s_datastore;	/* datastore backpointer */
	char			s_loctoken[MAXPATHLEN];
	char			*s_conname;	/* container name */
	boolean_t		s_nonblock;	/* container opened NONBLOCK */
	struct dsvc_synch_ops	*s_ops;		/* pointer to ops vector */
	void			*s_data;	/* synch-layer private data */
} dsvc_synch_t;

/*
 * Synchronization operations; each synchronization strategy must implement
 * these operations.  Right now, we only have one synchronization strategy,
 * but this may change someday.
 */
typedef struct dsvc_synch_ops {
	int		(*synch_init)(dsvc_synch_t *, unsigned int);
	void		(*synch_fini)(dsvc_synch_t *);
	int		(*synch_rdlock)(dsvc_synch_t *, void **);
	int		(*synch_wrlock)(dsvc_synch_t *, void **);
	int		(*synch_unlock)(dsvc_synch_t *, void *);
} dsvc_synch_ops_t;

#define	DSVC_SYNCH_INIT(sp, flags)	((sp)->s_ops->synch_init((sp), (flags)))
#define	DSVC_SYNCH_FINI(sp)		((sp)->s_ops->synch_fini((sp)))
#define	DSVC_SYNCH_RDLOCK(sp, cp)	((sp)->s_ops->synch_rdlock((sp), (cp)))
#define	DSVC_SYNCH_WRLOCK(sp, cp)	((sp)->s_ops->synch_wrlock((sp), (cp)))
#define	DSVC_SYNCH_UNLOCK(sp, c)	((sp)->s_ops->synch_unlock((sp), (c)))

/*
 * We divide the dsvc_synchtype_t up into two parts: a strategy part and a
 * flags part.  Right now, the only flag tells private layer to request
 * cross-host synchronization.  This is here instead of <dhcp_svc_public.h>
 * since it's not a public interface and there's nowhere better to put it.
 */
#define	DSVC_SYNCH_FLAGMASK		0xffff0000
#define	DSVC_SYNCH_STRATMASK		0x0000ffff
#define	DSVC_SYNCH_CROSSHOST		0x00010000

/*
 * Private layer handle, one per open instance of a container.
 * Allocated by open_dd(), destroyed by close_dd().
 */
typedef struct dsvc_handle {
	dsvc_datastore_t	d_desc;		/* datastore descriptor */
	void			*d_instance;	/* dlopen() instance  */
	dsvc_contype_t		d_type;		/* container type */
	dsvc_conid_t		d_conid;	/* container id */
	void			*d_hand;	/* public module handle */
	dsvc_synch_t		*d_synch;	/* synchronization state */
	dsvc_splapi_t		d_api;		/* service provider layer API */
} *dsvc_handle_t;

/*
 * Quick-n-dirty check for an invalid dsvc_handle_t.
 */
#define	DSVC_HANDLE_INVAL(h)	((h) == NULL || (h)->d_instance == NULL || \
				(h)->d_hand == NULL)

extern int enumerate_dd(char ***, int *);
extern int list_dd(dsvc_datastore_t *, dsvc_contype_t, char ***, uint_t *);
extern int status_dd(dsvc_datastore_t *);
extern int mklocation_dd(dsvc_datastore_t *);
extern int add_dd_entry(dsvc_handle_t, void *);
extern int modify_dd_entry(dsvc_handle_t, const void *, void *);
extern int delete_dd_entry(dsvc_handle_t, void *);
extern int close_dd(dsvc_handle_t *);
extern int remove_dd(dsvc_datastore_t *, dsvc_contype_t, const char *);
extern int open_dd(dsvc_handle_t *, dsvc_datastore_t *, dsvc_contype_t,
	    const char *, uint_t);
extern int lookup_dd(dsvc_handle_t, boolean_t, uint_t, int, const void *,
	    void **, uint_t *);
extern void free_dd(dsvc_handle_t, void *);
extern void free_dd_list(dsvc_handle_t, void *);
extern int confopt_to_datastore(dhcp_confopt_t *, dsvc_datastore_t *);
extern int module_synchtype(dsvc_datastore_t *, dsvc_synchtype_t *);

/*
 * Under DEBUG, the DHCP_CONFOPT_ROOT environment variable can be set to
 * the path of a directory for the DHCP server to use an alternate root
 * for its configuration information and datastores.
 */
#ifdef DEBUG
#define	DHCP_CONFOPT_ROOT ((getenv("DHCP_CONFOPT_ROOT") != NULL) ? \
			    getenv("DHCP_CONFOPT_ROOT") : "")
#else
#define	DHCP_CONFOPT_ROOT ""
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* !_DHCP_SVC_PRIVATE_H */