All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chad Kimes <chkimes@github.com>
To: grub-devel@gnu.org
Cc: Chad Kimes <chkimes@github.com>
Subject: [PATCH 2/2] Add net_set_vlan command
Date: Fri,  4 Mar 2022 22:46:36 -0500	[thread overview]
Message-ID: <20220305034636.316835-2-chkimes@github.com> (raw)
In-Reply-To: <20220305034636.316835-1-chkimes@github.com>

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



  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 [PATCH 1/2] Add vlan information to net_ls_addr output Chad Kimes
2022-03-05  3:46 ` Chad Kimes [this message]
2022-03-17 23:03   ` [PATCH 2/2] Add net_set_vlan command 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 2/2] Add net_set_vlan command 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-2-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.