Quellcode durchsuchen

Merge pull request #330 from hduffddybz/ipv6

Add conditional compilation about IPv6 sources and headers, change code style
Bernard Xiong vor 10 Jahren
Ursprung
Commit
fe4f74a6b1

+ 1 - 1
components/net/SConscript

@@ -7,7 +7,7 @@ objs = []
 list = os.listdir(os.path.join(RTT_ROOT, 'components', 'net'))
 
 # the default version of LWIP is 1.4.1
-if not GetDepend('RT_USING_LWIP132') and not GetDepend('RT_USING_LWIP140'):
+if not GetDepend('RT_USING_LWIP132') and not GetDepend('RT_USING_LWIP140') and not GetDepend('RT_USING_LWIP_HEAD'):
     AddDepend('RT_USING_LWIP141')
 
 for d in list:

+ 4 - 0
components/net/lwip-head/CHANGELOG

@@ -6,6 +6,10 @@ HISTORY
 
  ++ New features:
 
+  2013-08-19: Simon Goldschmidt
+  * netif.h: bug #42998: made NETIF_MAX_HWADDR_LEN overridable for some special
+    networks
+
   2013-03-17: Simon Goldschmidt (patch by Ghobad Emadi)
   * opt.h, etharp.c: Added LWIP_HOOK_ETHARP_GET_GW to implement IPv4 routing with
     multiple gateways

+ 10 - 4
components/net/lwip-head/SConscript

@@ -29,12 +29,18 @@ src/core/tcp_out.c
 src/core/timers.c
 src/core/udp.c
 src/core/inet_chksum.c
+src/netif/etharp.c
+src/netif/ethernetif.c
+src/netif/slipif.c
 src/core/ipv4/autoip.c
 src/core/ipv4/icmp.c
 src/core/ipv4/igmp.c
 src/core/ipv4/ip4.c
 src/core/ipv4/ip4_addr.c
 src/core/ipv4/ip_frag.c
+""")
+
+ipv6_src = Split("""
 src/core/ipv6/dhcp6.c
 src/core/ipv6/ethip6.c
 src/core/ipv6/icmp6.c
@@ -44,9 +50,6 @@ src/core/ipv6/ip6.c
 src/core/ipv6/ip6_frag.c
 src/core/ipv6/mld6.c
 src/core/ipv6/nd6.c
-src/netif/etharp.c
-src/netif/ethernetif.c
-src/netif/slipif.c
 """)
 
 snmp_src = Split("""
@@ -91,10 +94,13 @@ src/netif/ppp/polarssl/sha1.c
 path = [GetCurrentDir() + '/src',
     GetCurrentDir() + '/src/include',
     GetCurrentDir() + '/src/include/ipv4',
-	GetCurrentDir() + '/src/include/ipv6',
+    GetCurrentDir() + '/src/include/ipv6',
     GetCurrentDir() + '/src/arch/include',
     GetCurrentDir() + '/src/include/netif']
 
+if GetDepend(['RT_LWIP_IPV6']):
+    src += ipv6_src
+
 if GetDepend(['RT_LWIP_SNMP']):
     src += snmp_src
 

+ 9 - 16
components/net/lwip-head/src/arch/sys_arch.c

@@ -95,15 +95,16 @@ static void tcpip_init_done_callback(void *arg)
             if (netif_default == RT_NULL)
                 netif_set_default(ethif->netif);
 #ifdef LWIP_IPV6
-			ethif->netif->output_ip6 = ethip6_output;
-			netif_create_ip6_linklocal_address(ethif->netif, 1);
-	#ifdef LWIP_IPV6_AUTOCONFIG
-			ethif->netif->ip6_autoconfig_enabled = 1;
-	#endif
-	#ifdef LWIP_IPV6_MLD
-			ethif->netif->mld_mac_filter = NULL;
-	#endif
+            ethif->netif->output_ip6 = ethip6_output;
+            netif_create_ip6_linklocal_address(ethif->netif, 1);
+#ifdef LWIP_IPV6_AUTOCONFIG
+            ethif->netif->ip6_autoconfig_enabled = 1;
 #endif
+#ifdef LWIP_IPV6_MLD
+            ethif->netif->mld_mac_filter = NULL;
+#endif
+#endif
+
 #if LWIP_DHCP
             if (ethif->flags & NETIF_FLAG_DHCP)
             {
@@ -175,14 +176,6 @@ int lwip_system_init(void)
         netifapi_netif_set_addr(netif_default, &ipaddr, &netmask, &gw);
     }
 #endif
-/*#if LWIP_IPV6 && LWIP_IPV6_MLD
-	ip6_addr_t ip6addr_group;
-	IP6_ADDR(&ip6addr_group, 0, 0xfe, 0x80, 0x00, 0x00);
-	IP6_ADDR(&ip6addr_group, 0, 0x00, 0x00, 0x00, 0x00);
-	IP6_ADDR(&ip6addr_group, 0, 0x00, 0x00, 0x00, 0x00);
-	IP6_ADDR(&ip6addr_group, 0, 0x00, 0x00, 0x00, 0x01);
-	netif_mld_mac_filter_fn(netif_default, &ip6addr_group, 0);
-#endif*/
 	rt_kprintf("lwIP-%d.%d.%d initialized!\n", LWIP_VERSION_MAJOR, LWIP_VERSION_MINOR, LWIP_VERSION_REVISION);
 
 	return 0;

+ 1 - 1
components/net/lwip-head/src/core/init.c

@@ -106,7 +106,7 @@
   #error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h"
 #endif
 /* There must be sufficient timeouts, taking into account requirements of the subsystems. */
-#if (LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0))))
+#if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)))
   #error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts"
 #endif
 #if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS))

+ 5 - 2
components/net/lwip-head/src/include/lwip/netif.h

@@ -60,9 +60,12 @@ extern "C" {
 /* Throughout this file, IP addresses are expected to be in
  * the same byte order as in IP_PCB. */
 
-/** must be the maximum of all used hardware address lengths
-    across all types of interfaces in use */
+/** Must be the maximum of all used hardware address lengths
+    across all types of interfaces in use.
+    This does not have to be changed, normally. */
+#ifndef NETIF_MAX_HWADDR_LEN
 #define NETIF_MAX_HWADDR_LEN 6U
+#endif
 
 /** Whether the network interface is 'up'. This is
  * a software flag used to control whether this network

+ 1 - 1
components/net/lwip-head/src/include/lwip/opt.h

@@ -502,7 +502,7 @@
  *  Old packets are dropped, new packets are queued.
  */ 
 #ifndef ARP_QUEUE_LEN
-#define ARP_QUEUE_LEN 3
+#define ARP_QUEUE_LEN                   3
 #endif
 
 /**

+ 6 - 5
components/net/lwip-head/src/lwipopts.h

@@ -10,14 +10,15 @@
 #define LWIP_NETCONN                1
 
 #ifdef RT_LWIP_IPV6
-#define LWIP_IPV6		   			1
+#define LWIP_IPV6                   1
 //#define LWIP_IPV6_DHCP6	       	    1
-#define LWIP_ICMP6		    		1
-#define LWIP_IPV6_NUM_ADDRESSES	    3
-#endif
+#define LWIP_ICMP6                  1
+#define LWIP_IPV6_NUM_ADDRESSES     3
 
 #ifdef RT_LWIP_IPV6_AUTOCONFIG
-#define LWIP_IPV6_AUTOCONFIG	    1
+#define LWIP_IPV6_AUTOCONFIG        1
+#endif
+
 #endif
 
 #ifdef RT_LWIP_IPV6_MLD

+ 23 - 21
components/net/lwip-head/src/netif/ethernetif.c

@@ -208,18 +208,18 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_
     /* if tcp thread has been started up, we add this netif to the system */
     if (rt_thread_find("tcpip") != RT_NULL)
     {
-		struct ip_addr ipaddr, netmask, gw;
+        struct ip_addr ipaddr, netmask, gw;
 #if !LWIP_DHCP
-      	IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
+        IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
         IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
         IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
 
 #else
-		IP4_ADDR(&ipaddr, 0, 0, 0, 0);
-		IP4_ADDR(&gw, 0, 0, 0, 0);
-		IP4_ADDR(&netmask, 0, 0, 0, 0);
+        IP4_ADDR(&ipaddr, 0, 0, 0, 0);
+        IP4_ADDR(&gw, 0, 0, 0, 0);
+        IP4_ADDR(&netmask, 0, 0, 0, 0);
 #endif
-		netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
+        netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
     }
 
     return RT_EOK;
@@ -437,6 +437,7 @@ void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
 }
 FINSH_FUNCTION_EXPORT(set_if, set network interface address);
 
+#if LWIP_IPV6
 void set_if6(char* netif_name, char* ip6_addr)
 {
 	struct netif* netif = netif_list;
@@ -467,6 +468,7 @@ void set_if6(char* netif_name, char* ip6_addr)
 	}	
 }
 FINSH_FUNCTION_EXPORT(set_if6, set ipv6 local address)
+#endif
 
 #if LWIP_DNS
 #include <lwip/dns.h>
@@ -514,12 +516,12 @@ void list_if(void)
         rt_kprintf("ip address: %s\n", ipaddr_ntoa(&(netif->ip_addr)));
         rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw)));
         rt_kprintf("net mask  : %s\n", ipaddr_ntoa(&(netif->netmask)));
-		
-		rt_kprintf("link-local address: %s\n", ip6addr_ntoa(&(netif->ip6_addr[0])));
-		rt_kprintf("ipv6[1] address: %s\n", ip6addr_ntoa(&(netif->ip6_addr[1])));
-		rt_kprintf("\r\n");
-
-		netif = netif->next;
+#if LWIP_IPV6	
+        rt_kprintf("link-local address: %s\n", ip6addr_ntoa(&(netif->ip6_addr[0])));
+        rt_kprintf("ipv6[1] address: %s\n", ip6addr_ntoa(&(netif->ip6_addr[1])));
+        rt_kprintf("\r\n");
+#endif
+        netif = netif->next;
     }
 
 #if LWIP_DNS
@@ -558,13 +560,13 @@ void list_tcps(void)
     rt_kprintf("Active PCB states:\n");
     for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
     {
-			#ifndef LWIP_IPV6
+#ifndef LWIP_IPV6
         strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip)));
         strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip)));
-			#else
-				strcpy(local_ip_str, ip6addr_ntoa((ip6_addr_t *)&(pcb->local_ip)));
+#else
+        strcpy(local_ip_str, ip6addr_ntoa((ip6_addr_t *)&(pcb->local_ip)));
         strcpy(remote_ip_str, ip6addr_ntoa((ip6_addr_t *)&(pcb->remote_ip)));
-			#endif
+#endif
         rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ",
                    num++,
                    local_ip_str,
@@ -588,13 +590,13 @@ void list_tcps(void)
     num = 0;
     for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next)
     {
-			#ifndef LWIP_IPV6
-				strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip)));
+#ifndef LWIP_IPV6
+        strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip)));
         strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip)));
-			#else
-				strcpy(local_ip_str, ip6addr_ntoa((ip6_addr_t *)&(pcb->local_ip)));
+#else
+        strcpy(local_ip_str, ip6addr_ntoa((ip6_addr_t *)&(pcb->local_ip)));
         strcpy(remote_ip_str, ip6addr_ntoa((ip6_addr_t *)&(pcb->remote_ip)));
-			#endif
+#endif
 
         rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ",
                    num++,

+ 4 - 5
components/net/lwip-head/test/unit/dhcp/test_dhcp.c

@@ -369,7 +369,6 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
     case 3:
     case 4:
     case 5:
-    case 6:
       {
         const u8_t arpproto[] = { 0x08, 0x06 };
 
@@ -379,7 +378,7 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
         check_pkt(p, 12, arpproto, sizeof(arpproto)); /* eth level proto: ip */
         break;
       }
-    case 7:
+    case 6:
       {
         const u8_t fake_arp[6] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab };
         const u8_t ipproto[] = { 0x08, 0x00 };
@@ -773,13 +772,13 @@ START_TEST(test_dhcp_relayed)
   }
 
   fail_unless(netif_is_up(&net_test));
-  fail_unless(txpacket == 6, "txpacket = %d", txpacket);
+  fail_unless(txpacket == 5, "txpacket = %d", txpacket);
 
   /* We need to send arp response here.. */
 
   send_pkt(&net_test, arp_resp, sizeof(arp_resp));
 
-  fail_unless(txpacket == 7, "txpacket = %d", txpacket);
+  fail_unless(txpacket == 6, "txpacket = %d", txpacket);
   fail_unless(netif_is_up(&net_test));
 
   xid = htonl(net_test.dhcp->xid); /* xid updated */
@@ -790,7 +789,7 @@ START_TEST(test_dhcp_relayed)
     tick_lwip();
   }
 
-  fail_unless(txpacket == 7, "txpacket = %d", txpacket);
+  fail_unless(txpacket == 6, "txpacket = %d", txpacket);
 
   netif_remove(&net_test);