5252#include "lwip/dns.h"
5353#include "lwip/dhcp.h"
5454#include "netif/ethernet.h"
55+ #if LWIP_IPV6
56+ #include "lwip/ethip6.h"
57+ #endif
5558
5659#include "ticks.h"
5760
@@ -541,6 +544,10 @@ static err_t eth_netif_init(struct netif *netif) {
541544 netif -> output = etharp_output ;
542545 netif -> mtu = 1500 ;
543546 netif -> flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP ;
547+ #if LWIP_IPV6
548+ netif -> output_ip6 = ethip6_output ;
549+ netif -> flags |= NETIF_FLAG_MLD6 ;
550+ #endif
544551 // Checksums only need to be checked on incoming frames, not computed on outgoing frames
545552 NETIF_SET_CHECKSUM_CTRL (netif ,
546553 NETIF_CHECKSUM_CHECK_IP
@@ -556,25 +563,31 @@ static void eth_lwip_init(eth_t *self) {
556563 struct netif * n = & self -> netif ;
557564 ip_addr_t ipconfig [4 ];
558565
566+ #if LWIP_IPV6
567+ for (int i = 0 ; i < 4 ; i ++ ) {
568+ IP_ADDR4 (& ipconfig [i ], 0 , 0 , 0 , 0 );
569+ }
570+ #endif
571+
559572 self -> netif .hwaddr_len = 6 ;
560573 if (self == & eth_instance0 ) {
561574 memcpy (self -> netif .hwaddr , hw_addr , 6 );
562- IP4_ADDR (& ipconfig [0 ], 192 , 168 , 0 , 2 );
575+ IP_ADDR4 (& ipconfig [0 ], 192 , 168 , 0 , 2 );
563576 #if defined ENET_DUAL_PORT
564577 } else {
565578 memcpy (self -> netif .hwaddr , hw_addr_1 , 6 );
566- IP4_ADDR (& ipconfig [0 ], 192 , 168 , 0 , 3 );
579+ IP_ADDR4 (& ipconfig [0 ], 192 , 168 , 0 , 3 );
567580 #endif
568581 }
569- IP4_ADDR (& ipconfig [1 ], 255 , 255 , 255 , 0 );
570- IP4_ADDR (& ipconfig [2 ], 192 , 168 , 0 , 1 );
571- IP4_ADDR (& ipconfig [3 ], 8 , 8 , 8 , 8 );
582+ IP_ADDR4 (& ipconfig [1 ], 255 , 255 , 255 , 0 );
583+ IP_ADDR4 (& ipconfig [2 ], 192 , 168 , 0 , 1 );
584+ IP_ADDR4 (& ipconfig [3 ], 8 , 8 , 8 , 8 );
572585
573586 MICROPY_PY_LWIP_ENTER
574587
575588 n -> name [0 ] = 'e' ;
576589 n -> name [1 ] = (self == & eth_instance0 ? '0' : '1' );
577- netif_add (n , & ipconfig [0 ], & ipconfig [1 ], & ipconfig [2 ], self , eth_netif_init , ethernet_input );
590+ netif_add (n , ip_2_ip4 ( & ipconfig [0 ]), ip_2_ip4 ( & ipconfig [1 ]), ip_2_ip4 ( & ipconfig [2 ]) , self , eth_netif_init , ethernet_input );
578591 netif_set_hostname (n , mod_network_hostname_data );
579592 netif_set_default (n );
580593 netif_set_up (n );
@@ -585,6 +598,10 @@ static void eth_lwip_init(eth_t *self) {
585598
586599 netif_set_link_up (n );
587600
601+ #if LWIP_IPV6
602+ netif_create_ip6_linklocal_address (n , 1 );
603+ #endif
604+
588605 MICROPY_PY_LWIP_EXIT
589606}
590607
@@ -593,7 +610,7 @@ static void eth_lwip_deinit(eth_t *self) {
593610 for (struct netif * netif = netif_list ; netif != NULL ; netif = netif -> next ) {
594611 if (netif == & self -> netif ) {
595612 netif_remove (netif );
596- netif -> ip_addr . addr = 0 ;
613+ netif_set_addr ( netif , IP4_ADDR_ANY4 , IP4_ADDR_ANY4 , IP4_ADDR_ANY4 ) ;
597614 netif -> flags = 0 ;
598615 }
599616 }
@@ -608,7 +625,7 @@ int eth_link_status(eth_t *self) {
608625 struct netif * netif = & self -> netif ;
609626 if ((netif -> flags & (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP ))
610627 == (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP )) {
611- if (netif -> ip_addr . addr != 0 ) {
628+ if (! ip4_addr_isany_val ( * netif_ip4_addr ( netif )) ) {
612629 return 3 ; // link up
613630 } else {
614631 return 2 ; // link no-ip;
0 commit comments