Action of lwip nd when link state changes

When netif up or link up, netif_issue_reports will be called, in which, for nd, rs_count will be reset, so that after the link is up, rs will be resent.

 1 static void
 2 netif_issue_reports(struct netif* netif, u8_t report_type)
 3 {
22 
23 #if LWIP_IPV6
24   if (report_type & NETIF_REPORT_TYPE_IPV6) {
25 #if LWIP_IPV6_MLD
26     /* send mld memberships */
27     mld6_report_groups(netif);
28 #endif /* LWIP_IPV6_MLD */
29 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
30     /* Send Router Solicitation messages. */
31     netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT;
32 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
33   }
34 #endif /* LWIP_IPV6 */
35 }

When netif is down (no link down), the prefix, neighbor, router, and destination cache of nd will be cleared (IPv4 will clear the arp cache)

 1 void
 2 netif_set_down(struct netif *netif)
 3 {
 4   if (netif->flags & NETIF_FLAG_UP) {
 5     netif->flags &= ~NETIF_FLAG_UP;
 6     MIB2_COPY_SYSUPTIME_TO(&netif->ts);
 7 
 8 #if LWIP_IPV6
 9     nd6_cleanup_netif(netif);
10 #endif /* LWIP_IPV6 */
11 
12     NETIF_STATUS_CALLBACK(netif);
13   }
14 }

In nd6_cleanup_netif,

 1 void
 2 nd6_cleanup_netif(struct netif *netif)
 3 {
 4   u8_t i;
 5   s8_t router_index;
 6   for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) {
 7     if (prefix_list[i].netif == netif) {
 8       prefix_list[i].netif = NULL;
 9       prefix_list[i].flags = 0;
10     }
11   }
12   for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
13     if (neighbor_cache[i].netif == netif) {
14       for (router_index = 0; router_index < LWIP_ND6_NUM_ROUTERS; router_index++) {
15         if (default_router_list[router_index].neighbor_entry == &neighbor_cache[i]) {
16           default_router_list[router_index].neighbor_entry = NULL;
17           default_router_list[router_index].flags = 0;
18         }
19       }
20       neighbor_cache[i].isrouter = 0;
21       nd6_free_neighbor_cache_entry(i);
22     }
23   }
24 }

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325065935&siteId=291194637