diff options
Diffstat (limited to 'libdhcp')
-rw-r--r-- | libdhcp/dhcp_client.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/libdhcp/dhcp_client.c b/libdhcp/dhcp_client.c index e5f3232..fc40861 100644 --- a/libdhcp/dhcp_client.c +++ b/libdhcp/dhcp_client.c @@ -198,6 +198,9 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c client->state == STATE_INIT_REBOOT || /* variant initial selection */ client->state == STATE_BOUND || /* T1 expired, start renew */ client->state == STATE_RENEWING ); /* T2 expired, start rebind */ + + /* For convenience in switch blocks, a list of the states that + * are not in the above assert(). */ #define IMPOSSIBLE_REQUEST_STATES \ STATE_INIT: \ case STATE_REQUESTING: \ @@ -241,13 +244,10 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c msg.xid = uint32be_marshal(client->xid); msg.secs = uint16be_marshal((VCALL(bootclock, get_time_ns) - client->time_ns_init)/NS_PER_S); switch (msgtyp) { - case DHCP_MSGTYP_DISCOVER: - case DHCP_MSGTYP_INFORM: - case DHCP_MSGTYP_REQUEST: + case DHCP_MSGTYP_DISCOVER: case DHCP_MSGTYP_INFORM: case DHCP_MSGTYP_REQUEST: msg.flags = uint16be_marshal(server_broadcasts ? DHCP_FLAG_BROADCAST : 0); break; - case DHCP_MSGTYP_DECLINE: - case DHCP_MSGTYP_RELEASE: + case DHCP_MSGTYP_DECLINE: case DHCP_MSGTYP_RELEASE: msg.flags = uint16be_marshal(0); break; } @@ -264,8 +264,6 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c msg.ciaddr = client->lease_client_addr; break; case IMPOSSIBLE_REQUEST_STATES: assert_notreached("invalid client state for sending DHCPREQUEST"); - default: - assert_notreached("invalid client state"); } break; case DHCP_MSGTYP_DECLINE: msg.ciaddr = net_ip4_addr_zero; break; case DHCP_MSGTYP_RELEASE: msg.ciaddr = client->lease_client_addr; break; @@ -284,7 +282,8 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c msg.options[optlen++] = dhcp_magic_cookie[2]; msg.options[optlen++] = dhcp_magic_cookie[3]; - /* Options. */ + /* Options. + * https://datatracker.ietf.org/doc/html/rfc2131#page-38 */ static uint8_t parameter_request_list[] = { DHCP_OPT_SUBNET_MASK, DHCP_OPT_ROUTER, @@ -613,9 +612,9 @@ static ssize_t dhcp_client_recv(struct dhcp_client *client, struct dhcp_recv_msg /* Validate values of options. */ if (ret->options[DHCP_OPT_CLASS_ID].len) { /* https://datatracker.ietf.org/doc/html/rfc6842#page-4 */ - if (ret->options[DHCP_OPT_CLASS_ID].len != client->self_id_len) - goto ignore; - if (memcmp(ret->options[DHCP_OPT_CLASS_ID].dat, client->self_id_dat, client->self_id_len)) + if (ret->options[DHCP_OPT_CLASS_ID].len != client->self_id_len || + memcmp(ret->options[DHCP_OPT_CLASS_ID].dat, client->self_id_dat, client->self_id_len)) + /* ignore messages that aren't to us */ goto ignore; } @@ -824,7 +823,7 @@ __attribute__((noreturn)) void dhcp_client_main(implements_net_iface *iface, .sock = VCALL(iface, udp_conn, DHCP_PORT_CLIENT), .self_eth_addr = VCALL(iface, hwaddr), - /* Lease. */ + /* Mutable. */ .state = STATE_INIT, }; if (self_hostname) |