xref: /illumos-gate/usr/src/common/net/dhcp/dhcp_impl.h (revision 90f050286227cf4c4f8aa425555d04723d331d48)
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 1999-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DHCP_IMPL_H
28 #define	_DHCP_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Common definitions used by Sun DHCP implementations
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <netinet/udp.h>
44 #include <netinet/dhcp.h>
45 #include <dhcp_symbol_common.h>
46 #include <sys/sunos_dhcp_class.h>
47 
48 /* Packet fields */
49 #define	CD_PACKET_START		0
50 #define	CD_POPCODE		0	/* packet opcode */
51 #define	CD_PHTYPE		1	/* packet header type */
52 #define	CD_PHLEN		2	/* packet header len */
53 #define	CD_PHOPS		3	/* packet header len */
54 #define	CD_PXID			4	/* packet hops */
55 #define	CD_PSECS		8	/* packet xid */
56 #define	CD_PFLAGS		10	/* packet secs */
57 #define	CD_PCIADDR		12	/* packet flags */
58 #define	CD_YIADDR		16	/* client's ip address */
59 #define	CD_SIADDR		20	/* Bootserver's ip address */
60 #define	CD_GIADDR		24	/* BOOTP relay agent address */
61 #define	CD_PCHADDR		28	/* BOOTP relay agent address */
62 #define	CD_SNAME		44	/* Hostname of Bootserver, or opts */
63 #define	CD_BOOTFILE		108	/* File to boot or opts */
64 #define	CD_PCOOKIE		236	/* packet cookie */
65 #define	CD_POPTIONS		240	/* packet options */
66 #define	CD_PACKET_END		CD_POPTIONS
67 
68 /* Internal server options */
69 #define	CD_INTRNL_START		1024
70 #define	CD_BOOL_HOSTNAME	1024	/* Entry wants hostname (Nameserv) */
71 #define	CD_BOOL_LEASENEG	1025	/* Entry's lease is negotiable */
72 #define	CD_BOOL_ECHO_VCLASS	1026	/* Echo Vendor class back to Entry */
73 #define	CD_BOOTPATH		1027	/* prefix path to File to boot */
74 #define	CD_INTRNL_END		1027
75 
76 /* Error codes that could be generated while parsing packets */
77 #define	DHCP_ERR_OFFSET		512
78 #define	DHCP_GARBLED_MSG_TYPE	(DHCP_ERR_OFFSET+0)
79 #define	DHCP_WRONG_MSG_TYPE	(DHCP_ERR_OFFSET+1)
80 #define	DHCP_BAD_OPT_OVLD	(DHCP_ERR_OFFSET+2)
81 
82 /*
83  * Arbitrary "maximum" client ID length (in bytes), used by various bits
84  * of the standalone code.  This needs to go away someday.
85  */
86 #define	DHCP_MAX_CID_LEN	64
87 
88 /*
89  * Generic DHCP option structure.
90  */
91 typedef struct {
92 	uint8_t    code;
93 	uint8_t    len;
94 	uint8_t    value[1];
95 } DHCP_OPT;
96 
97 /*
98  * Generic DHCP packet list. Ensure that _REENTRANT bracketed code stays at
99  * bottom of this definition - the client doesn't include it. Scan.c in
100  * libdhcp isn't aware of it either...
101  */
102 #define	MAX_PKT_LIST	5	/* maximum list size */
103 typedef struct  dhcp_list {
104 	PKT			*pkt;		/* client packet */
105 	uint_t			len;		/* packet len */
106 	int			rfc1048;	/* RFC1048 options - boolean */
107 	struct dhcp_list 	*prev;
108 	struct dhcp_list 	*next;
109 	uint8_t			offset;		/* BOOTP packet offset */
110 				/*
111 				 * standard/site options
112 				 */
113 	DHCP_OPT		*opts[DHCP_LAST_OPT + 1];
114 
115 				/*
116 				 * Vendor specific options (client only)
117 				 */
118 	DHCP_OPT		*vs[VS_OPTION_END - VS_OPTION_START + 1];
119 
120 	struct in_addr		off_ip;		/* Address OFFERed */
121 
122 } PKT_LIST;
123 
124 extern int dhcp_options_scan(PKT_LIST *, boolean_t);
125 extern boolean_t dhcp_getinfo_pl(PKT_LIST *, uchar_t, uint16_t, uint16_t,
126     void *, size_t *);
127 
128 #ifdef	__cplusplus
129 }
130 #endif
131 
132 #endif	/* _DHCP_IMPL_H */
133