2e69076
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2e69076
From: Javier Martinez Canillas <javierm@redhat.com>
2e69076
Date: Tue, 10 Mar 2020 11:23:49 +0100
2e69076
Subject: [PATCH] efi/net: Print a debug message if parsing the address fails
2e69076
2e69076
Currently if parsing the address fails an error message is printed. But in
2e69076
most cases this isn't a fatal error since the grub_efi_net_parse_address()
2e69076
function is only used to match an address with a network interface to use.
2e69076
2e69076
And if this fails, the default interface is used which is good enough for
2e69076
most cases. So instead of printing an error that would pollute the console
2e69076
just print a debug message if the address is not parsed correctly.
2e69076
2e69076
A user can enable debug messages for the efinet driver to have information
2e69076
about the failure and the fact that the default interface is being used.
2e69076
2e69076
Related: rhbz#1732765
2e69076
2e69076
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2e69076
---
2e69076
 grub-core/net/efi/net.c | 18 +++++++++++-------
2e69076
 1 file changed, 11 insertions(+), 7 deletions(-)
2e69076
2e69076
diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c
2e69076
index 84573937b18..a3f0535d43c 100644
2e69076
--- a/grub-core/net/efi/net.c
2e69076
+++ b/grub-core/net/efi/net.c
2e69076
@@ -778,9 +778,9 @@ grub_efi_net_parse_address (const char *address,
2e69076
 	}
2e69076
     }
2e69076
 
2e69076
-  return grub_error (GRUB_ERR_NET_BAD_ADDRESS,
2e69076
-		   N_("unrecognised network address `%s'"),
2e69076
-		   address);
2e69076
+  grub_dprintf ("efinet", "unrecognised network address '%s'\n", address);
2e69076
+
2e69076
+  return GRUB_ERR_NET_BAD_ADDRESS;
2e69076
 }
2e69076
 
2e69076
 static grub_efi_net_interface_t *
2e69076
@@ -795,10 +795,7 @@ match_route (const char *server)
2e69076
   err = grub_efi_net_parse_address (server, &ip4, &ip6, &is_ip6, 0);
2e69076
 
2e69076
   if (err)
2e69076
-    {
2e69076
-      grub_print_error ();
2e69076
       return NULL;
2e69076
-    }
2e69076
 
2e69076
   if (is_ip6)
2e69076
     {
2e69076
@@ -1233,8 +1230,15 @@ grub_net_open_real (const char *name __attribute__ ((unused)))
2e69076
   /*FIXME: Use DNS translate name to address */
2e69076
   net_interface = match_route (server);
2e69076
 
2e69076
+  if (!net_interface && net_default_interface)
2e69076
+    {
2e69076
+      net_interface = net_default_interface;
2e69076
+      grub_dprintf ("efinet", "interface lookup failed, using default '%s'\n",
2e69076
+                    net_interface->name);
2e69076
+    }
2e69076
+
2e69076
   /*XXX: should we check device with default gateway ? */
2e69076
-  if (!net_interface && !(net_interface = net_default_interface))
2e69076
+  if (!net_interface)
2e69076
     {
2e69076
       grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' no route found"),
2e69076
 		  name);