summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-03-30 11:40:20 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-04-03 11:39:27 +0800
commit1f9e76d840e20bd5a0f1c425e741f343aa81929f (patch)
treeab4347b5ee88fcec71a9afe48d99dff4eab62e9e
parentaf387f080f8f74931a9ca0b36192e624a2c2fbd1 (diff)
downloadbarebox-1f9e76d840e20bd5a0f1c425e741f343aa81929f.tar.gz
barebox-1f9e76d840e20bd5a0f1c425e741f343aa81929f.tar.xz
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>
-rw-r--r--net/dhcp.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/net/dhcp.c b/net/dhcp.c
index 9168221a9e..4d559da1d2 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -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)
@@ -188,6 +193,11 @@ struct dhcp_opt dhcp_options[] = {
.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,
.barebox_var_name = "bootfile",
@@ -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");