xref: /onnv-gate/usr/src/lib/libdhcpsvc/head/dhcp_svc_public.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _DHCP_SVC_PUBLIC_H
28*0Sstevel@tonic-gate #define	_DHCP_SVC_PUBLIC_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * Contains published interfaces to the DHCP data service.
34*0Sstevel@tonic-gate  */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #ifdef	__cplusplus
37*0Sstevel@tonic-gate extern "C" {
38*0Sstevel@tonic-gate #endif
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #include <sys/types.h>
41*0Sstevel@tonic-gate #include <netinet/in.h>			/* struct in_addr */
42*0Sstevel@tonic-gate #include <netinet/dhcp.h>
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #define	DSVC_PUBLIC_VERSION	1	/* version of public layer interface */
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate  * Errors which can be returned from the defined API
48*0Sstevel@tonic-gate  * Note: must be kept in sync with errmsgs[] in private/errmsgs.c.
49*0Sstevel@tonic-gate  */
50*0Sstevel@tonic-gate #define	DSVC_SUCCESS		0	/* success */
51*0Sstevel@tonic-gate #define	DSVC_EXISTS		1	/* object already exists */
52*0Sstevel@tonic-gate #define	DSVC_ACCESS		2	/* access denied */
53*0Sstevel@tonic-gate #define	DSVC_NO_CRED		3	/* no underlying credential */
54*0Sstevel@tonic-gate #define	DSVC_NOENT		4	/* object doesn't exist */
55*0Sstevel@tonic-gate #define	DSVC_BUSY		5	/* object temporarily busy (again) */
56*0Sstevel@tonic-gate #define	DSVC_INVAL		6	/* invalid argument(s) */
57*0Sstevel@tonic-gate #define	DSVC_INTERNAL		7	/* internal data store error */
58*0Sstevel@tonic-gate #define	DSVC_UNAVAILABLE	8	/* underlying service required by */
59*0Sstevel@tonic-gate 					/* public module unavailable */
60*0Sstevel@tonic-gate #define	DSVC_COLLISION		9	/* update collision */
61*0Sstevel@tonic-gate #define	DSVC_UNSUPPORTED	10	/* operation not supported */
62*0Sstevel@tonic-gate #define	DSVC_NO_MEMORY		11	/* operation ran out of memory */
63*0Sstevel@tonic-gate #define	DSVC_NO_RESOURCES	12	/* non-memory resources unavailable */
64*0Sstevel@tonic-gate #define	DSVC_BAD_RESOURCE	13	/* malformed/missing RESOURCE setting */
65*0Sstevel@tonic-gate #define	DSVC_BAD_PATH		14	/* malformed/missing PATH setting */
66*0Sstevel@tonic-gate #define	DSVC_MODULE_VERSION	15	/* public layer version mismatch */
67*0Sstevel@tonic-gate #define	DSVC_MODULE_ERR		16	/* internal public module error */
68*0Sstevel@tonic-gate #define	DSVC_MODULE_LOAD_ERR	17	/* error loading public module */
69*0Sstevel@tonic-gate #define	DSVC_MODULE_UNLOAD_ERR	18	/* error unloading public module */
70*0Sstevel@tonic-gate #define	DSVC_MODULE_CFG_ERR	19	/* Module configuration failure */
71*0Sstevel@tonic-gate #define	DSVC_SYNCH_ERR		20	/* error in synchronization protocol */
72*0Sstevel@tonic-gate #define	DSVC_NO_LOCKMGR		21	/* cannot contact lock manager */
73*0Sstevel@tonic-gate #define	DSVC_NO_LOCATION	22	/* location nonexistent */
74*0Sstevel@tonic-gate #define	DSVC_BAD_CONVER		23	/* malformed/missing CONVER setting */
75*0Sstevel@tonic-gate #define	DSVC_NO_TABLE		24	/* container does not exist */
76*0Sstevel@tonic-gate #define	DSVC_TABLE_EXISTS	25	/* container already exists */
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate #define	DSVC_NERR		(DSVC_TABLE_EXISTS + 1)
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate /*
81*0Sstevel@tonic-gate  * Flags that can be passed to open_*
82*0Sstevel@tonic-gate  */
83*0Sstevel@tonic-gate #define	DSVC_CREATE		0x01	/* create container; must not exist */
84*0Sstevel@tonic-gate #define	DSVC_READ		0x02	/* open container for reading */
85*0Sstevel@tonic-gate #define	DSVC_WRITE		0x04	/* open container for writing */
86*0Sstevel@tonic-gate #define	DSVC_NONBLOCK		0x08	/* open container in nonblocking mode */
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate /*
89*0Sstevel@tonic-gate  * Query macros - used for initializing query flags to lookup_*
90*0Sstevel@tonic-gate  */
91*0Sstevel@tonic-gate #define	DSVC_QINIT(q)		((q) = 0)
92*0Sstevel@tonic-gate #define	DSVC_QEQ(q, v)		((q) = ((q) | (v) | ((v) << 16)))
93*0Sstevel@tonic-gate #define	DSVC_QNEQ(q, v)		((q) = ((~((v) << 16)) & (q)) | (v))
94*0Sstevel@tonic-gate #define	DSVC_QISEQ(q, v)	(((q) & (v)) && ((q) & ((v) << 16)))
95*0Sstevel@tonic-gate #define	DSVC_QISNEQ(q, v)	(((q) & (v)) && (!((q) & ((v) << 16))))
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate #define	DSVC_MAX_MACSYM_LEN	128	/* max length of a macro or symbol */
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate /*
100*0Sstevel@tonic-gate  * DHCP Configuration Container (dhcptab(4))
101*0Sstevel@tonic-gate  */
102*0Sstevel@tonic-gate #define	DT_DHCPTAB		"dhcptab"	/* Default name of container */
103*0Sstevel@tonic-gate #define	DT_SYMBOL		's'
104*0Sstevel@tonic-gate #define	DT_MACRO		'm'
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate /* Query flags for lookup_dt */
107*0Sstevel@tonic-gate #define	DT_QKEY			0x01
108*0Sstevel@tonic-gate #define	DT_QTYPE		0x02
109*0Sstevel@tonic-gate #define	DT_QALL			(DT_QKEY|DT_QTYPE)
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /*
112*0Sstevel@tonic-gate  * Consumer's dhcptab record form. Dynamically allocated by underlying data
113*0Sstevel@tonic-gate  * store.  dt_sig is set by underlying data store -- it's opaque to the
114*0Sstevel@tonic-gate  * DHCP service, and is used by the data store to detect update collisions.
115*0Sstevel@tonic-gate  * All fields must be fixed-width types and in host byte order.  Note that
116*0Sstevel@tonic-gate  * SUNWbinfiles writes these records directly to disk, thus changing its
117*0Sstevel@tonic-gate  * definition may introduce binary compatibility problems.  Note also that
118*0Sstevel@tonic-gate  * fields have been carefully ordered to avoid internal padding and the
119*0Sstevel@tonic-gate  * structure's size is 64-bit aligned to avoid capricious trailing padding.
120*0Sstevel@tonic-gate  */
121*0Sstevel@tonic-gate typedef struct {
122*0Sstevel@tonic-gate 	uint64_t	dt_sig;			/* Opaque atomic cookie */
123*0Sstevel@tonic-gate 	char		*dt_value;		/* Value of type dt_type */
124*0Sstevel@tonic-gate 	char		dt_key[DSVC_MAX_MACSYM_LEN + 1]; /* Macro/symbol name */
125*0Sstevel@tonic-gate 	char		dt_type;		/* Type of data */
126*0Sstevel@tonic-gate 	char		dt_pad[2];		/* Pad to 64-bit boundary */
127*0Sstevel@tonic-gate } dt_rec_t;
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate typedef struct dt_rec_list {
130*0Sstevel@tonic-gate 	dt_rec_t		*dtl_rec;
131*0Sstevel@tonic-gate 	struct dt_rec_list	*dtl_next;	/* Next record in the list */
132*0Sstevel@tonic-gate } dt_rec_list_t;
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate /*
135*0Sstevel@tonic-gate  * DHCP Network Container (dhcp_network(4))
136*0Sstevel@tonic-gate  */
137*0Sstevel@tonic-gate #define	DN_MAX_CID_LEN		(DSVC_MAX_MACSYM_LEN / 2)
138*0Sstevel@tonic-gate #define	DN_MAX_COMMENT_LEN	48
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate /* Query flags for lookup_dn */
141*0Sstevel@tonic-gate #define	DN_QCID			0x0001
142*0Sstevel@tonic-gate #define	DN_QCIP			0x0002
143*0Sstevel@tonic-gate #define	DN_QSIP			0x0004
144*0Sstevel@tonic-gate #define	DN_QLEASE		0x0008
145*0Sstevel@tonic-gate #define	DN_QMACRO		0x0010
146*0Sstevel@tonic-gate #define	DN_QFDYNAMIC		0x0020
147*0Sstevel@tonic-gate #define	DN_QFAUTOMATIC		0x0040
148*0Sstevel@tonic-gate #define	DN_QFMANUAL		0x0080
149*0Sstevel@tonic-gate #define	DN_QFUNUSABLE		0x0100
150*0Sstevel@tonic-gate #define	DN_QFBOOTP_ONLY		0x0200
151*0Sstevel@tonic-gate #define	DN_QALL			(DN_QCID | DN_QCIP | DN_QSIP | DN_QLEASE |\
152*0Sstevel@tonic-gate 				    DN_QMACRO | DN_QFDYNAMIC | DN_QFAUTOMATIC |\
153*0Sstevel@tonic-gate 				    DN_QFMANUAL | DN_QFUNUSABLE |\
154*0Sstevel@tonic-gate 				    DN_QFBOOTP_ONLY)
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate /* dn_flags values */
157*0Sstevel@tonic-gate #define	DN_FDYNAMIC		0x00	/* Non-permanent */
158*0Sstevel@tonic-gate #define	DN_FAUTOMATIC		0x01	/* Lease is permanent */
159*0Sstevel@tonic-gate #define	DN_FMANUAL		0x02	/* Manually allocated (sacred) */
160*0Sstevel@tonic-gate #define	DN_FUNUSABLE		0x04	/* Address is unusable */
161*0Sstevel@tonic-gate #define	DN_FBOOTP_ONLY		0x08	/* Address is reserved for BOOTP */
162*0Sstevel@tonic-gate #define	DN_FALL			(DN_FDYNAMIC | DN_FAUTOMATIC | DN_FMANUAL |\
163*0Sstevel@tonic-gate 				    DN_FUNUSABLE | DN_FBOOTP_ONLY)
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate /*
166*0Sstevel@tonic-gate  * Consumer's DHCP network container record form. Dynamically allocated by
167*0Sstevel@tonic-gate  * underlying data store.  dn_sig is set by underlying data store -- it's
168*0Sstevel@tonic-gate  * opaque to the DHCP service, and is used by the data store to detect
169*0Sstevel@tonic-gate  * update collisions.  All fields must be fixed-width types and in host
170*0Sstevel@tonic-gate  * byte order. Note that SUNWbinfiles writes these records directly to
171*0Sstevel@tonic-gate  * disk, thus changing its definition may introduce binary compatibility
172*0Sstevel@tonic-gate  * problems.  Note also that fields have been carefully ordered to avoid
173*0Sstevel@tonic-gate  * internal padding and the structure's size is 64-bit aligned to avoid
174*0Sstevel@tonic-gate  * capricious trailing padding.
175*0Sstevel@tonic-gate  */
176*0Sstevel@tonic-gate typedef struct {
177*0Sstevel@tonic-gate 	uint64_t	dn_sig;			/* Opaque atomic cookie */
178*0Sstevel@tonic-gate 	struct in_addr	dn_cip;			/* Client IP address */
179*0Sstevel@tonic-gate 	struct in_addr	dn_sip;			/* Server IP address */
180*0Sstevel@tonic-gate 	lease_t		dn_lease;		/* Abs lease expiration */
181*0Sstevel@tonic-gate 	char		dn_macro[DSVC_MAX_MACSYM_LEN + 1];
182*0Sstevel@tonic-gate 	char		dn_comment[DN_MAX_COMMENT_LEN + 1];
183*0Sstevel@tonic-gate 	uchar_t		dn_cid[DN_MAX_CID_LEN];	/* Opaque client id */
184*0Sstevel@tonic-gate 	uchar_t		dn_cid_len;		/* Length of client id */
185*0Sstevel@tonic-gate 	uchar_t		dn_flags;		/* Flags */
186*0Sstevel@tonic-gate } dn_rec_t;
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate typedef struct dn_rec_list {
189*0Sstevel@tonic-gate 	dn_rec_t		*dnl_rec;	/* The record itself */
190*0Sstevel@tonic-gate 	struct dn_rec_list	*dnl_next;	/* Next entry in the list */
191*0Sstevel@tonic-gate } dn_rec_list_t;
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate /*
194*0Sstevel@tonic-gate  * Synchronization Service Type and values.
195*0Sstevel@tonic-gate  */
196*0Sstevel@tonic-gate typedef uint32_t dsvc_synchtype_t;
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate #define	DSVC_SYNCH_NONE		0		/* no synch type */
199*0Sstevel@tonic-gate #define	DSVC_SYNCH_DSVCD	1		/* dsvclockd(1M) synch type */
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate /*
202*0Sstevel@tonic-gate  * Generic API provided by SMI
203*0Sstevel@tonic-gate  */
204*0Sstevel@tonic-gate extern dt_rec_t	*alloc_dtrec(const char *, char, const char *);
205*0Sstevel@tonic-gate extern dn_rec_t *alloc_dnrec(const uchar_t *, uchar_t, uchar_t, struct in_addr,
206*0Sstevel@tonic-gate 		    struct in_addr, lease_t, const char *, const char *);
207*0Sstevel@tonic-gate extern dt_rec_list_t *add_dtrec_to_list(dt_rec_t *, dt_rec_list_t *);
208*0Sstevel@tonic-gate extern dn_rec_list_t *add_dnrec_to_list(dn_rec_t *, dn_rec_list_t *);
209*0Sstevel@tonic-gate extern void	free_dtrec(dt_rec_t *);
210*0Sstevel@tonic-gate extern void	free_dnrec(dn_rec_t *);
211*0Sstevel@tonic-gate extern void	free_dtrec_list(dt_rec_list_t *);
212*0Sstevel@tonic-gate extern void	free_dnrec_list(dn_rec_list_t *);
213*0Sstevel@tonic-gate extern const char *dhcpsvc_errmsg(uint_t);
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate /*
216*0Sstevel@tonic-gate  * The remaining functions are not directly callable by the libdhcpsvc
217*0Sstevel@tonic-gate  * implementation; don't expose them to it.
218*0Sstevel@tonic-gate  */
219*0Sstevel@tonic-gate #ifndef	_DHCPSVC_IMPL
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate /*
222*0Sstevel@tonic-gate  * Generic Service Provider Layer API provided by data store implementor
223*0Sstevel@tonic-gate  */
224*0Sstevel@tonic-gate extern int	status(const char *);
225*0Sstevel@tonic-gate extern int	version(int *);
226*0Sstevel@tonic-gate extern int	configure(const char *);
227*0Sstevel@tonic-gate extern int	mklocation(const char *);
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate /*
230*0Sstevel@tonic-gate  * dhcptab Service Provider Layer API
231*0Sstevel@tonic-gate  */
232*0Sstevel@tonic-gate extern int	list_dt(const char *, char ***, uint_t *);
233*0Sstevel@tonic-gate extern int	open_dt(void **, const char *, uint_t);
234*0Sstevel@tonic-gate extern int	close_dt(void **);
235*0Sstevel@tonic-gate extern int	add_dt(void *, dt_rec_t *);
236*0Sstevel@tonic-gate extern int	remove_dt(const char *);
237*0Sstevel@tonic-gate extern int	modify_dt(void *, const dt_rec_t *, dt_rec_t *);
238*0Sstevel@tonic-gate extern int	delete_dt(void *, const dt_rec_t *);
239*0Sstevel@tonic-gate extern int	lookup_dt(void *, boolean_t, uint_t, int,
240*0Sstevel@tonic-gate 		    const dt_rec_t *, dt_rec_list_t **, uint_t *);
241*0Sstevel@tonic-gate /*
242*0Sstevel@tonic-gate  * DHCP Network Service Provider Layer API
243*0Sstevel@tonic-gate  * IP address arguments are host order.
244*0Sstevel@tonic-gate  */
245*0Sstevel@tonic-gate extern int	list_dn(const char *, char ***, uint_t *);
246*0Sstevel@tonic-gate extern int	open_dn(void **, const char *, uint_t, const struct in_addr *,
247*0Sstevel@tonic-gate 		    const struct in_addr *);
248*0Sstevel@tonic-gate extern int	close_dn(void **);
249*0Sstevel@tonic-gate extern int	add_dn(void *, dn_rec_t *);
250*0Sstevel@tonic-gate extern int	remove_dn(const char *, const struct in_addr *);
251*0Sstevel@tonic-gate extern int	modify_dn(void *, const dn_rec_t *, dn_rec_t *);
252*0Sstevel@tonic-gate extern int	delete_dn(void *, const dn_rec_t *);
253*0Sstevel@tonic-gate extern int	lookup_dn(void *, boolean_t, uint_t, int,
254*0Sstevel@tonic-gate 		    const dn_rec_t *, dn_rec_list_t **, uint_t *);
255*0Sstevel@tonic-gate #endif
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate #ifdef	__cplusplus
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate #endif
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate #endif	/* !_DHCP_SVC_PUBLIC_H */
262