在某个环境中,BIOS进行无线连接,经常无法从路由器上获取IP地址。
根据路由器的LOG分析,DHCP DISCOVER,OFFER后即无响应,DORA过程不全。
通过增加重试以及修复超时时间,可以从路由器获取IP地址。
DHCP DORA 过程
1. DHCP Discover Message
Source IP: 0.0.0.0
Destination IP: 255.255.255.255
Source MAC: DHCP Client Machine MAC Address
Destination MAC: FF:FF:FF:FF:FF:FF
2. DHCP Offer Message
Source IP: DHCP Server IP Address
Destination IP: 255.255.255.255
Source MAC: DHCP Server Machine MAC Address
Destination MAC: DHCP client MAC Address
3. DHCP Request Message
Source IP: 0.0.0.0
Destination IP: 255.255.255.255
Source MAC: DHCP Client Machine MAC Address
Destination MAC: DHCP Server MAC Address
4. DHCP Acknowledge Message
Source IP: DHCP Server IP Address
Destination IP: 255.255.255.255
Source MAC: DHCP Server Machine MAC Address
Destination MAC: DHCP client MAC Address
UEFI中的相关代码
//edk2-vUDK2018\MdeModulePkg\Universal\Network\Dhcp4Dxe\Dhcp4Io.c
VOID
EFIAPI
DhcpOnTimerTick (
IN EFI_EVENT Event,
IN VOID *Context
)
{
...
//
// Check the retransmit timer
//
if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {
//
// Select offer at each timeout if any offer received.
//
if (DhcpSb->DhcpState == Dhcp4Selecting && DhcpSb->LastOffer != NULL) {
Status = DhcpChooseOffer (DhcpSb);
if (EFI_ERROR(Status)) {
if (DhcpSb->LastOffer != NULL) {
FreePool (DhcpSb->LastOffer);
DhcpSb->LastOffer = NULL;
}
} else {
goto ON_EXIT;
}
}
if (++DhcpSb->CurRetry < DhcpSb->MaxRetries) {
//
// Still has another try
//
DhcpRetransmit (DhcpSb);
DhcpSetTransmitTimer (DhcpSb);
} else if (DHCP_CONNECTED (DhcpSb->DhcpState)) {
//
// Retransmission failed, if the DHCP request is initiated by
// user, adjust the current state according to the lease life.
// Otherwise do nothing to wait the lease to timeout
//
if (DhcpSb->ExtraRefresh != 0) {
Status = EFI_SUCCESS;
if (DhcpSb->LeaseLife < DhcpSb->T1) {
Status = DhcpSetState (DhcpSb, Dhcp4Bound, FALSE);
} else if (DhcpSb->LeaseLife < DhcpSb->T2) {
Status = DhcpSetState (DhcpSb, Dhcp4Renewing, FALSE);
} else if (DhcpSb->LeaseLife < DhcpSb->Lease) {
Status = DhcpSetState (DhcpSb, Dhcp4Rebinding, FALSE);
} else {
goto END_SESSION;
}
DhcpSb->IoStatus = EFI_TIMEOUT;
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND);
}
} else {
goto END_SESSION;
}
}
...
}
路由器 OK, NG时的Log.
<OK>
*DHCP Socket Task: 13:58:47.145: 0c:7a:15:45:64:33 DHCP processing DHCP DISCOVER (1)
*DHCP Socket Task: 13:58:47.145: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX1, secs: 0, flags: 80
*DHCP Socket Task: 13:58:47.145: 0c:7a:15:45:64:33 DHCP successfully bridged packet to DS
*DHCP Socket Task: 13:58:47.147: 0c:7a:15:45:64:33 DHCP processing DHCP OFFER (2)
*DHCP Socket Task: 13:58:47.147: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX1, secs: 0, flags: 80
*DHCP Socket Task: 13:58:47.147: 0c:7a:15:45:64:33 DHCP successfully bridged packet to STA
*DHCP Socket Task: 13:58:48.017: 0c:7a:15:45:64:33 DHCP processing DHCP REQUEST (3)
*DHCP Socket Task: 13:58:48.017: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX1, secs: 0, flags: 80
*DHCP Socket Task: 13:58:48.017: 0c:7a:15:45:64:33 DHCP successfully bridged packet to DS
*DHCP Socket Task: 13:58:48.060: 0c:7a:15:45:64:33 DHCP processing DHCP ACK (5)
*DHCP Socket Task: 13:58:48.060: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX1, secs: 0, flags: 80
*DHCP Socket Task: 13:58:48.060: 0c:7a:15:45:64:33 DHCP successfully bridged packet to STA
<NG>
*DHCP Socket Task: 14:03:14.128: 0c:7a:15:45:64:33 DHCP processing DHCP DISCOVER (1)
*DHCP Socket Task: 14:03:14.128: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX2, secs: 0, flags: 80
*DHCP Socket Task: 14:03:14.128: 0c:7a:15:45:64:33 DHCP successfully bridged packet to DS
*DHCP Socket Task: 14:03:14.269: 0c:7a:15:45:64:33 DHCP processing DHCP OFFER (2)
*DHCP Socket Task: 14:03:14.269: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX2, secs: 0, flags: 80
*DHCP Socket Task: 14:03:14.269: 0c:7a:15:45:64:33 DHCP successfully bridged packet to STA
<NG>
*DHCP Socket Task: 14:06:15.477: 0c:7a:15:45:64:33 DHCP processing DHCP DISCOVER (1)
*DHCP Socket Task: 14:06:15.477: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX3, secs: 0, flags: 80
*DHCP Socket Task: 14:06:15.477: 0c:7a:15:45:64:33 DHCP successfully bridged packet to DS
*DHCP Socket Task: 14:06:15.546: 0c:7a:15:45:64:33 DHCP processing DHCP OFFER (2)
*DHCP Socket Task: 14:06:15.546: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX3, secs: 0, flags: 80
*DHCP Socket Task: 14:06:15.546: 0c:7a:15:45:64:33 DHCP successfully bridged packet to STA
<NG>
*DHCP Socket Task: 14:10:16.014: 0c:7a:15:45:64:33 DHCP processing DHCP DISCOVER (1)
*DHCP Socket Task: 14:10:16.014: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX4, secs: 0, flags: 80
*DHCP Socket Task: 14:10:16.014: 0c:7a:15:45:64:33 DHCP successfully bridged packet to DS
*DHCP Socket Task: 14:10:16.174: 0c:7a:15:45:64:33 DHCP processing DHCP OFFER (2)
*DHCP Socket Task: 14:10:16.174: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX4, secs: 0, flags: 80
<OK>
*DHCP Socket Task: 14:15:30.652: 0c:7a:15:45:64:33 DHCP processing DHCP DISCOVER (1)
*DHCP Socket Task: 14:15:30.652: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX5, secs: 0, flags: 80
*DHCP Socket Task: 14:15:30.652: 0c:7a:15:45:64:33 DHCP successfully bridged packet to DS
*DHCP Socket Task: 14:15:30.654: 0c:7a:15:45:64:33 DHCP processing DHCP OFFER (2)
*DHCP Socket Task: 14:15:30.654: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX5, secs: 0, flags: 80
*DHCP Socket Task: 14:15:30.654: 0c:7a:15:45:64:33 DHCP successfully bridged packet to STA
*DHCP Socket Task: 14:15:31.535: 0c:7a:15:45:64:33 DHCP processing DHCP REQUEST (3)
*DHCP Socket Task: 14:15:31.535: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX5, secs: 0, flags: 80
*DHCP Socket Task: 14:15:31.535: 0c:7a:15:45:64:33 DHCP successfully bridged packet to DS
*DHCP Socket Task: 14:15:31.538: 0c:7a:15:45:64:33 DHCP processing DHCP ACK (5)
*DHCP Socket Task: 14:15:31.538: 0c:7a:15:45:64:33 DHCP xid: 0xXXXXXXX5, secs: 0, flags: 80
*DHCP Socket Task: 14:15:31.538: 0c:7a:15:45:64:33 DHCP successfully bridged packet to STA