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