]> TLD Linux GIT Repositories - packages/grub2.git/blob - add-vlan-tag-support.patch
- added options to enable unrestricted boot
[packages/grub2.git] / add-vlan-tag-support.patch
1 diff -urNp grub-2.02-rc1.orig/grub-core/kern/ieee1275/init.c grub-2.02-rc1/grub-core/kern/ieee1275/init.c
2 --- grub-2.02-rc1.orig/grub-core/kern/ieee1275/init.c   2017-02-08 15:06:05.420317447 +0000
3 +++ grub-2.02-rc1/grub-core/kern/ieee1275/init.c        2017-02-08 15:06:17.784317308 +0000
4 @@ -125,6 +125,7 @@ grub_machine_get_bootlocation (char **de
5        char *dev, *canon;
6        char *ptr;
7        dev = grub_ieee1275_get_aliasdevname (bootpath);
8 +      grub_ieee1275_parse_net_options (bootpath);
9        canon = grub_ieee1275_canonicalise_devname (dev);
10        ptr = canon + grub_strlen (canon) - 1;
11        while (ptr > canon && (*ptr == ',' || *ptr == ':'))
12 diff -urNp grub-2.02-rc1.orig/grub-core/kern/ieee1275/openfw.c grub-2.02-rc1/grub-core/kern/ieee1275/openfw.c
13 --- grub-2.02-rc1.orig/grub-core/kern/ieee1275/openfw.c 2017-02-08 15:06:05.420317447 +0000
14 +++ grub-2.02-rc1/grub-core/kern/ieee1275/openfw.c      2017-02-08 15:06:17.785317308 +0000
15 @@ -23,6 +23,7 @@
16  #include <grub/mm.h>
17  #include <grub/ieee1275/ieee1275.h>
18  #include <grub/net.h>
19 +#include <grub/env.h>
20  
21  enum grub_ieee1275_parse_type
22  {
23 @@ -451,6 +452,35 @@ fail:
24    return ret;
25  }
26  
27 +int
28 +grub_ieee1275_parse_net_options (const char *path)
29 +{
30 +  char *comma;
31 +  char *args;
32 +  char *option = 0;
33 +
34 +  args = grub_ieee1275_get_devargs (path);
35 +  if (!args)
36 +    /* There is no option.  */
37 +    return -1;
38 +
39 +  do
40 +    {
41 +      comma = grub_strchr (args, ',');
42 +      if (! comma)
43 +        option = grub_strdup (args);
44 +      else
45 +        option = grub_strndup (args, (grub_size_t)(comma - args));
46 +      args = comma + 1;
47 +
48 +      if (! grub_strncmp(option, "vtag", 4))
49 +          grub_env_set ("vlan-tag", option + grub_strlen("vtag="));
50 +
51 +    } while (comma);
52 +
53 +  return 0;
54 +}
55 +
56  char *
57  grub_ieee1275_get_device_type (const char *path)
58  {
59 diff -urNp grub-2.02-rc1.orig/grub-core/net/ethernet.c grub-2.02-rc1/grub-core/net/ethernet.c
60 --- grub-2.02-rc1.orig/grub-core/net/ethernet.c 2017-02-08 15:06:05.433317447 +0000
61 +++ grub-2.02-rc1/grub-core/net/ethernet.c      2017-02-08 15:06:17.785317308 +0000
62 @@ -23,6 +23,7 @@
63  #include <grub/net/arp.h>
64  #include <grub/net/netbuff.h>
65  #include <grub/net.h>
66 +#include <grub/env.h>
67  #include <grub/time.h>
68  #include <grub/net/arp.h>
69  
70 @@ -56,10 +57,19 @@ send_ethernet_packet (struct grub_net_ne
71  {
72    struct etherhdr *eth;
73    grub_err_t err;
74 +  grub_uint32_t vlantag = 0;
75 +  grub_uint8_t etherhdr_size;
76  
77 -  COMPILE_TIME_ASSERT (sizeof (*eth) < GRUB_NET_MAX_LINK_HEADER_SIZE);
78 +  etherhdr_size = sizeof (*eth);
79 +  COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE);
80  
81 -  err = grub_netbuff_push (nb, sizeof (*eth));
82 +  const char *vlantag_text = grub_env_get ("vlan-tag");
83 +  if (vlantag_text != 0) {
84 +      etherhdr_size += 4;
85 +      vlantag = grub_strtoul (vlantag_text, 0, 16);
86 +  }
87 +
88 +  err = grub_netbuff_push (nb, etherhdr_size);
89    if (err)
90      return err;
91    eth = (struct etherhdr *) nb->data;
92 @@ -76,6 +86,19 @@ send_ethernet_packet (struct grub_net_ne
93         return err;
94        inf->card->opened = 1;
95      }
96 +
97 +  /* Check if a vlan-tag is needed. */
98 +  if (vlantag != 0)
99 +    {
100 +      /* Move eth type to the right */
101 +      grub_memcpy((char *) nb->data + etherhdr_size - 2,
102 +                  (char *) nb->data + etherhdr_size - 6, 2);
103 +
104 +      /* Add the tag in the middle */
105 +      grub_memcpy((char *) nb->data + etherhdr_size - 6,
106 +                  &vlantag, 4);
107 +    }
108 +
109    return inf->card->driver->send (inf->card, nb);
110  }
111  
112 @@ -90,10 +113,23 @@ grub_net_recv_ethernet_packet (struct gr
113    grub_net_link_level_address_t hwaddress;
114    grub_net_link_level_address_t src_hwaddress;
115    grub_err_t err;
116 +  grub_uint8_t etherhdr_size = sizeof (*eth);
117 +
118 +  grub_uint16_t vlantag_identifier = 0;
119 +  grub_memcpy (&vlantag_identifier, nb->data + etherhdr_size - 2, 2);
120 +
121 +  /* Check if a vlan-tag is present. */
122 +  if (vlantag_identifier == VLANTAG_IDENTIFIER)
123 +    {
124 +      etherhdr_size += 4;
125 +      /* Move eth type to the original position */
126 +      grub_memcpy((char *) nb->data + etherhdr_size - 6,
127 +                  (char *) nb->data + etherhdr_size - 2, 2);
128 +    }
129  
130    eth = (struct etherhdr *) nb->data;
131    type = grub_be_to_cpu16 (eth->type);
132 -  err = grub_netbuff_pull (nb, sizeof (*eth));
133 +  err = grub_netbuff_pull (nb, etherhdr_size);
134    if (err)
135      return err;
136  
137 diff -urNp grub-2.02-rc1.orig/include/grub/ieee1275/ieee1275.h grub-2.02-rc1/include/grub/ieee1275/ieee1275.h
138 --- grub-2.02-rc1.orig/include/grub/ieee1275/ieee1275.h 2017-02-08 15:06:05.445317447 +0000
139 +++ grub-2.02-rc1/include/grub/ieee1275/ieee1275.h      2017-02-08 15:06:17.787317308 +0000
140 @@ -227,6 +227,7 @@ char *EXPORT_FUNC(grub_ieee1275_get_alia
141  char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);
142  char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path);
143  char *EXPORT_FUNC(grub_ieee1275_get_devname) (const char *path);
144 +int EXPORT_FUNC(grub_ieee1275_parse_net_options) (const char *path);
145  
146  void EXPORT_FUNC(grub_ieee1275_devalias_init_iterator) (struct grub_ieee1275_devalias *alias);
147  void EXPORT_FUNC(grub_ieee1275_devalias_free) (struct grub_ieee1275_devalias *alias);
148 diff -urNp grub-2.02-rc1.orig/include/grub/net.h grub-2.02-rc1/include/grub/net.h
149 --- grub-2.02-rc1.orig/include/grub/net.h       2017-02-08 15:06:05.446317447 +0000
150 +++ grub-2.02-rc1/include/grub/net.h    2017-02-08 15:06:17.788317308 +0000
151 @@ -561,4 +561,6 @@ extern char *grub_net_default_server;
152  #define GRUB_NET_INTERVAL 400
153  #define GRUB_NET_INTERVAL_ADDITION 20
154  
155 +#define VLANTAG_IDENTIFIER 0x8100
156 +
157  #endif /* ! GRUB_NET_HEADER */