DHCP request fields insufficiency fixed
This commit is contained in:
parent
048aa6f1db
commit
11d7431d96
@ -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, ¶mReq, {IPv4_ADDR_TO_BE_BYTES(reqAddr)}};
|
DhcpOption reqIp = {DHCP_OPT_RequestedIpAddress, 4, ¶mReq, {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) {
|
||||||
ip4_addr addrOffer = props->yiaddr;
|
const DhcpOption * serverIdentifier = dhcp_get_option(opts, DHCP_OPT_ServerId);
|
||||||
ip4_addr serverAddr = props->siaddr;
|
if (serverIdentifier != NULL) {
|
||||||
|
ip4_addr serverAddr;
|
||||||
dhcp_request(addrOffer, serverAddr);
|
FETCH_DWORD(&serverAddr, serverIdentifier->value);
|
||||||
|
ip4_addr addrOffer = props->yiaddr;
|
||||||
|
dhcp_request(addrOffer, serverAddr);
|
||||||
|
}
|
||||||
|
|
||||||
s.state = DHCP_REQUESTING;
|
s.state = DHCP_REQUESTING;
|
||||||
}
|
}
|
||||||
@ -292,8 +299,8 @@ static void dhcp_process(DhcpProps *props, DhcpOption *opts) {
|
|||||||
uint32_t dhcpLeaseTime_s;
|
uint32_t dhcpLeaseTime_s;
|
||||||
FETCH_DWORD_H2N(&dhcpLeaseTime_s, opt->value);
|
FETCH_DWORD_H2N(&dhcpLeaseTime_s, opt->value);
|
||||||
|
|
||||||
AlarmUserData params = { 0 };
|
AlarmUserData params = {0};
|
||||||
timer_sched_rel(E.tmr, ((int64_t)dhcpLeaseTime_s) * 1000000, NULL, params);
|
timer_sched_rel(E.tmr, ((int64_t) dhcpLeaseTime_s) * 1000000, NULL, params);
|
||||||
|
|
||||||
MSG("DHCP done!\n");
|
MSG("DHCP done!\n");
|
||||||
MSG("IP: ");
|
MSG("IP: ");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user