bb3942d
From 2fd539ed1c41b7a771a78fb2a7ef8c89b4231b4b Mon Sep 17 00:00:00 2001
bb3942d
From: Chad Kimes <chkimes@github.com>
bb3942d
Date: Mon, 21 Mar 2022 17:29:15 -0400
bb3942d
Subject: [PATCH 333/336] net/net: Add vlan information to net_ls_addr output
bb3942d
bb3942d
Example output:
bb3942d
  grub> net_ls_addr
bb3942d
  efinet1 00:11:22:33:44:55 192.0.2.100 vlan100
bb3942d
bb3942d
Signed-off-by: Chad Kimes <chkimes@github.com>
bb3942d
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
bb3942d
---
bb3942d
 grub-core/net/net.c | 19 ++++++++++++++++++-
bb3942d
 include/grub/net.h  |  6 ++++++
bb3942d
 2 files changed, 24 insertions(+), 1 deletion(-)
bb3942d
bb3942d
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
bb3942d
index 1001c611d..f37f34cb8 100644
bb3942d
--- a/grub-core/net/net.c
bb3942d
+++ b/grub-core/net/net.c
bb3942d
@@ -795,6 +795,20 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str)
bb3942d
     }
bb3942d
 }
bb3942d
 
bb3942d
+void
bb3942d
+grub_net_vlan_to_str (grub_uint16_t vlantag, char *str)
bb3942d
+{
bb3942d
+  str[0] = 0;
bb3942d
+
bb3942d
+  /* 12 bits are used to identify the vlan in 802.1Q. */
bb3942d
+  vlantag = vlantag & 0x0fff;
bb3942d
+
bb3942d
+  if (vlantag == 0)
bb3942d
+    return;
bb3942d
+
bb3942d
+  grub_snprintf (str, GRUB_NET_MAX_STR_VLAN_LEN, "vlan%u", vlantag);
bb3942d
+}
bb3942d
+
bb3942d
 int
bb3942d
 grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a,
bb3942d
 		     const grub_net_link_level_address_t *b)
bb3942d
@@ -1340,9 +1354,12 @@ grub_cmd_listaddrs (struct grub_command *cmd __attribute__ ((unused)),
bb3942d
   {
bb3942d
     char bufh[GRUB_NET_MAX_STR_HWADDR_LEN];
bb3942d
     char bufn[GRUB_NET_MAX_STR_ADDR_LEN];
bb3942d
+    char bufv[GRUB_NET_MAX_STR_VLAN_LEN];
bb3942d
+
bb3942d
     grub_net_hwaddr_to_str (&inf->hwaddress, bufh);
bb3942d
     grub_net_addr_to_str (&inf->address, bufn);
bb3942d
-    grub_printf ("%s %s %s\n", inf->name, bufh, bufn);
bb3942d
+    grub_net_vlan_to_str (inf->vlantag, bufv);
bb3942d
+    grub_printf ("%s %s %s %s\n", inf->name, bufh, bufn, bufv);
bb3942d
   }
bb3942d
   return GRUB_ERR_NONE;
bb3942d
 }
bb3942d
diff --git a/include/grub/net.h b/include/grub/net.h
bb3942d
index 9e4898cc6..d771afa47 100644
bb3942d
--- a/include/grub/net.h
bb3942d
+++ b/include/grub/net.h
bb3942d
@@ -599,12 +599,18 @@ grub_net_addr_cmp (const grub_net_network_level_address_t *a,
bb3942d
 	"XX:XX:XX:XX:XX:XX:XX:XX:"\
bb3942d
 	"XX:XX:XX:XX:XX:XX:XX:XX"))
bb3942d
 
bb3942d
+/* Max VLAN id = 4094 */
bb3942d
+#define GRUB_NET_MAX_STR_VLAN_LEN (sizeof ("vlanXXXX"))
bb3942d
+
bb3942d
 void
bb3942d
 grub_net_addr_to_str (const grub_net_network_level_address_t *target,
bb3942d
 		      char *buf);
bb3942d
 void
bb3942d
 grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
bb3942d
 
bb3942d
+void
bb3942d
+grub_net_vlan_to_str (grub_uint16_t vlantag, char *str);
bb3942d
+
bb3942d
 grub_err_t
bb3942d
 grub_env_set_net_property (const char *intername, const char *suffix,
bb3942d
                            const char *value, grub_size_t len);
bb3942d
-- 
bb3942d
2.41.0
bb3942d