add grub_env_set_net_property function

* grub-core/net/bootp.c: Remove set_env_limn_ro.
* grub-core/net/net.c: Add grub_env_set_net_property.
* include/grub/net.h: Likewise.
This commit is contained in:
Paulo Flabiano Smorigo 2014-02-04 18:41:38 -02:00
parent 006c78f378
commit e4dbf247b6
4 changed files with 66 additions and 47 deletions

View file

@ -1,3 +1,11 @@
2014-02-04 Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Add grub_env_set_net_property function.
* grub-core/net/bootp.c: Remove set_env_limn_ro.
* grub-core/net/net.c: Add grub_env_set_net_property.
* include/grub/net.h: Likewise.
2014-02-03 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-mkrescue.c: Build fix for argp.h with older gcc.

View file

@ -25,41 +25,6 @@
#include <grub/net/udp.h>
#include <grub/datetime.h>
static char *
grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)),
const char *val __attribute__ ((unused)))
{
return NULL;
}
static void
set_env_limn_ro (const char *intername, const char *suffix,
const char *value, grub_size_t len)
{
char *varname, *varvalue;
char *ptr;
varname = grub_xasprintf ("net_%s_%s", intername, suffix);
if (!varname)
return;
for (ptr = varname; *ptr; ptr++)
if (*ptr == ':')
*ptr = '_';
varvalue = grub_malloc (len + 1);
if (!varvalue)
{
grub_free (varname);
return;
}
grub_memcpy (varvalue, value, len);
varvalue[len] = 0;
grub_env_set (varname, varvalue);
grub_register_variable_hook (varname, 0, grub_env_write_readonly);
grub_env_export (varname);
grub_free (varname);
grub_free (varvalue);
}
static void
parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
{
@ -136,20 +101,24 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
}
continue;
case GRUB_NET_BOOTP_HOSTNAME:
set_env_limn_ro (name, "hostname", (const char *) ptr, taglength);
break;
grub_env_set_net_property (name, "hostname", (const char *) ptr,
taglength);
break;
case GRUB_NET_BOOTP_DOMAIN:
set_env_limn_ro (name, "domain", (const char *) ptr, taglength);
break;
grub_env_set_net_property (name, "domain", (const char *) ptr,
taglength);
break;
case GRUB_NET_BOOTP_ROOT_PATH:
set_env_limn_ro (name, "rootpath", (const char *) ptr, taglength);
break;
grub_env_set_net_property (name, "rootpath", (const char *) ptr,
taglength);
break;
case GRUB_NET_BOOTP_EXTENSIONS_PATH:
set_env_limn_ro (name, "extensionspath", (const char *) ptr, taglength);
break;
grub_env_set_net_property (name, "extensionspath", (const char *) ptr,
taglength);
break;
/* If you need any other options please contact GRUB
development team. */
@ -211,8 +180,8 @@ grub_net_configure_by_dhcp_ack (const char *name,
}
if (size > OFFSET_OF (boot_file, bp))
set_env_limn_ro (name, "boot_file", (char *) bp->boot_file,
sizeof (bp->boot_file));
grub_env_set_net_property (name, "boot_file", bp->boot_file,
sizeof (bp->boot_file));
if (is_def)
grub_net_default_server = 0;
if (is_def && !grub_net_default_server && bp->server_ip)
@ -243,8 +212,8 @@ grub_net_configure_by_dhcp_ack (const char *name,
if (size > OFFSET_OF (server_name, bp)
&& bp->server_name[0])
{
set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name,
sizeof (bp->server_name));
grub_env_set_net_property (name, "dhcp_server_name", bp->server_name,
sizeof (bp->server_name));
if (is_def && !grub_net_default_server)
{
grub_net_default_server = grub_strdup (bp->server_name);

View file

@ -1480,6 +1480,44 @@ receive_packets (struct grub_net_card *card, int *stop_condition)
grub_print_error ();
}
static char *
grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)),
const char *val __attribute__ ((unused)))
{
return NULL;
}
grub_err_t
grub_env_set_net_property (const char *intername, const char *suffix,
const char *value, grub_size_t len)
{
char *varname, *varvalue;
char *ptr;
varname = grub_xasprintf ("net_%s_%s", intername, suffix);
if (!varname)
return grub_errno;
for (ptr = varname; *ptr; ptr++)
if (*ptr == ':')
*ptr = '_';
varvalue = grub_malloc (len + 1);
if (!varvalue)
{
grub_free (varname);
return grub_errno;
}
grub_memcpy (varvalue, value, len);
varvalue[len] = 0;
grub_err_t ret = grub_env_set (varname, varvalue);
grub_register_variable_hook (varname, 0, grub_env_write_readonly);
grub_env_export (varname);
grub_free (varname);
grub_free (varvalue);
return ret;
}
void
grub_net_poll_cards (unsigned time, int *stop_condition)
{

View file

@ -480,6 +480,10 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target,
void
grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
grub_err_t
grub_env_set_net_property (const char *intername, const char *suffix,
const char *value, grub_size_t len);
void
grub_net_poll_cards (unsigned time, int *stop_condition);