Commit 8b9c53221f6ce30ad132e3202e6d445bc21ed8aa
1 parent
a36b12f95a
Exists in
master
and in
54 other branches
net: Move RARP receive logic out of net.c
Separate this functionality out of the net.c behemoth Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Acked-by: Simon Glass <sjg@chromium.org> Acked-by: Mike Frysinger <vapier@gentoo.org>
Showing 3 changed files with 37 additions and 48 deletions Side-by-side Diff
net/net.c
... | ... | @@ -82,9 +82,7 @@ |
82 | 82 | #include "arp.h" |
83 | 83 | #include "bootp.h" |
84 | 84 | #include "tftp.h" |
85 | -#ifdef CONFIG_CMD_RARP | |
86 | 85 | #include "rarp.h" |
87 | -#endif | |
88 | 86 | #include "nfs.h" |
89 | 87 | #ifdef CONFIG_STATUS_LED |
90 | 88 | #include <status_led.h> |
... | ... | @@ -853,9 +851,6 @@ |
853 | 851 | { |
854 | 852 | Ethernet_t *et; |
855 | 853 | IP_t *ip; |
856 | -#ifdef CONFIG_CMD_RARP | |
857 | - ARP_t *arp; | |
858 | -#endif | |
859 | 854 | IPaddr_t tmp; |
860 | 855 | IPaddr_t src_ip; |
861 | 856 | int x; |
... | ... | @@ -960,27 +955,7 @@ |
960 | 955 | |
961 | 956 | #ifdef CONFIG_CMD_RARP |
962 | 957 | case PROT_RARP: |
963 | - debug("Got RARP\n"); | |
964 | - arp = (ARP_t *)ip; | |
965 | - if (len < ARP_HDR_SIZE) { | |
966 | - printf("bad length %d < %d\n", len, ARP_HDR_SIZE); | |
967 | - return; | |
968 | - } | |
969 | - | |
970 | - if ((ntohs(arp->ar_op) != RARPOP_REPLY) || | |
971 | - (ntohs(arp->ar_hrd) != ARP_ETHER) || | |
972 | - (ntohs(arp->ar_pro) != PROT_IP) || | |
973 | - (arp->ar_hln != 6) || (arp->ar_pln != 4)) { | |
974 | - | |
975 | - puts("invalid RARP header\n"); | |
976 | - } else { | |
977 | - NetCopyIP(&NetOurIP, &arp->ar_data[16]); | |
978 | - if (NetServerIP == 0) | |
979 | - NetCopyIP(&NetServerIP, &arp->ar_data[6]); | |
980 | - memcpy(NetServerEther, &arp->ar_data[0], 6); | |
981 | - | |
982 | - (*packetHandler)(0, 0, 0, 0, 0); | |
983 | - } | |
958 | + rarp_receive(ip, len); | |
984 | 959 | break; |
985 | 960 | #endif |
986 | 961 | case PROT_IP: |
net/rarp.c
... | ... | @@ -29,33 +29,50 @@ |
29 | 29 | #include "rarp.h" |
30 | 30 | #include "tftp.h" |
31 | 31 | |
32 | -#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */ | |
32 | +#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */ | |
33 | 33 | #ifndef CONFIG_NET_RETRY_COUNT |
34 | -# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ | |
34 | +#define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ | |
35 | 35 | #else |
36 | -# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) | |
36 | +#define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) | |
37 | 37 | #endif |
38 | 38 | |
39 | +int RarpTry; | |
39 | 40 | |
40 | -int RarpTry; | |
41 | - | |
42 | 41 | /* |
43 | 42 | * Handle a RARP received packet. |
44 | 43 | */ |
45 | -static void | |
46 | -RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2, | |
47 | - unsigned dummi3) | |
44 | +void rarp_receive(IP_t *ip, unsigned len) | |
48 | 45 | { |
49 | - debug("Got good RARP\n"); | |
50 | - net_auto_load(); | |
46 | + ARP_t *arp; | |
47 | + | |
48 | + debug("Got RARP\n"); | |
49 | + arp = (ARP_t *)ip; | |
50 | + if (len < ARP_HDR_SIZE) { | |
51 | + printf("bad length %d < %d\n", len, ARP_HDR_SIZE); | |
52 | + return; | |
53 | + } | |
54 | + | |
55 | + if ((ntohs(arp->ar_op) != RARPOP_REPLY) || | |
56 | + (ntohs(arp->ar_hrd) != ARP_ETHER) || | |
57 | + (ntohs(arp->ar_pro) != PROT_IP) || | |
58 | + (arp->ar_hln != 6) || (arp->ar_pln != 4)) { | |
59 | + | |
60 | + puts("invalid RARP header\n"); | |
61 | + } else { | |
62 | + NetCopyIP(&NetOurIP, &arp->ar_data[16]); | |
63 | + if (NetServerIP == 0) | |
64 | + NetCopyIP(&NetServerIP, &arp->ar_data[6]); | |
65 | + memcpy(NetServerEther, &arp->ar_data[0], 6); | |
66 | + debug("Got good RARP\n"); | |
67 | + net_auto_load(); | |
68 | + } | |
51 | 69 | } |
52 | 70 | |
53 | 71 | |
54 | 72 | /* |
55 | 73 | * Timeout on BOOTP request. |
56 | 74 | */ |
57 | -static void | |
58 | -RarpTimeout(void) | |
75 | +static void RarpTimeout(void) | |
59 | 76 | { |
60 | 77 | if (RarpTry >= TIMEOUT_COUNT) { |
61 | 78 | puts("\nRetry count exceeded; starting again\n"); |
62 | 79 | |
... | ... | @@ -67,10 +84,8 @@ |
67 | 84 | } |
68 | 85 | |
69 | 86 | |
70 | -void | |
71 | -RarpRequest(void) | |
87 | +void RarpRequest(void) | |
72 | 88 | { |
73 | - int i; | |
74 | 89 | uchar *pkt; |
75 | 90 | ARP_t *rarp; |
76 | 91 | |
77 | 92 | |
... | ... | @@ -90,13 +105,11 @@ |
90 | 105 | memcpy(&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */ |
91 | 106 | /* dest ET addr = source ET addr ??*/ |
92 | 107 | memcpy(&rarp->ar_data[10], NetOurEther, 6); |
93 | - /* dest. IP addr set to broadcast */ | |
94 | - for (i = 0; i <= 3; i++) | |
95 | - rarp->ar_data[16 + i] = 0xff; | |
108 | + /* dest IP addr set to broadcast */ | |
109 | + memset(&rarp->ar_data[16], 0xff, 4); | |
96 | 110 | |
97 | 111 | NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE); |
98 | 112 | |
99 | 113 | NetSetTimeout(TIMEOUT, RarpTimeout); |
100 | - NetSetHandler(RarpHandler); | |
101 | 114 | } |
net/rarp.h
... | ... | @@ -21,15 +21,13 @@ |
21 | 21 | * MA 02111-1307 USA |
22 | 22 | */ |
23 | 23 | |
24 | +#if defined(CONFIG_CMD_RARP) | |
24 | 25 | |
25 | 26 | #ifndef __RARP_H__ |
26 | 27 | #define __RARP_H__ |
27 | 28 | |
28 | -#ifndef __NET_H__ | |
29 | 29 | #include <net.h> |
30 | -#endif /* __NET_H__ */ | |
31 | 30 | |
32 | - | |
33 | 31 | /**********************************************************************/ |
34 | 32 | /* |
35 | 33 | * Global functions and variables. |
36 | 34 | |
... | ... | @@ -37,9 +35,12 @@ |
37 | 35 | |
38 | 36 | extern int RarpTry; |
39 | 37 | |
38 | +/* Process the receipt of a RARP packet */ | |
39 | +extern void rarp_receive(IP_t *ip, unsigned len); | |
40 | 40 | extern void RarpRequest(void); /* Send a RARP request */ |
41 | 41 | |
42 | 42 | /**********************************************************************/ |
43 | 43 | |
44 | 44 | #endif /* __RARP_H__ */ |
45 | +#endif |