netif的状态变化可以设置回调函数,
主要有三项变化,
1 netif up or down,address change,address state change(IPv6)
2 link up or down;
3 netif移除
这三项状态变化可以触发用户编写的回调函数
1 #if LWIP_NETIF_STATUS_CALLBACK 2 /** This function is called when the netif state is set to up or down 3 */ 4 netif_status_callback_fn status_callback; 5 #endif /* LWIP_NETIF_STATUS_CALLBACK */ 6 #if LWIP_NETIF_LINK_CALLBACK 7 /** This function is called when the netif link is set to up or down 8 */ 9 netif_status_callback_fn link_callback; 10 #endif /* LWIP_NETIF_LINK_CALLBACK */ 11 #if LWIP_NETIF_REMOVE_CALLBACK 12 /** This function is called when the netif has been removed */ 13 netif_status_callback_fn remove_callback; 14 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
此外,netif变化,还可以触发IP等协议,用的是netif_issue_reports,
netif的变化主要有,
1 netif up; 此处会检查link up是否满足,也满足,才会issue
2 link up; 此处会检查netif up是否满足,也满足,才会issue
3 address change; 此处会检查address state是否是valid,也满足,才会issue
4 address state change(IPv6) 此处会检查状态是否从不有效变为有效,若是,才会issue
对于IPv4,可以发送ARP,IGMP;对于IPv6,可以发送MLD,重新发送RS等。
1 /** Send ARP/IGMP/MLD/RS events, e.g. on link-up/netif-up or addr-change 2 */ 3 static void 4 netif_issue_reports(struct netif* netif, u8_t report_type) 5 { 6 #if LWIP_IPV4 7 if ((report_type & NETIF_REPORT_TYPE_IPV4) && 8 !ip4_addr_isany_val(*netif_ip4_addr(netif))) { 9 #if LWIP_ARP 10 /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */ 11 if (netif->flags & (NETIF_FLAG_ETHARP)) { 12 etharp_gratuitous(netif); 13 } 14 #endif /* LWIP_ARP */ 15 16 #if LWIP_IGMP 17 /* resend IGMP memberships */ 18 if (netif->flags & NETIF_FLAG_IGMP) { 19 igmp_report_groups(netif); 20 } 21 #endif /* LWIP_IGMP */ 22 } 23 #endif /* LWIP_IPV4 */ 24 25 #if LWIP_IPV6 26 if (report_type & NETIF_REPORT_TYPE_IPV6) { 27 #if LWIP_IPV6_MLD 28 /* send mld memberships */ 29 mld6_report_groups(netif); 30 #endif /* LWIP_IPV6_MLD */ 31 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 32 /* Send Router Solicitation messages. */ 33 netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT; 34 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ 35 } 36 #endif /* LWIP_IPV6 */ 37 }
对于ND协议,主要是将rs_count置为初值。
1 netif up; 此处会检查link up是否满足,也满足,才会issue
2 link up; 此处会检查netif up是否满足,也满足,才会issue
3 address change; 此处会检查address state是否是valid,也满足,才会issue
4 address state change(IPv6) 此处会检查状态是否从不有效变为有效,若是,才会issue
ND的前缀信息何时删除???