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