Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,165 @@ find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, | |
|
||
#define OFFSET_OF(x, y) ((grub_size_t)((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y))) | ||
|
||
void | ||
grub_net_process_dhcp_ack (struct grub_net_network_level_interface *inter, | ||
const struct grub_net_bootp_packet *bp, | ||
grub_size_t size, | ||
int is_def, char **device, char **path) | ||
{ | ||
int mask = -1; | ||
char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; | ||
const grub_uint8_t *opt; | ||
grub_uint8_t opt_len, overload = 0; | ||
const char *boot_file = 0, *server_name = 0; | ||
grub_size_t boot_file_len, server_name_len; | ||
|
||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_OVERLOAD, &opt_len); | ||
if (opt && opt_len == 1) | ||
overload = *opt; | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_TFTP_SERVER_NAME, &opt_len); | ||
if (opt && opt_len) | ||
{ | ||
server_name = (const char *) opt; | ||
server_name_len = opt_len; | ||
} | ||
else if (size > OFFSET_OF (server_name, bp) && !(overload & GRUB_DHCP_OPT_OVERLOAD_SNAME) && | ||
bp->server_name[0]) | ||
{ | ||
server_name = bp->server_name; | ||
server_name_len = sizeof (bp->server_name); | ||
} | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_BOOTFILE_NAME, &opt_len); | ||
if (opt && opt_len) | ||
{ | ||
boot_file = (const char *) opt; | ||
boot_file_len = opt_len; | ||
} | ||
else if (size > OFFSET_OF (boot_file, bp) && !(overload && GRUB_DHCP_OPT_OVERLOAD_FILE) && | ||
bp->boot_file[0]) | ||
{ | ||
boot_file = bp->boot_file; | ||
boot_file_len = sizeof (bp->boot_file); | ||
} | ||
|
||
if (bp->server_ip) | ||
{ | ||
grub_snprintf (server_ip, sizeof (server_ip), "%d.%d.%d.%d", | ||
((grub_uint8_t *) &bp->server_ip)[0], | ||
((grub_uint8_t *) &bp->server_ip)[1], | ||
((grub_uint8_t *) &bp->server_ip)[2], | ||
((grub_uint8_t *) &bp->server_ip)[3]); | ||
grub_env_set_net_property (inter->name, "next_server", server_ip, sizeof (server_ip)); | ||
grub_print_error (); | ||
} | ||
|
||
if (device && !*device && bp->server_ip) | ||
{ | ||
*device = grub_xasprintf ("tftp,%s", server_ip); | ||
grub_print_error (); | ||
} | ||
|
||
if (server_name) | ||
{ | ||
grub_env_set_net_property (inter->name, "dhcp_server_name", server_name, server_name_len); | ||
if (is_def && !grub_net_default_server) | ||
{ | ||
grub_net_default_server = grub_strdup (server_name); | ||
grub_print_error (); | ||
} | ||
if (device && !*device) | ||
{ | ||
*device = grub_xasprintf ("tftp,%s", server_name); | ||
grub_print_error (); | ||
} | ||
} | ||
|
||
if (boot_file) | ||
{ | ||
grub_env_set_net_property (inter->name, "boot_file", boot_file, boot_file_len); | ||
if (path) | ||
{ | ||
*path = grub_strndup (boot_file, boot_file_len); | ||
grub_print_error (); | ||
if (*path) | ||
{ | ||
char *slash; | ||
slash = grub_strrchr (*path, '/'); | ||
if (slash) | ||
*slash = 0; | ||
else | ||
**path = 0; | ||
} | ||
} | ||
} | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_NETMASK, &opt_len); | ||
if (opt && opt_len == 4) | ||
{ | ||
int i; | ||
for (i = 0; i < 32; i++) | ||
if (!(opt[i / 8] & (1 << (7 - (i % 8))))) | ||
break; | ||
mask = i; | ||
} | ||
grub_net_add_ipv4_local (inter, mask); | ||
|
||
/* We do not implement dead gateway detection and the first entry SHOULD | ||
be preferred one */ | ||
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_ROUTER, &opt_len); | ||
if (opt && opt_len && !(opt_len & 3)) | ||
{ | ||
grub_net_network_level_netaddress_t target; | ||
grub_net_network_level_address_t gw; | ||
char *rname; | ||
|
||
target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; | ||
target.ipv4.base = 0; | ||
target.ipv4.masksize = 0; | ||
gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; | ||
gw.ipv4 = grub_get_unaligned32 (opt); | ||
rname = grub_xasprintf ("%s:default", inter->name); | ||
if (rname) | ||
grub_net_add_route_gw (rname, target, gw, 0); | ||
grub_free (rname); | ||
} | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_DNS, &opt_len); | ||
if (opt && opt_len && !(opt_len & 3)) | ||
{ | ||
int i; | ||
for (i = 0; i < opt_len / 4; i++) | ||
{ | ||
struct grub_net_network_level_address s; | ||
|
||
s.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; | ||
s.ipv4 = grub_get_unaligned32 (opt); | ||
s.option = DNS_OPTION_PREFER_IPV4; | ||
grub_net_add_dns_server (&s); | ||
opt += 4; | ||
} | ||
} | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_HOSTNAME, &opt_len); | ||
if (opt && opt_len) | ||
grub_env_set_net_property (inter->name, "hostname", (const char *) opt, opt_len); | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_DOMAIN, &opt_len); | ||
if (opt && opt_len) | ||
grub_env_set_net_property (inter->name, "domain", (const char *) opt, opt_len); | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_ROOT_PATH, &opt_len); | ||
if (opt && opt_len) | ||
grub_env_set_net_property (inter->name, "rootpath", (const char *) opt, opt_len); | ||
|
||
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_EXTENSIONS_PATH, &opt_len); | ||
if (opt && opt_len) | ||
grub_env_set_net_property (inter->name, "extensionspath", (const char *) opt, opt_len); | ||
} | ||
|
||
struct grub_net_network_level_interface * | ||
grub_net_configure_by_dhcp_ack (const char *name, | ||
struct grub_net_card *card, | ||
|
@@ -224,12 +383,7 @@ grub_net_configure_by_dhcp_ack (const char *name, | |
grub_net_network_level_address_t addr; | ||
grub_net_link_level_address_t hwaddr; | ||
struct grub_net_network_level_interface *inter; | ||
int mask = -1; | ||
char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; | ||
const grub_uint8_t *opt; | ||
grub_uint8_t opt_len, overload = 0; | ||
const char *boot_file = 0, *server_name = 0; | ||
grub_size_t boot_file_len, server_name_len; | ||
|
||
addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; | ||
addr.ipv4 = bp->your_ip; | ||
|
@@ -248,6 +402,7 @@ grub_net_configure_by_dhcp_ack (const char *name, | |
if (!inter) | ||
return 0; | ||
|
||
#if 0 | ||
opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_OVERLOAD, &opt_len); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if (opt && opt_len == 1) | ||
overload = *opt; | ||
|
@@ -288,7 +443,8 @@ grub_net_configure_by_dhcp_ack (const char *name, | |
grub_env_set_net_property (name, "next_server", server_ip, sizeof (server_ip)); | ||
grub_print_error (); | ||
} | ||
|
||
#endif | ||
|
||
if (is_def) | ||
grub_net_default_server = 0; | ||
if (is_def && !grub_net_default_server && bp->server_ip) | ||
|
@@ -303,7 +459,8 @@ grub_net_configure_by_dhcp_ack (const char *name, | |
grub_env_export ("net_default_interface"); | ||
} | ||
|
||
if (device && !*device && bp->server_ip) | ||
#if 0 | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if (device && !*device && bp->server_ip) | ||
{ | ||
*device = grub_xasprintf ("tftp,%s", server_ip); | ||
grub_print_error (); | ||
|
@@ -405,6 +562,10 @@ grub_net_configure_by_dhcp_ack (const char *name, | |
opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_EXTENSIONS_PATH, &opt_len); | ||
if (opt && opt_len) | ||
grub_env_set_net_property (name, "extensionspath", (const char *) opt, opt_len); | ||
#endif | ||
|
||
grub_net_process_dhcp_ack (inter, bp, size, is_def, device, path); | ||
This comment has been minimized.
Sorry, something went wrong.
martinezjavier
|
||
|
||
|
||
inter->dhcp_ack = grub_malloc (size); | ||
if (inter->dhcp_ack) | ||
|
why are you disabling this code ?