xref: /openbsd/sbin/dhcpleased/dhcpleased.h (revision c6841532)
1 /*	$OpenBSD: dhcpleased.h,v 1.4 2021/04/10 17:22:34 florian Exp $	*/
2 
3 /*
4  * Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
5  * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
6  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #define	_PATH_DHCPLEASED_SOCKET	"/dev/dhcpleased.sock"
22 #define	DHCPLEASED_USER		"_dhcp"
23 #define	DHCPLEASED_RTA_LABEL	"dhcpleased"
24 #define	SERVER_PORT		67
25 #define	CLIENT_PORT		68
26 #define	_PATH_LEASE		"/var/db/dhcpleased/"
27 #define	LEASE_PREFIX		"version: 1\nip: "
28 #define	LEASE_SIZE		sizeof(LEASE_PREFIX"xxx.xxx.xxx.xxx\n")
29 /* MAXDNAME from arpa/namesr.h */
30 #define	DHCPLEASED_MAX_DNSSL	1025
31 #define	MAX_RDNS_COUNT		8 /* max nameserver in a RTM_PROPOSAL */
32 
33 #define	DHCP_COOKIE		{99, 130, 83, 99}
34 
35 /* Possible values for hardware type (htype) field. */
36 #define	HTYPE_ETHER		1
37 #define	HTYPE_IPSEC_TUNNEL	31
38 
39 /* DHCP op code */
40 #define	DHCP_BOOTREQUEST		1
41 #define	DHCP_BOOTREPLY			2
42 
43 /* DHCP Option codes: */
44 #define	DHO_PAD				0
45 #define	DHO_SUBNET_MASK			1
46 #define	DHO_TIME_OFFSET			2
47 #define	DHO_ROUTERS			3
48 #define	DHO_TIME_SERVERS		4
49 #define	DHO_NAME_SERVERS		5
50 #define	DHO_DOMAIN_NAME_SERVERS		6
51 #define	DHO_LOG_SERVERS			7
52 #define	DHO_COOKIE_SERVERS		8
53 #define	DHO_LPR_SERVERS			9
54 #define	DHO_IMPRESS_SERVERS		10
55 #define	DHO_RESOURCE_LOCATION_SERVERS	11
56 #define	DHO_HOST_NAME			12
57 #define	DHO_BOOT_SIZE			13
58 #define	DHO_MERIT_DUMP			14
59 #define	DHO_DOMAIN_NAME			15
60 #define	DHO_SWAP_SERVER			16
61 #define	DHO_ROOT_PATH			17
62 #define	DHO_EXTENSIONS_PATH		18
63 #define	DHO_IP_FORWARDING		19
64 #define	DHO_NON_LOCAL_SOURCE_ROUTING	20
65 #define	DHO_POLICY_FILTER		21
66 #define	DHO_MAX_DGRAM_REASSEMBLY	22
67 #define	DHO_DEFAULT_IP_TTL		23
68 #define	DHO_PATH_MTU_AGING_TIMEOUT	24
69 #define	DHO_PATH_MTU_PLATEAU_TABLE	25
70 #define	DHO_INTERFACE_MTU		26
71 #define	DHO_ALL_SUBNETS_LOCAL		27
72 #define	DHO_BROADCAST_ADDRESS		28
73 #define	DHO_PERFORM_MASK_DISCOVERY	29
74 #define	DHO_MASK_SUPPLIER		30
75 #define	DHO_ROUTER_DISCOVERY		31
76 #define	DHO_ROUTER_SOLICITATION_ADDRESS	32
77 #define	DHO_STATIC_ROUTES		33
78 #define	DHO_TRAILER_ENCAPSULATION	34
79 #define	DHO_ARP_CACHE_TIMEOUT		35
80 #define	DHO_IEEE802_3_ENCAPSULATION	36
81 #define	DHO_DEFAULT_TCP_TTL		37
82 #define	DHO_TCP_KEEPALIVE_INTERVAL	38
83 #define	DHO_TCP_KEEPALIVE_GARBAGE	39
84 #define	DHO_NIS_DOMAIN			40
85 #define	DHO_NIS_SERVERS			41
86 #define	DHO_NTP_SERVERS			42
87 #define	DHO_VENDOR_ENCAPSULATED_OPTIONS	43
88 #define	DHO_NETBIOS_NAME_SERVERS	44
89 #define	DHO_NETBIOS_DD_SERVER		45
90 #define	DHO_NETBIOS_NODE_TYPE		46
91 #define	DHO_NETBIOS_SCOPE		47
92 #define	DHO_FONT_SERVERS		48
93 #define	DHO_X_DISPLAY_MANAGER		49
94 #define	DHO_DHCP_REQUESTED_ADDRESS	50
95 #define	DHO_DHCP_LEASE_TIME		51
96 #define	DHO_DHCP_OPTION_OVERLOAD	52
97 #define	DHO_DHCP_MESSAGE_TYPE		53
98 #define	DHO_DHCP_SERVER_IDENTIFIER	54
99 #define	DHO_DHCP_PARAMETER_REQUEST_LIST	55
100 #define	DHO_DHCP_MESSAGE		56
101 #define	DHO_DHCP_MAX_MESSAGE_SIZE	57
102 #define	DHO_DHCP_RENEWAL_TIME		58
103 #define	DHO_DHCP_REBINDING_TIME		59
104 #define	DHO_DHCP_CLASS_IDENTIFIER	60
105 #define	DHO_DHCP_CLIENT_IDENTIFIER	61
106 #define	DHO_NISPLUS_DOMAIN		64
107 #define	DHO_NISPLUS_SERVERS		65
108 #define	DHO_TFTP_SERVER			66
109 #define	DHO_BOOTFILE_NAME		67
110 #define	DHO_MOBILE_IP_HOME_AGENT	68
111 #define	DHO_SMTP_SERVER			69
112 #define	DHO_POP_SERVER			70
113 #define	DHO_NNTP_SERVER			71
114 #define	DHO_WWW_SERVER			72
115 #define	DHO_FINGER_SERVER		73
116 #define	DHO_IRC_SERVER			74
117 #define	DHO_STREETTALK_SERVER		75
118 #define	DHO_STREETTALK_DIRECTORY_ASSISTANCE_SERVER	76
119 #define	DHO_DHCP_USER_CLASS_ID		77
120 #define	DHO_RELAY_AGENT_INFORMATION	82
121 #define	DHO_NDS_SERVERS			85
122 #define	DHO_NDS_TREE_NAME		86
123 #define	DHO_NDS_CONTEXT			87
124 #define	DHO_DOMAIN_SEARCH		119
125 #define	DHO_CLASSLESS_STATIC_ROUTES	121
126 #define	DHO_TFTP_CONFIG_FILE		144
127 #define	DHO_VOIP_CONFIGURATION_SERVER	150
128 #define	DHO_CLASSLESS_MS_STATIC_ROUTES	249
129 #define	DHO_AUTOPROXY_SCRIPT		252
130 #define	DHO_END				255
131 #define	DHO_COUNT			256	/* # of DHCP options */
132 
133 /* DHCP message types. */
134 #define	DHCPDISCOVER	1
135 #define	DHCPOFFER	2
136 #define	DHCPREQUEST	3
137 #define	DHCPDECLINE	4
138 #define	DHCPACK		5
139 #define	DHCPNAK		6
140 #define	DHCPRELEASE	7
141 #define	DHCPINFORM	8
142 
143 #define	IMSG_DATA_SIZE(imsg)	((imsg).hdr.len - IMSG_HEADER_SIZE)
144 #define	DHCP_SNAME_LEN		64
145 #define	DHCP_FILE_LEN		128
146 
147 struct dhcp_hdr {
148 	uint8_t		op;	/* Message opcode/type */
149 	uint8_t		htype;	/* Hardware addr type (see net/if_types.h) */
150 	uint8_t		hlen;	/* Hardware addr length */
151 	uint8_t		hops;	/* Number of relay agent hops from client */
152 	uint32_t	xid;	/* Transaction ID */
153 	uint16_t	secs;	/* Seconds since client started looking */
154 	uint16_t	flags;	/* Flag bits */
155 	struct in_addr	ciaddr;	/* Client IP address (if already in use) */
156 	struct in_addr	yiaddr;	/* Client IP address */
157 	struct in_addr	siaddr;	/* IP address of next server to talk to */
158 	struct in_addr	giaddr;	/* DHCP relay agent IP address */
159 	uint8_t		chaddr[16];		/* Client hardware address */
160 	char		sname[DHCP_SNAME_LEN];	/* Server name */
161 	char		file[DHCP_FILE_LEN];	/* Boot filename */
162 };
163 
164 struct imsgev {
165 	struct imsgbuf	 ibuf;
166 	void		(*handler)(int, short, void *);
167 	struct event	 ev;
168 	short		 events;
169 };
170 
171 enum imsg_type {
172 	IMSG_NONE,
173 #ifndef	SMALL
174 	IMSG_CTL_LOG_VERBOSE,
175 	IMSG_CTL_SHOW_INTERFACE_INFO,
176 	IMSG_CTL_SEND_REQUEST,
177 	IMSG_CTL_END,
178 #endif	/* SMALL */
179 	IMSG_SEND_DISCOVER,
180 	IMSG_SEND_REQUEST,
181 	IMSG_SOCKET_IPC,
182 	IMSG_OPEN_BPFSOCK,
183 	IMSG_BPFSOCK,
184 	IMSG_UDPSOCK,
185 	IMSG_CLOSE_UDPSOCK,
186 	IMSG_ROUTESOCK,
187 	IMSG_CONTROLFD,
188 	IMSG_STARTUP,
189 	IMSG_UPDATE_IF,
190 	IMSG_REMOVE_IF,
191 	IMSG_DHCP,
192 	IMSG_CONFIGURE_INTERFACE,
193 	IMSG_DECONFIGURE_INTERFACE,
194 	IMSG_PROPOSE_RDNS,
195 	IMSG_WITHDRAW_RDNS,
196 	IMSG_REPROPOSE_RDNS,
197 };
198 
199 #ifndef	SMALL
200 struct ctl_engine_info {
201 	uint32_t		if_index;
202 	int			running;
203 	int			link_state;
204 	char			state[sizeof("IF_INIT_REBOOT")];
205 	struct timespec		request_time;
206 	struct in_addr		server_identifier;
207 	struct in_addr		dhcp_server; /* for unicast */
208 	struct in_addr		requested_ip;
209 	struct in_addr		mask;
210 	struct in_addr		router;
211 	struct in_addr		nameservers[MAX_RDNS_COUNT];
212 	uint32_t		lease_time;
213 	uint32_t		renewal_time;
214 	uint32_t		rebinding_time;
215 };
216 
217 #endif	/* SMALL */
218 
219 struct imsg_ifinfo {
220 	uint32_t		if_index;
221 	int			rdomain;
222 	int			running;
223 	int			link_state;
224 	struct ether_addr	hw_address;
225 	char			lease[LEASE_SIZE];
226 };
227 
228 struct imsg_propose_rdns {
229 	uint32_t		if_index;
230 	int			rdomain;
231 	int			rdns_count;
232 	struct in_addr		rdns[MAX_RDNS_COUNT];
233 };
234 
235 struct imsg_dhcp {
236 	uint32_t		if_index;
237 	ssize_t			len;
238 	uint8_t			ether_align[2];
239 	uint8_t			packet[1500];
240 };
241 
242 
243 struct imsg_req_discover {
244 	uint32_t		if_index;
245 	uint32_t		xid;
246 };
247 
248 struct imsg_req_request {
249 	uint32_t		if_index;
250 	uint32_t		xid;
251 	struct in_addr		requested_ip;
252 	struct in_addr		server_identifier;
253 	struct in_addr		dhcp_server;
254 };
255 
256 /* dhcpleased.c */
257 void		imsg_event_add(struct imsgev *);
258 int		imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
259 		    int, void *, uint16_t);
260 #ifndef	SMALL
261 const char	*sin_to_str(struct sockaddr_in *);
262 #else
263 #define	sin_to_str(x...)	""
264 #endif	/* SMALL */
265