net: Hide more code behind CONFIG_CMD_TFTPPUT

This commit reduces code size a little by making the ICMP handler only
available to tftpput. This is reasonable since it is the only user at
present (ping just uses the normal handler).

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2011-10-26 14:18:38 +00:00 committed by Wolfgang Denk
parent 206d68fdd4
commit 39bccd21d0
2 changed files with 12 additions and 2 deletions

View file

@ -215,7 +215,9 @@ volatile uchar *NetRxPackets[PKTBUFSRX];
/* Current RX packet handler */ /* Current RX packet handler */
static rxhand_f *packetHandler; static rxhand_f *packetHandler;
#ifdef CONFIG_CMD_TFTPPUT
static rxhand_icmp_f *packet_icmp_handler; /* Current ICMP rx handler */ static rxhand_icmp_f *packet_icmp_handler; /* Current ICMP rx handler */
#endif
/* Current timeout handler */ /* Current timeout handler */
static thand_f *timeHandler; static thand_f *timeHandler;
/* Time base value */ /* Time base value */
@ -576,9 +578,11 @@ restart:
} }
done: done:
#ifdef CONFIG_CMD_TFTPPUT
/* Clear out the handlers */ /* Clear out the handlers */
NetSetHandler(NULL); NetSetHandler(NULL);
net_set_icmp_handler(NULL); net_set_icmp_handler(NULL);
#endif
return ret; return ret;
} }
@ -653,10 +657,12 @@ NetSetHandler(rxhand_f *f)
packetHandler = f; packetHandler = f;
} }
#ifdef CONFIG_CMD_TFTPPUT
void net_set_icmp_handler(rxhand_icmp_f *f) void net_set_icmp_handler(rxhand_icmp_f *f)
{ {
packet_icmp_handler = f; packet_icmp_handler = f;
} }
#endif
void void
NetSetTimeout(ulong iv, thand_f *f) NetSetTimeout(ulong iv, thand_f *f)
@ -1397,10 +1403,12 @@ static void receive_icmp(IP_t *ip, int len, IPaddr_t src_ip, Ethernet_t *et)
break; break;
#endif #endif
default: default:
#ifdef CONFIG_CMD_TFTPPUT
if (packet_icmp_handler) if (packet_icmp_handler)
packet_icmp_handler(icmph->type, icmph->code, packet_icmp_handler(icmph->type, icmph->code,
ntohs(ip->udp_dst), src_ip, ntohs(ip->udp_src), ntohs(ip->udp_dst), src_ip, ntohs(ip->udp_src),
icmph->un.data, ntohs(ip->udp_len)); icmph->un.data, ntohs(ip->udp_len));
#endif
break; break;
} }
} }

View file

@ -421,7 +421,7 @@ TftpSend(void)
TftpOurPort, len); TftpOurPort, len);
} }
#ifdef CONFIG_CMD_TFTPPUT
static void icmp_handler(unsigned type, unsigned code, unsigned dest, static void icmp_handler(unsigned type, unsigned code, unsigned dest,
IPaddr_t sip, unsigned src, uchar *pkt, unsigned len) IPaddr_t sip, unsigned src, uchar *pkt, unsigned len)
{ {
@ -430,6 +430,7 @@ static void icmp_handler(unsigned type, unsigned code, unsigned dest,
restart("TFTP server died"); restart("TFTP server died");
} }
} }
#endif
static void static void
TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
@ -771,8 +772,9 @@ void TftpStart(enum proto_t protocol)
NetSetTimeout(TftpTimeoutMSecs, TftpTimeout); NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
NetSetHandler(TftpHandler); NetSetHandler(TftpHandler);
#ifdef CONFIG_CMD_TFTPPUT
net_set_icmp_handler(icmp_handler); net_set_icmp_handler(icmp_handler);
#endif
TftpRemotePort = WELL_KNOWN_PORT; TftpRemotePort = WELL_KNOWN_PORT;
TftpTimeoutCount = 0; TftpTimeoutCount = 0;
/* Use a pseudo-random port unless a specific port is set */ /* Use a pseudo-random port unless a specific port is set */