grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obtaining the MAC address of the boot NIC for a PXE boot


From: Andrey Borzenkov
Subject: Re: Obtaining the MAC address of the boot NIC for a PXE boot
Date: Sun, 5 May 2013 09:17:08 +0400

В Sat, 04 May 2013 23:19:50 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <address@hidden> пишет:

> Patch for net_default_*. Please test.
> 
> === modified file 'grub-core/net/bootp.c'
> --- grub-core/net/bootp.c     2013-01-20 13:24:47 +0000
> +++ grub-core/net/bootp.c     2013-05-04 21:16:02 +0000
> @@ -211,6 +211,9 @@
>        grub_print_error ();
>      }
>  
> +  if (is_def)
> +    grub_env_set ("net_default_interface", name);
> +
>    if (device && !*device && bp->server_ip)
>      {
>        *device = grub_xasprintf ("tftp,%d.%d.%d.%d",
> 
> === modified file 'grub-core/net/net.c'
> --- grub-core/net/net.c       2013-01-21 01:33:46 +0000
> +++ grub-core/net/net.c       2013-05-04 21:13:29 +0000
> @@ -1,6 +1,6 @@
>  /*
>   *  GRUB  --  GRand Unified Bootloader
> - *  Copyright (C) 2010,2011  Free Software Foundation, Inc.
> + *  Copyright (C) 2010,2011,2012,2013  Free Software Foundation, Inc.
>   *
>   *  GRUB is free software: you can redistribute it and/or modify
>   *  it under the terms of the GNU General Public License as published by
> @@ -813,6 +813,65 @@
>    return grub_net_default_server ? : "";
>  }
>  
> +static const char *
> +defip_get_env (struct grub_env_var *var __attribute__ ((unused)),
> +            const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  const char *ret = NULL;
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_ip", intf);
> +      ret = grub_env_get (buf);

This will crash if grub_xasprintf fails.

> +      grub_free (buf);
> +    }
> +  return ret;
> +}
> +
> +static char *
> +defip_set_env (struct grub_env_var *var __attribute__ ((unused)),
> +            const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_ip", intf);
> +      grub_env_set (buf, val);
> +      grub_free (buf);
> +    }
> +  return NULL;
> +}
> +
> +
> +static const char *
> +defmac_get_env (struct grub_env_var *var __attribute__ ((unused)),
> +            const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  const char *ret = NULL;
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_mac", intf);
> +      ret = grub_env_get (buf);
> +      grub_free (buf);
> +    }
> +  return ret;
> +}
> +
> +static char *
> +defmac_set_env (struct grub_env_var *var __attribute__ ((unused)),
> +            const char *val)
> +{
> +  const char *intf = grub_env_get ("net_default_interface");
> +  if (intf)
> +    {
> +      char *buf = grub_xasprintf ("net_%s_mac", intf);
> +      grub_env_set (buf, val);
> +      grub_free (buf);
> +    }
> +  return NULL;
> +}
> +
>  
>  static void
>  grub_net_network_level_interface_register (struct 
> grub_net_network_level_interface *inter)
> @@ -1560,6 +1619,10 @@
>                              defserver_set_env);
>    grub_register_variable_hook ("pxe_default_server", defserver_get_env,
>                              defserver_set_env);
> +  grub_register_variable_hook ("net_default_ip", defip_get_env,
> +                            defip_set_env);
> +  grub_register_variable_hook ("net_default_mac", defmac_get_env,
> +                            defmac_set_env);
>  
>    cmd_addaddr = grub_register_command ("net_add_addr", grub_cmd_addaddr,
>                                       /* TRANSLATORS: HWADDRESS stands for
> 
> 

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]