Skip to contentSkip to conversation

question about net/net.c

U-Boot-Users Robin Getz 3 participants 3 messages Oct 21, 2004

lore
Share & tools
lore

Robin Getz

author
#0 lore raw

I had a question about the latest version of net/net.c

scenario is as follows.

1. u-boot initiates a tftp transfer
2. u-boot sets a flag "NetArpWaitPacketMAC = 1"
3. u-boot sends ARP Request on network to find the MAC address of tftp server
4. server is a little slow, and u-boot has not yet received the ARP so, u-boot sends ARP Request on network to find the MAC address of tftp server
5. tftp server responds back to first request with it's MAC address, and u-boot sees this, and accepts it.
6. u-boot sets the flag "NetArpWaitPacketMAC = 0" as it got the ARP reply
7. tftp server responds back to second request with it's MAC address, and u-boot sees this, and accepts it.

At this point as u-boot is not waiting (NetArpWaitPacketMAC is 0) for ARP reply breaks out of the switch that handles ARP reply. But this break is not to return from the complete handler and thus falls into RARP handler code.

8. u-boot prints out "invalid RARP header".

This can be observed in net\net.c "NetReceive" function.

===============================================

void
NetReceive(volatile uchar * inpkt, int len)
{

[snip/snip]

         switch (x) {

         case PROT_ARP:
                 switch (ntohs(arp->ar_op)) {
                 case ARPOP_REQUEST:             /* reply with our IP 
address    */
                         return;

                 case ARPOP_REPLY:               /* arp reply */
                         /* are we waiting for a reply */
                         if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
                                 break;
                         return;
                 default:
                         return;
                 }

         case PROT_RARP:
                 break;

==================================================
am I missing something or shouldn't there be a break; above the 'case PROT_RARP:' to handle this?

Thanks
-Robin

#1 lore raw
Quoted 3 lines · In message <[email protected]> you wrote:

am I missing something or shouldn't there be a break; above the 'case PROT_RARP:' to handle this?

Can you please re-send this question in form of a (suggested / potential) patch? That would be much more readable.

Thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A man either lives life as it happens to him, meets  it  head-on  and
licks it, or he turns his back on it and starts to wither away.
	-- Dr. Boyce, "The Menagerie" ("The Cage"), stardate unknown
#2 lore raw
In reply to Robin Getz

Pseudo patch...

Quoted 6 lines · Robin Getz

void
NetReceive(volatile uchar * inpkt, int len)
{

[snip/snip]

Quoted 11 lines
         switch (x) { // 1:st switch

         case PROT_ARP:
                 switch (ntohs(arp->ar_op)) { // 2:nd switch
                 case ARPOP_REQUEST:             /* reply with our IP
address    */
                         return;

                 case ARPOP_REPLY:               /* arp reply */
                         /* are we waiting for a reply */
                         if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)

- break; // (current) breaks 2:nd switch
+ return; //

Quoted 5 lines
                         return;
                 default:
				
                         return;
                 }
		    // We end up here after break with ARPOP_REPLY and not waiting

+ break;
or
+ /* no break, fall through */ // (current)

Quoted 3 lines
         case PROT_RARP:
                 break;

My guess is that break should be replaced with return. But the second break would be nice too...

/RogerL

Optronic dp AB