mirror of
https://github.com/Stichting-MINIX-Research-Foundation/u-boot.git
synced 2025-09-10 12:39:22 -04:00
net: tftpput: Move ICMP code into its own function
NetReceive() is a very long function with a lot of indent. Before adding code to the ICMP bit, split it out. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
d67f10ce0f
commit
8f79bb17a4
101
net/net.c
101
net/net.c
@ -1331,6 +1331,62 @@ static inline IP_t *NetDefragment(IP_t *ip, int *lenp)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receive an ICMP packet. We deal with REDIRECT and PING here, and silently
|
||||||
|
* drop others.
|
||||||
|
*
|
||||||
|
* @parma ip IP packet containing the ICMP
|
||||||
|
*/
|
||||||
|
static void receive_icmp(IP_t *ip, int len, IPaddr_t src_ip, Ethernet_t *et)
|
||||||
|
{
|
||||||
|
ICMP_t *icmph = (ICMP_t *)&ip->udp_src;
|
||||||
|
|
||||||
|
switch (icmph->type) {
|
||||||
|
case ICMP_REDIRECT:
|
||||||
|
if (icmph->code != ICMP_REDIR_HOST)
|
||||||
|
return;
|
||||||
|
printf(" ICMP Host Redirect to %pI4 ",
|
||||||
|
&icmph->un.gateway);
|
||||||
|
break;
|
||||||
|
#if defined(CONFIG_CMD_PING)
|
||||||
|
case ICMP_ECHO_REPLY:
|
||||||
|
/*
|
||||||
|
* IP header OK. Pass the packet to the
|
||||||
|
* current handler.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* XXX point to ip packet - should this use
|
||||||
|
* packet_icmp_handler?
|
||||||
|
*/
|
||||||
|
(*packetHandler)((uchar *)ip, 0, src_ip, 0, 0);
|
||||||
|
break;
|
||||||
|
case ICMP_ECHO_REQUEST:
|
||||||
|
debug("Got ICMP ECHO REQUEST, return %d bytes\n",
|
||||||
|
ETHER_HDR_SIZE + len);
|
||||||
|
|
||||||
|
memcpy(&et->et_dest[0], &et->et_src[0], 6);
|
||||||
|
memcpy(&et->et_src[0], NetOurEther, 6);
|
||||||
|
|
||||||
|
ip->ip_sum = 0;
|
||||||
|
ip->ip_off = 0;
|
||||||
|
NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
|
||||||
|
NetCopyIP((void *)&ip->ip_src, &NetOurIP);
|
||||||
|
ip->ip_sum = ~NetCksum((uchar *)ip,
|
||||||
|
IP_HDR_SIZE_NO_UDP >> 1);
|
||||||
|
|
||||||
|
icmph->type = ICMP_ECHO_REPLY;
|
||||||
|
icmph->checksum = 0;
|
||||||
|
icmph->checksum = ~NetCksum((uchar *)icmph,
|
||||||
|
(len - IP_HDR_SIZE_NO_UDP) >> 1);
|
||||||
|
(void) eth_send((uchar *)et,
|
||||||
|
ETHER_HDR_SIZE + len);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NetReceive(volatile uchar *inpkt, int len)
|
NetReceive(volatile uchar *inpkt, int len)
|
||||||
{
|
{
|
||||||
@ -1617,49 +1673,8 @@ NetReceive(volatile uchar *inpkt, int len)
|
|||||||
* sure if there aren't any other situations.
|
* sure if there aren't any other situations.
|
||||||
*/
|
*/
|
||||||
if (ip->ip_p == IPPROTO_ICMP) {
|
if (ip->ip_p == IPPROTO_ICMP) {
|
||||||
ICMP_t *icmph = (ICMP_t *)&(ip->udp_src);
|
receive_icmp(ip, len, src_ip, et);
|
||||||
|
return;
|
||||||
switch (icmph->type) {
|
|
||||||
case ICMP_REDIRECT:
|
|
||||||
if (icmph->code != ICMP_REDIR_HOST)
|
|
||||||
return;
|
|
||||||
printf(" ICMP Host Redirect to %pI4 ",
|
|
||||||
&icmph->un.gateway);
|
|
||||||
return;
|
|
||||||
#if defined(CONFIG_CMD_PING)
|
|
||||||
case ICMP_ECHO_REPLY:
|
|
||||||
/*
|
|
||||||
* IP header OK. Pass the packet to the
|
|
||||||
* current handler.
|
|
||||||
*/
|
|
||||||
/* XXX point to ip packet */
|
|
||||||
(*packetHandler)((uchar *)ip, 0, src_ip, 0, 0);
|
|
||||||
return;
|
|
||||||
case ICMP_ECHO_REQUEST:
|
|
||||||
debug("Got ICMP ECHO REQUEST, return %d bytes\n",
|
|
||||||
ETHER_HDR_SIZE + len);
|
|
||||||
|
|
||||||
memcpy(&et->et_dest[0], &et->et_src[0], 6);
|
|
||||||
memcpy(&et->et_src[0], NetOurEther, 6);
|
|
||||||
|
|
||||||
ip->ip_sum = 0;
|
|
||||||
ip->ip_off = 0;
|
|
||||||
NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
|
|
||||||
NetCopyIP((void *)&ip->ip_src, &NetOurIP);
|
|
||||||
ip->ip_sum = ~NetCksum((uchar *)ip,
|
|
||||||
IP_HDR_SIZE_NO_UDP >> 1);
|
|
||||||
|
|
||||||
icmph->type = ICMP_ECHO_REPLY;
|
|
||||||
icmph->checksum = 0;
|
|
||||||
icmph->checksum = ~NetCksum((uchar *)icmph,
|
|
||||||
(len - IP_HDR_SIZE_NO_UDP) >> 1);
|
|
||||||
(void) eth_send((uchar *)et,
|
|
||||||
ETHER_HDR_SIZE + len);
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */
|
} else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user