MeterLogger
Data Structures | Macros | Typedefs | Functions | Variables
netif.h File Reference
#include "lwip/opt.h"
#include "lwip/err.h"
#include "lwip/ip_addr.h"
#include "lwip/def.h"
#include "lwip/pbuf.h"
Include dependency graph for netif.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  netif
 

Macros

#define ENABLE_LOOPBACK   (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
 
#define NETIF_MAX_HWADDR_LEN   6U
 
#define NETIF_FLAG_UP   0x01U
 
#define NETIF_FLAG_BROADCAST   0x02U
 
#define NETIF_FLAG_POINTTOPOINT   0x04U
 
#define NETIF_FLAG_DHCP   0x08U
 
#define NETIF_FLAG_LINK_UP   0x10U
 
#define NETIF_FLAG_ETHARP   0x20U
 
#define NETIF_FLAG_ETHERNET   0x40U
 
#define NETIF_FLAG_IGMP   0x80U
 
#define NETIF_INIT_SNMP(netif, type, speed)
 
#define netif_is_up(netif)   (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
 
#define netif_is_link_up(netif)   (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
 

Typedefs

typedef err_t(* netif_init_fn) (struct netif *netif)
 
typedef err_t(* netif_input_fn) (struct pbuf *p, struct netif *inp)
 
typedef err_t(* netif_output_fn) (struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
 
typedef err_t(* netif_linkoutput_fn) (struct netif *netif, struct pbuf *p)
 
typedef void(* netif_status_callback_fn) (struct netif *netif)
 
typedef err_t(* netif_igmp_mac_filter_fn) (struct netif *netif, ip_addr_t *group, u8_t action)
 
typedef void(* dhcp_event_fn) (void)
 

Functions

void netif_init (void) ICACHE_FLASH_ATTR
 
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) ICACHE_FLASH_ATTR
 
void netif_set_addr (struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) ICACHE_FLASH_ATTR
 
void netif_remove (struct netif *netif) ICACHE_FLASH_ATTR
 
struct netifnetif_find (char *name) ICACHE_FLASH_ATTR
 
void netif_set_default (struct netif *netif) ICACHE_FLASH_ATTR
 
void netif_set_ipaddr (struct netif *netif, ip_addr_t *ipaddr) ICACHE_FLASH_ATTR
 
void netif_set_netmask (struct netif *netif, ip_addr_t *netmask) ICACHE_FLASH_ATTR
 
void netif_set_gw (struct netif *netif, ip_addr_t *gw) ICACHE_FLASH_ATTR
 
void netif_set_up (struct netif *netif) ICACHE_FLASH_ATTR
 
void netif_set_down (struct netif *netif) ICACHE_FLASH_ATTR
 
void netif_set_link_up (struct netif *netif) ICACHE_FLASH_ATTR
 
void netif_set_link_down (struct netif *netif) ICACHE_FLASH_ATTR
 

Variables

struct netifnetif_list
 
struct netifnetif_default
 

Macro Definition Documentation

◆ ENABLE_LOOPBACK

#define ENABLE_LOOPBACK   (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)

Definition at line 37 of file netif.h.

◆ NETIF_FLAG_BROADCAST

#define NETIF_FLAG_BROADCAST   0x02U

If set, the netif has broadcast capability. Set by the netif driver in its init function.

Definition at line 72 of file netif.h.

Referenced by ip4_addr_isbroadcast().

◆ NETIF_FLAG_DHCP

#define NETIF_FLAG_DHCP   0x08U

If set, the interface is configured using DHCP. Set by the DHCP code when starting or stopping DHCP.

Definition at line 78 of file netif.h.

◆ NETIF_FLAG_ETHARP

#define NETIF_FLAG_ETHARP   0x20U

If set, the netif is an ethernet device using ARP. Set by the netif driver in its init function. Used to check input packet types and use of DHCP.

Definition at line 88 of file netif.h.

Referenced by netif_set_down(), netif_set_link_up(), netif_set_up(), tcpip_input(), and tcpip_thread().

◆ NETIF_FLAG_ETHERNET

#define NETIF_FLAG_ETHERNET   0x40U

If set, the netif is an ethernet device. It might not use ARP or TCP/IP if it is used for PPPoE only.

Definition at line 92 of file netif.h.

Referenced by tcpip_input(), and tcpip_thread().

◆ NETIF_FLAG_IGMP

#define NETIF_FLAG_IGMP   0x80U

If set, the netif has IGMP capability. Set by the netif driver in its init function.

Definition at line 95 of file netif.h.

Referenced by ip_input(), netif_add(), netif_remove(), netif_set_link_up(), and netif_set_up().

◆ NETIF_FLAG_LINK_UP

#define NETIF_FLAG_LINK_UP   0x10U

If set, the interface has an active link (set by the network interface driver). Either set by the netif driver in its init function (if the link is up at that time) or at a later point once the link comes up (if link detection is supported by the hardware).

Definition at line 84 of file netif.h.

Referenced by netif_set_link_down(), netif_set_link_up(), and netif_set_up().

◆ NETIF_FLAG_POINTTOPOINT

#define NETIF_FLAG_POINTTOPOINT   0x04U

If set, the netif is one end of a point-to-point connection. Set by the netif driver in its init function.

Definition at line 75 of file netif.h.

◆ NETIF_FLAG_UP

#define NETIF_FLAG_UP   0x01U

Whether the network interface is 'up'. This is a software flag used to control whether this network interface is enabled and processes traffic. It is set by the startup code (for static IP configuration) or by dhcp/autoip when an address has been assigned.

Definition at line 69 of file netif.h.

Referenced by netif_set_down(), netif_set_link_up(), and netif_set_up().

◆ NETIF_INIT_SNMP

#define NETIF_INIT_SNMP (   netif,
  type,
  speed 
)

Definition at line 252 of file netif.h.

◆ netif_is_link_up

#define netif_is_link_up (   netif)    (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)

Ask if a link is up

Definition at line 295 of file netif.h.

◆ netif_is_up

#define netif_is_up (   netif)    (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)

Ask if an interface is up

Definition at line 286 of file netif.h.

Referenced by espconn_udp_sendto(), espconn_udp_sent(), ip_input(), ip_route(), ip_router(), and netif_remove().

◆ NETIF_MAX_HWADDR_LEN

#define NETIF_MAX_HWADDR_LEN   6U

must be the maximum of all used hardware address lengths across all types of interfaces in use

Definition at line 61 of file netif.h.

Typedef Documentation

◆ dhcp_event_fn

typedef void(* dhcp_event_fn) (void)

Definition at line 134 of file netif.h.

◆ netif_igmp_mac_filter_fn

typedef err_t(* netif_igmp_mac_filter_fn) (struct netif *netif, ip_addr_t *group, u8_t action)

Function prototype for netif igmp_mac_filter functions

Definition at line 130 of file netif.h.

◆ netif_init_fn

typedef err_t(* netif_init_fn) (struct netif *netif)

Function prototype for netif init functions. Set up flags and output/linkoutput callback functions in this function.

Parameters
netifThe netif to initialize

Definition at line 102 of file netif.h.

◆ netif_input_fn

typedef err_t(* netif_input_fn) (struct pbuf *p, struct netif *inp)

Function prototype for netif->input functions. This function is saved as 'input' callback function in the netif struct. Call it when a packet has been received.

Parameters
pThe received packet, copied into a pbuf
inpThe netif which received the packet

Definition at line 109 of file netif.h.

◆ netif_linkoutput_fn

typedef err_t(* netif_linkoutput_fn) (struct netif *netif, struct pbuf *p)

Function prototype for netif->linkoutput functions. Only used for ethernet netifs. This function is called by ARP when a packet shall be sent.

Parameters
netifThe netif which shall send a packet
pThe packet to send (raw ethernet packet)

Definition at line 126 of file netif.h.

◆ netif_output_fn

typedef err_t(* netif_output_fn) (struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)

Function prototype for netif->output functions. Called by lwIP when a packet shall be sent. For ethernet netif, set this to 'etharp_output' and set 'linkoutput'.

Parameters
netifThe netif which shall send a packet
pThe packet to send (p->payload points to IP header)
ipaddrThe IP address to which the packet shall be sent

Definition at line 118 of file netif.h.

◆ netif_status_callback_fn

typedef void(* netif_status_callback_fn) (struct netif *netif)

Function prototype for netif status- or link-callback functions.

Definition at line 128 of file netif.h.

Function Documentation

◆ netif_add()

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.

Definition at line 137 of file netif.c.

References ERR_OK, netif::flags, netif::gw, netif::input, netif::ip_addr, ip_addr_debug_print, ip_addr_set_zero, LWIP_ASSERT, LWIP_DEBUGF, netif::name, NETIF_DEBUG, NETIF_FLAG_IGMP, netif_list, netif_set_addr(), netif::netmask, netif::next, NULL, netif::num, snmp_inc_iflist, state, and netif::state.

Referenced by netif_init().

139 {
140  static u8_t netifnum = 0;
141 
142  LWIP_ASSERT("No init function given", init != NULL);
143 
144  /* reset new interface configuration state */
145  ip_addr_set_zero(&netif->ip_addr);
146  ip_addr_set_zero(&netif->netmask);
147  ip_addr_set_zero(&netif->gw);
148  netif->flags = 0;
149 #if LWIP_DHCP
150  /* netif not under DHCP control by default */
151  netif->dhcp = NULL;
152  netif->dhcps_pcb = NULL;
153 #endif /* LWIP_DHCP */
154 #if LWIP_AUTOIP
155  /* netif not under AutoIP control by default */
156  netif->autoip = NULL;
157 #endif /* LWIP_AUTOIP */
158 #if LWIP_NETIF_STATUS_CALLBACK
159  netif->status_callback = NULL;
160 #endif /* LWIP_NETIF_STATUS_CALLBACK */
161 #if LWIP_NETIF_LINK_CALLBACK
162  netif->link_callback = NULL;
163 #endif /* LWIP_NETIF_LINK_CALLBACK */
164 #if LWIP_IGMP
165  netif->igmp_mac_filter = NULL;
166 #endif /* LWIP_IGMP */
167 #if ENABLE_LOOPBACK
168  netif->loop_first = NULL;
169  netif->loop_last = NULL;
170 #endif /* ENABLE_LOOPBACK */
171 
172  /* remember netif specific state information data */
173  netif->state = state;
174  netif->num = netifnum++;
175  netif->input = input;
176 #if LWIP_NETIF_HWADDRHINT
177  netif->addr_hint = NULL;
178 #endif /* LWIP_NETIF_HWADDRHINT*/
179 #if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
180  netif->loop_cnt_current = 0;
181 #endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
182 
183 #if IP_NAPT
184  netif->napt = 0;
185 #endif /* IP_NAPT */
186 
187  netif_set_addr(netif, ipaddr, netmask, gw);
188 
189  /* call user specified initialization function for netif */
190  if (init(netif) != ERR_OK) {
191  return NULL;
192  }
193 
194  /* add this netif to the list */
195  netif->next = netif_list;
196  netif_list = netif;
197  snmp_inc_iflist();
198 
199 #if LWIP_IGMP
200  /* start IGMP processing */
201  if (netif->flags & NETIF_FLAG_IGMP) {
202  igmp_start(netif);
203  }
204 #endif /* LWIP_IGMP */
205 
206  LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
207  netif->name[0], netif->name[1]));
209  LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
211  LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
213  LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
214  return netif;
215 }
struct netif * netif_list
Definition: netif.c:75
#define NULL
Definition: def.h:47
#define ip_addr_debug_print(debug, ipaddr)
Definition: ip_addr.h:212
#define NETIF_DEBUG
Definition: opt.h:1819
u8_t num
Definition: netif.h:197
ip_addr_t gw
Definition: netif.h:146
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
struct netif * next
Definition: netif.h:141
#define snmp_inc_iflist()
Definition: snmp.h:253
#define ERR_OK
Definition: err.h:52
static state_t * state
Definition: aes.c:67
u8_t flags
Definition: netif.h:193
#define NETIF_FLAG_IGMP
Definition: netif.h:95
ip_addr_t ip_addr
Definition: netif.h:144
#define ip_addr_set_zero(ipaddr)
Definition: ip_addr.h:168
void * state
Definition: netif.h:171
unsigned char u8_t
Definition: cc.h:52
netif_input_fn input
Definition: netif.h:150
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:65
char name[2]
Definition: netif.h:195
ip_addr_t netmask
Definition: netif.h:145
void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)
Definition: netif.c:227
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netif_find()

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')

Definition at line 291 of file netif.c.

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

292 {
293  struct netif *netif;
294  u8_t num;
295 
296  if (name == NULL) {
297  return NULL;
298  }
299 
300  num = name[2] - '0';
301 
302  for(netif = netif_list; netif != NULL; netif = netif->next) {
303  if (num == netif->num &&
304  name[0] == netif->name[0] &&
305  name[1] == netif->name[1]) {
306  LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
307  return netif;
308  }
309  }
310  LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
311  return NULL;
312 }
struct netif * netif_list
Definition: netif.c:75
#define NULL
Definition: def.h:47
#define NETIF_DEBUG
Definition: opt.h:1819
u8_t num
Definition: netif.h:197
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
struct netif * next
Definition: netif.h:141
Definition: netif.h:139
unsigned char u8_t
Definition: cc.h:52
char name[2]
Definition: netif.h:195

◆ netif_init()

void netif_init ( void  )

Definition at line 104 of file netif.c.

References IP4_ADDR, ip_input(), netif_add(), netif_set_up(), NULL, and tcpip_input().

Referenced by lwip_init().

105 {
106 #if LWIP_HAVE_LOOPIF
107  ip_addr_t loop_ipaddr, loop_netmask, loop_gw;
108  IP4_ADDR(&loop_gw, 127,0,0,1);
109  IP4_ADDR(&loop_ipaddr, 127,0,0,1);
110  IP4_ADDR(&loop_netmask, 255,0,0,0);
111 
112 #if NO_SYS
113  netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, netif_loopif_init, ip_input);
114 #else /* NO_SYS */
115  netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, netif_loopif_init, tcpip_input);
116 #endif /* NO_SYS */
117  netif_set_up(&loop_netif);
118 
119 #endif /* LWIP_HAVE_LOOPIF */
120 }
#define NULL
Definition: def.h:47
void netif_set_up(struct netif *netif)
Definition: netif.c:454
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)
Definition: netif.c:137
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
Definition: ip_addr.h:64
err_t tcpip_input(struct pbuf *p, struct netif *inp)
Definition: tcpip.c:156
err_t ip_input(struct pbuf *p, struct netif *inp) ICACHE_FLASH_ATTR
Definition: ip.c:923
#define IP4_ADDR(ipaddr, a, b, c, d)
Definition: ip_addr.h:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netif_remove()

void netif_remove ( struct netif netif)

Remove a network interface from the list of lwIP netifs.

Parameters
netifthe network interface to remove

Definition at line 241 of file netif.c.

References netif::flags, LWIP_DEBUGF, 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.

242 {
243  if (netif == NULL) {
244  return;
245  }
246 
247 #if LWIP_IGMP
248  /* stop IGMP processing */
249  if (netif->flags & NETIF_FLAG_IGMP) {
250  igmp_stop(netif);
251  }
252 #endif /* LWIP_IGMP */
253  if (netif_is_up(netif)) {
254  /* set netif down before removing (call callback function) */
255  netif_set_down(netif);
256  }
257 
259 
260  /* is it the first netif? */
261  if (netif_list == netif) {
262  netif_list = netif->next;
263  } else {
264  /* look for netif further down the list */
265  struct netif * tmpNetif;
266  for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {
267  if (tmpNetif->next == netif) {
268  tmpNetif->next = netif->next;
269  break;
270  }
271  }
272  if (tmpNetif == NULL)
273  return; /* we didn't find any netif today */
274  }
275  snmp_dec_iflist();
276  /* this netif is default? */
277  if (netif_default == netif) {
278  /* reset default netif */
280  }
281  LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
282 }
struct netif * netif_list
Definition: netif.c:75
struct netif * netif_default
Definition: netif.c:76
#define NULL
Definition: def.h:47
#define NETIF_DEBUG
Definition: opt.h:1819
void netif_set_default(struct netif *netif)
Definition: netif.c:431
#define snmp_delete_ipaddridx_tree(ni)
Definition: snmp.h:279
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
#define snmp_dec_iflist()
Definition: snmp.h:254
struct netif * next
Definition: netif.h:141
u8_t flags
Definition: netif.h:193
#define NETIF_FLAG_IGMP
Definition: netif.h:95
void netif_set_down(struct netif *netif)
Definition: netif.c:491
#define netif_is_up(netif)
Definition: netif.h:286
Here is the call graph for this function:

◆ netif_set_addr()

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

Definition at line 227 of file netif.c.

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

Referenced by netif_add().

229 {
230  netif_set_ipaddr(netif, ipaddr);
231  netif_set_netmask(netif, netmask);
232  netif_set_gw(netif, gw);
233 }
void netif_set_gw(struct netif *netif, ip_addr_t *gw)
Definition: netif.c:389
ip_addr_t gw
Definition: netif.h:146
void netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)
Definition: netif.c:324
void netif_set_netmask(struct netif *netif, ip_addr_t *netmask)
Definition: netif.c:410
ip_addr_t netmask
Definition: netif.h:145
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netif_set_default()

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

Definition at line 431 of file netif.c.

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

Referenced by espconn_udp_sendto(), espconn_udp_sent(), and netif_remove().

432 {
433  if (netif == NULL) {
434  /* remove default route */
435  snmp_delete_iprteidx_tree(1, netif);
436  } else {
437  /* install default route */
438  snmp_insert_iprteidx_tree(1, netif);
439  }
440  netif_default = netif;
441  LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
442  netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
443 }
struct netif * netif_default
Definition: netif.c:76
#define NULL
Definition: def.h:47
#define NETIF_DEBUG
Definition: opt.h:1819
#define snmp_delete_iprteidx_tree(dflt, ni)
Definition: snmp.h:281
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
char name[2]
Definition: netif.h:195
#define snmp_insert_iprteidx_tree(dflt, ni)
Definition: snmp.h:280
Here is the caller graph for this function:

◆ netif_set_down()

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()

Definition at line 491 of file netif.c.

References netif::flags, NETIF_FLAG_ETHARP, NETIF_FLAG_UP, NETIF_STATUS_CALLBACK, and snmp_get_sysuptime.

Referenced by netif_remove().

492 {
493  if (netif->flags & NETIF_FLAG_UP) {
494  netif->flags &= ~NETIF_FLAG_UP;
495 #if LWIP_SNMP
496  snmp_get_sysuptime(&netif->ts);
497 #endif
498 
499 #if LWIP_ARP
500  if (netif->flags & NETIF_FLAG_ETHARP) {
501  etharp_cleanup_netif(netif);
502  }
503 #endif /* LWIP_ARP */
504  NETIF_STATUS_CALLBACK(netif);
505  }
506 }
#define NETIF_FLAG_UP
Definition: netif.h:69
#define NETIF_STATUS_CALLBACK(n)
Definition: netif.c:66
#define NETIF_FLAG_ETHARP
Definition: netif.h:88
u8_t flags
Definition: netif.h:193
#define snmp_get_sysuptime(value)
Definition: snmp.h:239
Here is the caller graph for this function:

◆ netif_set_gw()

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

Definition at line 389 of file netif.c.

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 netif_set_addr().

390 {
391  ip_addr_set(&(netif->gw), gw);
392  LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
393  netif->name[0], netif->name[1],
394  ip4_addr1_16(&netif->gw),
395  ip4_addr2_16(&netif->gw),
396  ip4_addr3_16(&netif->gw),
397  ip4_addr4_16(&netif->gw)));
398 }
#define ip4_addr3_16(ipaddr)
Definition: ip_addr.h:228
#define ip_addr_set(dest, src)
Definition: ip_addr.h:164
#define U16_F
Definition: cc.h:61
#define NETIF_DEBUG
Definition: opt.h:1819
#define LWIP_DBG_TRACE
Definition: debug.h:56
ip_addr_t gw
Definition: netif.h:146
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
#define LWIP_DBG_STATE
Definition: debug.h:58
#define ip4_addr4_16(ipaddr)
Definition: ip_addr.h:229
#define ip4_addr1_16(ipaddr)
Definition: ip_addr.h:226
char name[2]
Definition: netif.h:195
#define ip4_addr2_16(ipaddr)
Definition: ip_addr.h:227
Here is the caller graph for this function:

◆ netif_set_ipaddr()

void netif_set_ipaddr ( struct netif netif,
ip_addr_t ipaddr 
)

Change the IP address of a network interface

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

Definition at line 324 of file netif.c.

References ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, netif::ip_addr, ip_addr_cmp, ip_addr_isany, ip_addr_islinklocal, ip_addr_set, LWIP_AUTOIP, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, NETIF_DEBUG, NULL, snmp_delete_ipaddridx_tree, snmp_delete_iprteidx_tree, snmp_insert_ipaddridx_tree, snmp_insert_iprteidx_tree, and U16_F.

Referenced by netif_set_addr().

325 {
326  /* TODO: Handling of obsolete pcbs */
327  /* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */
328 #if LWIP_TCP
329  struct tcp_pcb *pcb;
330  struct tcp_pcb_listen *lpcb;
331 
332  /* address is actually being changed? */
333  if (ipaddr && (ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) {
334  /* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */
335  LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
336  pcb = tcp_active_pcbs;
337  while (pcb != NULL) {
338  /* PCB bound to current local interface address? */
339  if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))
340 #if LWIP_AUTOIP
341  /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */
342  && !ip_addr_islinklocal(&(pcb->local_ip))
343 #endif /* LWIP_AUTOIP */
344  ) {
345  /* this connection must be aborted */
346  struct tcp_pcb *next = pcb->next;
347  LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb));
348  tcp_abort(pcb);
349  pcb = next;
350  } else {
351  pcb = pcb->next;
352  }
353  }
354  for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
355  /* PCB bound to current local interface address? */
356  if ((!(ip_addr_isany(&(lpcb->local_ip)))) &&
357  (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr)))) {
358  /* The PCB is listening to the old ipaddr and
359  * is set to listen to the new one instead */
360  ip_addr_set(&(lpcb->local_ip), ipaddr);
361  }
362  }
363  }
364 #endif
366  snmp_delete_iprteidx_tree(0,netif);
367  /* set new IP address to netif */
368  ip_addr_set(&(netif->ip_addr), ipaddr);
370  snmp_insert_iprteidx_tree(0,netif);
371 
372  LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IP address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
373  netif->name[0], netif->name[1],
374  ip4_addr1_16(&netif->ip_addr),
375  ip4_addr2_16(&netif->ip_addr),
376  ip4_addr3_16(&netif->ip_addr),
377  ip4_addr4_16(&netif->ip_addr)));
378 }
#define ip4_addr3_16(ipaddr)
Definition: ip_addr.h:228
#define ip_addr_set(dest, src)
Definition: ip_addr.h:164
#define U16_F
Definition: cc.h:61
#define NULL
Definition: def.h:47
#define NETIF_DEBUG
Definition: opt.h:1819
#define LWIP_DBG_TRACE
Definition: debug.h:56
#define snmp_insert_ipaddridx_tree(ni)
Definition: snmp.h:278
#define snmp_delete_ipaddridx_tree(ni)
Definition: snmp.h:279
#define snmp_delete_iprteidx_tree(dflt, ni)
Definition: snmp.h:281
#define ip_addr_islinklocal(addr1)
Definition: ip_addr.h:210
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
#define ip_addr_cmp(addr1, addr2)
Definition: ip_addr.h:198
#define LWIP_DBG_STATE
Definition: debug.h:58
#define ip4_addr4_16(ipaddr)
Definition: ip_addr.h:229
ip_addr_t ip_addr
Definition: netif.h:144
#define ip_addr_isany(addr1)
Definition: ip_addr.h:200
#define LWIP_AUTOIP
Definition: opt.h:681
#define ip4_addr1_16(ipaddr)
Definition: ip_addr.h:226
char name[2]
Definition: netif.h:195
#define ip4_addr2_16(ipaddr)
Definition: ip_addr.h:227
#define snmp_insert_iprteidx_tree(dflt, ni)
Definition: snmp.h:280
Here is the caller graph for this function:

◆ netif_set_link_down()

void netif_set_link_down ( struct netif netif)

Called by a driver when its link goes down

Definition at line 562 of file netif.c.

References ERR_MEM, ERR_OK, netif::flags, ip_input(), pbuf::len, LINK_STATS_INC, LWIP_ASSERT, LWIP_LOOPBACK_MAX_PBUFS, LWIP_UNUSED_ARG, NETIF_FLAG_LINK_UP, NETIF_LINK_CALLBACK, netif_list, pbuf::next, netif::next, NULL, pbuf_alloc(), pbuf_clen(), pbuf_copy(), pbuf_free(), PBUF_LINK, PBUF_RAM, snmp_add_ifinoctets, snmp_add_ifoutoctets, snmp_inc_ifinucastpkts, snmp_inc_ifoutdiscards, snmp_inc_ifoutucastpkts, SYS_ARCH_DECL_PROTECT, SYS_ARCH_PROTECT, SYS_ARCH_UNPROTECT, tcpip_callback, and pbuf::tot_len.

563 {
564  if (netif->flags & NETIF_FLAG_LINK_UP) {
565  netif->flags &= ~NETIF_FLAG_LINK_UP;
566  NETIF_LINK_CALLBACK(netif);
567  }
568 }
#define NETIF_FLAG_LINK_UP
Definition: netif.h:84
u8_t flags
Definition: netif.h:193
#define NETIF_LINK_CALLBACK(n)
Definition: netif.c:72
Here is the call graph for this function:

◆ netif_set_link_up()

void netif_set_link_up ( struct netif netif)

Called by a driver when its link goes up

Definition at line 523 of file netif.c.

References netif::flags, NETIF_FLAG_ETHARP, NETIF_FLAG_IGMP, NETIF_FLAG_LINK_UP, NETIF_FLAG_UP, and NETIF_LINK_CALLBACK.

524 {
525  if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
526  netif->flags |= NETIF_FLAG_LINK_UP;
527 
528 #if LWIP_DHCP
529  if (netif->dhcp) {
530  dhcp_network_changed(netif);
531  }
532 #endif /* LWIP_DHCP */
533 
534 #if LWIP_AUTOIP
535  if (netif->autoip) {
536  autoip_network_changed(netif);
537  }
538 #endif /* LWIP_AUTOIP */
539 
540  if (netif->flags & NETIF_FLAG_UP) {
541 #if LWIP_ARP
542  /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */
543  if (netif->flags & NETIF_FLAG_ETHARP) {
544  etharp_gratuitous(netif);
545  }
546 #endif /* LWIP_ARP */
547 
548 #if LWIP_IGMP
549  /* resend IGMP memberships */
550  if (netif->flags & NETIF_FLAG_IGMP) {
551  igmp_report_groups( netif);
552  }
553 #endif /* LWIP_IGMP */
554  }
555  NETIF_LINK_CALLBACK(netif);
556  }
557 }
#define NETIF_FLAG_UP
Definition: netif.h:69
#define NETIF_FLAG_LINK_UP
Definition: netif.h:84
#define NETIF_FLAG_ETHARP
Definition: netif.h:88
u8_t flags
Definition: netif.h:193
#define NETIF_FLAG_IGMP
Definition: netif.h:95
#define NETIF_LINK_CALLBACK(n)
Definition: netif.c:72

◆ netif_set_netmask()

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

Definition at line 410 of file netif.c.

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 netif_set_addr().

411 {
412  snmp_delete_iprteidx_tree(0, netif);
413  /* set new netmask to netif */
414  ip_addr_set(&(netif->netmask), netmask);
415  snmp_insert_iprteidx_tree(0, netif);
416  LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
417  netif->name[0], netif->name[1],
418  ip4_addr1_16(&netif->netmask),
419  ip4_addr2_16(&netif->netmask),
420  ip4_addr3_16(&netif->netmask),
421  ip4_addr4_16(&netif->netmask)));
422 }
#define ip4_addr3_16(ipaddr)
Definition: ip_addr.h:228
#define ip_addr_set(dest, src)
Definition: ip_addr.h:164
#define U16_F
Definition: cc.h:61
#define NETIF_DEBUG
Definition: opt.h:1819
#define LWIP_DBG_TRACE
Definition: debug.h:56
#define snmp_delete_iprteidx_tree(dflt, ni)
Definition: snmp.h:281
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:94
#define LWIP_DBG_STATE
Definition: debug.h:58
#define ip4_addr4_16(ipaddr)
Definition: ip_addr.h:229
#define ip4_addr1_16(ipaddr)
Definition: ip_addr.h:226
char name[2]
Definition: netif.h:195
#define ip4_addr2_16(ipaddr)
Definition: ip_addr.h:227
ip_addr_t netmask
Definition: netif.h:145
#define snmp_insert_iprteidx_tree(dflt, ni)
Definition: snmp.h:280
Here is the caller graph for this function:

◆ netif_set_up()

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()

Definition at line 454 of file netif.c.

References netif::flags, NETIF_FLAG_ETHARP, NETIF_FLAG_IGMP, NETIF_FLAG_LINK_UP, NETIF_FLAG_UP, NETIF_STATUS_CALLBACK, and snmp_get_sysuptime.

Referenced by netif_init().

455 {
456  if (!(netif->flags & NETIF_FLAG_UP)) {
457  netif->flags |= NETIF_FLAG_UP;
458 
459 #if LWIP_SNMP
460  snmp_get_sysuptime(&netif->ts);
461 #endif /* LWIP_SNMP */
462 
463  NETIF_STATUS_CALLBACK(netif);
464 
465  if (netif->flags & NETIF_FLAG_LINK_UP) {
466 #if LWIP_ARP
467  /* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */
468  if (netif->flags & (NETIF_FLAG_ETHARP)) {
469  etharp_gratuitous(netif);
470  }
471 #endif /* LWIP_ARP */
472 
473 #if LWIP_IGMP
474  /* resend IGMP memberships */
475  if (netif->flags & NETIF_FLAG_IGMP) {
476  igmp_report_groups( netif);
477  }
478 #endif /* LWIP_IGMP */
479  }
480  }
481 }
#define NETIF_FLAG_UP
Definition: netif.h:69
#define NETIF_FLAG_LINK_UP
Definition: netif.h:84
#define NETIF_STATUS_CALLBACK(n)
Definition: netif.c:66
#define NETIF_FLAG_ETHARP
Definition: netif.h:88
u8_t flags
Definition: netif.h:193
#define NETIF_FLAG_IGMP
Definition: netif.h:95
#define snmp_get_sysuptime(value)
Definition: snmp.h:239
Here is the caller graph for this function:

Variable Documentation

◆ netif_default

struct netif* netif_default

The default network interface.

Definition at line 76 of file netif.c.

Referenced by ip_route(), and ip_router().

◆ netif_list

struct netif* netif_list

The list of network interfaces.

Definition at line 75 of file netif.c.

Referenced by ip_input(), ip_route(), ip_router(), netif_add(), netif_set_link_down(), patch_netif_ap(), and wifi_softap_ip_config().