Blame SOURCES/0454-Add-vlan-tag-support.patch

f96e0b
From de04741fe79fc4d2c65a9ea5f4d9ef40bd36ae21 Mon Sep 17 00:00:00 2001
f96e0b
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f96e0b
Date: Tue, 30 Oct 2012 15:19:39 -0200
f96e0b
Subject: [PATCH 454/482] Add vlan-tag support
f96e0b
f96e0b
This patch adds support for virtual LAN (VLAN) tagging. VLAN tagging allows
f96e0b
multiple VLANs in a bridged network to share the same physical network link but
f96e0b
maintain isolation:
f96e0b
f96e0b
http://en.wikipedia.org/wiki/IEEE_802.1Q
f96e0b
f96e0b
This patch should fix this bugzilla:
f96e0b
https://bugzilla.redhat.com/show_bug.cgi?id=871563
f96e0b
---
f96e0b
 grub-core/kern/ieee1275/init.c   |  1 +
f96e0b
 grub-core/kern/ieee1275/openfw.c | 30 ++++++++++++++++++++++++++++
f96e0b
 grub-core/net/ethernet.c         | 42 +++++++++++++++++++++++++++++++++++++---
f96e0b
 include/grub/ieee1275/ieee1275.h |  1 +
f96e0b
 include/grub/net.h               |  2 ++
f96e0b
 5 files changed, 73 insertions(+), 3 deletions(-)
f96e0b
f96e0b
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
f96e0b
index ce8eadb..3af15d8 100644
f96e0b
--- a/grub-core/kern/ieee1275/init.c
f96e0b
+++ b/grub-core/kern/ieee1275/init.c
f96e0b
@@ -117,6 +117,7 @@ grub_machine_get_bootlocation (char **device, char **path)
f96e0b
       char *dev, *canon;
f96e0b
       char *ptr;
f96e0b
       dev = grub_ieee1275_get_aliasdevname (bootpath);
f96e0b
+      grub_ieee1275_parse_net_options (bootpath);
f96e0b
       canon = grub_ieee1275_canonicalise_devname (dev);
f96e0b
       ptr = canon + grub_strlen (canon) - 1;
f96e0b
       while (ptr > canon && (*ptr == ',' || *ptr == ':'))
f96e0b
diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
f96e0b
index 09e9e57..2a01146 100644
f96e0b
--- a/grub-core/kern/ieee1275/openfw.c
f96e0b
+++ b/grub-core/kern/ieee1275/openfw.c
f96e0b
@@ -23,6 +23,7 @@
f96e0b
 #include <grub/mm.h>
f96e0b
 #include <grub/ieee1275/ieee1275.h>
f96e0b
 #include <grub/net.h>
f96e0b
+#include <grub/env.h>
f96e0b
 
f96e0b
 enum grub_ieee1275_parse_type
f96e0b
 {
f96e0b
@@ -451,6 +452,35 @@ fail:
f96e0b
   return ret;
f96e0b
 }
f96e0b
 
f96e0b
+int
f96e0b
+grub_ieee1275_parse_net_options (const char *path)
f96e0b
+{
f96e0b
+  char *comma;
f96e0b
+  char *args;
f96e0b
+  char *option = 0;
f96e0b
+
f96e0b
+  args = grub_ieee1275_get_devargs (path);
f96e0b
+  if (!args)
f96e0b
+    /* There is no option.  */
f96e0b
+    return -1;
f96e0b
+
f96e0b
+  do
f96e0b
+    {
f96e0b
+      comma = grub_strchr (args, ',');
f96e0b
+      if (! comma)
f96e0b
+        option = grub_strdup (args);
f96e0b
+      else
f96e0b
+        option = grub_strndup (args, (grub_size_t)(comma - args));
f96e0b
+      args = comma + 1;
f96e0b
+
f96e0b
+      if (! grub_strncmp(option, "vtag", 4))
f96e0b
+          grub_env_set ("vlan-tag", option + grub_strlen("vtag="));
f96e0b
+
f96e0b
+    } while (comma);
f96e0b
+
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
 char *
f96e0b
 grub_ieee1275_get_device_type (const char *path)
f96e0b
 {
f96e0b
diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c
f96e0b
index b38e2c8..5e45d46 100644
f96e0b
--- a/grub-core/net/ethernet.c
f96e0b
+++ b/grub-core/net/ethernet.c
f96e0b
@@ -23,6 +23,7 @@
f96e0b
 #include <grub/net/arp.h>
f96e0b
 #include <grub/net/netbuff.h>
f96e0b
 #include <grub/net.h>
f96e0b
+#include <grub/env.h>
f96e0b
 #include <grub/time.h>
f96e0b
 #include <grub/net/arp.h>
f96e0b
 
f96e0b
@@ -56,10 +57,19 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
f96e0b
 {
f96e0b
   struct etherhdr *eth;
f96e0b
   grub_err_t err;
f96e0b
+  grub_uint32_t vlantag = 0;
f96e0b
+  grub_uint8_t etherhdr_size;
f96e0b
 
f96e0b
-  COMPILE_TIME_ASSERT (sizeof (*eth) < GRUB_NET_MAX_LINK_HEADER_SIZE);
f96e0b
+  etherhdr_size = sizeof (*eth);
f96e0b
+  COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
f96e0b
 
f96e0b
-  err = grub_netbuff_push (nb, sizeof (*eth));
f96e0b
+  const char *vlantag_text = grub_env_get ("vlan-tag");
f96e0b
+  if (vlantag_text != 0) {
f96e0b
+      etherhdr_size += 4;
f96e0b
+      vlantag = grub_strtoul (vlantag_text, 0, 16);
f96e0b
+  }
f96e0b
+
f96e0b
+  err = grub_netbuff_push (nb, etherhdr_size);
f96e0b
   if (err)
f96e0b
     return err;
f96e0b
   eth = (struct etherhdr *) nb->data;
f96e0b
@@ -76,6 +86,19 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
f96e0b
 	return err;
f96e0b
       inf->card->opened = 1;
f96e0b
     }
f96e0b
+
f96e0b
+  /* Check if a vlan-tag is needed. */
f96e0b
+  if (vlantag != 0)
f96e0b
+    {
f96e0b
+      /* Move eth type to the right */
f96e0b
+      grub_memcpy((char *) nb->data + etherhdr_size - 2,
f96e0b
+                  (char *) nb->data + etherhdr_size - 6, 2);
f96e0b
+
f96e0b
+      /* Add the tag in the middle */
f96e0b
+      grub_memcpy((char *) nb->data + etherhdr_size - 6,
f96e0b
+                  &vlantag, 4);
f96e0b
+    }
f96e0b
+
f96e0b
   return inf->card->driver->send (inf->card, nb);
f96e0b
 }
f96e0b
 
f96e0b
@@ -90,10 +113,23 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
f96e0b
   grub_net_link_level_address_t hwaddress;
f96e0b
   grub_net_link_level_address_t src_hwaddress;
f96e0b
   grub_err_t err;
f96e0b
+  grub_uint8_t etherhdr_size = sizeof (*eth);
f96e0b
+
f96e0b
+  grub_uint16_t vlantag_identifier = 0;
f96e0b
+  grub_memcpy (&vlantag_identifier, nb->data + etherhdr_size - 2, 2);
f96e0b
+
f96e0b
+  /* Check if a vlan-tag is present. */
f96e0b
+  if (vlantag_identifier == VLANTAG_IDENTIFIER)
f96e0b
+    {
f96e0b
+      etherhdr_size += 4;
f96e0b
+      /* Move eth type to the original position */
f96e0b
+      grub_memcpy((char *) nb->data + etherhdr_size - 6,
f96e0b
+                  (char *) nb->data + etherhdr_size - 2, 2);
f96e0b
+    }
f96e0b
 
f96e0b
   eth = (struct etherhdr *) nb->data;
f96e0b
   type = grub_be_to_cpu16 (eth->type);
f96e0b
-  err = grub_netbuff_pull (nb, sizeof (*eth));
f96e0b
+  err = grub_netbuff_pull (nb, etherhdr_size);
f96e0b
   if (err)
f96e0b
     return err;
f96e0b
 
f96e0b
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
f96e0b
index eabbe9b..61d5769 100644
f96e0b
--- a/include/grub/ieee1275/ieee1275.h
f96e0b
+++ b/include/grub/ieee1275/ieee1275.h
f96e0b
@@ -229,6 +229,7 @@ void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
f96e0b
 						struct grub_ieee1275_devalias *alias);
f96e0b
 int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script);
f96e0b
 int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text);
f96e0b
+int EXPORT_FUNC(grub_ieee1275_parse_net_options) (const char *path);
f96e0b
 
f96e0b
 #define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
f96e0b
 
f96e0b
diff --git a/include/grub/net.h b/include/grub/net.h
f96e0b
index e677246..fe29b16 100644
f96e0b
--- a/include/grub/net.h
f96e0b
+++ b/include/grub/net.h
f96e0b
@@ -533,4 +533,6 @@ extern char *grub_net_default_server;
f96e0b
 #define GRUB_NET_TRIES 40
f96e0b
 #define GRUB_NET_INTERVAL 400
f96e0b
 
f96e0b
+#define VLANTAG_IDENTIFIER 0x8100
f96e0b
+
f96e0b
 #endif /* ! GRUB_NET_HEADER */
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b