summaryrefslogtreecommitdiffstats
path: root/net/net.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-14 16:08:04 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-05-15 08:16:30 +0200
commitbe0404c21f22da2d736168b2e56a9ae583cc3e95 (patch)
tree637570fff15aee4bc8f44376a04b4068fbeeb38f /net/net.c
parent22b878d2518a2b31c5991f9c47a2b176f0ac246d (diff)
downloadbarebox-be0404c21f22da2d736168b2e56a9ae583cc3e95.tar.gz
barebox-be0404c21f22da2d736168b2e56a9ae583cc3e95.tar.xz
net: Allow to use multiple network interfaces at once
In barebox network packets always go out at the current ethernet device and are expected to be received from the current interface. This has some side effects. When for example an NFS is mounted when one interface is active and the interface is changed afterwards the NFS packets leave the new interface, but the NFS server won't be reachable there. Instead of changing the whole network traffic to the current ethernet interface we now initialize a network connection with the current network interface, but then the connection will continue to use that interface even when the current interface is changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/net/net.c b/net/net.c
index e43a3aba66..f54267ae50 100644
--- a/net/net.c
+++ b/net/net.c
@@ -241,7 +241,7 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)
arp_ether = ether;
- ret = eth_send(arp_packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
+ ret = eth_send(edev, arp_packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
if (ret)
return ret;
arp_start = get_time_ns();
@@ -253,7 +253,7 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)
if (is_timeout(arp_start, 3 * SECOND)) {
printf("T ");
arp_start = get_time_ns();
- ret = eth_send(arp_packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
+ ret = eth_send(edev, arp_packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
if (ret)
return ret;
retries++;
@@ -358,6 +358,7 @@ static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
con = xzalloc(sizeof(*con));
con->packet = net_alloc_packet();
con->priv = ctx;
+ con->edev = edev;
memset(con->packet, 0, PKTSIZE);
con->et = (struct ethernet *)con->packet;
@@ -437,7 +438,7 @@ static int net_ip_send(struct net_connection *con, int len)
con->ip->check = 0;
con->ip->check = ~net_checksum((unsigned char *)con->ip, sizeof(struct iphdr));
- return eth_send(con->packet, ETHER_HDR_SIZE + sizeof(struct iphdr) + len);
+ return eth_send(con->edev, con->packet, ETHER_HDR_SIZE + sizeof(struct iphdr) + len);
}
int net_udp_send(struct net_connection *con, int len)
@@ -480,7 +481,7 @@ static int net_answer_arp(unsigned char *pkt, int len)
if (!packet)
return 0;
memcpy(packet, pkt, ETHER_HDR_SIZE + ARP_HDR_SIZE);
- ret = eth_send(packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
+ ret = eth_send(edev, packet, ETHER_HDR_SIZE + ARP_HDR_SIZE);
free(packet);
return ret;
@@ -497,9 +498,8 @@ static void net_bad_packet(unsigned char *pkt, int len)
#endif
}
-static int net_handle_arp(unsigned char *pkt, int len)
+static int net_handle_arp(struct eth_device *edev, unsigned char *pkt, int len)
{
- struct eth_device *edev = eth_get_current();
struct arprequest *arp;
debug("%s: got arp\n", __func__);
@@ -580,10 +580,9 @@ static int net_handle_icmp(unsigned char *pkt, int len)
return 0;
}
-static int net_handle_ip(unsigned char *pkt, int len)
+static int net_handle_ip(struct eth_device *edev, unsigned char *pkt, int len)
{
struct iphdr *ip = (struct iphdr *)(pkt + ETHER_HDR_SIZE);
- struct eth_device *edev = eth_get_current();
IPaddr_t tmp;
debug("%s\n", __func__);
@@ -634,10 +633,10 @@ int net_receive(struct eth_device *edev, unsigned char *pkt, int len)
switch (et_protlen) {
case PROT_ARP:
- ret = net_handle_arp(pkt, len);
+ ret = net_handle_arp(edev, pkt, len);
break;
case PROT_IP:
- ret = net_handle_ip(pkt, len);
+ ret = net_handle_ip(edev, pkt, len);
break;
default:
debug("%s: got unknown protocol type: %d\n", __func__, et_protlen);