xref: /illumos-gate/usr/src/uts/common/netinet/dhcp.h (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
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 1996-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
26  */
27 
28 /*
29  * dhcp.h - Generic DHCP definitions, as per RFC's 2131 and 2132.
30  */
31 
32 #ifndef	_DHCP_H
33 #define	_DHCP_H
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #ifdef  _REENTRANT
40 #include <thread.h>
41 #endif  /* _REENTRANT */
42 
43 /*
44  * DHCP option codes.
45  */
46 
47 #define	CD_PAD			0
48 #define	CD_END			255
49 #define	CD_SUBNETMASK		1
50 #define	CD_TIMEOFFSET		2
51 #define	CD_ROUTER		3
52 #define	CD_TIMESERV		4
53 #define	CD_IEN116_NAME_SERV	5
54 #define	CD_DNSSERV		6
55 #define	CD_LOG_SERV		7
56 #define	CD_COOKIE_SERV		8
57 #define	CD_LPR_SERV		9
58 #define	CD_IMPRESS_SERV		10
59 #define	CD_RESOURCE_SERV	11
60 #define	CD_HOSTNAME		12
61 #define	CD_BOOT_SIZE		13
62 #define	CD_DUMP_FILE		14
63 #define	CD_DNSDOMAIN		15
64 #define	CD_SWAP_SERV		16
65 #define	CD_ROOT_PATH		17
66 #define	CD_EXTEND_PATH		18
67 
68 /* IP layer parameters */
69 #define	CD_IP_FORWARDING_ON	19
70 #define	CD_NON_LCL_ROUTE_ON	20
71 #define	CD_POLICY_FILTER	21
72 #define	CD_MAXIPSIZE		22
73 #define	CD_IPTTL		23
74 #define	CD_PATH_MTU_TIMEOUT	24
75 #define	CD_PATH_MTU_TABLE_SZ	25
76 
77 /* IP layer parameters per interface */
78 #define	CD_MTU			26
79 #define	CD_ALL_SUBNETS_LCL_ON	27
80 #define	CD_BROADCASTADDR	28
81 #define	CD_MASK_DISCVRY_ON	29
82 #define	CD_MASK_SUPPLIER_ON	30
83 #define	CD_ROUTER_DISCVRY_ON	31
84 #define	CD_ROUTER_SOLICIT_SERV	32
85 #define	CD_STATIC_ROUTE		33
86 
87 /* Link Layer Parameters per Interface */
88 #define	CD_TRAILER_ENCAPS_ON	34
89 #define	CD_ARP_TIMEOUT		35
90 #define	CD_ETHERNET_ENCAPS_ON	36
91 
92 /* TCP Parameters */
93 #define	CD_TCP_TTL		37
94 #define	CD_TCP_KALIVE_INTVL	38
95 #define	CD_TCP_KALIVE_GRBG_ON	39
96 
97 /* Application layer parameters */
98 #define	CD_NIS_DOMAIN		40
99 #define	CD_NIS_SERV		41
100 #define	CD_NTP_SERV		42
101 #define	CD_VENDOR_SPEC		43
102 
103 /* NetBIOS parameters */
104 #define	CD_NETBIOS_NAME_SERV	44
105 #define	CD_NETBIOS_DIST_SERV	45
106 #define	CD_NETBIOS_NODE_TYPE	46
107 #define	CD_NETBIOS_SCOPE	47
108 
109 /* X Window parameters */
110 #define	CD_XWIN_FONT_SERV	48
111 #define	CD_XWIN_DISP_SERV	49
112 
113 /* DHCP protocol extension options */
114 #define	CD_REQUESTED_IP_ADDR	50
115 #define	CD_LEASE_TIME		51
116 #define	CD_OPTION_OVERLOAD	52
117 #define	CD_DHCP_TYPE		53
118 #define	CD_SERVER_ID		54
119 #define	CD_REQUEST_LIST		55
120 #define	CD_MESSAGE		56
121 #define	CD_MAX_DHCP_SIZE	57
122 #define	CD_T1_TIME		58
123 #define	CD_T2_TIME		59
124 #define	CD_CLASS_ID		60
125 #define	CD_CLIENT_ID		61
126 
127 /* Netware options */
128 #define	CD_NW_IP_DOMAIN		62
129 #define	CD_NW_IP_OPTIONS	63
130 
131 /* Nisplus options */
132 #define	CD_NISPLUS_DMAIN	64
133 #define	CD_NISPLUS_SERVS	65
134 
135 /* Optional sname/bootfile options */
136 #define	CD_TFTP_SERV_NAME	66
137 #define	CD_OPT_BOOTFILE_NAME	67
138 
139 /* Additional server options */
140 #define	CD_MOBILE_IP_AGENT	68
141 #define	CD_SMTP_SERVS		69
142 #define	CD_POP3_SERVS		70
143 #define	CD_NNTP_SERVS		71
144 #define	CD_WWW_SERVS		72
145 #define	CD_FINGER_SERVS		73
146 #define	CD_IRC_SERVS		74
147 
148 /* Streettalk options */
149 #define	CD_STREETTALK_SERVS	75
150 #define	CD_STREETTALK_DA_SERVS	76
151 
152 /* User class identifier */
153 #define	CD_USER_CLASS_ID	77
154 
155 /* Newer options */
156 
157 #define	CD_SLPDA		78
158 #define	CD_SLPSS		79
159 #define	CD_CLIENTFQDN		81
160 #define	CD_AGENTOPT		82
161 
162 /*
163  * Per RFC 3679, option 89 was "Never published as standard and [is] not in
164  * general use". See active CD_CLIENTFQDN and RFC 4702.
165  */
166 #define	CD_FQDN			89
167 
168 #define	CD_PXEARCHi		93
169 #define	CD_PXENIIi		94
170 #define	CD_PXECID		95
171 #define	CD_MULTICST		107
172 
173 #define	DHCP_FIRST_OPT		CD_SUBNETMASK
174 #define	DHCP_LAST_STD		CD_MULTICST
175 #define	DHCP_SITE_OPT		128		/* inclusive */
176 #define	DHCP_END_SITE		254
177 #define	DHCP_LAST_OPT		DHCP_END_SITE	/* last op code */
178 
179 #define	DHCP_MAX_OPT_SIZE	255	/* maximum option size in octets */
180 
181 /*
182  * DHCP Packet. What will fit in a ethernet frame. We may use a smaller
183  * size, based on what our transport can handle.
184  */
185 #define	DHCP_DEF_MAX_SIZE	576	/* as spec'ed in RFC 2131 */
186 #define	PKT_BUFFER		1486	/* max possible size of pkt buffer */
187 #define	BASE_PKT_SIZE		240	/* everything but the options */
188 typedef struct dhcp {
189 	uint8_t		op;		/* message opcode */
190 	uint8_t		htype;		/* Hardware address type */
191 	uint8_t		hlen;		/* Hardware address length */
192 	uint8_t		hops;		/* Used by relay agents */
193 	uint32_t	xid;		/* transaction id */
194 	uint16_t	secs;		/* Secs elapsed since client boot */
195 	uint16_t	flags;		/* DHCP Flags field */
196 	struct in_addr	ciaddr;		/* client IP addr */
197 	struct in_addr	yiaddr;		/* 'Your' IP addr. (from server) */
198 	struct in_addr	siaddr;		/* Boot server IP addr */
199 	struct in_addr	giaddr;		/* Relay agent IP addr */
200 	uint8_t		chaddr[16];	/* Client hardware addr */
201 	uint8_t		sname[64];	/* Optl. boot server hostname */
202 	uint8_t		file[128];	/* boot file name (ascii path) */
203 	uint8_t		cookie[4];	/* Magic cookie */
204 	uint8_t		options[60];	/* Options */
205 } PKT;
206 
207 typedef uint32_t	lease_t; /* DHCP lease time (32 bit quantity) */
208 
209 /*
210  * DHCP packet types. As per protocol.
211  */
212 #define	DISCOVER	((uint8_t)1)
213 #define	OFFER		((uint8_t)2)
214 #define	REQUEST		((uint8_t)3)
215 #define	DECLINE		((uint8_t)4)
216 #define	ACK		((uint8_t)5)
217 #define	NAK		((uint8_t)6)
218 #define	RELEASE		((uint8_t)7)
219 #define	INFORM		((uint8_t)8)
220 
221 /*
222  * Generic DHCP protocol defines
223  */
224 #define	DHCP_PERM	((lease_t)0xffffffff)	/* "permanent" lease time */
225 #define	BOOTREQUEST		(1)		/* BOOTP REQUEST opcode */
226 #define	BOOTREPLY		(2)		/* BOOTP REPLY opcode */
227 #define	BOOTMAGIC	{ 99, 130, 83, 99 }	/* rfc1048 magic cookie */
228 #define	BCAST_MASK	0x8000			/* BROADCAST flag */
229 
230 #ifdef	__cplusplus
231 }
232 #endif
233 
234 #endif	/* _DHCP_H */
235