1 /* $OpenBSD: dhcpleased.h,v 1.15 2023/11/25 12:00:39 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_LOCKFILE "/dev/dhcpleased.lock" 22 #define _PATH_CONF_FILE "/etc/dhcpleased.conf" 23 #define _PATH_DHCPLEASED_SOCKET "/dev/dhcpleased.sock" 24 #define DHCPLEASED_USER "_dhcp" 25 #define DHCPLEASED_RTA_LABEL "dhcpleased" 26 #define SERVER_PORT 67 27 #define CLIENT_PORT 68 28 #define _PATH_LEASE "/var/db/dhcpleased/" 29 #define LEASE_VERSION "version: 2" 30 #define LEASE_IP_PREFIX "ip: " 31 #define LEASE_NEXTSERVER_PREFIX "next-server: " 32 #define LEASE_BOOTFILE_PREFIX "filename: " 33 #define LEASE_HOSTNAME_PREFIX "host-name: " 34 #define LEASE_DOMAIN_PREFIX "domain-name: " 35 #define LEASE_SIZE 4096 36 /* MAXDNAME from arpa/namesr.h */ 37 #define DHCPLEASED_MAX_DNSSL 1025 38 #define MAX_RDNS_COUNT 8 /* max nameserver in a RTM_PROPOSAL */ 39 40 /* A 1500 bytes packet can hold less than 300 classless static routes */ 41 #define MAX_DHCP_ROUTES 256 42 43 #define DHCP_COOKIE {99, 130, 83, 99} 44 45 /* Possible values for hardware type (htype) field. */ 46 #define HTYPE_NONE 0 47 #define HTYPE_ETHER 1 48 #define HTYPE_IPSEC_TUNNEL 31 49 50 /* DHCP op code */ 51 #define DHCP_BOOTREQUEST 1 52 #define DHCP_BOOTREPLY 2 53 54 /* DHCP Option codes: */ 55 #define DHO_PAD 0 56 #define DHO_SUBNET_MASK 1 57 #define DHO_TIME_OFFSET 2 58 #define DHO_ROUTERS 3 59 #define DHO_TIME_SERVERS 4 60 #define DHO_NAME_SERVERS 5 61 #define DHO_DOMAIN_NAME_SERVERS 6 62 #define DHO_LOG_SERVERS 7 63 #define DHO_COOKIE_SERVERS 8 64 #define DHO_LPR_SERVERS 9 65 #define DHO_IMPRESS_SERVERS 10 66 #define DHO_RESOURCE_LOCATION_SERVERS 11 67 #define DHO_HOST_NAME 12 68 #define DHO_BOOT_SIZE 13 69 #define DHO_MERIT_DUMP 14 70 #define DHO_DOMAIN_NAME 15 71 #define DHO_SWAP_SERVER 16 72 #define DHO_ROOT_PATH 17 73 #define DHO_EXTENSIONS_PATH 18 74 #define DHO_IP_FORWARDING 19 75 #define DHO_NON_LOCAL_SOURCE_ROUTING 20 76 #define DHO_POLICY_FILTER 21 77 #define DHO_MAX_DGRAM_REASSEMBLY 22 78 #define DHO_DEFAULT_IP_TTL 23 79 #define DHO_PATH_MTU_AGING_TIMEOUT 24 80 #define DHO_PATH_MTU_PLATEAU_TABLE 25 81 #define DHO_INTERFACE_MTU 26 82 #define DHO_ALL_SUBNETS_LOCAL 27 83 #define DHO_BROADCAST_ADDRESS 28 84 #define DHO_PERFORM_MASK_DISCOVERY 29 85 #define DHO_MASK_SUPPLIER 30 86 #define DHO_ROUTER_DISCOVERY 31 87 #define DHO_ROUTER_SOLICITATION_ADDRESS 32 88 #define DHO_STATIC_ROUTES 33 89 #define DHO_TRAILER_ENCAPSULATION 34 90 #define DHO_ARP_CACHE_TIMEOUT 35 91 #define DHO_IEEE802_3_ENCAPSULATION 36 92 #define DHO_DEFAULT_TCP_TTL 37 93 #define DHO_TCP_KEEPALIVE_INTERVAL 38 94 #define DHO_TCP_KEEPALIVE_GARBAGE 39 95 #define DHO_NIS_DOMAIN 40 96 #define DHO_NIS_SERVERS 41 97 #define DHO_NTP_SERVERS 42 98 #define DHO_VENDOR_ENCAPSULATED_OPTIONS 43 99 #define DHO_NETBIOS_NAME_SERVERS 44 100 #define DHO_NETBIOS_DD_SERVER 45 101 #define DHO_NETBIOS_NODE_TYPE 46 102 #define DHO_NETBIOS_SCOPE 47 103 #define DHO_FONT_SERVERS 48 104 #define DHO_X_DISPLAY_MANAGER 49 105 #define DHO_DHCP_REQUESTED_ADDRESS 50 106 #define DHO_DHCP_LEASE_TIME 51 107 #define DHO_DHCP_OPTION_OVERLOAD 52 108 #define DHO_DHCP_MESSAGE_TYPE 53 109 #define DHO_DHCP_SERVER_IDENTIFIER 54 110 #define DHO_DHCP_PARAMETER_REQUEST_LIST 55 111 #define DHO_DHCP_MESSAGE 56 112 #define DHO_DHCP_MAX_MESSAGE_SIZE 57 113 #define DHO_DHCP_RENEWAL_TIME 58 114 #define DHO_DHCP_REBINDING_TIME 59 115 #define DHO_DHCP_CLASS_IDENTIFIER 60 116 #define DHO_DHCP_CLIENT_IDENTIFIER 61 117 #define DHO_NISPLUS_DOMAIN 64 118 #define DHO_NISPLUS_SERVERS 65 119 #define DHO_TFTP_SERVER 66 120 #define DHO_BOOTFILE_NAME 67 121 #define DHO_MOBILE_IP_HOME_AGENT 68 122 #define DHO_SMTP_SERVER 69 123 #define DHO_POP_SERVER 70 124 #define DHO_NNTP_SERVER 71 125 #define DHO_WWW_SERVER 72 126 #define DHO_FINGER_SERVER 73 127 #define DHO_IRC_SERVER 74 128 #define DHO_STREETTALK_SERVER 75 129 #define DHO_STREETTALK_DIRECTORY_ASSISTANCE_SERVER 76 130 #define DHO_DHCP_USER_CLASS_ID 77 131 #define DHO_RELAY_AGENT_INFORMATION 82 132 #define DHO_NDS_SERVERS 85 133 #define DHO_NDS_TREE_NAME 86 134 #define DHO_NDS_CONTEXT 87 135 #define DHO_IPV6_ONLY_PREFERRED 108 136 #define DHO_DOMAIN_SEARCH 119 137 #define DHO_CLASSLESS_STATIC_ROUTES 121 138 #define DHO_TFTP_CONFIG_FILE 144 139 #define DHO_VOIP_CONFIGURATION_SERVER 150 140 #define DHO_CLASSLESS_MS_STATIC_ROUTES 249 141 #define DHO_AUTOPROXY_SCRIPT 252 142 #define DHO_END 255 143 #define DHO_COUNT 256 /* # of DHCP options */ 144 145 /* DHCP message types. */ 146 #define DHCPDISCOVER 1 147 #define DHCPOFFER 2 148 #define DHCPREQUEST 3 149 #define DHCPDECLINE 4 150 #define DHCPACK 5 151 #define DHCPNAK 6 152 #define DHCPRELEASE 7 153 #define DHCPINFORM 8 154 155 /* Ignore parts of DHCP lease */ 156 #define IGN_ROUTES 1 157 #define IGN_DNS 2 158 159 #define MAX_SERVERS 16 /* max servers that can be ignored per if */ 160 161 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE) 162 #define DHCP_SNAME_LEN 64 163 #define DHCP_FILE_LEN 128 164 165 struct dhcp_hdr { 166 uint8_t op; /* Message opcode/type */ 167 uint8_t htype; /* Hardware addr type (see net/if_types.h) */ 168 uint8_t hlen; /* Hardware addr length */ 169 uint8_t hops; /* Number of relay agent hops from client */ 170 uint32_t xid; /* Transaction ID */ 171 uint16_t secs; /* Seconds since client started looking */ 172 uint16_t flags; /* Flag bits */ 173 struct in_addr ciaddr; /* Client IP address (if already in use) */ 174 struct in_addr yiaddr; /* Client IP address */ 175 struct in_addr siaddr; /* IP address of next server to talk to */ 176 struct in_addr giaddr; /* DHCP relay agent IP address */ 177 uint8_t chaddr[16]; /* Client hardware address */ 178 char sname[DHCP_SNAME_LEN]; /* Server name */ 179 char file[DHCP_FILE_LEN]; /* Boot filename */ 180 }; 181 182 struct imsgev { 183 struct imsgbuf ibuf; 184 void (*handler)(int, short, void *); 185 struct event ev; 186 short events; 187 }; 188 189 struct dhcp_route { 190 struct in_addr dst; 191 struct in_addr mask; 192 struct in_addr gw; 193 }; 194 195 enum imsg_type { 196 IMSG_NONE, 197 #ifndef SMALL 198 IMSG_CTL_LOG_VERBOSE, 199 IMSG_CTL_SHOW_INTERFACE_INFO, 200 IMSG_CTL_SEND_REQUEST, 201 IMSG_CTL_RELOAD, 202 IMSG_CTL_END, 203 IMSG_RECONF_CONF, 204 IMSG_RECONF_IFACE, 205 IMSG_RECONF_VC_ID, 206 IMSG_RECONF_C_ID, 207 IMSG_RECONF_H_NAME, 208 IMSG_RECONF_END, 209 #endif /* SMALL */ 210 IMSG_SEND_DISCOVER, 211 IMSG_SEND_REQUEST, 212 IMSG_SOCKET_IPC, 213 IMSG_OPEN_BPFSOCK, 214 IMSG_BPFSOCK, 215 IMSG_UDPSOCK, 216 IMSG_CLOSE_UDPSOCK, 217 IMSG_ROUTESOCK, 218 IMSG_CONTROLFD, 219 IMSG_STARTUP, 220 IMSG_UPDATE_IF, 221 IMSG_REMOVE_IF, 222 IMSG_DHCP, 223 IMSG_CONFIGURE_INTERFACE, 224 IMSG_DECONFIGURE_INTERFACE, 225 IMSG_PROPOSE_RDNS, 226 IMSG_WITHDRAW_RDNS, 227 IMSG_WITHDRAW_ROUTES, 228 IMSG_REPROPOSE_RDNS, 229 IMSG_REQUEST_REBOOT, 230 }; 231 232 #ifndef SMALL 233 struct ctl_engine_info { 234 uint32_t if_index; 235 int running; 236 int link_state; 237 char state[sizeof("IF_INIT_REBOOT")]; 238 struct timespec request_time; 239 struct in_addr server_identifier; 240 struct in_addr dhcp_server; /* for unicast */ 241 struct in_addr requested_ip; 242 struct in_addr mask; 243 struct dhcp_route routes[MAX_DHCP_ROUTES]; 244 int routes_len; 245 struct in_addr nameservers[MAX_RDNS_COUNT]; 246 uint32_t lease_time; 247 uint32_t renewal_time; 248 uint32_t rebinding_time; 249 }; 250 251 struct iface_conf { 252 SIMPLEQ_ENTRY(iface_conf) entry; 253 char name[IF_NAMESIZE]; 254 uint8_t *vc_id; 255 int vc_id_len; 256 uint8_t *c_id; 257 int c_id_len; 258 char *h_name; 259 int ignore; 260 struct in_addr ignore_servers[MAX_SERVERS]; 261 int ignore_servers_len; 262 int prefer_ipv6; 263 }; 264 265 struct dhcpleased_conf { 266 SIMPLEQ_HEAD(iface_conf_head, iface_conf) iface_list; 267 }; 268 269 #endif /* SMALL */ 270 271 struct imsg_ifinfo { 272 uint32_t if_index; 273 int rdomain; 274 int running; 275 int link_state; 276 struct ether_addr hw_address; 277 char lease[LEASE_SIZE]; 278 }; 279 280 struct imsg_propose_rdns { 281 uint32_t if_index; 282 int rdomain; 283 int rdns_count; 284 struct in_addr rdns[MAX_RDNS_COUNT]; 285 }; 286 287 struct imsg_dhcp { 288 uint32_t if_index; 289 ssize_t len; 290 uint8_t ether_align[2]; 291 uint8_t packet[1500]; 292 }; 293 294 struct imsg_req_dhcp { 295 uint32_t if_index; 296 uint32_t xid; 297 struct in_addr ciaddr; 298 struct in_addr requested_ip; 299 struct in_addr server_identifier; 300 struct in_addr dhcp_server; 301 }; 302 303 /* dhcpleased.c */ 304 void imsg_event_add(struct imsgev *); 305 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, 306 pid_t, int, void *, uint16_t); 307 #ifndef SMALL 308 void config_clear(struct dhcpleased_conf *); 309 struct dhcpleased_conf *config_new_empty(void); 310 void merge_config(struct dhcpleased_conf *, struct 311 dhcpleased_conf *); 312 const char *sin_to_str(struct sockaddr_in *); 313 314 /* frontend.c */ 315 struct iface_conf *find_iface_conf(struct iface_conf_head *, char *); 316 int *changed_ifaces(struct dhcpleased_conf *, struct 317 dhcpleased_conf *); 318 319 /* printconf.c */ 320 void print_config(struct dhcpleased_conf *); 321 322 /* parse.y */ 323 struct dhcpleased_conf *parse_config(const char *); 324 int cmdline_symset(char *); 325 #else 326 #define sin_to_str(x...) "" 327 #endif /* SMALL */ 328 329