All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add Virtual LAN (VLAN) support
@ 2012-10-30 15:56 Paulo Flabiano Smorigo/Brazil/IBM
  2012-12-10 15:26 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 2+ messages in thread
From: Paulo Flabiano Smorigo/Brazil/IBM @ 2012-10-30 15:56 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 334 bytes --]

Hi all,

This patch adds support for virtual LAN (VLAN) tagging. VLAN tagging  
allows multiple VLANs in a bridged network to share the same physical  
network link but maintain isolation:

http://en.wikipedia.org/wiki/IEEE_802.1Q

-- 
Paulo Flabiano Smorigo
Software Engineer
Linux Technology Center - IBM Systems & Technology Group

[-- Attachment #2: vlantag_support.patch --]
[-- Type: text/x-patch, Size: 5991 bytes --]

=== modified file 'ChangeLog'
--- ChangeLog	2012-10-28 10:55:22 +0000
+++ ChangeLog	2012-10-30 15:10:13 +0000
@@ -1,3 +1,17 @@
+2012-10-30  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
+
+	Virtual LAN (VLAN) support added.
+
+	* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_parse_net_options):
+	New function.
+	* grub-core/kern/ieee1275/init.c (grub_machine_get_bootlocation):
+	Increase buffer.  Add function.
+	* grub-core/net/ethernet.c (send_ethernet_packet): Add vlan-tag
+	validation.
+	(grub_net_recv_ethernet_packet): Likewise.
+	* include/grub/ieee1275/ieee1275.h: New proto.
+	* include/grub/net.h: New define.
+
 2012-10-28  Grégoire Sutre  <gregoire.sutre@gmail.com>

 	* util/grub.d/10_netbsd.in: Fix tab indentation and make sure

=== modified file 'grub-core/kern/ieee1275/init.c'
--- grub-core/kern/ieee1275/init.c	2012-06-11 18:44:38 +0000
+++ grub-core/kern/ieee1275/init.c	2012-10-29 19:08:55 +0000
@@ -82,7 +82,7 @@
 void
 grub_machine_get_bootlocation (char **device, char **path)
 {
-  char bootpath[64]; /* XXX check length */
+  char bootpath[256]; /* XXX check length */
   char *filename;
   char *type;

@@ -102,6 +102,7 @@
       char *dev, *canon;
       char *ptr;
       dev = grub_ieee1275_get_aliasdevname (bootpath);
+      grub_ieee1275_parse_net_options (bootpath);
       canon = grub_ieee1275_canonicalise_devname (dev);
       ptr = canon + grub_strlen (canon) - 1;
       while (ptr > canon && (*ptr == ',' || *ptr == ':'))

=== modified file 'grub-core/kern/ieee1275/openfw.c'
--- grub-core/kern/ieee1275/openfw.c	2012-06-20 21:31:59 +0000
+++ grub-core/kern/ieee1275/openfw.c	2012-10-29 17:26:41 +0000
@@ -23,6 +23,7 @@
 #include <grub/mm.h>
 #include <grub/ieee1275/ieee1275.h>
 #include <grub/net.h>
+#include <grub/env.h>

 enum grub_ieee1275_parse_type
 {
@@ -413,6 +414,35 @@
   return ret;
 }

+int
+grub_ieee1275_parse_net_options (const char *path)
+{
+  char *comma;
+  char *args;
+  char *option = 0;
+
+  args = grub_ieee1275_get_devargs (path);
+  if (!args)
+    /* There is no option.  */
+    return -1;
+
+  do
+    {
+      comma = grub_strchr (args, ',');
+      if (! comma)
+        option = grub_strdup (args);
+      else
+        option = grub_strndup (args, (grub_size_t)(comma - args));
+      args = comma + 1;
+
+      if (! grub_strncmp(option, "vtag", 4))
+          grub_env_set ("vlan-tag", option + grub_strlen("vtag="));
+
+    } while (comma);
+
+  return 0;
+}
+
 char *
 grub_ieee1275_get_device_type (const char *path)
 {

=== modified file 'grub-core/net/ethernet.c'
--- grub-core/net/ethernet.c	2011-10-13 18:53:22 +0000
+++ grub-core/net/ethernet.c	2012-10-30 13:15:08 +0000
@@ -23,6 +23,7 @@
 #include <grub/net/arp.h>
 #include <grub/net/netbuff.h>
 #include <grub/net.h>
+#include <grub/env.h>
 #include <grub/time.h>
 #include <grub/net/arp.h>

@@ -56,10 +57,19 @@
 {
   struct etherhdr *eth;
   grub_err_t err;
-
-  COMPILE_TIME_ASSERT (sizeof (*eth) < GRUB_NET_MAX_LINK_HEADER_SIZE);
-
-  err = grub_netbuff_push (nb, sizeof (*eth));
+  grub_uint32_t vlantag = 0;
+  grub_uint8_t etherhdr_size;
+
+  etherhdr_size = sizeof (*eth);
+  COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
+
+  const char *vlantag_text = grub_env_get ("vlan-tag");
+  if (vlantag_text != 0) {
+      etherhdr_size += 4;
+      vlantag = grub_strtoul (vlantag_text, 0, 16);
+  }
+
+  err = grub_netbuff_push (nb, etherhdr_size);
   if (err)
     return err;
   eth = (struct etherhdr *) nb->data;
@@ -76,6 +86,19 @@
 	return err;
       inf->card->opened = 1;
     }
+
+  /* Check if a vlan-tag is needed. */
+  if (vlantag != 0)
+    {
+      /* Move eth type to the right */
+      grub_memcpy((char *) nb->data + etherhdr_size - 2,
+                  (char *) nb->data + etherhdr_size - 6, 2);
+
+      /* Add the tag in the middle */
+      grub_memcpy((char *) nb->data + etherhdr_size - 6,
+                  &vlantag, 4);
+    }
+
   return inf->card->driver->send (inf->card, nb);
 }

@@ -90,10 +113,23 @@
   grub_net_link_level_address_t hwaddress;
   grub_net_link_level_address_t src_hwaddress;
   grub_err_t err;
+  grub_uint8_t etherhdr_size = sizeof (*eth);
+
+  grub_uint16_t vlantag_identifier = 0;
+  grub_memcpy (&vlantag_identifier, nb->data + etherhdr_size - 2, 2);
+
+  /* Check if a vlan-tag is present. */
+  if (vlantag_identifier == VLANTAG_IDENTIFIER)
+    {
+      etherhdr_size += 4;
+      /* Move eth type to the original position */
+      grub_memcpy((char *) nb->data + etherhdr_size - 6,
+                  (char *) nb->data + etherhdr_size - 2, 2);
+    }

   eth = (struct etherhdr *) nb->data;
   type = grub_be_to_cpu16 (eth->type);
-  err = grub_netbuff_pull (nb, sizeof (*eth));
+  err = grub_netbuff_pull (nb, etherhdr_size);
   if (err)
     return err;


=== modified file 'include/grub/ieee1275/ieee1275.h'
--- include/grub/ieee1275/ieee1275.h	2012-09-18 09:52:19 +0000
+++ include/grub/ieee1275/ieee1275.h	2012-10-29 17:25:13 +0000
@@ -210,5 +210,6 @@
 char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);
 char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);
 char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path);
+int EXPORT_FUNC(grub_ieee1275_parse_net_options) (const char *path);

 #endif /* ! GRUB_IEEE1275_HEADER */

=== modified file 'include/grub/net.h'
--- include/grub/net.h	2012-06-22 12:17:46 +0000
+++ include/grub/net.h	2012-10-29 19:10:48 +0000
@@ -523,4 +523,6 @@
 #define GRUB_NET_TRIES 40
 #define GRUB_NET_INTERVAL 400

+#define VLANTAG_IDENTIFIER 0x8100
+
 #endif /* ! GRUB_NET_HEADER */


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

* Re: [PATCH] Add Virtual LAN (VLAN) support
  2012-10-30 15:56 [PATCH] Add Virtual LAN (VLAN) support Paulo Flabiano Smorigo/Brazil/IBM
@ 2012-12-10 15:26 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-12-10 15:26 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 708 bytes --]

On 30.10.2012 16:56, Paulo Flabiano Smorigo/Brazil/IBM wrote:

> Hi all,
> 
> This patch adds support for virtual LAN (VLAN) tagging. VLAN tagging
> allows multiple VLANs in a bridged network to share the same physical
> network link but maintain isolation:
> 
> http://en.wikipedia.org/wiki/IEEE_802.1Q
> 

vlan_tag should be an interface property, not a global variable. Also
you need to increase the maximal ethernet size, otherwise you may get
out of packet error.

> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel



-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

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

end of thread, other threads:[~2012-12-10 15:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-30 15:56 [PATCH] Add Virtual LAN (VLAN) support Paulo Flabiano Smorigo/Brazil/IBM
2012-12-10 15:26 ` Vladimir 'φ-coder/phcoder' Serbinenko

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.