All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add vlan information to net_ls_addr output
@ 2022-03-05  3:46 Chad Kimes
  2022-03-05  3:46 ` [PATCH 2/2] Add net_set_vlan command Chad Kimes
  2022-03-17 22:52 ` [PATCH 1/2] Add vlan information to net_ls_addr output Daniel Kiper
  0 siblings, 2 replies; 6+ messages in thread
From: Chad Kimes @ 2022-03-05  3:46 UTC (permalink / raw)
  To: grub-devel; +Cc: Chad Kimes

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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] Add net_set_vlan command
  2022-03-05  3:46 [PATCH 1/2] Add vlan information to net_ls_addr output Chad Kimes
@ 2022-03-05  3:46 ` Chad Kimes
  2022-03-17 23:03   ` Daniel Kiper
  2022-03-17 22:52 ` [PATCH 1/2] Add vlan information to net_ls_addr output Daniel Kiper
  1 sibling, 1 reply; 6+ messages in thread
From: Chad Kimes @ 2022-03-05  3:46 UTC (permalink / raw)
  To: grub-devel; +Cc: Chad Kimes

Previously there was no way to set the 802.1Q VLAN identifier, despite
support for vlantag in the net module. The only location vlantag was
being populated was from PXE boot and only for Open Firmware hardware.
This commit allows users to manually configure VLAN information for any
interface.

Example usage:
  grub> net_ls_addr
  efinet1 00:11:22:33:44:55 192.168.0.100
  grub> net_set_vlan efinet1 100
  grub> net_ls_addr
  efinet1 00:11:22:33:44:55 192.168.0.100 vlan100
  grub> net_set_vlan efinet1 0
  efinet1 00:11:22:33:44:55 192.168.0.100

Signed-off-by: Chad Kimes <chkimes@github.com>
---
 docs/grub.texi      |  9 +++++++++
 grub-core/net/net.c | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index caba8befb..5758ec285 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -5553,6 +5553,7 @@ This command is only available on AArch64 systems.
 * net_ls_cards::                List network cards
 * net_ls_dns::                  List DNS servers
 * net_ls_routes::               List routing entries
+* net_set_vlan::                Set vlan id on an interface
 * net_nslookup::                Perform a DNS lookup
 @end menu
 
@@ -5721,6 +5722,14 @@ List routing entries.
 @end deffn
 
 
+@node net_set_vlan
+@subsection net_set_vlan
+
+@deffn Command net_set_vlan @var{interface} @var{vlanid}
+Set the 802.1Q VLAN identifier on @var{interface} to @var{vlanid}.
+@end deffn
+
+
 @node net_nslookup
 @subsection net_nslookup
 
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 33e35d5b5..f2acd2ecf 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -1176,6 +1176,35 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)),
     }
 }
 
+static grub_err_t
+grub_cmd_setvlan (struct grub_command *cmd __attribute__ ((unused)),
+		  int argc, char **args)
+{
+  if (argc < 2)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
+
+  const char *vlanptr = args[1];
+  unsigned long vlantag;
+  vlantag = grub_strtoul (vlanptr, &vlanptr, 10);
+
+  if (vlantag > 4094)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid vlan id"));
+
+  struct grub_net_network_level_interface *inter;
+
+  FOR_NET_NETWORK_LEVEL_INTERFACES (inter)
+    {
+      if (grub_strcmp (inter->name, args[0]) != 0)
+	continue;
+
+      inter->vlantag = vlantag;
+      return GRUB_ERR_NONE;
+    }
+
+  return grub_error (GRUB_ERR_BAD_ARGUMENT,
+                     N_("network interface not found"));
+}
+
 static void
 print_net_address (const grub_net_network_level_netaddress_t *target)
 {
@@ -1892,7 +1921,7 @@ static struct grub_preboot *fini_hnd;
 
 static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute;
 static grub_command_t cmd_lsroutes, cmd_lscards;
-static grub_command_t cmd_lsaddr, cmd_slaac;
+static grub_command_t cmd_lsaddr, cmd_slaac, cmd_setvlan;
 
 GRUB_MOD_INIT(net)
 {
@@ -1935,6 +1964,9 @@ GRUB_MOD_INIT(net)
 				       "", N_("list network cards"));
   cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs,
 				       "", N_("list network addresses"));
+  cmd_setvlan = grub_register_command ("net_set_vlan", grub_cmd_setvlan,
+				       N_("SHORTNAME VLANID"),
+				       N_("Set an interace's vlan id."));
   grub_bootp_init ();
   grub_dns_init ();
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] Add vlan information to net_ls_addr output
  2022-03-05  3:46 [PATCH 1/2] Add vlan information to net_ls_addr output Chad Kimes
  2022-03-05  3:46 ` [PATCH 2/2] Add net_set_vlan command Chad Kimes
@ 2022-03-17 22:52 ` Daniel Kiper
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel Kiper @ 2022-03-17 22:52 UTC (permalink / raw)
  To: Chad Kimes; +Cc: grub-devel

Hey,

First of all, if you send multiple patches please add cover letter to
the patch series. Her is a good example [1].

On Fri, Mar 04, 2022 at 10:46:35PM -0500, Chad Kimes via Grub-devel wrote:
> Example output:
>   grub> net_ls_addr
>   efinet1 00:11:22:33:44:55 192.168.0.100 vlan100

If you give examples please use addresses from example IP network,
192.0.2.0/24 [2].

> 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];

Please add empty line here.

>      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
> + */

Please fix this comment [3].

> +#define GRUB_NET_MAX_STR_VLAN_LEN (sizeof ("vlanXXXX"))

Daniel

[1] https://lists.gnu.org/archive/html/grub-devel/2022-03/msg00081.html
[2] https://datatracker.ietf.org/doc/html/rfc5737
[3] https://www.gnu.org/software/grub/manual/grub-dev/grub-dev.html#Comments


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] Add net_set_vlan command
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Kiper @ 2022-03-17 23:03 UTC (permalink / raw)
  To: Chad Kimes; +Cc: grub-devel

On Fri, Mar 04, 2022 at 10:46:36PM -0500, Chad Kimes via Grub-devel wrote:
> Previously there was no way to set the 802.1Q VLAN identifier, despite
> support for vlantag in the net module. The only location vlantag was
> being populated was from PXE boot and only for Open Firmware hardware.
> This commit allows users to manually configure VLAN information for any
> interface.
>
> Example usage:
>   grub> net_ls_addr
>   efinet1 00:11:22:33:44:55 192.168.0.100
>   grub> net_set_vlan efinet1 100
>   grub> net_ls_addr
>   efinet1 00:11:22:33:44:55 192.168.0.100 vlan100
>   grub> net_set_vlan efinet1 0
>   efinet1 00:11:22:33:44:55 192.168.0.100

The same comment as for the patch #1.

> Signed-off-by: Chad Kimes <chkimes@github.com>
> ---
>  docs/grub.texi      |  9 +++++++++
>  grub-core/net/net.c | 34 +++++++++++++++++++++++++++++++++-
>  2 files changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/docs/grub.texi b/docs/grub.texi
> index caba8befb..5758ec285 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -5553,6 +5553,7 @@ This command is only available on AArch64 systems.
>  * net_ls_cards::                List network cards
>  * net_ls_dns::                  List DNS servers
>  * net_ls_routes::               List routing entries
> +* net_set_vlan::                Set vlan id on an interface
>  * net_nslookup::                Perform a DNS lookup
>  @end menu
>
> @@ -5721,6 +5722,14 @@ List routing entries.
>  @end deffn
>
>
> +@node net_set_vlan
> +@subsection net_set_vlan
> +
> +@deffn Command net_set_vlan @var{interface} @var{vlanid}
> +Set the 802.1Q VLAN identifier on @var{interface} to @var{vlanid}.
> +@end deffn

May I ask you to add an example here?

>  @node net_nslookup
>  @subsection net_nslookup
>
> diff --git a/grub-core/net/net.c b/grub-core/net/net.c
> index 33e35d5b5..f2acd2ecf 100644
> --- a/grub-core/net/net.c
> +++ b/grub-core/net/net.c
> @@ -1176,6 +1176,35 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)),
>      }
>  }
>
> +static grub_err_t
> +grub_cmd_setvlan (struct grub_command *cmd __attribute__ ((unused)),
> +		  int argc, char **args)
> +{
> +  if (argc < 2)
> +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
> +
> +  const char *vlanptr = args[1];

Please declare all variables at the beginning of the function.

> +  unsigned long vlantag;
> +  vlantag = grub_strtoul (vlanptr, &vlanptr, 10);
> +
> +  if (vlantag > 4094)
> +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid vlan id"));

This check is bogus. Please take a look at commit ac8a37dda (net/http:
Allow use of non-standard TCP/IP ports) how it should be done properly.

> +  struct grub_net_network_level_interface *inter;

Please move this to the beginning of the function.

> +  FOR_NET_NETWORK_LEVEL_INTERFACES (inter)
> +    {
> +      if (grub_strcmp (inter->name, args[0]) != 0)
> +	continue;
> +
> +      inter->vlantag = vlantag;
> +      return GRUB_ERR_NONE;
> +    }
> +
> +  return grub_error (GRUB_ERR_BAD_ARGUMENT,
> +                     N_("network interface not found"));
> +}
> +
>  static void
>  print_net_address (const grub_net_network_level_netaddress_t *target)
>  {
> @@ -1892,7 +1921,7 @@ static struct grub_preboot *fini_hnd;
>
>  static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute;
>  static grub_command_t cmd_lsroutes, cmd_lscards;
> -static grub_command_t cmd_lsaddr, cmd_slaac;
> +static grub_command_t cmd_lsaddr, cmd_slaac, cmd_setvlan;
>
>  GRUB_MOD_INIT(net)
>  {
> @@ -1935,6 +1964,9 @@ GRUB_MOD_INIT(net)
>  				       "", N_("list network cards"));
>    cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs,
>  				       "", N_("list network addresses"));
> +  cmd_setvlan = grub_register_command ("net_set_vlan", grub_cmd_setvlan,
> +				       N_("SHORTNAME VLANID"),

Why do we need that if other commands have empty string here?

> +				       N_("Set an interace's vlan id."));

Please be consistent with earlier grub_register_command() calls and
start sentence with lower case and drop full stop at the end of it.

Daniel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] Add net_set_vlan command
  2022-03-17 23:03   ` Daniel Kiper
@ 2022-03-21 18:23     ` Chad Kimes
  0 siblings, 0 replies; 6+ messages in thread
From: Chad Kimes @ 2022-03-21 18:23 UTC (permalink / raw)
  To: Daniel Kiper; +Cc: grub-devel

Thanks for the review! I'll re-submit this and the other patch series shortly.

On Thu, Mar 17, 2022 at 7:03 PM Daniel Kiper <dkiper@net-space.pl> wrote:
>
> On Fri, Mar 04, 2022 at 10:46:36PM -0500, Chad Kimes via Grub-devel wrote:
> > Previously there was no way to set the 802.1Q VLAN identifier, despite
> > support for vlantag in the net module. The only location vlantag was
> > being populated was from PXE boot and only for Open Firmware hardware.
> > This commit allows users to manually configure VLAN information for any
> > interface.
> >
> > Example usage:
> >   grub> net_ls_addr
> >   efinet1 00:11:22:33:44:55 192.168.0.100
> >   grub> net_set_vlan efinet1 100
> >   grub> net_ls_addr
> >   efinet1 00:11:22:33:44:55 192.168.0.100 vlan100
> >   grub> net_set_vlan efinet1 0
> >   efinet1 00:11:22:33:44:55 192.168.0.100
>
> The same comment as for the patch #1.
>
> > Signed-off-by: Chad Kimes <chkimes@github.com>
> > ---
> >  docs/grub.texi      |  9 +++++++++
> >  grub-core/net/net.c | 34 +++++++++++++++++++++++++++++++++-
> >  2 files changed, 42 insertions(+), 1 deletion(-)
> >
> > diff --git a/docs/grub.texi b/docs/grub.texi
> > index caba8befb..5758ec285 100644
> > --- a/docs/grub.texi
> > +++ b/docs/grub.texi
> > @@ -5553,6 +5553,7 @@ This command is only available on AArch64 systems.
> >  * net_ls_cards::                List network cards
> >  * net_ls_dns::                  List DNS servers
> >  * net_ls_routes::               List routing entries
> > +* net_set_vlan::                Set vlan id on an interface
> >  * net_nslookup::                Perform a DNS lookup
> >  @end menu
> >
> > @@ -5721,6 +5722,14 @@ List routing entries.
> >  @end deffn
> >
> >
> > +@node net_set_vlan
> > +@subsection net_set_vlan
> > +
> > +@deffn Command net_set_vlan @var{interface} @var{vlanid}
> > +Set the 802.1Q VLAN identifier on @var{interface} to @var{vlanid}.
> > +@end deffn
>
> May I ask you to add an example here?
>
> >  @node net_nslookup
> >  @subsection net_nslookup
> >
> > diff --git a/grub-core/net/net.c b/grub-core/net/net.c
> > index 33e35d5b5..f2acd2ecf 100644
> > --- a/grub-core/net/net.c
> > +++ b/grub-core/net/net.c
> > @@ -1176,6 +1176,35 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)),
> >      }
> >  }
> >
> > +static grub_err_t
> > +grub_cmd_setvlan (struct grub_command *cmd __attribute__ ((unused)),
> > +               int argc, char **args)
> > +{
> > +  if (argc < 2)
> > +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
> > +
> > +  const char *vlanptr = args[1];
>
> Please declare all variables at the beginning of the function.
>
> > +  unsigned long vlantag;
> > +  vlantag = grub_strtoul (vlanptr, &vlanptr, 10);
> > +
> > +  if (vlantag > 4094)
> > +    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid vlan id"));
>
> This check is bogus. Please take a look at commit ac8a37dda (net/http:
> Allow use of non-standard TCP/IP ports) how it should be done properly.
>
> > +  struct grub_net_network_level_interface *inter;
>
> Please move this to the beginning of the function.
>
> > +  FOR_NET_NETWORK_LEVEL_INTERFACES (inter)
> > +    {
> > +      if (grub_strcmp (inter->name, args[0]) != 0)
> > +     continue;
> > +
> > +      inter->vlantag = vlantag;
> > +      return GRUB_ERR_NONE;
> > +    }
> > +
> > +  return grub_error (GRUB_ERR_BAD_ARGUMENT,
> > +                     N_("network interface not found"));
> > +}
> > +
> >  static void
> >  print_net_address (const grub_net_network_level_netaddress_t *target)
> >  {
> > @@ -1892,7 +1921,7 @@ static struct grub_preboot *fini_hnd;
> >
> >  static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute;
> >  static grub_command_t cmd_lsroutes, cmd_lscards;
> > -static grub_command_t cmd_lsaddr, cmd_slaac;
> > +static grub_command_t cmd_lsaddr, cmd_slaac, cmd_setvlan;
> >
> >  GRUB_MOD_INIT(net)
> >  {
> > @@ -1935,6 +1964,9 @@ GRUB_MOD_INIT(net)
> >                                      "", N_("list network cards"));
> >    cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs,
> >                                      "", N_("list network addresses"));
> > +  cmd_setvlan = grub_register_command ("net_set_vlan", grub_cmd_setvlan,
> > +                                    N_("SHORTNAME VLANID"),
>
> Why do we need that if other commands have empty string here?

The format is following the other net commands above this that modify data
instead of just list data. For example:

  cmd_addroute = grub_register_command ("net_add_route", grub_cmd_addroute,
                                        /* TRANSLATORS: "gw" is a keyword.  */
                                        N_("SHORTNAME NET [INTERFACE|
gw GATEWAY]"),
                                        N_("Add a network route."));
  cmd_delroute = grub_register_command ("net_del_route", grub_cmd_delroute,
                                        N_("SHORTNAME"),
                                        N_("Delete a network route."));

I'll move the new command after these lines and before the ls commands so that
it's more clear.

>
> > +                                    N_("Set an interace's vlan id."));
>
> Please be consistent with earlier grub_register_command() calls and
> start sentence with lower case and drop full stop at the end of it.

Same as above.

>
> Daniel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] Add vlan information to net_ls_addr output
  2022-03-21 21:29 [PATCH 0/2] Add command-line management of VLAN config Chad Kimes
@ 2022-03-21 21:29 ` Chad Kimes
  0 siblings, 0 replies; 6+ messages in thread
From: Chad Kimes @ 2022-03-21 21:29 UTC (permalink / raw)
  To: grub-devel; +Cc: Chad Kimes

Example output:
  grub> net_ls_addr
  efinet1 00:11:22:33:44:55 192.0.2.100 vlan100

Signed-off-by: Chad Kimes <chkimes@github.com>
---
 grub-core/net/net.c | 19 ++++++++++++++++++-
 include/grub/net.h  |  6 ++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 4d3eb5c1a..b957b30e4 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,12 @@ 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..b2d044ceb 100644
--- a/include/grub/net.h
+++ b/include/grub/net.h
@@ -512,12 +512,18 @@ 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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-21 21:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-05  3:46 [PATCH 1/2] Add vlan information to net_ls_addr output Chad Kimes
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
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

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.