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

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