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) 2000 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_NETWORK_H
28*0Sstevel@tonic-gate #define	_DHCP_NETWORK_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  * Implementation-specific data structures and constants for the binary
34*0Sstevel@tonic-gate  * files dhcp_network container.  These structures are subject to change at
35*0Sstevel@tonic-gate  * any time.
36*0Sstevel@tonic-gate  */
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #include <sys/types.h>
39*0Sstevel@tonic-gate #include <dhcp_svc_public.h>
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate #ifdef __cplusplus
42*0Sstevel@tonic-gate extern "C" {
43*0Sstevel@tonic-gate #endif
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate /*
46*0Sstevel@tonic-gate  * The client id hash size is based on the idea that, given a perfect hash,
47*0Sstevel@tonic-gate  * the hash chain length shouldn't be more than the number of buckets.
48*0Sstevel@tonic-gate  * Given a worst case network with 2^24 addresses, that means we should
49*0Sstevel@tonic-gate  * have 4096 buckets; we shrink this by a bit to make the dn_header_t size
50*0Sstevel@tonic-gate  * be a power of two (32768 bytes).  Note that we assert that a header is
51*0Sstevel@tonic-gate  * this size in open_dn().
52*0Sstevel@tonic-gate  */
53*0Sstevel@tonic-gate #define	DN_CIDHASHSZ	4056
54*0Sstevel@tonic-gate #define	DN_MAGIC	0x0d6c92e4	/* "dhcpnet" in hexadecimal world */
55*0Sstevel@tonic-gate #define	DN_NOIMAGE	0x80		/* image field not in use */
56*0Sstevel@tonic-gate #define	DN_NOREC	0x00000000	/* "no record" id value, must be zero */
57*0Sstevel@tonic-gate #define	DN_TEMPREC	0xffffffff	/* "temp record" id value */
58*0Sstevel@tonic-gate #define	DN_HASHHEAD	0xfffffffe	/* "hash chain head" id value */
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate typedef uint32_t dn_recid_t;		/* record id type */
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate  * Macros to compute the record id for a record with address `addr' in a
64*0Sstevel@tonic-gate  * container with netmask `mask', and to convert a record id `recid' to its
65*0Sstevel@tonic-gate  * starting file offset within its container.  Note that we reserve the
66*0Sstevel@tonic-gate  * record id value of 0 for DN_NOREC for reasons explained in open_dn().
67*0Sstevel@tonic-gate  */
68*0Sstevel@tonic-gate #define	RECID(addr, mask)	((dn_recid_t)(((addr) & ~(mask)) + 1))
69*0Sstevel@tonic-gate #define	RECID2OFFSET(recid)						\
70*0Sstevel@tonic-gate 	(((recid) == DN_TEMPREC) ? offsetof(dn_header_t, dnh_temp) :	\
71*0Sstevel@tonic-gate 	(sizeof (dn_header_t) + ((off_t)sizeof (dn_filerec_t) * ((recid) - 1))))
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate /*
74*0Sstevel@tonic-gate  * What each dn_rec_t looks like on-disk -- contains the dn_rec_t, pointers
75*0Sstevel@tonic-gate  * to the previous and next dn_rec_t's on its client id hash.  See the big
76*0Sstevel@tonic-gate  * theory statement in dhcp_network.c for a discussion on the redundant
77*0Sstevel@tonic-gate  * dn_recid_t's.
78*0Sstevel@tonic-gate  */
79*0Sstevel@tonic-gate typedef struct dn_filerec {
80*0Sstevel@tonic-gate 	dn_recid_t	rec_next[2];	/* id of next record in cidhash */
81*0Sstevel@tonic-gate 	dn_recid_t	rec_prev[2];	/* id of prev record in cidhash */
82*0Sstevel@tonic-gate 	dn_rec_t	rec_dn;		/* actual dn_rec_t */
83*0Sstevel@tonic-gate } dn_filerec_t;
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate /*
86*0Sstevel@tonic-gate  * Header atop each dhcp_network container -- contains some basic
87*0Sstevel@tonic-gate  * information about the container and an array of buckets to chain client
88*0Sstevel@tonic-gate  * id hashes from.  See the big theory statement in dhcp_network.c for a
89*0Sstevel@tonic-gate  * discussion on the redundant dn_recid_t's and the concept of "images".
90*0Sstevel@tonic-gate  */
91*0Sstevel@tonic-gate typedef struct dn_header {
92*0Sstevel@tonic-gate 	unsigned char	dnh_version;	/* container version */
93*0Sstevel@tonic-gate 	unsigned char	dnh_dirty;	/* container might be dirty */
94*0Sstevel@tonic-gate 	unsigned char 	dnh_image;	/* container's active image */
95*0Sstevel@tonic-gate 	unsigned char	dnh_tempimage; 	/* temporary record's image */
96*0Sstevel@tonic-gate 	uint32_t	dnh_magic;	/* container magic */
97*0Sstevel@tonic-gate 	ipaddr_t	dnh_network;	/* network number of table */
98*0Sstevel@tonic-gate 	ipaddr_t	dnh_netmask;	/* netmask of network number */
99*0Sstevel@tonic-gate 	dn_filerec_t	dnh_temp;	/* temporary record used in modify_dn */
100*0Sstevel@tonic-gate 	uint32_t	dnh_checks;	/* number of check_dn full runs */
101*0Sstevel@tonic-gate 	uint32_t	dnh_errors;	/* number of errors caught */
102*0Sstevel@tonic-gate 	uint32_t	dnh_pad[4];	/* for future use */
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate 	/*
105*0Sstevel@tonic-gate 	 * Note: read_header() assumes that dnh_cidhash is the last member.
106*0Sstevel@tonic-gate 	 */
107*0Sstevel@tonic-gate 	dn_recid_t	dnh_cidhash[DN_CIDHASHSZ][2]; /* cid hash buckets */
108*0Sstevel@tonic-gate } dn_header_t;
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate /*
111*0Sstevel@tonic-gate  * Per-instance state for each handle returned from open_dn.
112*0Sstevel@tonic-gate  */
113*0Sstevel@tonic-gate typedef struct dn_handle {
114*0Sstevel@tonic-gate 	int		dh_fd; 		/* fd for open file pointer */
115*0Sstevel@tonic-gate 	unsigned int	dh_oflags;	/* flags passed into open_dn */
116*0Sstevel@tonic-gate 	ipaddr_t	dh_netmask;	/* cached netmask of container */
117*0Sstevel@tonic-gate } dn_handle_t;
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate #ifdef __cplusplus
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate #endif
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate #endif /* _DHCP_NETWORK_H */
124