From: Chad Kimes <chkimes@github.com>
To: grub-devel@gnu.org
Cc: Chad Kimes <chkimes@github.com>
Subject: [PATCH 1/2] Add vlan information to net_ls_addr output
Date: Fri, 4 Mar 2022 22:46:35 -0500 [thread overview]
Message-ID: <20220305034636.316835-1-chkimes@github.com> (raw)
Example output:
grub> net_ls_addr
efinet1 00:11:22:33:44:55 192.168.0.100 vlan100
Signed-off-by: Chad Kimes <chkimes@github.com>
---
grub-core/net/net.c | 18 +++++++++++++++++-
include/grub/net.h | 8 ++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 4d3eb5c1a..33e35d5b5 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -781,6 +781,20 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str)
grub_printf (_("Unsupported hw address type %d\n"), addr->type);
}
+void
+grub_net_vlan_to_str (grub_uint16_t vlantag, char *str)
+{
+ str[0] = 0;
+
+ /* 12 bits are used to identify the vlan in 802.1Q */
+ vlantag = vlantag & 0xFFF;
+
+ if (vlantag == 0)
+ return;
+
+ grub_snprintf (str, GRUB_NET_MAX_STR_VLAN_LEN, "vlan%u", vlantag);
+}
+
int
grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a,
const grub_net_link_level_address_t *b)
@@ -1250,9 +1264,11 @@ grub_cmd_listaddrs (struct grub_command *cmd __attribute__ ((unused)),
{
char bufh[GRUB_NET_MAX_STR_HWADDR_LEN];
char bufn[GRUB_NET_MAX_STR_ADDR_LEN];
+ char bufv[GRUB_NET_MAX_STR_VLAN_LEN];
grub_net_hwaddr_to_str (&inf->hwaddress, bufh);
grub_net_addr_to_str (&inf->address, bufn);
- grub_printf ("%s %s %s\n", inf->name, bufh, bufn);
+ grub_net_vlan_to_str (inf->vlantag, bufv);
+ grub_printf ("%s %s %s %s\n", inf->name, bufh, bufn, bufv);
}
return GRUB_ERR_NONE;
}
diff --git a/include/grub/net.h b/include/grub/net.h
index 7ae4b6bd8..7fccad8ec 100644
--- a/include/grub/net.h
+++ b/include/grub/net.h
@@ -512,12 +512,20 @@ grub_net_addr_cmp (const grub_net_network_level_address_t *a,
#define GRUB_NET_MAX_STR_HWADDR_LEN (sizeof ("XX:XX:XX:XX:XX:XX"))
+/*
+ Max VLAN id = 4094
+ */
+#define GRUB_NET_MAX_STR_VLAN_LEN (sizeof ("vlanXXXX"))
+
void
grub_net_addr_to_str (const grub_net_network_level_address_t *target,
char *buf);
void
grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
+void
+grub_net_vlan_to_str (grub_uint16_t vlantag, char *str);
+
grub_err_t
grub_env_set_net_property (const char *intername, const char *suffix,
const char *value, grub_size_t len);
--
2.25.1
next reply other threads:[~2022-03-05 3:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-05 3:46 Chad Kimes [this message]
2022-03-05 3:46 ` [PATCH 2/2] Add net_set_vlan command Chad Kimes
2022-03-17 23:03 ` Daniel Kiper
2022-03-21 18:23 ` Chad Kimes
2022-03-17 22:52 ` [PATCH 1/2] Add vlan information to net_ls_addr output Daniel Kiper
-- strict thread matches above, loose matches on Subject: below --
2022-03-21 21:29 [PATCH 0/2] Add command-line management of VLAN config Chad Kimes
2022-03-21 21:29 ` [PATCH 1/2] Add vlan information to net_ls_addr output Chad Kimes
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-all 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=20220305034636.316835-1-chkimes@github.com \
--to=chkimes@github.com \
--cc=grub-devel@gnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.