]> TLD Linux GIT Repositories - packages/grub2.git/blob - dhcp-client-id-and-uuid-options-added.patch
- grub2 from PLD
[packages/grub2.git] / dhcp-client-id-and-uuid-options-added.patch
1 From d63a0b7fd665fae1dd34d3e86127b93dd87b8114 Mon Sep 17 00:00:00 2001
2 From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
3 Date: Tue, 27 Nov 2012 17:18:53 -0200
4 Subject: [PATCH 2/3] DHCP client ID and UUID options added.
5
6 ---
7  grub-core/net/bootp.c |   56 +++++++++++++++++++++++++++++++++++++++++--------
8  include/grub/net.h    |    2 ++
9  2 files changed, 49 insertions(+), 9 deletions(-)
10
11 diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
12 index bc07d53..3b4130d 100644
13 --- a/grub-core/net/bootp.c
14 +++ b/grub-core/net/bootp.c
15 @@ -51,6 +51,14 @@ set_env_limn_ro (const char *intername, const char *suffix,
16    grub_register_variable_hook (varname, 0, grub_env_write_readonly);
17  }
18  
19 +static char
20 +hexdigit (grub_uint8_t val)
21 +{
22 +  if (val < 10)
23 +    return val + '0';
24 +  return val + 'a' - 10;
25 +}
26 +
27  static void
28  parse_dhcp_vendor (const char *name, void *vend, int limit, int *mask)
29  {
30 @@ -81,6 +89,9 @@ parse_dhcp_vendor (const char *name, void *vend, int limit, int *mask)
31  
32        taglength = *ptr++;
33  
34 +      grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n",
35 +                   tagtype, tagtype, taglength);
36 +
37        switch (tagtype)
38         {
39         case GRUB_NET_BOOTP_NETMASK:
40 @@ -121,7 +132,9 @@ parse_dhcp_vendor (const char *name, void *vend, int limit, int *mask)
41                 grub_net_add_dns_server (&s);
42                 ptr += 4;
43               }
44 -         }
45 +            /* Skip adittional increment */
46 +            continue;
47 +          }
48           break;
49         case GRUB_NET_BOOTP_HOSTNAME:
50           set_env_limn_ro (name, "hostname", (char *) ptr, taglength);
51 @@ -139,6 +152,39 @@ parse_dhcp_vendor (const char *name, void *vend, int limit, int *mask)
52           set_env_limn_ro (name, "extensionspath", (char *) ptr, taglength);
53           break;
54  
55 +        case GRUB_NET_BOOTP_CLIENT_ID:
56 +         set_env_limn_ro (name, "clientid", (char *) ptr, taglength);
57 +          break;
58 +
59 +        case GRUB_NET_BOOTP_CLIENT_UUID:
60 +            {
61 +              if (taglength != 17)
62 +                break;
63 +
64 +              /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */
65 +
66 +              ptr += 1;
67 +              taglength -= 1;
68 +
69 +              char *val = grub_malloc (2 * taglength + 4 + 1);
70 +              int i = 0;
71 +              int j = 0;
72 +              for (i = 0; i < taglength; i++)
73 +                {
74 +                  val[2 * i + j] = hexdigit (ptr[i] >> 4);
75 +                  val[2 * i + 1 + j] = hexdigit (ptr[i] & 0xf);
76 +
77 +                  if ((i == 3) || (i == 5) || (i == 7) || (i == 9))
78 +                    {
79 +                      j++;
80 +                      val[2 * i + 1+ j] = '-';
81 +                    }
82 +                }
83 +
84 +              set_env_limn_ro (name, "clientuuid", (char *) val, 2 * taglength + 4);
85 +            }
86 +          break;
87 +
88           /* If you need any other options please contact GRUB
89              developpement team.  */
90         }
91 @@ -299,14 +345,6 @@ grub_net_process_dhcp (struct grub_net_buff *nb,
92      }
93  }
94  
95 -static char
96 -hexdigit (grub_uint8_t val)
97 -{
98 -  if (val < 10)
99 -    return val + '0';
100 -  return val + 'a' - 10;
101 -}
102 -
103  static grub_err_t
104  grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
105                   int argc, char **args)
106 diff --git a/include/grub/net.h b/include/grub/net.h
107 index a7e5b2c..45348dd 100644
108 --- a/include/grub/net.h
109 +++ b/include/grub/net.h
110 @@ -423,6 +423,8 @@ enum
111      GRUB_NET_BOOTP_DOMAIN = 0x0f,
112      GRUB_NET_BOOTP_ROOT_PATH = 0x11,
113      GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12,
114 +    GRUB_NET_BOOTP_CLIENT_ID = 0x3d,
115 +    GRUB_NET_BOOTP_CLIENT_UUID = 0x61,
116      GRUB_NET_BOOTP_END = 0xff
117    };
118  
119 -- 
120 1.7.10.4
121