1 /*
2  * Copyright (C) 2004-2020 Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (c) 1995-2003 by Internet Software Consortium
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  *   Internet Systems Consortium, Inc.
10  *   950 Charter Street
11  *   Redwood City, CA 94063
12  *   <info@isc.org>
13  *   https://www.isc.org/
14  *
15  * This software has been written for Internet Systems Consortium
16  * by Ted Lemon in cooperation with Vixie Enterprises.  To learn more
17  * about Internet Systems Consortium, see ``https://www.isc.org''.
18  * To learn more about Vixie Enterprises, see ``http://www.vix.com''.
19  */
20 
21 /*
22  * NOTE: This files is imported from ISC DHCP. It uses C notation.
23  *       Format kept for easier merge.
24  */
25 
26 #ifndef DHCP_H
27 #define DHCP_H
28 
29 #include <stdint.h>
30 
31 /// @note Code points in comments are those assigned by IANA
32 /// but not yet implemented in Kea.
33 /// To implement a standard option, remove the comment characters,
34 /// add an entry in std_option_defs.h, add a stdOptionDefs4 unit test
35 /// in tests/libdhcp++_unittest.cc and update dhcp4-std-options-list-part2
36 /// in the dhcp4-srv.xml source file of the user guide.
37 
38 namespace isc {
39 namespace dhcp {
40 
41 /* IPv4 Broadcast address */
42 #define DHCP_IPV4_BROADCAST_ADDRESS "255.255.255.255"
43 
44 /* BOOTP (rfc951) message types */
45 enum BOOTPTypes {
46     BOOTREQUEST = 1,
47     BOOTREPLY = 2
48 };
49 
50 /* Possible values for flags field... */
51 static const uint16_t BOOTP_BROADCAST = 32768L;
52 
53 /// @brief Possible values for hardware type (htype) field.
54 enum HType {
55     HTYPE_UNDEFINED = 0, ///< not specified or undefined
56     HTYPE_ETHER = 1,     ///< Ethernet 10Mbps
57     HTYPE_DOCSIS = 1,    ///< The traffic captures we have from cable modems as
58                          ///  well as this list by IANA:
59                          ///  http://www.iana.org/assignments/
60                          ///  arp-parameters/arp-parameters.xhtml suggest that
61                          ///  Ethernet (1) should be used in DOCSIS environment.
62     HTYPE_IEEE802 = 6,   ///< IEEE 802.2 Token Ring
63     HTYPE_FDDI = 8       ///< FDDI
64     /// TODO Add infiniband here
65 };
66 
67 /* DHCP Option codes: */
68 enum DHCPOptionType {
69     DHO_PAD                          = 0, /* RFC2132 */
70     DHO_SUBNET_MASK                  = 1,
71     DHO_TIME_OFFSET                  = 2,
72     DHO_ROUTERS                      = 3,
73     DHO_TIME_SERVERS                 = 4,
74     DHO_NAME_SERVERS                 = 5,
75     DHO_DOMAIN_NAME_SERVERS          = 6,
76     DHO_LOG_SERVERS                  = 7,
77     DHO_COOKIE_SERVERS               = 8,
78     DHO_LPR_SERVERS                  = 9,
79     DHO_IMPRESS_SERVERS              = 10,
80     DHO_RESOURCE_LOCATION_SERVERS    = 11,
81     DHO_HOST_NAME                    = 12,
82     DHO_BOOT_SIZE                    = 13,
83     DHO_MERIT_DUMP                   = 14,
84     DHO_DOMAIN_NAME                  = 15,
85     DHO_SWAP_SERVER                  = 16,
86     DHO_ROOT_PATH                    = 17,
87     DHO_EXTENSIONS_PATH              = 18,
88     DHO_IP_FORWARDING                = 19,
89     DHO_NON_LOCAL_SOURCE_ROUTING     = 20,
90     DHO_POLICY_FILTER                = 21,
91     DHO_MAX_DGRAM_REASSEMBLY         = 22,
92     DHO_DEFAULT_IP_TTL               = 23,
93     DHO_PATH_MTU_AGING_TIMEOUT       = 24,
94     DHO_PATH_MTU_PLATEAU_TABLE       = 25,
95     DHO_INTERFACE_MTU                = 26,
96     DHO_ALL_SUBNETS_LOCAL            = 27,
97     DHO_BROADCAST_ADDRESS            = 28,
98     DHO_PERFORM_MASK_DISCOVERY       = 29,
99     DHO_MASK_SUPPLIER                = 30,
100     DHO_ROUTER_DISCOVERY             = 31,
101     DHO_ROUTER_SOLICITATION_ADDRESS  = 32,
102     DHO_STATIC_ROUTES                = 33,
103     DHO_TRAILER_ENCAPSULATION        = 34,
104     DHO_ARP_CACHE_TIMEOUT            = 35,
105     DHO_IEEE802_3_ENCAPSULATION      = 36,
106     DHO_DEFAULT_TCP_TTL              = 37,
107     DHO_TCP_KEEPALIVE_INTERVAL       = 38,
108     DHO_TCP_KEEPALIVE_GARBAGE        = 39,
109     DHO_NIS_DOMAIN                   = 40,
110     DHO_NIS_SERVERS                  = 41,
111     DHO_NTP_SERVERS                  = 42,
112     DHO_VENDOR_ENCAPSULATED_OPTIONS  = 43,
113     DHO_NETBIOS_NAME_SERVERS         = 44,
114     DHO_NETBIOS_DD_SERVER            = 45,
115     DHO_NETBIOS_NODE_TYPE            = 46,
116     DHO_NETBIOS_SCOPE                = 47,
117     DHO_FONT_SERVERS                 = 48,
118     DHO_X_DISPLAY_MANAGER            = 49,
119     DHO_DHCP_REQUESTED_ADDRESS       = 50,
120     DHO_DHCP_LEASE_TIME              = 51,
121     DHO_DHCP_OPTION_OVERLOAD         = 52,
122     DHO_DHCP_MESSAGE_TYPE            = 53,
123     DHO_DHCP_SERVER_IDENTIFIER       = 54,
124     DHO_DHCP_PARAMETER_REQUEST_LIST  = 55,
125     DHO_DHCP_MESSAGE                 = 56,
126     DHO_DHCP_MAX_MESSAGE_SIZE        = 57,
127     DHO_DHCP_RENEWAL_TIME            = 58,
128     DHO_DHCP_REBINDING_TIME          = 59,
129     DHO_VENDOR_CLASS_IDENTIFIER      = 60,
130     DHO_DHCP_CLIENT_IDENTIFIER       = 61,
131     DHO_NWIP_DOMAIN_NAME             = 62, /* RFC2242 */
132     DHO_NWIP_SUBOPTIONS              = 63, /* RFC2242 */
133     DHO_NISP_DOMAIN_NAME             = 64, /* RFC2132 */
134     DHO_NISP_SERVER_ADDR             = 65,
135     DHO_TFTP_SERVER_NAME             = 66,
136     DHO_BOOT_FILE_NAME               = 67,
137     DHO_HOME_AGENT_ADDRS             = 68,
138     DHO_SMTP_SERVER                  = 69,
139     DHO_POP3_SERVER                  = 70,
140     DHO_NNTP_SERVER                  = 71,
141     DHO_WWW_SERVER                   = 72,
142     DHO_FINGER_SERVER                = 73,
143     DHO_IRC_SERVER                   = 74,
144     DHO_STREETTALK_SERVER            = 75,
145     DHO_STDASERVER                   = 76,
146     DHO_USER_CLASS                   = 77, /* RFC3004 */
147     DHO_DIRECTORY_AGENT              = 78, /* RFC2610 */
148     DHO_SERVICE_SCOPE                = 79, /* RFC4039 */
149 //  DHO_RAPID_COMMIT                 = 80, /* RFC4702 */
150     DHO_FQDN                         = 81, /* RFC4702 */
151     DHO_DHCP_AGENT_OPTIONS           = 82, /* RFC3046 */
152 //  DHO_ISNS                         = 83, /* RFC4174 */
153     // 84 is removed/unassigned
154     DHO_NDS_SERVERS                  = 85, /* RFC2241 */
155     DHO_NDS_TREE_NAME                = 86, /* RFC2241 */
156     DHO_NDS_CONTEXT                  = 87, /* RFC2241 */
157     DHO_BCMCS_DOMAIN_NAME_LIST       = 88, /* RFC4280 */
158     DHO_BCMCS_IPV4_ADDR              = 89, /* RFC4280 */
159     DHO_AUTHENTICATE                 = 90, /* RFC3118 */
160     DHO_CLIENT_LAST_TRANSACTION_TIME = 91, /* RFC4388 */
161     DHO_ASSOCIATED_IP                = 92, /* RFC4388 */
162     DHO_SYSTEM                       = 93, /* RFC4578 */
163     DHO_NDI                          = 94, /* RFC4578 */
164 //  DHO_LDAP                         = 95, /* RFC3679 */
165     // 96 is removed/unassigned
166     DHO_UUID_GUID                    = 97, /* RFC4578 */
167     DHO_USER_AUTH                    = 98, /* RFC2485 */
168     DHO_GEOCONF_CIVIC                = 99, /* RFC4776 */
169     DHO_PCODE                        = 100, /* RFC4833 */
170     DHO_TCODE                        = 101, /* RFC4833 */
171     // 102-107 are removed/unassigned
172     DHO_V6_ONLY_PREFERRED            = 108, /* RFC8925 */
173     // 109-111 are removed/unassigned
174     DHO_NETINFO_ADDR                 = 112, /* RFC3679 */
175     DHO_NETINFO_TAG                  = 113, /* RFC3679 */
176     DHO_URL                          = 114, /* RFC3679 */
177     // 115 is removed/unassigned
178     DHO_AUTO_CONFIG                  = 116, /* RFC2563 */
179     DHO_NAME_SERVICE_SEARCH          = 117, /* RFC2937 */
180     DHO_SUBNET_SELECTION             = 118, /* RFC3011 */
181     DHO_DOMAIN_SEARCH                = 119, /* RFC3397 */
182 //  DHO_SIP_SERVERS                  = 120, /* RFC3361 */
183 //  DHO_CLASSLESS_STATIC_ROUTE       = 121, /* RFC3442 */
184 //  DHO_CCC                          = 122, /* RFC3495 */
185 //  DHO_GEOCONF                      = 123, /* RFC3825 */
186     DHO_VIVCO_SUBOPTIONS             = 124, /* RFC3925 */
187     DHO_VIVSO_SUBOPTIONS             = 125, /* RFC3925 */
188     // 126-127 are removed/unassigned
189     // 128-135 have multiple definitions including PXE
190     DHO_PANA_AGENT                   = 136, /* RFC5192 */
191     DHO_V4_LOST                      = 137, /* RFC5223 */
192     DHO_CAPWAP_AC_V4                 = 138, /* RFC5417 */
193 //  DHO_IPV4_ADDR_MOS                = 139, /* RFC5678 */
194 //  DHO_IPV4_FQDN_MOS                = 140, /* RFC5678 */
195     DHO_SIP_UA_CONF_SERVICE_DOMAINS  = 141, /* RFC6011 */
196 //  DHO_IPV4_ADDR_ANDSF              = 142, /* RFC6153 */
197     // 143 is removed/unassigned
198 //  DHO_GEOLOC                       = 144,
199 //  DHO_FORCERENEW_NONCE_CAPABLE     = 145, /* RFC5859 */
200     DHO_RDNSS_SELECT                 = 146,
201     // 147-149 are removed/unassigned
202     // 150 have multiple definitions
203 //  DHO_STATUS_CODE                  = 151,
204 //  DHO_BASE_TIME                    = 152,
205 //  DHO_START_TIME_OF_STATE          = 153,
206 //  DHO_QUERY_START_TIME             = 154,
207 //  DHO_QUERY_END_TIME               = 155,
208 //  DHO_DHCP_STATE                   = 156,
209 //  DHO_DATA_SOURCE                  = 157,
210 //  DHO_V4_PCP_SERVER                = 158,
211     DHO_V4_PORTPARAMS                = 159,
212     DHO_V4_CAPTIVE_PORTAL            = 160,
213     // 161-209 are removed/unassigned
214 //  DHO_PATH_PREFIX                  = 210, /* RFC5071 */
215 //  DHO_REBOOT_TIME                  = 211, /* RFC5071 */
216     DHO_6RD                          = 212, /* RFC5969 */
217     DHO_V4_ACCESS_DOMAIN             = 213, /* RFC5986 */
218     // 214-219 are removed/unassigned
219 //  DHO_SUBNET_ALLOC                 = 220,
220 //  DHO_VSS                          = 221, /* RFC6607 */
221     // 222-223 are removed/unassigned
222     // 224-254 are reserved for private use
223 
224     DHO_END                          = 255 /* RFC2132 */
225 };
226 
227 /* DHCP message types. */
228 enum DHCPMessageType {
229     DHCP_NOTYPE         =  0, ///< Message Type option missing
230     DHCPDISCOVER        =  1,
231     DHCPOFFER           =  2,
232     DHCPREQUEST         =  3,
233     DHCPDECLINE         =  4,
234     DHCPACK             =  5,
235     DHCPNAK             =  6,
236     DHCPRELEASE         =  7,
237     DHCPINFORM          =  8,
238 //  DHCPFORCERENEW      =  9,
239     DHCPLEASEQUERY      =  10,
240     DHCPLEASEUNASSIGNED =  11,
241     DHCPLEASEUNKNOWN    =  12,
242     DHCPLEASEACTIVE     =  13,
243     DHCPBULKLEASEQUERY  =  14,
244     DHCPLEASEQUERYDONE  =  15,
245 // DHCPACTIVELEASEQUERY =  16,
246     DHCPLEASEQUERYSTATUS =  17,
247     DHCPTLS              =  18,
248     DHCP_TYPES_EOF
249 };
250 
251 static const uint16_t DHCP4_CLIENT_PORT = 68;
252 static const uint16_t DHCP4_SERVER_PORT = 67;
253 
254 /// Magic cookie validating dhcp options field (and bootp vendor
255 /// extensions field).
256 static const uint32_t DHCP_OPTIONS_COOKIE = 0x63825363;
257 
258 /* Relay Agent Information option subtypes: */
259 
260 static const uint16_t RAI_OPTION_AGENT_CIRCUIT_ID = 1; // RFC3046
261 static const uint16_t RAI_OPTION_REMOTE_ID = 2; // RFC3046
262 /* option 3 is reserved and will never be assigned */
263 static const uint16_t RAI_OPTION_DOCSIS_DEVICE_CLASS = 4; // RFC3256
264 static const uint16_t RAI_OPTION_LINK_SELECTION = 5; // RFC3527
265 static const uint16_t RAI_OPTION_SUBSCRIBER_ID = 6; //RFC3993
266 static const uint16_t RAI_OPTION_RADIUS = 7; //RFC4014
267 static const uint16_t RAI_OPTION_AUTH = 8; //RFC4030
268 static const uint16_t RAI_OPTION_VSI = 9; // RFC4243
269 static const uint16_t RAI_OPTION_RELAY_FLAGS = 10; // RFC5010
270 static const uint16_t RAI_OPTION_SERVER_ID_OVERRIDE = 11; // RFC5107
271 static const uint16_t RAI_OPTION_RELAY_ID = 12; //RFC6925
272 static const uint16_t RAI_OPTION_ACCESS_TECHNO_TYPE = 13; // RFC7839
273 static const uint16_t RAI_OPTION_ACCESS_NETWORK_NAME = 14; // RFC7839
274 static const uint16_t RAI_OPTION_ACCESS_POINT_NAME = 15; // RFC7839
275 static const uint16_t RAI_OPTION_ACCESS_POINT_BSSID = 16; // RFC7839
276 static const uint16_t RAI_OPTION_OPERATOR_ID = 17; // RFC7839
277 static const uint16_t RAI_OPTION_OPERATOR_REALM = 18; // RFC7839
278 static const uint16_t RAI_OPTION_RELAY_PORT = 19; // RFC8357
279 static const uint16_t RAI_OPTION_VIRTUAL_SUBNET_SELECT = 151; //RFC6607
280 static const uint16_t RAI_OPTION_VIRTUAL_SUBNET_SELECT_CTRL = 152; //RFC6607
281 
282 // TODO: Following are leftovers from dhcp.h import from ISC DHCP
283 // They will be converted to C++-style defines once they will start
284 // to be used.
285 #if 0
286 /* FQDN suboptions: */
287 #define FQDN_NO_CLIENT_UPDATE           1
288 #define FQDN_SERVER_UPDATE              2
289 #define FQDN_ENCODED                    3
290 #define FQDN_RCODE1                     4
291 #define FQDN_RCODE2                     5
292 #define FQDN_HOSTNAME                   6
293 #define FQDN_DOMAINNAME                 7
294 #define FQDN_FQDN                       8
295 #define FQDN_SUBOPTION_COUNT            8
296 
297 /* Enterprise Suboptions: */
298 #define VENDOR_ISC_SUBOPTIONS           2495
299 
300 #endif
301 
302 /* Client identifier types */
303 static const uint8_t CLIENT_ID_OPTION_TYPE_DUID = 255;
304 
305 } // end of isc::dhcp namespace
306 } // end of isc namespace
307 
308 #endif /* DHCP_H */
309