1 /* 2 * libwebsockets - small server side websockets and web server implementation 3 * 4 * Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 typedef enum { 26 LDHC_INIT_REBOOT, 27 LDHC_REBOOTING, /* jitterwait */ 28 LDHC_INIT, /* issue DHCPDISCOVER */ 29 LDHC_SELECTING, 30 LDHC_REQUESTING, 31 LDHC_REBINDING, 32 LDHC_BOUND, 33 LDHC_RENEWING 34 } lws_dhcpc_state_t; 35 36 enum { 37 LWSDHC4PDISCOVER = 1, 38 LWSDHC4POFFER, 39 LWSDHC4PREQUEST, 40 LWSDHC4PDECLINE, 41 LWSDHC4PACK, 42 LWSDHC4PNACK, 43 LWSDHC4PRELEASE, 44 45 LWSDHC4POPT_PAD = 0, 46 LWSDHC4POPT_SUBNET_MASK = 1, 47 LWSDHC4POPT_TIME_OFFSET = 2, 48 LWSDHC4POPT_ROUTER = 3, 49 LWSDHC4POPT_TIME_SERVER = 4, 50 LWSDHC4POPT_NAME_SERVER = 5, 51 LWSDHC4POPT_DNSERVER = 6, 52 LWSDHC4POPT_LOG_SERVER = 7, 53 LWSDHC4POPT_COOKIE_SERVER = 8, 54 LWSDHC4POPT_LPR_SERVER = 9, 55 LWSDHC4POPT_IMPRESS_SERVER = 10, 56 LWSDHC4POPT_RESLOC_SERVER = 11, 57 LWSDHC4POPT_HOST_NAME = 12, 58 LWSDHC4POPT_BOOTFILE_SIZE = 13, 59 LWSDHC4POPT_MERIT_DUMP_FILE = 14, 60 LWSDHC4POPT_DOMAIN_NAME = 15, 61 LWSDHC4POPT_SWAP_SERVER = 16, 62 LWSDHC4POPT_ROOT_PATH = 17, 63 LWSDHC4POPT_EXTENSIONS_PATH = 18, 64 LWSDHC4POPT_BROADCAST_ADS = 28, 65 66 LWSDHC4POPT_REQUESTED_ADS = 50, 67 LWSDHC4POPT_LEASE_TIME = 51, 68 LWSDHC4POPT_OPTION_OVERLOAD = 52, 69 LWSDHC4POPT_MESSAGE_TYPE = 53, 70 LWSDHC4POPT_SERVER_ID = 54, 71 LWSDHC4POPT_PARAM_REQ_LIST = 55, 72 LWSDHC4POPT_MESSAGE = 56, 73 LWSDHC4POPT_MAX_DHCP_MSG_SIZE = 57, 74 LWSDHC4POPT_RENEWAL_TIME = 58, /* AKA T1 */ 75 LWSDHC4POPT_REBINDING_TIME = 59, /* AKA T2 */ 76 LWSDHC4POPT_VENDOR_CLASS_ID = 60, 77 LWSDHC4POPT_CLIENT_ID = 61, 78 79 LWSDHC4POPT_END_OPTIONS = 255 80 }; 81 82 typedef struct lws_dhcpc_req { 83 lws_dll2_t list; 84 85 struct lws_context *context; 86 lws_sorted_usec_list_t sul_renew; 87 lws_sorted_usec_list_t sul_conn; 88 lws_sorted_usec_list_t sul_write; 89 dhcpc_cb_t cb; /* cb on completion / failure */ 90 void *opaque; /* ignored by lws, give to cb */ 91 92 /* these are separated so we can close the bcast one asynchronously */ 93 struct lws *wsi_raw; /* for broadcast */ 94 lws_dhcpc_state_t state; 95 96 lws_dhcpc_ifstate_t is; 97 98 uint16_t retry_count_conn; 99 uint16_t retry_count_write; 100 uint8_t xid[4]; 101 uint8_t af; /* address family */ 102 } lws_dhcpc_req_t; 103 /* interface name is overallocated here */ 104 105 void 106 lws_dhcpc4_retry_conn(struct lws_sorted_usec_list *sul); 107 108 int 109 lws_dhcpc4_parse(lws_dhcpc_req_t *r, void *in, size_t len); 110 111 void 112 lws_dhcpc_retry_write(struct lws_sorted_usec_list *sul); 113