summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-11-20 22:36:37 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-12-01 12:33:33 +0100
commit946bc95a4de8247ea884a3932470344e59618c3a (patch)
tree6d7772d5dba2f7c0ecab2aeb25905f265e17f650 /net
parent46f7781d361b2b4768c0a56c4fd6a9b11fe4157c (diff)
downloadbarebox-946bc95a4de8247ea884a3932470344e59618c3a.tar.gz
barebox-946bc95a4de8247ea884a3932470344e59618c3a.tar.xz
net: allow udp connections on specified network device
This allows the DHCP code to configure specific network devices so that DHCP no longer depends on any "current" network device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net')
-rw-r--r--net/net.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/net/net.c b/net/net.c
index f63d25531e..6cdffa4b8d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -144,9 +144,8 @@ static void arp_handler(struct arprequest *arp)
}
}
-static int arp_request(IPaddr_t dest, unsigned char *ether)
+static int arp_request(struct eth_device *edev, IPaddr_t dest, unsigned char *ether)
{
- struct eth_device *edev = eth_get_current();
char *pkt;
struct arprequest *arp;
uint64_t arp_start;
@@ -295,15 +294,17 @@ IPaddr_t net_get_gateway(void)
static LIST_HEAD(connection_list);
-static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
- void *ctx)
+static struct net_connection *net_new(struct eth_device *edev, IPaddr_t dest,
+ rx_handler_f *handler, void *ctx)
{
- struct eth_device *edev = eth_get_current();
struct net_connection *con;
int ret;
- if (!edev)
- return ERR_PTR(-ENETDOWN);
+ if (!edev) {
+ edev = eth_get_current();
+ if (!edev)
+ return ERR_PTR(-ENETDOWN);
+ }
if (!is_valid_ether_addr(edev->ethaddr)) {
char str[sizeof("xx:xx:xx:xx:xx:xx")];
@@ -332,7 +333,7 @@ static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
if (dest == IP_BROADCAST) {
memset(con->et->et_dest, 0xff, 6);
} else {
- ret = arp_request(dest, con->et->et_dest);
+ ret = arp_request(edev, dest, con->et->et_dest);
if (ret)
goto out;
}
@@ -356,10 +357,11 @@ out:
return ERR_PTR(ret);
}
-struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
- rx_handler_f *handler, void *ctx)
+struct net_connection *net_udp_eth_new(struct eth_device *edev, IPaddr_t dest,
+ uint16_t dport, rx_handler_f *handler,
+ void *ctx)
{
- struct net_connection *con = net_new(dest, handler, ctx);
+ struct net_connection *con = net_new(edev, dest, handler, ctx);
if (IS_ERR(con))
return con;
@@ -372,10 +374,16 @@ struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
return con;
}
+struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
+ rx_handler_f *handler, void *ctx)
+{
+ return net_udp_eth_new(NULL, dest, dport, handler, ctx);
+}
+
struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler,
void *ctx)
{
- struct net_connection *con = net_new(dest, handler, ctx);
+ struct net_connection *con = net_new(NULL, dest, handler, ctx);
if (IS_ERR(con))
return con;