Mistake on this page?
Report an issue in GitHub or email us
netif.h
Go to the documentation of this file.
1 /**
2  * @file
3  * netif API (to be used from TCPIP thread)
4  */
5 
6 /*
7  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * This file is part of the lwIP TCP/IP stack.
33  *
34  * Author: Adam Dunkels <adam@sics.se>
35  *
36  */
37 #ifndef LWIP_HDR_NETIF_H
38 #define LWIP_HDR_NETIF_H
39 
40 #include <stdbool.h>
41 #include "lwip/opt.h"
42 
43 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
44 
45 #include "lwip/err.h"
46 
47 #include "lwip/ip_addr.h"
48 
49 #include "lwip/def.h"
50 #include "lwip/pbuf.h"
51 #include "lwip/stats.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /* Throughout this file, IP addresses are expected to be in
58  * the same byte order as in IP_PCB. */
59 
60 /** Must be the maximum of all used hardware address lengths
61  across all types of interfaces in use.
62  This does not have to be changed, normally. */
63 #ifndef NETIF_MAX_HWADDR_LEN
64 #define NETIF_MAX_HWADDR_LEN 6U
65 #endif
66 
67 /** The size of a fully constructed netif name which the
68  * netif can be identified by in APIs. Composed of
69  * 2 chars, 3 (max) digits, and 1 \0
70  */
71 #define NETIF_NAMESIZE 6
72 
73 /**
74  * @defgroup netif_flags Flags
75  * @ingroup netif
76  * @{
77  */
78 
79 /** Whether the network interface is 'up'. This is
80  * a software flag used to control whether this network
81  * interface is enabled and processes traffic.
82  * It must be set by the startup code before this netif can be used
83  * (also for dhcp/autoip).
84  */
85 #define NETIF_FLAG_UP 0x01U
86 /** If set, the netif has broadcast capability.
87  * Set by the netif driver in its init function. */
88 #define NETIF_FLAG_BROADCAST 0x02U
89 /** If set, the interface has an active link
90  * (set by the network interface driver).
91  * Either set by the netif driver in its init function (if the link
92  * is up at that time) or at a later point once the link comes up
93  * (if link detection is supported by the hardware). */
94 #define NETIF_FLAG_LINK_UP 0x04U
95 /** If set, the netif is an ethernet device using ARP.
96  * Set by the netif driver in its init function.
97  * Used to check input packet types and use of DHCP. */
98 #define NETIF_FLAG_ETHARP 0x08U
99 /** If set, the netif is an ethernet device. It might not use
100  * ARP or TCP/IP if it is used for PPPoE only.
101  */
102 #define NETIF_FLAG_ETHERNET 0x10U
103 /** If set, the netif has IGMP capability.
104  * Set by the netif driver in its init function. */
105 #define NETIF_FLAG_IGMP 0x20U
106 /** If set, the netif has MLD6 capability.
107  * Set by the netif driver in its init function. */
108 #define NETIF_FLAG_MLD6 0x40U
109 
110 /**
111  * @}
112  */
113 
114 enum lwip_internal_netif_client_data_index
115 {
116 #if LWIP_IPV4
117 #if LWIP_DHCP
118  LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
119 #endif
120 #if LWIP_AUTOIP
121  LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
122 #endif
123 #if LWIP_IGMP
124  LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
125 #endif
126 #endif /* LWIP_IPV4 */
127 #if LWIP_IPV6
128 #if LWIP_IPV6_DHCP6
129  LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6,
130 #endif
131 #if LWIP_IPV6_MLD
132  LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
133 #endif
134 #endif /* LWIP_IPV6 */
135  LWIP_NETIF_CLIENT_DATA_INDEX_MAX
136 };
137 
138 #if LWIP_CHECKSUM_CTRL_PER_NETIF
139 #define NETIF_CHECKSUM_GEN_IP 0x0001
140 #define NETIF_CHECKSUM_GEN_UDP 0x0002
141 #define NETIF_CHECKSUM_GEN_TCP 0x0004
142 #define NETIF_CHECKSUM_GEN_ICMP 0x0008
143 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010
144 #define NETIF_CHECKSUM_CHECK_IP 0x0100
145 #define NETIF_CHECKSUM_CHECK_UDP 0x0200
146 #define NETIF_CHECKSUM_CHECK_TCP 0x0400
147 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800
148 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
149 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
150 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000
151 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
152 
153 struct netif;
154 
155 /** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or
156  * mld_mac_filter callback function. */
158  /** Delete a filter entry */
160  /** Add a filter entry */
162 };
163 
164 /** Function prototype for netif init functions. Set up flags and output/linkoutput
165  * callback functions in this function.
166  *
167  * @param netif The netif to initialize
168  */
169 typedef err_t (*netif_init_fn)(struct netif *netif);
170 /** Function prototype for netif->input functions. This function is saved as 'input'
171  * callback function in the netif struct. Call it when a packet has been received.
172  *
173  * @param p The received packet, copied into a pbuf
174  * @param inp The netif which received the packet
175  * @return ERR_OK if the packet was handled
176  * != ERR_OK is the packet was NOT handled, in this case, the caller has
177  * to free the pbuf
178  */
179 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
180 
181 #if LWIP_IPV4
182 /** Function prototype for netif->output functions. Called by lwIP when a packet
183  * shall be sent. For ethernet netif, set this to 'etharp_output' and set
184  * 'linkoutput'.
185  *
186  * @param netif The netif which shall send a packet
187  * @param p The packet to send (p->payload points to IP header)
188  * @param ipaddr The IP address to which the packet shall be sent
189  */
190 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
191  const ip4_addr_t *ipaddr);
192 #endif /* LWIP_IPV4*/
193 
194 #if LWIP_IPV6
195 /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet
196  * shall be sent. For ethernet netif, set this to 'ethip6_output' and set
197  * 'linkoutput'.
198  *
199  * @param netif The netif which shall send a packet
200  * @param p The packet to send (p->payload points to IP header)
201  * @param ipaddr The IPv6 address to which the packet shall be sent
202  */
203 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
204  const ip6_addr_t *ipaddr);
205 #endif /* LWIP_IPV6 */
206 
207 /** Function prototype for netif->linkoutput functions. Only used for ethernet
208  * netifs. This function is called by ARP when a packet shall be sent.
209  *
210  * @param netif The netif which shall send a packet
211  * @param p The packet to send (raw ethernet packet)
212  */
213 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
214 /** Function prototype for netif status- or link-callback functions. */
215 typedef void (*netif_status_callback_fn)(struct netif *netif);
216 #if LWIP_IPV4 && LWIP_IGMP
217 /** Function prototype for netif igmp_mac_filter functions */
218 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
219  const ip4_addr_t *group, enum netif_mac_filter_action action);
220 #endif /* LWIP_IPV4 && LWIP_IGMP */
221 #if LWIP_IPV6 && LWIP_IPV6_MLD
222 /** Function prototype for netif mld_mac_filter functions */
223 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
224  const ip6_addr_t *group, enum netif_mac_filter_action action);
225 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
226 
227 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || LWIP_IPV6_DHCP6 || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
228 #if LWIP_NUM_NETIF_CLIENT_DATA > 0
229 u8_t netif_alloc_client_data_id(void);
230 #endif
231 /** @ingroup netif_cd
232  * Set client data. Obtain ID from netif_alloc_client_data_id().
233  */
234 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
235 /** @ingroup netif_cd
236  * Get client data. Obtain ID from netif_alloc_client_data_id().
237  */
238 #define netif_get_client_data(netif, id) (netif)->client_data[(id)]
239 #endif
240 
241 #if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f))
242 typedef u16_t netif_addr_idx_t;
243 #define NETIF_ADDR_IDX_MAX 0x7FFF
244 #else
245 typedef u8_t netif_addr_idx_t;
246 #define NETIF_ADDR_IDX_MAX 0x7F
247 #endif
248 
249 #if LWIP_NETIF_HWADDRHINT
250 #define LWIP_NETIF_USE_HINTS 1
251 struct netif_hint {
252  netif_addr_idx_t addr_hint;
253 };
254 #else /* LWIP_NETIF_HWADDRHINT */
255 #define LWIP_NETIF_USE_HINTS 0
256 #endif /* LWIP_NETIF_HWADDRHINT */
257 
258 /** Generic data structure used for all lwIP network interfaces.
259  * The following fields should be filled in by the initialization
260  * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
261 struct netif {
262 #if !LWIP_SINGLE_NETIF
263  /** pointer to next in linked list */
264  struct netif *next;
265 #endif
266 
267 #if LWIP_IPV4
268  /** IP address configuration in network byte order */
269  ip_addr_t ip_addr;
270  ip_addr_t netmask;
271  ip_addr_t gw;
272 #endif /* LWIP_IPV4 */
273 #if LWIP_IPV6
274  /** Array of IPv6 addresses for this netif. */
276  /** The state of each IPv6 address (Tentative, Preferred, etc).
277  * @see ip6_addr.h */
278  u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
279 #if LWIP_IPV6_ADDRESS_LIFETIMES
280  /** Remaining valid and preferred lifetime of each IPv6 address, in seconds.
281  * For valid lifetimes, the special value of IP6_ADDR_LIFE_STATIC (0)
282  * indicates the address is static and has no lifetimes. */
283  u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES];
284  u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES];
285 #endif /* LWIP_IPV6_ADDRESS_LIFETIMES */
286 #endif /* LWIP_IPV6 */
287  /** This function is called by the network device driver
288  * to pass a packet up the TCP/IP stack. */
290 #if LWIP_IPV4
291  /** This function is called by the IP module when it wants
292  * to send a packet on the interface. This function typically
293  * first resolves the hardware address, then sends the packet.
294  * For ethernet physical layer, this is usually etharp_output() */
295  netif_output_fn output;
296 #endif /* LWIP_IPV4 */
297  /** This function is called by ethernet_output() when it wants
298  * to send a packet on the interface. This function outputs
299  * the pbuf as-is on the link medium. */
301 #if LWIP_IPV6
302  /** This function is called by the IPv6 module when it wants
303  * to send a packet on the interface. This function typically
304  * first resolves the hardware address, then sends the packet.
305  * For ethernet physical layer, this is usually ethip6_output() */
306  netif_output_ip6_fn output_ip6;
307 #endif /* LWIP_IPV6 */
308 #if LWIP_NETIF_STATUS_CALLBACK
309  /** This function is called when the netif state is set to up or down
310  */
311  netif_status_callback_fn status_callback;
312 #endif /* LWIP_NETIF_STATUS_CALLBACK */
313 #if LWIP_NETIF_LINK_CALLBACK
314  /** This function is called when the netif link is set to up or down
315  */
316  netif_status_callback_fn link_callback;
317 #endif /* LWIP_NETIF_LINK_CALLBACK */
318 #if LWIP_NETIF_REMOVE_CALLBACK
319  /** This function is called when the netif has been removed */
320  netif_status_callback_fn remove_callback;
321 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
322  /** This field can be set by the device driver and could point
323  * to state information for the device. */
324  void *state;
325 #ifdef netif_get_client_data
326  void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA];
327 #endif
328 #if LWIP_NETIF_HOSTNAME
329  /* the hostname for this netif, NULL is a valid value */
330  const char* hostname;
331 #endif /* LWIP_NETIF_HOSTNAME */
332 #if LWIP_CHECKSUM_CTRL_PER_NETIF
333  u16_t chksum_flags;
334 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
335  /** maximum transfer unit (in bytes) */
336  u16_t mtu;
337 #if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES
338  /** maximum transfer unit (in bytes), updated by RA */
339  u16_t mtu6;
340 #endif /* LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES */
341  /** link level hardware address of this interface */
343  /** number of bytes used in hwaddr */
345  /** flags (@see @ref netif_flags) */
346  u8_t flags;
347  /** descriptive abbreviation */
348  char name[2];
349  /** number of this interface. Used for @ref if_api and @ref netifapi_netif,
350  * as well as for IPv6 zones */
351  u8_t num;
352 #if LWIP_IPV6_AUTOCONFIG
353  /** is this netif enabled for IPv6 autoconfiguration */
354  u8_t ip6_autoconfig_enabled;
355 #endif /* LWIP_IPV6_AUTOCONFIG */
356 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
357  /** Number of Router Solicitation messages that remain to be sent. */
358  u8_t rs_count;
359 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
360 #if MIB2_STATS
361  /** link type (from "snmp_ifType" enum from snmp_mib2.h) */
362  u8_t link_type;
363  /** (estimate) link speed */
364  u32_t link_speed;
365  /** timestamp at last change made (up/down) */
366  u32_t ts;
367  /** counters */
368  struct stats_mib2_netif_ctrs mib2_counters;
369 #endif /* MIB2_STATS */
370 #if LWIP_IPV4 && LWIP_IGMP
371  /** This function could be called to add or delete an entry in the multicast
372  filter table of the ethernet MAC.*/
373  netif_igmp_mac_filter_fn igmp_mac_filter;
374 #endif /* LWIP_IPV4 && LWIP_IGMP */
375 #if LWIP_IPV6 && LWIP_IPV6_MLD
376  /** This function could be called to add or delete an entry in the IPv6 multicast
377  filter table of the ethernet MAC. */
378  netif_mld_mac_filter_fn mld_mac_filter;
379 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
380 #if LWIP_NETIF_USE_HINTS
381  struct netif_hint *hints;
382 #endif /* LWIP_NETIF_USE_HINTS */
383 #if ENABLE_LOOPBACK
384  /* List of packets to be queued for ourselves. */
385  struct pbuf *loop_first;
386  struct pbuf *loop_last;
387 #if LWIP_LOOPBACK_MAX_PBUFS
388  u16_t loop_cnt_current;
389 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
390 #endif /* ENABLE_LOOPBACK */
391 };
392 
393 #if LWIP_CHECKSUM_CTRL_PER_NETIF
394 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
395  (netif)->chksum_flags = chksumflags; } while(0)
396 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
397 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
398 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
399 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
400 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
401 
402 #if LWIP_SINGLE_NETIF
403 #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL)
404 #else /* LWIP_SINGLE_NETIF */
405 /** The list of network interfaces. */
406 extern struct netif *netif_list;
407 #define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next)
408 #endif /* LWIP_SINGLE_NETIF */
409 /** The default network interface. */
410 extern struct netif *netif_default;
411 
412 void netif_init(void);
413 
414 struct netif *netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input);
415 
416 #if LWIP_IPV4
417 struct netif *netif_add(struct netif *netif,
418  const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
419  void *state, netif_init_fn init, netif_input_fn input);
420 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
421  const ip4_addr_t *gw);
422 #else /* LWIP_IPV4 */
423 struct netif *netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input);
424 #endif /* LWIP_IPV4 */
425 void netif_remove(struct netif * netif);
426 
427 /* Returns a network interface given its name. The name is of the form
428  "et0", where the first two letters are the "name" field in the
429  netif structure, and the digit is in the num field in the same
430  structure. */
431 struct netif *netif_find(const char *name);
432 
433 /* Returns a network interface name in the form
434  "et0", where the first two letters are the "name" field in the
435  netif structure, and the digit is in the num field in the same
436  structure. */
437 const char *netif_get_name(struct netif *netif);
438 
439 void netif_set_default(struct netif *netif);
440 bool netif_check_default(struct netif *netif);
441 
442 
443 #if LWIP_IPV4
444 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
445 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
446 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
447 /** @ingroup netif_ip4 */
448 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
449 /** @ingroup netif_ip4 */
450 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
451 /** @ingroup netif_ip4 */
452 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
453 /** @ingroup netif_ip4 */
454 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
455 /** @ingroup netif_ip4 */
456 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
457 /** @ingroup netif_ip4 */
458 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
459 #endif /* LWIP_IPV4 */
460 
461 #define netif_set_flags(netif, set_flags) do { (netif)->flags = (u8_t)((netif)->flags | (set_flags)); } while(0)
462 #define netif_clear_flags(netif, clr_flags) do { (netif)->flags = (u8_t)((netif)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
463 #define netif_is_flag_set(nefif, flag) (((netif)->flags & (flag)) != 0)
464 
465 void netif_set_up(struct netif *netif);
466 void netif_set_down(struct netif *netif);
467 /** @ingroup netif
468  * Ask if an interface is up
469  */
470 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
471 
472 #if LWIP_NETIF_STATUS_CALLBACK
473 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
474 #endif /* LWIP_NETIF_STATUS_CALLBACK */
475 #if LWIP_NETIF_REMOVE_CALLBACK
476 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
477 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
478 
479 void netif_set_link_up(struct netif *netif);
480 void netif_set_link_down(struct netif *netif);
481 /** Ask if a link is up */
482 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
483 
484 #if LWIP_NETIF_LINK_CALLBACK
485 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
486 #endif /* LWIP_NETIF_LINK_CALLBACK */
487 
488 #if LWIP_NETIF_HOSTNAME
489 /** @ingroup netif */
490 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
491 /** @ingroup netif */
492 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
493 #endif /* LWIP_NETIF_HOSTNAME */
494 
495 #if LWIP_IGMP
496 /** @ingroup netif */
497 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
498 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
499 #endif /* LWIP_IGMP */
500 
501 #if LWIP_IPV6 && LWIP_IPV6_MLD
502 /** @ingroup netif */
503 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
504 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
505 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0)
506 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
507 
508 #if ENABLE_LOOPBACK
509 err_t netif_loop_output(struct netif *netif, struct pbuf *p);
510 void netif_poll(struct netif *netif);
511 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
512 void netif_poll_all(void);
513 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
514 #endif /* ENABLE_LOOPBACK */
515 
516 err_t netif_input(struct pbuf *p, struct netif *inp);
517 
518 #if LWIP_IPV6
519 /** @ingroup netif_ip6 */
520 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
521 /** @ingroup netif_ip6 */
522 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
523 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
524 void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3);
525 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
526 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state);
527 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr);
528 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit);
529 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx);
530 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0)
531 #if LWIP_IPV6_ADDRESS_LIFETIMES
532 #define netif_ip6_addr_valid_life(netif, i) \
533  (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC)
534 #define netif_ip6_addr_set_valid_life(netif, i, secs) \
535  do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0)
536 #define netif_ip6_addr_pref_life(netif, i) \
537  (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC)
538 #define netif_ip6_addr_set_pref_life(netif, i, secs) \
539  do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0)
540 #define netif_ip6_addr_isstatic(netif, i) \
541  (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC)
542 #else /* !LWIP_IPV6_ADDRESS_LIFETIMES */
543 #define netif_ip6_addr_isstatic(netif, i) (1) /* all addresses are static */
544 #endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */
545 #if LWIP_ND6_ALLOW_RA_UPDATES
546 #define netif_mtu6(netif) ((netif)->mtu6)
547 #else /* LWIP_ND6_ALLOW_RA_UPDATES */
548 #define netif_mtu6(netif) ((netif)->mtu)
549 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */
550 #endif /* LWIP_IPV6 */
551 
552 #if LWIP_NETIF_USE_HINTS
553 #define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint)
554 #define NETIF_RESET_HINTS(netif) (netif)->hints = NULL
555 #else /* LWIP_NETIF_USE_HINTS */
556 #define NETIF_SET_HINTS(netif, netifhint)
557 #define NETIF_RESET_HINTS(netif)
558 #endif /* LWIP_NETIF_USE_HINTS */
559 
560 u8_t netif_name_to_index(const char *name);
561 char * netif_index_to_name(u8_t idx, char *name);
562 struct netif* netif_get_by_index(u8_t idx);
563 
564 /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/
565 #define netif_get_index(netif) ((u8_t)((netif)->num + 1))
566 #define NETIF_NO_INDEX (0)
567 
568 /**
569  * @ingroup netif
570  * Extended netif status callback (NSC) reasons flags.
571  * May be extended in the future!
572  */
573 typedef u16_t netif_nsc_reason_t;
574 
575 /* used for initialization only */
576 #define LWIP_NSC_NONE 0x0000
577 /** netif was added. arg: NULL. Called AFTER netif was added. */
578 #define LWIP_NSC_NETIF_ADDED 0x0001
579 /** netif was removed. arg: NULL. Called BEFORE netif is removed. */
580 #define LWIP_NSC_NETIF_REMOVED 0x0002
581 /** link changed */
582 #define LWIP_NSC_LINK_CHANGED 0x0004
583 /** netif administrative status changed.\n
584  * up is called AFTER netif is set up.\n
585  * down is called BEFORE the netif is actually set down. */
586 #define LWIP_NSC_STATUS_CHANGED 0x0008
587 /** IPv4 address has changed */
588 #define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010
589 /** IPv4 gateway has changed */
590 #define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020
591 /** IPv4 netmask has changed */
592 #define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040
593 /** called AFTER IPv4 address/gateway/netmask changes have been applied */
594 #define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080
595 /** IPv6 address was added */
596 #define LWIP_NSC_IPV6_SET 0x0100
597 /** IPv6 address state has changed */
598 #define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200
599 
600 /** @ingroup netif
601  * Argument supplied to netif_ext_callback_fn.
602  */
603 typedef union
604 {
605  /** Args to LWIP_NSC_LINK_CHANGED callback */
607  {
608  /** 1: up; 0: down */
609  u8_t state;
610  } link_changed;
611  /** Args to LWIP_NSC_STATUS_CHANGED callback */
613  {
614  /** 1: up; 0: down */
615  u8_t state;
616  } status_changed;
617  /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWIP_NSC_IPV4_SETTINGS_CHANGED callback */
619  {
620  /** Old IPv4 address */
622  const ip_addr_t* old_netmask;
623  const ip_addr_t* old_gw;
624  } ipv4_changed;
625  /** Args to LWIP_NSC_IPV6_SET callback */
626  struct ipv6_set_s
627  {
628  /** Index of changed IPv6 address */
630  /** Old IPv6 address */
632  } ipv6_set;
633  /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */
635  {
636  /** Index of affected IPv6 address */
638  /** Old IPv6 address state */
639  u8_t old_state;
640  /** Affected IPv6 address */
642  } ipv6_addr_state_changed;
644 
645 /**
646  * @ingroup netif
647  * Function used for extended netif status callbacks
648  * Note: When parsing reason argument, keep in mind that more reasons may be added in the future!
649  * @param netif netif that is affected by change
650  * @param reason change reason
651  * @param args depends on reason, see reason description
652  */
653 typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args);
654 
655 #if LWIP_NETIF_EXT_STATUS_CALLBACK
656 struct netif_ext_callback;
657 typedef struct netif_ext_callback
658 {
659  netif_ext_callback_fn callback_fn;
660  struct netif_ext_callback* next;
661 } netif_ext_callback_t;
662 
663 #define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name;
664 void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn);
665 void netif_remove_ext_callback(netif_ext_callback_t* callback);
666 void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args);
667 #else
668 #define NETIF_DECLARE_EXT_CALLBACK(name)
669 #define netif_add_ext_callback(callback, fn)
670 #define netif_remove_ext_callback(callback)
671 #define netif_invoke_ext_callback(netif, reason, args)
672 #endif
673 
674 #ifdef __cplusplus
675 }
676 #endif
677 
678 #endif /* LWIP_HDR_NETIF_H */
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Function prototype for netif->input functions.
Definition: netif.h:179
void * state
This field can be set by the PPP protocol and could point to state information for the protocol...
u8_t flags
flags (
Definition: netif.h:346
Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWI...
Definition: netif.h:618
void(* netif_status_callback_fn)(struct netif *netif)
Function prototype for netif status- or link-callback functions.
Definition: netif.h:215
Add a filter entry.
Definition: netif.h:161
various utility macros
struct netif * netif_list
The list of network interfaces.
netif_input_fn input
This function is called by the PPP service to pass a packet up the TCP/IP stack.
struct netif * next
pointer to next in linked list
Definition: netif.h:264
u16_t mtu
maximum transfer unit (in bytes)
u16_t netif_nsc_reason_t
Extended netif status callback (NSC) reasons flags.
Definition: netif.h:573
lwIP Options Configuration
void(* netif_ext_callback_fn)(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
Function used for extended netif status callbacks Note: When parsing reason argument, keep in mind that more reasons may be added in the future!
Definition: netif.h:653
Args to LWIP_NSC_IPV6_SET callback.
Definition: netif.h:626
const ip_addr_t * old_address
Old IPv6 address.
Definition: netif.h:631
char name[2]
descriptive abbreviation
Definition: netif.h:348
Statistics API (to be used from TCPIP thread)
#define NETIF_MAX_HWADDR_LEN
Must be the maximum of all used hardware address lengths across all types of interfaces in use...
Definition: netif.h:64
netif_linkoutput_fn linkoutput
This function is called by ethernet_output() when it wants to send a packet on the interface...
Definition: netif.h:300
u8_t old_state
Old IPv6 address state.
Definition: netif.h:639
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
u8_t num
number of this interface.
Definition: netif.h:351
u8_t hwaddr[6U]
link level hardware address of this interface
Definition: netif.h:342
s8_t addr_index
Index of affected IPv6 address.
Definition: netif.h:637
Main packet buffer struct.
struct netif * netif_default
The default network interface.
const ip_addr_t * address
Affected IPv6 address.
Definition: netif.h:641
lwIP Error codes
Generic data structure used for all lwIP network interfaces.
u8_t hwaddr_len
number of bytes used in hwaddr
Definition: netif.h:344
err_t(* netif_init_fn)(struct netif *netif)
Function prototype for netif init functions.
Definition: netif.h:169
Argument supplied to netif_ext_callback_fn.
Definition: netif.h:603
s8_t addr_index
Index of changed IPv6 address.
Definition: netif.h:629
s8_t err_t
Define LWIP_ERR_T in cc.h if you want to use a different type for your platform (must be signed)...
Definition: err.h:96
#define LWIP_NUM_NETIF_CLIENT_DATA
LWIP_NUM_NETIF_CLIENT_DATA: Number of clients that may store data in client_data member array of stru...
Definition: opt.h:1666
Args to LWIP_NSC_STATUS_CHANGED callback.
Definition: netif.h:612
pbuf API
const ip_addr_t * old_address
Old IPv4 address.
Definition: netif.h:621
IP address structure for passing IP addresses by value.
Definition: nsapi_types.h:237
netif_mac_filter_action
MAC Filter Actions, these are passed to a netif&#39;s igmp_mac_filter or mld_mac_filter callback function...
Definition: netif.h:157
#define LWIP_IPV6_NUM_ADDRESSES
LWIP_IPV6_NUM_ADDRESSES: Number of IPv6 addresses per netif.
Definition: opt.h:2420
Delete a filter entry.
Definition: netif.h:159
Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback.
Definition: netif.h:634
IP address API (common IPv4 and IPv6)
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Function prototype for netif->linkoutput functions.
Definition: netif.h:213
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.