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

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