third_party/lwip/repo/lwip/src/core/netif.c
/**
 * Add a network interface to the list of lwIP netifs.
 *
 * @param netif a pre-allocated netif structure
 * @param ipaddr IP address for the new netif
 * @param netmask network mask for the new netif
 * @param gw default gateway IP address for the new netif
 * @param state opaque data passed to the new netif
 * @param init callback function that initializes the interface
 * @param input callback function that is called to pass
 * ingress packets up in the protocol layer stack.
 *
 * @return netif, or NULL if failed.
 */
Add a network interface to the list of lwIP netifs.

@return netif, or NULL if failed.
Add a network interface to the list of lwIP netifs . @return netif or NULL if failed .
struct netif *
netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
  ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
{
#if LWIP_IPV6
  u32_t i;
#endif
  LWIP_ASSERT("No init function given", init != NULL);
  ip_addr_set_zero(&netif->ip_addr);
  ip_addr_set_zero(&netif->netmask);
  ip_addr_set_zero(&netif->gw);
#if LWIP_IPV6
  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
    ip6_addr_set_zero(&netif->ip6_addr[i]);
    netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID);
  }
  netif->output_ip6 = netif_null_output_ip6;
#endif 
  netif->flags = 0;
#if LWIP_DHCP
  netif->dhcp = NULL;
#endif 
#if LWIP_AUTOIP
  netif->autoip = NULL;
#endif 
#if LWIP_IPV6_AUTOCONFIG
  netif->ip6_autoconfig_enabled = 0;
#endif 
#if LWIP_IPV6_SEND_ROUTER_SOLICIT
  netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT;
#endif 
#if LWIP_IPV6_DHCP6
  netif->dhcp6 = NULL;
#endif 
#if LWIP_NETIF_STATUS_CALLBACK
  netif->status_callback = NULL;
#endif 
#if LWIP_NETIF_LINK_CALLBACK
  netif->link_callback = NULL;
#endif 
#if LWIP_IGMP
  netif->igmp_mac_filter = NULL;
#endif 
#if LWIP_IPV6 && LWIP_IPV6_MLD
  netif->mld_mac_filter = NULL;
#endif 
#if ENABLE_LOOPBACK
  netif->loop_first = NULL;
  netif->loop_last = NULL;
#endif 
  netif->state = state;
  netif->num = netif_num++;
  netif->input = input;
  NETIF_SET_HWADDRHINT(netif, NULL);
#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
  netif->loop_cnt_current = 0;
#endif 
  netif_set_addr(netif, ipaddr, netmask, gw);
  if (init(netif) != ERR_OK) {
    return NULL;
  }
  netif->next = netif_list;
  netif_list = netif;
  snmp_inc_iflist();
#if LWIP_IGMP
  if (netif->flags & NETIF_FLAG_IGMP) {
    igmp_start(netif);
  }
#endif 
  LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
    netif->name[0], netif->name[1]));
  ip_addr_debug_print(NETIF_DEBUG, ipaddr);
  LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
  ip_addr_debug_print(NETIF_DEBUG, netmask);
  LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
  ip_addr_debug_print(NETIF_DEBUG, gw);
  LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
  return netif;
}
struct netif * netif_add ( struct netif * netif , ip_addr_t * ipaddr , ip_addr_t * netmask , ip_addr_t * gw , void * state , netif_init_fn init , netif_input_fn input ) { #if LWIP_IPV6 u32_t i ; #endif LWIP_ASSERT ( " " , init != NULL ) ; ip_addr_set_zero ( & netif -> ip_addr ) ; ip_addr_set_zero ( & netif -> netmask ) ; ip_addr_set_zero ( & netif -> gw ) ; #if LWIP_IPV6 for ( i = 0 ; i < LWIP_IPV6_NUM_ADDRESSES ; i ++ ) { ip6_addr_set_zero ( & netif -> ip6_addr [ i ] ) ; netif_ip6_addr_set_state ( netif , i , IP6_ADDR_INVALID ) ; } netif -> output_ip6 = netif_null_output_ip6 ; #endif netif -> flags = 0 ; #if LWIP_DHCP netif -> dhcp = NULL ; #endif #if LWIP_AUTOIP netif -> autoip = NULL ; #endif #if LWIP_IPV6_AUTOCONFIG netif -> ip6_autoconfig_enabled = 0 ; #endif #if LWIP_IPV6_SEND_ROUTER_SOLICIT netif -> rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT ; #endif #if LWIP_IPV6_DHCP6 netif -> dhcp6 = NULL ; #endif #if LWIP_NETIF_STATUS_CALLBACK netif -> status_callback = NULL ; #endif #if LWIP_NETIF_LINK_CALLBACK netif -> link_callback = NULL ; #endif #if LWIP_IGMP netif -> igmp_mac_filter = NULL ; #endif #if LWIP_IPV6 && LWIP_IPV6_MLD netif -> mld_mac_filter = NULL ; #endif #if ENABLE_LOOPBACK netif -> loop_first = NULL ; netif -> loop_last = NULL ; #endif netif -> state = state ; netif -> num = netif_num ++ ; netif -> input = input ; NETIF_SET_HWADDRHINT ( netif , NULL ) ; #if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS netif -> loop_cnt_current = 0 ; #endif netif_set_addr ( netif , ipaddr , netmask , gw ) ; if ( init ( netif ) != ERR_OK ) { return NULL ; } netif -> next = netif_list ; netif_list = netif ; snmp_inc_iflist ( ) ; #if LWIP_IGMP if ( netif -> flags & NETIF_FLAG_IGMP ) { igmp_start ( netif ) ; } #endif LWIP_DEBUGF ( NETIF_DEBUG , ( " " , netif -> name [ 0 ] , netif -> name [ 1 ] ) ) ; ip_addr_debug_print ( NETIF_DEBUG , ipaddr ) ; LWIP_DEBUGF ( NETIF_DEBUG , ( " " ) ) ; ip_addr_debug_print ( NETIF_DEBUG , netmask ) ; LWIP_DEBUGF ( NETIF_DEBUG , ( " " ) ) ; ip_addr_debug_print ( NETIF_DEBUG , gw ) ; LWIP_DEBUGF ( NETIF_DEBUG , ( " \n " ) ) ; return netif ; }
Add a network interface to the list of lwIP netifs.
Add a network interface to the list of lwIP netifs .
/* reset new interface configuration state */ /* LWIP_IPV6 */ /* netif not under DHCP control by default */ /* LWIP_DHCP */ /* netif not under AutoIP control by default */ /* LWIP_AUTOIP */ /* IPv6 address autoconfiguration not enabled by default */ /* LWIP_IPV6_AUTOCONFIG */ /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ /* netif not under DHCPv6 control by default */ /* LWIP_IPV6_DHCP6 */ /* LWIP_NETIF_STATUS_CALLBACK */ /* LWIP_NETIF_LINK_CALLBACK */ /* LWIP_IGMP */ /* LWIP_IPV6 && LWIP_IPV6_MLD */ /* ENABLE_LOOPBACK */ /* remember netif specific state information data */ /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */ /* call user specified initialization function for netif */ /* add this netif to the list */ /* start IGMP processing */ /* LWIP_IGMP */