Skip to content

Commit

Permalink
Add debug messages for DHCP state changes, Tftp progress, and PxeBc p…
Browse files Browse the repository at this point in the history
…rogress. (#188)

## Description

Add DEBUG message to Dhcp4Dxe

- [ No] Breaking change?
- Will this change break pre-existing builds or functionality without
action being taken?

## How This Was Tested

Not tested

## Integration Instructions

To only get the DHCP debug messages, edit your platform build .dsc to
add the debug flag to

Current:
NetworkPkg/Dhcp4Dxe/Dhcp4Dxe.inf

To get the new DEBUG_NET messages from Dhcp4Dxe:
  NetworkPkg/Dhcp4Dxe/Dhcp4Dxe.inf {
    <PcdsPatchableInModule>
      gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80084246
    <PcdsFixedAtBuild>
      gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel|0x80084246
}

Co-authored-by: kuqin12 <42554914+kuqin12@users.noreply.github.com>
  • Loading branch information
2 people authored and kenlautner committed Dec 18, 2023
1 parent efeff72 commit 1dce1f6
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 1 deletion.
7 changes: 7 additions & 0 deletions NetworkPkg/Dhcp4Dxe/Dhcp4Impl.c
Expand Up @@ -788,11 +788,13 @@ EfiDhcp4Start (
DhcpSb = Instance->Service;

if (DhcpSb->DhcpState == Dhcp4Stopped) {
DEBUG ((DEBUG_NET | DEBUG_ERROR, "%a: failed, in stopped state.\n", __FUNCTION__));
Status = EFI_NOT_STARTED;
goto ON_ERROR;
}

if ((DhcpSb->DhcpState != Dhcp4Init) && (DhcpSb->DhcpState != Dhcp4InitReboot)) {
DEBUG ((DEBUG_NET | DEBUG_ERROR, "%a: failed, !Init and !InitReboot state.\n", __FUNCTION__));
Status = EFI_ALREADY_STARTED;
goto ON_ERROR;
}
Expand Down Expand Up @@ -903,11 +905,13 @@ EfiDhcp4RenewRebind (
DhcpSb = Instance->Service;

if (DhcpSb->DhcpState == Dhcp4Stopped) {
DEBUG ((DEBUG_NET, "%a: failed, Dhcp4Stopped.\n", __FUNCTION__));
Status = EFI_NOT_STARTED;
goto ON_EXIT;
}

if (DhcpSb->DhcpState != Dhcp4Bound) {
DEBUG ((DEBUG_NET, "%a: failed, !Dhcp4Bound.\n", __FUNCTION__));
Status = EFI_ACCESS_DENIED;
goto ON_EXIT;
}
Expand Down Expand Up @@ -1016,6 +1020,7 @@ EfiDhcp4Release (
DhcpSb = Instance->Service;

if ((DhcpSb->DhcpState != Dhcp4InitReboot) && (DhcpSb->DhcpState != Dhcp4Bound)) {
DEBUG ((DEBUG_NET, "%a: failed, !InitReboot and !Bound.\n", __FUNCTION__));
Status = EFI_ACCESS_DENIED;
goto ON_EXIT;
}
Expand Down Expand Up @@ -1085,6 +1090,8 @@ EfiDhcp4Stop (

DhcpCleanLease (DhcpSb);

DEBUG ((DEBUG_NET, "%a: new state is Dhcp4Stopped.\n", __FUNCTION__));

DhcpSb->DhcpState = Dhcp4Stopped;
DhcpSb->ServiceState = DHCP_UNCONFIGED;

Expand Down
38 changes: 37 additions & 1 deletion NetworkPkg/Dhcp4Dxe/Dhcp4Io.c
Expand Up @@ -39,6 +39,7 @@ DhcpInitRequest (
Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_DISCOVER, NULL);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_NET | DEBUG_ERROR, "%a: SendError, new state is Dhcp4Init. Code=%r\n", __FUNCTION__, Status));
DhcpSb->DhcpState = Dhcp4Init;
return Status;
}
Expand All @@ -47,6 +48,7 @@ DhcpInitRequest (
Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_REQUEST, NULL);

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_NET | DEBUG_ERROR, "%a: SendError, new state is Dhcp4InitReboot. Code-%r\n", __FUNCTION__, Status));
DhcpSb->DhcpState = Dhcp4InitReboot;
return Status;
}
Expand Down Expand Up @@ -86,6 +88,8 @@ DhcpCallUser (
*NewPacket = NULL;
}

DEBUG ((DEBUG_NET, "%a: Calling user code with DhcpState=%d.\n", __FUNCTION__, Event));

//
// If user doesn't provide the call back function, return the value
// that directs the client to continue the normal process.
Expand Down Expand Up @@ -184,6 +188,8 @@ DhcpSetState (
{
EFI_STATUS Status;

DEBUG ((DEBUG_NET, "%a: Setting state to %d, CallUser=%d.\n", __FUNCTION__, State, CallUser));

if (CallUser) {
Status = EFI_SUCCESS;

Expand Down Expand Up @@ -425,6 +431,8 @@ DhcpCleanLease (
IN DHCP_SERVICE *DhcpSb
)
{
DEBUG ((DEBUG_NET, "%a: Setting state to Init.\n", __FUNCTION__));

DhcpSb->DhcpState = Dhcp4Init;
DhcpSb->Xid = DhcpSb->Xid + 1;
DhcpSb->ClientAddr = 0;
Expand Down Expand Up @@ -568,8 +576,10 @@ DhcpEndSession (
)
{
if (DHCP_CONNECTED (DhcpSb->DhcpState)) {
DEBUG ((DEBUG_NET, "%a: AddressLost.\n", __FUNCTION__));
DhcpCallUser (DhcpSb, Dhcp4AddressLost, NULL, NULL);
} else {
DEBUG ((DEBUG_NET, "%a: Fail.\n", __FUNCTION__));
DhcpCallUser (DhcpSb, Dhcp4Fail, NULL, NULL);
}

Expand Down Expand Up @@ -869,22 +879,28 @@ DhcpHandleReboot (
DhcpCallUser (DhcpSb, Dhcp4RcvdNak, Packet, NULL);

DhcpSb->ClientAddr = 0;
DhcpSb->DhcpState = Dhcp4Init;
DEBUG ((DEBUG_NET, "%a: NAK received, going to Init\n", __FUNCTION__));

DhcpSb->DhcpState = Dhcp4Init;

Status = DhcpInitRequest (DhcpSb);
goto ON_EXIT;
}

DEBUG ((DEBUG_NET, "%a: ACK Received.\n", __FUNCTION__));

//
// Check whether the ACK matches the selected offer
//
if (EFI_NTOHL (Head->YourAddr) != DhcpSb->ClientAddr) {
DEBUG ((DEBUG_NET, "%a: ACK didn't match offer.\n", __FUNCTION__));
Status = EFI_DEVICE_ERROR;
goto ON_EXIT;
}

Status = DhcpCallUser (DhcpSb, Dhcp4RcvdAck, Packet, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_NET, "%a: Error from CallUser - %r.\n", __FUNCTION__, Status));
goto ON_EXIT;
}

Expand All @@ -893,18 +909,21 @@ DhcpHandleReboot (
//
DhcpSb->Para = AllocateCopyPool (sizeof (DHCP_PARAMETER), Para);
if (DhcpSb->Para == NULL) {
DEBUG ((DEBUG_NET, "%a: Out of resources.\n", __FUNCTION__));
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}

DhcpSb->Selected = Packet;
Status = DhcpLeaseAcquired (DhcpSb);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_NET, "%a: Error from LeaseAcquired - %r.\n", __FUNCTION__, Status));
return Status;
}

DhcpSb->IoStatus = EFI_SUCCESS;
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_COMPLETION);
DEBUG ((DEBUG_NET, "%a: DHCP Complete.\n", __FUNCTION__));
return EFI_SUCCESS;

ON_EXIT:
Expand Down Expand Up @@ -954,13 +973,15 @@ DhcpInput (
ASSERT (UdpPacket != NULL);

if (DhcpSb->DhcpState == Dhcp4Stopped) {
DEBUG ((DEBUG_NET, "%a: Restarting due to state == Stopped.\n", __FUNCTION__));
goto RESTART;
}

//
// Validate the packet received
//
if (UdpPacket->TotalSize < sizeof (EFI_DHCP4_HEADER)) {
DEBUG ((DEBUG_NET, "%a: Restarting due to invalid header size.\n", __FUNCTION__));
goto RESTART;
}

Expand All @@ -971,6 +992,7 @@ DhcpInput (
Packet = (EFI_DHCP4_PACKET *)AllocatePool (Len);

if (Packet == NULL) {
DEBUG ((DEBUG_NET, "%a: Restarting due to out of resources.\n", __FUNCTION__));
goto RESTART;
}

Expand All @@ -979,6 +1001,7 @@ DhcpInput (
Packet->Length = NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *)Head);

if (Packet->Length != UdpPacket->TotalSize) {
DEBUG ((DEBUG_NET, "%a: Restarting due to incorrect packet length.\n", __FUNCTION__));
goto RESTART;
}

Expand All @@ -989,6 +1012,7 @@ DhcpInput (
(NTOHL (Head->Xid) != DhcpSb->Xid) ||
(CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0))
{
DEBUG ((DEBUG_NET, "%a: Restarting due to not our answer.\n", __FUNCTION__));
goto RESTART;
}

Expand All @@ -1000,6 +1024,7 @@ DhcpInput (
(Packet->Dhcp4.Magik == DHCP_OPTION_MAGIC) &&
EFI_ERROR (DhcpValidateOptions (Packet, &Para)))
{
DEBUG ((DEBUG_NET, "%a: Restarting due to bad options.\n", __FUNCTION__));
goto RESTART;
}

Expand All @@ -1017,10 +1042,12 @@ DhcpInput (
switch (DhcpSb->DhcpState) {
case Dhcp4Selecting:
Status = DhcpHandleSelect (DhcpSb, Packet, Para);
DEBUG ((DEBUG_NET, "%a: Selecting - code=%r.\n", __FUNCTION__, Status));
break;

case Dhcp4Requesting:
Status = DhcpHandleRequest (DhcpSb, Packet, Para);
DEBUG ((DEBUG_NET, "%a: Requesting - code=%r.\n", __FUNCTION__, Status));
break;

case Dhcp4InitReboot:
Expand All @@ -1029,17 +1056,20 @@ DhcpInput (
//
// Ignore the packet in INITREBOOT, INIT and BOUND states
//
DEBUG ((DEBUG_NET, "%a: Ignoring Init, InitReboot, Bound.\n", __FUNCTION__));
FreePool (Packet);
Status = EFI_SUCCESS;
break;

case Dhcp4Renewing:
case Dhcp4Rebinding:
Status = DhcpHandleRenewRebind (DhcpSb, Packet, Para);
DEBUG ((DEBUG_NET, "%a: Renew/Rebinding - code=%r.\n", __FUNCTION__, Status));
break;

case Dhcp4Rebooting:
Status = DhcpHandleReboot (DhcpSb, Packet, Para);
DEBUG ((DEBUG_NET, "%a: Rebooting - code=%r.\n", __FUNCTION__, Status));
break;
}

Expand Down Expand Up @@ -1391,6 +1421,8 @@ DhcpRetransmit (

ASSERT (DhcpSb->LastPacket != NULL);

DEBUG ((DEBUG_NET, "%a: Entry...\n", __FUNCTION__));

//
// For REQUEST message in Dhcp4Requesting state, do not change the secs fields.
//
Expand Down Expand Up @@ -1523,6 +1555,7 @@ DhcpOnTimerTick (
}

DhcpSb->IoStatus = EFI_TIMEOUT;
DEBUG ((DEBUG_NET, "%a: Timeout\n", __FUNCTION__));
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND);
}
} else {
Expand Down Expand Up @@ -1607,13 +1640,16 @@ DhcpOnTimerTick (
Instance = NET_LIST_USER_STRUCT (Entry, DHCP_PROTOCOL, Link);
Instance->Timeout--;
if ((Instance->Timeout == 0) && (Instance->Token != NULL)) {
DEBUG ((DEBUG_NET, "%a: Calling PxeDhcpDone\n", __FUNCTION__));
PxeDhcpDone (Instance);
}
}

return;

END_SESSION:
DEBUG ((DEBUG_NET, "%a: Ending session with timeout\n", __FUNCTION__));

DhcpEndSession (DhcpSb, EFI_TIMEOUT);

return;
Expand Down
12 changes: 12 additions & 0 deletions NetworkPkg/Mtftp4Dxe/Mtftp4Impl.c
Expand Up @@ -492,6 +492,8 @@ Mtftp4Start (
//
Token->Status = EFI_NOT_READY;

DEBUG ((DEBUG_NET, "%a: Starting request, type=%d\n", __FUNCTION__, (UINT32)Operation));

//
// Build and send an initial requests
//
Expand Down Expand Up @@ -637,6 +639,8 @@ EfiMtftp4Configure (
return EFI_INVALID_PARAMETER;
}

DEBUG ((DEBUG_NET, "%a: Entry\n", __FUNCTION__));

Instance = MTFTP4_PROTOCOL_FROM_THIS (This);

if (ConfigData == NULL) {
Expand Down Expand Up @@ -693,6 +697,8 @@ EfiMtftp4Configure (
gBS->RestoreTPL (OldTpl);
}

DEBUG ((DEBUG_NET, "%a: Exit Success\n", __FUNCTION__));

return EFI_SUCCESS;
}

Expand Down Expand Up @@ -794,6 +800,8 @@ EfiMtftp4ReadFile (
IN EFI_MTFTP4_TOKEN *Token
)
{
DEBUG ((DEBUG_NET, "%a: Entry\n", __FUNCTION__));

return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_RRQ);
}

Expand Down Expand Up @@ -854,6 +862,8 @@ EfiMtftp4WriteFile (
IN EFI_MTFTP4_TOKEN *Token
)
{
DEBUG ((DEBUG_NET, "%a: Entry\n", __FUNCTION__));

return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_WRQ);
}

Expand Down Expand Up @@ -923,6 +933,8 @@ EfiMtftp4ReadDirectory (
IN EFI_MTFTP4_TOKEN *Token
)
{
DEBUG ((DEBUG_NET, "%a: Entry\n", __FUNCTION__));

return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_DIR);
}

Expand Down

0 comments on commit 1dce1f6

Please sign in to comment.