public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Igor Kulchytskyy via groups.io" <igork=ami.com@groups.io>
To: Nickle Wang <nicklew@nvidia.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Abner Chang <abner.chang@amd.com>, Nick Ramirez <nramirez@nvidia.com>
Subject: Re: [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: fix netmask check issue
Date: Tue, 25 Jul 2023 02:24:09 +0000	[thread overview]
Message-ID: <BLAPR10MB5185B0A7615CF5197063A998A803A@BLAPR10MB5185.namprd10.prod.outlook.com> (raw)
In-Reply-To: <20230725001438.1292-1-nicklew@nvidia.com>

Reviewed-by: Igor Kulchytskyy  <igork@ami.com>

-----Original Message-----
From: Nickle Wang <nicklew@nvidia.com>
Sent: Monday, July 24, 2023 8:15 PM
To: devel@edk2.groups.io
Cc: Abner Chang <abner.chang@amd.com>; Igor Kulchytskyy <igork@ami.com>; Nick Ramirez <nramirez@nvidia.com>
Subject: [EXTERNAL] [PATCH] RedfishPkg/RedfishDiscoverDxe: fix netmask check issue


**CAUTION: The e-mail below is from an external source. Please exercise caution before opening attachments, clicking links, or following guidance.**

- Add NTOHL() for coverting IP address from EFI_IPv4_ADDRESS to
IP4_ADDR so that IP4_IS_VALID_NETMASK() return correct value.
- Add DumpIpv4Address() in RedfishDebugLib and print IP address
when invalid IP or subnet mask address is detected.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 .../RedfishDiscoverDxe/RedfishDiscoverDxe.inf |  2 ++
 RedfishPkg/Include/Library/RedfishDebugLib.h  | 17 ++++++++++++
 .../RedfishDiscoverInternal.h                 |  1 +
 .../Library/RedfishDebugLib/RedfishDebugLib.c | 26 +++++++++++++++++++
 .../RedfishDiscoverDxe/RedfishDiscoverDxe.c   | 11 +++++---
 5 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.inf b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.inf
index 345bacf44d20..950098bf6a0d 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.inf
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.inf
@@ -2,6 +2,7 @@
 #  Implementation of EFI_REDFISH_DISCOVER_PROTOCOL interfaces.
 #
 #  (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
+#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -34,6 +35,7 @@
   DebugLib
   MemoryAllocationLib
   PrintLib
+  RedfishDebugLib
   RestExLib
   UefiLib
   UefiBootServicesTableLib
diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h b/RedfishPkg/Include/Library/RedfishDebugLib.h
index da7e0d0bc9fc..5f75bad12a7f 100644
--- a/RedfishPkg/Include/Library/RedfishDebugLib.h
+++ b/RedfishPkg/Include/Library/RedfishDebugLib.h
@@ -121,4 +121,21 @@ DumpHttpStatusCode (
   IN EFI_HTTP_STATUS_CODE  HttpStatusCode
   );

+/**
+
+  This function dump the IPv4 address in given error level.
+
+  @param[in]  ErrorLevel  DEBUG macro error level
+  @param[in]  Ipv4Address IPv4 address to dump
+
+  @retval     EFI_SUCCESS         IPv4 address string is printed.
+  @retval     Others              Errors occur.
+
+**/
+EFI_STATUS
+DumpIpv4Address (
+  IN UINTN             ErrorLevel,
+  IN EFI_IPv4_ADDRESS  *Ipv4Address
+  );
+
 #endif
diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h
index d24c4081d9c0..01454acc1d9d 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h
@@ -28,6 +28,7 @@
 #include <Library/MemoryAllocationLib.h>
 #include <Library/NetLib.h>
 #include <Library/PrintLib.h>
+#include <Library/RedfishDebugLib.h>
 #include <Library/RestExLib.h>
 #include <Library/UefiLib.h>
 #include <Library/UefiBootServicesTableLib.h>
diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
index 0b2a9a5c4ec8..efa9a5ca1319 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
@@ -340,3 +340,29 @@ DumpRedfishResponse (

   return EFI_SUCCESS;
 }
+
+/**
+
+  This function dump the IPv4 address in given error level.
+
+  @param[in]  ErrorLevel  DEBUG macro error level
+  @param[in]  Ipv4Address IPv4 address to dump
+
+  @retval     EFI_SUCCESS         IPv4 address string is printed.
+  @retval     Others              Errors occur.
+
+**/
+EFI_STATUS
+DumpIpv4Address (
+  IN UINTN             ErrorLevel,
+  IN EFI_IPv4_ADDRESS  *Ipv4Address
+  )
+{
+  if (Ipv4Address == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((ErrorLevel, "%d.%d.%d.%d\n", Ipv4Address->Addr[0], Ipv4Address->Addr[1], Ipv4Address->Addr[2], Ipv4Address->Addr[3]));
+
+  return EFI_SUCCESS;
+}
diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
index 470b4c9e0060..17c88ad82db4 100644
--- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
+++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
@@ -531,15 +531,17 @@ DiscoverRedfishHostInterface (
       IP4_COPY_ADDRESS ((VOID *)&Instance->HostSubnetMask.v4, (VOID *)Data->HostIpMask);

       if (EFI_IP4_EQUAL (&Instance->HostIpAddress.v4, &mZeroIp4Addr)) {
-        DEBUG ((DEBUG_ERROR, "%a: invalid host IP address: zero address\n", __func__));
+        DEBUG ((DEBUG_ERROR, "%a: invalid host IP address: ", __func__));
+        DumpIpv4Address (DEBUG_ERROR, &Instance->HostIpAddress.v4);
         //
         // Invalid IP address detected. Change address format to Unknown and use system default address.
         //
         Instance->HostAddrFormat = REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
       }

-      if (!IP4_IS_VALID_NETMASK (EFI_IP4 (Instance->HostSubnetMask.v4))) {
-        DEBUG ((DEBUG_ERROR, "%a: invalid subnet mask address\n", __func__));
+      if (!IP4_IS_VALID_NETMASK (NTOHL (EFI_IP4 (Instance->HostSubnetMask.v4)))) {
+        DEBUG ((DEBUG_ERROR, "%a: invalid subnet mask address: ", __func__));
+        DumpIpv4Address (DEBUG_ERROR, &Instance->HostSubnetMask.v4);
         //
         // Invalid subnet mast address detected. Change address format to Unknown and use system default address.
         //
@@ -553,7 +555,8 @@ DiscoverRedfishHostInterface (
       IP4_COPY_ADDRESS ((VOID *)&Instance->TargetIpAddress.v4, (VOID *)Data->RedfishServiceIpAddress);

       if (EFI_IP4_EQUAL (&Instance->TargetIpAddress.v4, &mZeroIp4Addr)) {
-        DEBUG ((DEBUG_ERROR, "%a: invalid service IP address: zero address\n", __func__));
+        DEBUG ((DEBUG_ERROR, "%a: invalid service IP address: ", __func__));
+        DumpIpv4Address (DEBUG_ERROR, &Instance->TargetIpAddress.v4);
       }
     } else {
       IP6_COPY_ADDRESS ((VOID *)&Instance->TargetIpAddress.v6, (VOID *)Data->RedfishServiceIpAddress);
--
2.17.1

-The information contained in this message may be confidential and proprietary to American Megatrends (AMI). This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107216): https://edk2.groups.io/g/devel/message/107216
Mute This Topic: https://groups.io/mt/100341380/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2023-07-25  2:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25  0:14 [edk2-devel] [PATCH] RedfishPkg/RedfishDiscoverDxe: fix netmask check issue Nickle Wang via groups.io
2023-07-25  2:24 ` Igor Kulchytskyy via groups.io [this message]
2023-07-25 15:17 ` Chang, Abner via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BLAPR10MB5185B0A7615CF5197063A998A803A@BLAPR10MB5185.namprd10.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox