changeset 1116:f886ab6517f0

Add initial ARP for better IP address handling
author gthomas
date Tue, 15 Jul 2003 16:21:41 +0000
parents e032de9c97e2
children c461c509e6ef
files packages/redboot/current/ChangeLog packages/redboot/current/include/net/net.h packages/redboot/current/src/net/arp.c packages/redboot/current/src/net/net_io.c
diffstat 4 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/packages/redboot/current/ChangeLog
+++ b/packages/redboot/current/ChangeLog
@@ -1,3 +1,13 @@
+2003-07-15  Gary Thomas  <gary@mlbassoc.com>
+
+	* include/net/net.h: 
+	* src/net/arp.c (__arp_request): Allow ARP of self - used during
+	initialization to "broadcast" that an IP address is in use.
+
+	* src/net/net_io.c (net_init): When using a static IP, send an
+	initial ARP to see if any other node is using this address.
+	Also, some minor cosmetic cleanups to remove warnings.
+
 2003-07-15  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* doc/redboot_installing.sgml (AT91): Tell users to switch JP1
--- a/packages/redboot/current/include/net/net.h
+++ b/packages/redboot/current/include/net/net.h
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -433,7 +433,7 @@ extern void __arp_handler(pktbuf_t *pkt)
  * Return true and fills in 'eth_addr' if successful, false
  * if unsuccessful.
  */
-extern int __arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr);
+extern int __arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr, int allow_self);
 
 /*
  * Lookup an address from the local ARP cache.  If not found,
--- a/packages/redboot/current/src/net/arp.c
+++ b/packages/redboot/current/src/net/arp.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -113,7 +113,7 @@ void
  *       -1 if unsuccessful.
  */
 int
-__arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr)
+__arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr, int allow_self)
 {
     pktbuf_t *pkt;
     arp_header_t *arp;
@@ -121,10 +121,12 @@ int
     enet_addr_t   bcast_addr;
     int           retry;
 
-    // Special case request for self
-    if (!memcmp(ip_addr, __local_ip_addr, 4)) {
-        memcpy(eth_addr, __local_enet_addr, sizeof(enet_addr_t));
-        return 0;
+    if (!allow_self) {
+        // Special case request for self
+        if (!memcmp(ip_addr, __local_ip_addr, 4)) {
+            memcpy(eth_addr, __local_enet_addr, sizeof(enet_addr_t));
+            return 0;
+        }
     }
 
     /* just fail if can't get a buffer */
@@ -199,7 +201,7 @@ int
         host = &__local_ip_gate;
 #endif
     }
-    if (__arp_request(host, &rt->enet_addr) < 0) {
+    if (__arp_request(host, &rt->enet_addr, 0) < 0) {
         return -1;
     } else {
         memcpy(&routes[next_arp], rt, sizeof(*rt));
--- a/packages/redboot/current/src/net/net_io.c
+++ b/packages/redboot/current/src/net/net_io.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -679,8 +679,7 @@ net_init(void)
     flash_get_config("net_debug", &net_debug, CONFIG_BOOL);
     flash_get_config("gdb_port", &gdb_port, CONFIG_INT);
     flash_get_config("bootp", &use_bootp, CONFIG_BOOL);
-    if (!use_bootp)
-    {
+    if (!use_bootp) {
         flash_get_IP("bootp_my_ip", &__local_ip_addr);
 #ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
         flash_get_IP("bootp_my_ip_mask", &__local_ip_mask);
@@ -717,7 +716,7 @@ net_init(void)
 	else
 #endif
 	{
-	    for (index = 0; t = net_devtab_entry(index); index++) {
+	    for (index = 0; (t = net_devtab_entry(index)) != NULL; index++) {
 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
 		if (index == default_index)
 		    continue;
@@ -761,7 +760,12 @@ net_init(void)
             }
         }
     } else {
+        enet_addr_t enet_addr;
         have_net = true;  // Assume values in FLASH were OK
+        // Tell the world that we are using this fixed IP address
+        if (__arp_request((ip_addr_t *)__local_ip_addr, &enet_addr, 1) >= 0) {
+            diag_printf("Warning: IP address %s in use\n", inet_ntoa((in_addr_t *)&__local_ip_addr));
+        }
     }
     if (have_net) {
         diag_printf("Ethernet %s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
@@ -825,7 +829,8 @@ do_ip_addr(int argc, char *argv[])
             unsigned long mask;
             *slash_pos = '\0';
             slash_pos++;
-            if( !parse_num(slash_pos, &mask_len, 0, 0) ||  mask_len <= 0 || mask_len > 32 ) {
+            if( !parse_num(slash_pos, (unsigned long *)&mask_len, 0, 0) ||  
+                mask_len <= 0 || mask_len > 32 ) {
                 diag_printf("Invalid mask length: %s\n", slash_pos);
                 return;
             }