9
0
Fork 0

net: dhcp: add support of tftp name server

if the DNS is enable resolve it. The server ip will be set if no server ip it
is set in the bootp.
Export it via env dhcp_tftp_server_name.

E.g. the ISC dhcp server can be configured with

   | class "at91sam9x5ek" {
   |         match if substring (option vendor-class-identifier,0,20) = "barebox-at91sam9x
   |
   |         filename "/tftpboot/atmel/at91sam9x5/sam9x5ek/zImage";
   |         option tftp-server-name "192.168.200.98";
   |         option root-path "192.168.200.98:/opt/work/buildroot/build/sam9x5/target";
   |         }
   | }

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2012-03-30 11:40:20 +08:00
parent af387f080f
commit 1f9e76d840
1 changed files with 17 additions and 3 deletions

View File

@ -75,6 +75,7 @@ static dhcp_state_t dhcp_state;
static uint32_t dhcp_leasetime;
static IPaddr_t net_dhcp_server_ip;
static uint64_t dhcp_start;
static char dhcp_tftpname[256];
struct dhcp_opt {
unsigned char option;
@ -114,10 +115,14 @@ static void env_ip_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
static void env_str_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
{
char str[256];
char *tmp = str;
memcpy(str, popt, optlen);
str[optlen] = 0;
setenv(opt->barebox_var_name, str);
if (opt->data)
tmp = opt->data;
memcpy(tmp, popt, optlen);
tmp[optlen] = 0;
setenv(opt->barebox_var_name, tmp);
}
static void copy_uint32_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
@ -187,6 +192,11 @@ struct dhcp_opt dhcp_options[] = {
.handle = copy_ip_handle,
.data = &net_dhcp_server_ip,
.optional = true,
}, {
.option = 66,
.handle = env_str_handle,
.barebox_var_name = "dhcp_tftp_server_name",
.data = dhcp_tftpname,
}, {
.option = 67,
.handle = bootfile_vendorex_handle,
@ -396,6 +406,9 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
popt += oplen + 2; /* Process next option */
}
if (dhcp_tftpname[0] != 0)
net_set_serverip(resolv(dhcp_tftpname));
}
static int dhcp_message_type(unsigned char *popt)
@ -601,3 +614,4 @@ BAREBOX_MAGICVAR(hostname, "hostname returned from DHCP request");
BAREBOX_MAGICVAR(domainname, "domainname returned from DHCP request");
BAREBOX_MAGICVAR(rootpath, "rootpath returned from DHCP request");
BAREBOX_MAGICVAR(dhcp_vendor_id, "vendor id to send to the DHCP server");
BAREBOX_MAGICVAR(dhcp_tftp_server_name, "TFTP server Name returned from DHCP request");