summaryrefslogtreecommitdiffstats
path: root/net/dhcp.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-11-20 22:46:47 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-12-14 14:29:42 +0100
commitab84733e570b889324f2594685f7f5d33b3c39be (patch)
tree0a75d7c782667cefb892b8a86772875f62a879c9 /net/dhcp.c
parent946bc95a4de8247ea884a3932470344e59618c3a (diff)
downloadbarebox-ab84733e570b889324f2594685f7f5d33b3c39be.tar.gz
barebox-ab84733e570b889324f2594685f7f5d33b3c39be.tar.xz
net: dhcp: Allow to specify network device
Instead of allowing to DHCP only on the "current" network device, allow to specify the desired network device. This is a first step to get rid of the concept of a "current" network device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net/dhcp.c')
-rw-r--r--net/dhcp.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/net/dhcp.c b/net/dhcp.c
index 37aad8f1ff..82f60f0535 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -79,6 +79,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 struct eth_device *dhcp_edev;
static char dhcp_tftpname[256];
static const char* dhcp_get_barebox_global(const char * var)
@@ -126,7 +127,7 @@ static void netmask_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen
IPaddr_t ip;
ip = net_read_ip(popt);
- net_set_netmask(ip);
+ net_set_netmask(dhcp_edev, ip);
}
static void gateway_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
@@ -369,7 +370,7 @@ static void bootp_copy_net_params(struct bootp *bp)
IPaddr_t tmp_ip;
tmp_ip = net_read_ip(&bp->bp_yiaddr);
- net_set_ip(tmp_ip);
+ net_set_ip(dhcp_edev, tmp_ip);
tmp_ip = net_read_ip(&bp->bp_siaddr);
if (tmp_ip != 0)
@@ -618,7 +619,7 @@ static void dhcp_handler(void *ctx, char *packet, unsigned int len)
dhcp_options_process((u8 *)&bp->bp_vend[4], bp);
bootp_copy_net_params(bp); /* Store net params from reply */
dhcp_state = BOUND;
- ip = net_get_ip();
+ ip = net_get_ip(dhcp_edev);
printf("DHCP client bound to address %pI4\n", &ip);
return;
}
@@ -646,12 +647,14 @@ static void dhcp_reset_env(void)
}
}
-int dhcp(int retries, struct dhcp_req_param *param)
+int dhcp(struct eth_device *edev, int retries, struct dhcp_req_param *param)
{
int ret = 0;
dhcp_reset_env();
+ dhcp_edev = edev;
+
dhcp_set_param_data(DHCP_HOSTNAME, param->hostname);
dhcp_set_param_data(DHCP_VENDOR_ID, param->vendor_id);
dhcp_set_param_data(DHCP_CLIENT_ID, param->client_id);
@@ -661,7 +664,7 @@ int dhcp(int retries, struct dhcp_req_param *param)
if (!retries)
retries = DHCP_DEFAULT_RETRY;
- dhcp_con = net_udp_new(IP_BROADCAST, PORT_BOOTPS, dhcp_handler, NULL);
+ dhcp_con = net_udp_eth_new(edev, IP_BROADCAST, PORT_BOOTPS, dhcp_handler, NULL);
if (IS_ERR(dhcp_con)) {
ret = PTR_ERR(dhcp_con);
goto out;
@@ -671,7 +674,7 @@ int dhcp(int retries, struct dhcp_req_param *param)
if (ret)
goto out1;
- net_set_ip(0);
+ net_set_ip(dhcp_edev, 0);
dhcp_start = get_time_ns();
ret = bootp_request(); /* Basically same as BOOTP */