DHCP request fields insufficiency fixed

This commit is contained in:
Wiesner András 2023-02-24 15:47:34 +01:00
parent 048aa6f1db
commit 11d7431d96

View File

@ -215,7 +215,7 @@ static void dhcp_discover() {
memcpy(props.chaddr, s.intf->mac, ETH_HW_ADDR_LEN); memcpy(props.chaddr, s.intf->mac, ETH_HW_ADDR_LEN);
DhcpOption optEnd = {DHCP_OPT_End, 0, NULL}; DhcpOption optEnd = {DHCP_OPT_End, 0, NULL};
uint16_t maxSize = 1500; uint16_t maxSize = 1500; // TODO...
DhcpOption maxMsgSize = {DHCP_OPT_MaxMsgSize, 2, &optEnd, {UINT16_TO_BE_BYTES(maxSize)}}; DhcpOption maxMsgSize = {DHCP_OPT_MaxMsgSize, 2, &optEnd, {UINT16_TO_BE_BYTES(maxSize)}};
DhcpOption msgType = {DHCP_OPT_MsgType, 1, &maxMsgSize, {DHCPDISCOVER}}; DhcpOption msgType = {DHCP_OPT_MsgType, 1, &maxMsgSize, {DHCPDISCOVER}};
@ -239,11 +239,15 @@ void dhcp_request(ip4_addr reqAddr, ip4_addr dhcpServerAddr) {
memcpy(props.chaddr, s.intf->mac, ETH_HW_ADDR_LEN); memcpy(props.chaddr, s.intf->mac, ETH_HW_ADDR_LEN);
uint16_t maxSize = 1500; // TODO...
DhcpOption optEnd = {DHCP_OPT_End, 0, NULL}; DhcpOption optEnd = {DHCP_OPT_End, 0, NULL};
DhcpOption paramReq = {DHCP_OPT_ParamReqList, 4, &optEnd, {1, 3, 6, 51}}; // TODO... DhcpOption paramReq = {DHCP_OPT_ParamReqList, 4, &optEnd, {1, 3, 6, 51}}; // TODO...
DhcpOption reqIp = {DHCP_OPT_RequestedIpAddress, 4, &paramReq, {IPv4_ADDR_TO_BE_BYTES(reqAddr)}}; DhcpOption reqIp = {DHCP_OPT_RequestedIpAddress, 4, &paramReq, {IPv4_ADDR_TO_BE_BYTES(reqAddr)}};
DhcpOption clId = {DHCP_OPT_ClientIdentifier, 7, &reqIp, {DHCP_HW_TYPE_ETHERNET, HWADDR_TO_BE_BYTES(s.intf->mac)}}; DhcpOption serverIp = {DHCP_OPT_ServerId, 4, &reqIp, {IPv4_ADDR_TO_BE_BYTES(dhcpServerAddr)}};
DhcpOption msgType = {DHCP_OPT_MsgType, 1, &clId, {DHCPREQUEST}}; DhcpOption clId = {DHCP_OPT_ClientIdentifier, 7, &serverIp, {DHCP_HW_TYPE_ETHERNET, HWADDR_TO_BE_BYTES(s.intf->mac)}};
DhcpOption maxMsgSize = {DHCP_OPT_MaxMsgSize, 2, &clId, {UINT16_TO_BE_BYTES(maxSize)}};
DhcpOption msgType = {DHCP_OPT_MsgType, 1, &maxMsgSize, {DHCPREQUEST}};
dhcp_send(&props, &msgType); dhcp_send(&props, &msgType);
} }
@ -261,10 +265,13 @@ static void dhcp_process(DhcpProps *props, DhcpOption *opts) {
case DHCP_SELECTING: { case DHCP_SELECTING: {
const DhcpOption *msgType = dhcp_get_option(opts, DHCP_OPT_MsgType); const DhcpOption *msgType = dhcp_get_option(opts, DHCP_OPT_MsgType);
if (msgType->value[0] == DHCPOFFER) { if (msgType->value[0] == DHCPOFFER) {
const DhcpOption * serverIdentifier = dhcp_get_option(opts, DHCP_OPT_ServerId);
if (serverIdentifier != NULL) {
ip4_addr serverAddr;
FETCH_DWORD(&serverAddr, serverIdentifier->value);
ip4_addr addrOffer = props->yiaddr; ip4_addr addrOffer = props->yiaddr;
ip4_addr serverAddr = props->siaddr;
dhcp_request(addrOffer, serverAddr); dhcp_request(addrOffer, serverAddr);
}
s.state = DHCP_REQUESTING; s.state = DHCP_REQUESTING;
} }