Microchip® Advanced Software Framework

netif.c File Reference

lwIP network interface abstraction

#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/ip_addr.h"
#include "lwip/ip6_addr.h"
#include "lwip/netif.h"
#include "lwip/tcp_impl.h"
#include "lwip/snmp.h"
#include "lwip/igmp.h"
#include "netif/etharp.h"
#include "lwip/stats.h"
#include "lwip/autoip.h"
#include "lwip/dhcp.h"
#include "lwip/mld6.h"

Macros

#define ipX_input(in, netif)   (IP6H_V((const struct ip6_hdr *)in->payload) == 6) ? ip6_input(in, netif) : ip_input(in, netif)
 
#define NETIF_LINK_CALLBACK(n)
 
#define NETIF_STATUS_CALLBACK(n)   do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)
 

Functions

struct netifnetif_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)
 Add a network interface to the list of lwIP netifs. More...
 
void netif_create_ip6_linklocal_address (struct netif *netif, u8_t from_mac_48bit)
 
struct netifnetif_find (char *name)
 Find a network interface by searching for its name. More...
 
s8_t netif_get_ip6_addr_match (struct netif *netif, ip6_addr_t *ip6addr)
 
void netif_init (void)
 
static err_t netif_null_output_ip6 (struct netif *netif, struct pbuf *p, ip6_addr_t *ipaddr)
 
void netif_remove (struct netif *netif)
 Remove a network interface from the list of lwIP netifs. More...
 
void netif_set_addr (struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)
 Change IP address configuration for a network interface (including netmask and default gateway). More...
 
void netif_set_default (struct netif *netif)
 Set a network interface as the default network interface (used to output all packets for which no specific route is found) More...
 
void netif_set_down (struct netif *netif)
 Bring an interface down, disabling any traffic processing. More...
 
void netif_set_gw (struct netif *netif, ip_addr_t *gw)
 Change the default gateway for a network interface. More...
 
void netif_set_ipaddr (struct netif *netif, ip_addr_t *ipaddr)
 Change the IP address of a network interface. More...
 
void netif_set_link_down (struct netif *netif)
 Called by a driver when its link goes down. More...
 
void netif_set_link_up (struct netif *netif)
 Called by a driver when its link goes up. More...
 
void netif_set_netmask (struct netif *netif, ip_addr_t *netmask)
 Change the netmask of a network interface. More...
 
void netif_set_status_callback (struct netif *netif, netif_status_callback_fn status_callback)
 Set callback to be called when interface is brought up/down. More...
 
void netif_set_up (struct netif *netif)
 Bring an interface up, available for processing traffic. More...
 

Variables

struct netifnetif_default
 The default network interface. More...
 
struct netifnetif_list
 The list of network interfaces. More...
 
static u8_t netif_num
 

#define ipX_input (   in,
  netif 
)    (IP6H_V((const struct ip6_hdr *)in->payload) == 6) ? ip6_input(in, netif) : ip_input(in, netif)
#define NETIF_LINK_CALLBACK (   n)
#define NETIF_STATUS_CALLBACK (   n)    do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)

Referenced by netif_set_down(), and netif_set_up().

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 
)

Add a network interface to the list of lwIP netifs.

Parameters
netifa pre-allocated netif structure
ipaddrIP address for the new netif
netmasknetwork mask for the new netif
gwdefault gateway IP address for the new netif
stateopaque data passed to the new netif
initcallback function that initializes the interface
inputcallback function that is called to pass ingress packets up in the protocol layer stack.
Returns
netif, or NULL if failed.

References netif::autoip, netif::dhcp, ERR_OK, netif::flags, netif::gw, netif::input, netif::ip6_addr, IP6_ADDR_INVALID, ip6_addr_set_zero, netif::ip6_autoconfig_enabled, netif::ip_addr, ip_addr_debug_print, ip_addr_set_zero, LWIP_ASSERT, LWIP_DEBUGF, netif::mld_mac_filter, netif::name, NETIF_DEBUG, NETIF_FLAG_IGMP, netif_ip6_addr_set_state, netif_list, netif_null_output_ip6(), netif_num, netif_set_addr(), NETIF_SET_HWADDRHINT, netif::netmask, netif::next, NULL, netif::num, netif::output_ip6, netif::rs_count, snmp_inc_iflist, netif::state, and netif::status_callback.

Referenced by net_add_wilc_netif(), and netif_init().

void netif_create_ip6_linklocal_address ( struct netif netif,
u8_t  from_mac_48bit 
)
struct netif* netif_find ( char *  name)

Find a network interface by searching for its name.

Parameters
namethe name of the netif (like netif->name) plus concatenated number in ascii representation (e.g. 'en0')

References LWIP_DEBUGF, netif::name, NETIF_DEBUG, netif::next, NULL, and netif::num.

s8_t netif_get_ip6_addr_match ( struct netif netif,
ip6_addr_t ip6addr 
)

References ip6_addr_cmp, and netif_ip6_addr.

Referenced by udp_input().

static err_t netif_null_output_ip6 ( struct netif netif,
struct pbuf p,
ip6_addr_t ipaddr 
)
static

References ERR_IF, and void.

Referenced by netif_add().

void netif_remove ( struct netif netif)

Remove a network interface from the list of lwIP netifs.

Parameters
netifthe network interface to remove

References netif::flags, LWIP_DEBUGF, mld6_stop(), NETIF_DEBUG, NETIF_FLAG_IGMP, netif_is_up, netif_set_default(), netif_set_down(), netif::next, NULL, snmp_dec_iflist, and snmp_delete_ipaddridx_tree.

Referenced by net_remove_wilc_netif().

void netif_set_addr ( struct netif netif,
ip_addr_t ipaddr,
ip_addr_t netmask,
ip_addr_t gw 
)

Change IP address configuration for a network interface (including netmask and default gateway).

Parameters
netifthe network interface to change
ipaddrthe new IP address
netmaskthe new netmask
gwthe new default gateway

References netif_set_gw(), netif_set_ipaddr(), and netif_set_netmask().

Referenced by net_set_interface_address(), and netif_add().

void netif_set_default ( struct netif netif)

Set a network interface as the default network interface (used to output all packets for which no specific route is found)

Parameters
netifthe default network interface

References LWIP_DEBUGF, netif::name, NETIF_DEBUG, NULL, snmp_delete_iprteidx_tree, and snmp_insert_iprteidx_tree.

Referenced by net_add_wilc_netif(), and netif_remove().

void netif_set_down ( struct netif netif)

Bring an interface down, disabling any traffic processing.

Note
: Enabling DHCP on a down interface will make it come up once configured.
See Also
dhcp_start()

References etharp_cleanup_netif(), netif::flags, NETIF_FLAG_ETHARP, NETIF_FLAG_UP, NETIF_STATUS_CALLBACK, and snmp_get_sysuptime.

Referenced by autoip_network_changed(), autoip_start(), autoip_stop(), dhcp_handle_nak(), dhcp_network_changed(), dhcp_release(), net_interface_down_imp(), and netif_remove().

void netif_set_gw ( struct netif netif,
ip_addr_t gw 
)

Change the default gateway for a network interface.

Parameters
netifthe network interface to change
gwthe new default gateway
Note
call netif_set_addr() if you also want to change ip address and netmask

References netif::gw, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, ip_addr_set, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, NETIF_DEBUG, and U16_F.

Referenced by autoip_bind(), dhcp_bind(), dhcp_handle_nak(), dhcp_release(), and netif_set_addr().

void netif_set_ipaddr ( struct netif netif,
ip_addr_t ipaddr 
)
void netif_set_link_down ( struct netif netif)

Called by a driver when its link goes down.

References netif::flags, NETIF_FLAG_LINK_UP, and NETIF_LINK_CALLBACK.

Referenced by net_interface_down_imp().

void netif_set_netmask ( struct netif netif,
ip_addr_t netmask 
)

Change the netmask of a network interface.

Parameters
netifthe network interface to change
netmaskthe new netmask
Note
call netif_set_addr() if you also want to change ip address and default gateway

References ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, ip_addr_set, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, NETIF_DEBUG, netif::netmask, snmp_delete_iprteidx_tree, snmp_insert_iprteidx_tree, and U16_F.

Referenced by autoip_bind(), dhcp_bind(), dhcp_handle_nak(), dhcp_release(), and netif_set_addr().

void netif_set_status_callback ( struct netif netif,
netif_status_callback_fn  status_callback 
)

Set callback to be called when interface is brought up/down.

References status_callback(), and netif::status_callback.

Referenced by net_add_wilc_netif().

void netif_set_up ( struct netif netif)

Bring an interface up, available for processing traffic.

Note
: Enabling DHCP on a down interface will make it come up once configured.
See Also
dhcp_start()

References etharp_gratuitous, netif::flags, mld6_report_groups(), NETIF_FLAG_ETHARP, NETIF_FLAG_IGMP, NETIF_FLAG_LINK_UP, NETIF_FLAG_UP, NETIF_STATUS_CALLBACK, netif::rs_count, and snmp_get_sysuptime.

Referenced by autoip_bind(), dhcp_bind(), net_interface_up_imp(), and netif_init().

struct netif* netif_default

The default network interface.

Referenced by ip6_route(), and ip_route().

u8_t netif_num
static

Referenced by netif_add().