mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-09 03:21:51 +00:00
net: Refactor packet length computations
Save the length when it is computed instead of forgetting it and subtracting pointers to figure it out again. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Acked-by: Simon Glass <sjg@chromium.org> Acked-by: Mike Frysinger <vapier@gentoo.org>
This commit is contained in:
parent
9214637a56
commit
00f33268ab
3 changed files with 16 additions and 10 deletions
13
net/arp.c
13
net/arp.c
|
@ -52,12 +52,14 @@ void ArpRequest(void)
|
||||||
{
|
{
|
||||||
uchar *pkt;
|
uchar *pkt;
|
||||||
struct arp_hdr *arp;
|
struct arp_hdr *arp;
|
||||||
|
int eth_hdr_size;
|
||||||
|
|
||||||
debug("ARP broadcast %d\n", NetArpWaitTry);
|
debug("ARP broadcast %d\n", NetArpWaitTry);
|
||||||
|
|
||||||
pkt = NetTxPacket;
|
pkt = NetTxPacket;
|
||||||
|
|
||||||
pkt += NetSetEther(pkt, NetBcastAddr, PROT_ARP);
|
eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_ARP);
|
||||||
|
pkt += eth_hdr_size;
|
||||||
|
|
||||||
arp = (struct arp_hdr *) pkt;
|
arp = (struct arp_hdr *) pkt;
|
||||||
|
|
||||||
|
@ -86,7 +88,7 @@ void ArpRequest(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
|
NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP);
|
||||||
(void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
|
(void) eth_send(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArpTimeoutCheck(void)
|
void ArpTimeoutCheck(void)
|
||||||
|
@ -118,6 +120,7 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
|
||||||
struct arp_hdr *arp;
|
struct arp_hdr *arp;
|
||||||
IPaddr_t reply_ip_addr;
|
IPaddr_t reply_ip_addr;
|
||||||
uchar *pkt;
|
uchar *pkt;
|
||||||
|
int eth_hdr_size;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have to deal with two types of ARP packets:
|
* We have to deal with two types of ARP packets:
|
||||||
|
@ -155,14 +158,14 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
|
||||||
/* reply with our IP address */
|
/* reply with our IP address */
|
||||||
debug("Got ARP REQUEST, return our IP\n");
|
debug("Got ARP REQUEST, return our IP\n");
|
||||||
pkt = (uchar *)et;
|
pkt = (uchar *)et;
|
||||||
pkt += NetSetEther(pkt, et->et_src, PROT_ARP);
|
eth_hdr_size = NetSetEther(pkt, et->et_src, PROT_ARP);
|
||||||
|
pkt += eth_hdr_size;
|
||||||
arp->ar_op = htons(ARPOP_REPLY);
|
arp->ar_op = htons(ARPOP_REPLY);
|
||||||
memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
|
memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
|
||||||
NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
|
NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
|
||||||
memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
|
memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
|
||||||
NetCopyIP(&arp->ar_spa, &NetOurIP);
|
NetCopyIP(&arp->ar_spa, &NetOurIP);
|
||||||
(void) eth_send((uchar *)et,
|
(void) eth_send((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
|
||||||
(pkt - (uchar *)et) + ARP_HDR_SIZE);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case ARPOP_REPLY: /* arp reply */
|
case ARPOP_REPLY: /* arp reply */
|
||||||
|
|
|
@ -42,6 +42,7 @@ static int ping_send(void)
|
||||||
{
|
{
|
||||||
static uchar mac[6];
|
static uchar mac[6];
|
||||||
uchar *pkt;
|
uchar *pkt;
|
||||||
|
int eth_hdr_size;
|
||||||
|
|
||||||
/* XXX always send arp request */
|
/* XXX always send arp request */
|
||||||
|
|
||||||
|
@ -53,13 +54,13 @@ static int ping_send(void)
|
||||||
NetArpWaitPacketMAC = mac;
|
NetArpWaitPacketMAC = mac;
|
||||||
|
|
||||||
pkt = NetArpWaitTxPacket;
|
pkt = NetArpWaitTxPacket;
|
||||||
pkt += NetSetEther(pkt, mac, PROT_IP);
|
eth_hdr_size = NetSetEther(pkt, mac, PROT_IP);
|
||||||
|
pkt += eth_hdr_size;
|
||||||
|
|
||||||
set_icmp_header(pkt, NetPingIP);
|
set_icmp_header(pkt, NetPingIP);
|
||||||
|
|
||||||
/* size of the waiting packet */
|
/* size of the waiting packet */
|
||||||
NetArpWaitTxPacketSize =
|
NetArpWaitTxPacketSize = eth_hdr_size + IP_ICMP_HDR_SIZE;
|
||||||
(pkt - NetArpWaitTxPacket) + IP_HDR_SIZE + 8;
|
|
||||||
|
|
||||||
/* and do the ARP request */
|
/* and do the ARP request */
|
||||||
NetArpWaitTry = 1;
|
NetArpWaitTry = 1;
|
||||||
|
|
|
@ -88,11 +88,13 @@ void RarpRequest(void)
|
||||||
{
|
{
|
||||||
uchar *pkt;
|
uchar *pkt;
|
||||||
struct arp_hdr *rarp;
|
struct arp_hdr *rarp;
|
||||||
|
int eth_hdr_size;
|
||||||
|
|
||||||
printf("RARP broadcast %d\n", ++RarpTry);
|
printf("RARP broadcast %d\n", ++RarpTry);
|
||||||
pkt = NetTxPacket;
|
pkt = NetTxPacket;
|
||||||
|
|
||||||
pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
|
eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_RARP);
|
||||||
|
pkt += eth_hdr_size;
|
||||||
|
|
||||||
rarp = (struct arp_hdr *)pkt;
|
rarp = (struct arp_hdr *)pkt;
|
||||||
|
|
||||||
|
@ -108,7 +110,7 @@ void RarpRequest(void)
|
||||||
/* dest IP addr set to broadcast */
|
/* dest IP addr set to broadcast */
|
||||||
memset(&rarp->ar_data[16], 0xff, 4);
|
memset(&rarp->ar_data[16], 0xff, 4);
|
||||||
|
|
||||||
NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
|
NetSendPacket(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
|
||||||
|
|
||||||
NetSetTimeout(TIMEOUT, RarpTimeout);
|
NetSetTimeout(TIMEOUT, RarpTimeout);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue