xref: /minix/minix/lib/liblwip/dist/src/include/lwip/netif.h (revision fb9c64b2)
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_DHCP
116    LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
117 #endif
118 #if LWIP_AUTOIP
119    LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
120 #endif
121 #if LWIP_IGMP
122    LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
123 #endif
124 #if LWIP_IPV6_MLD
125    LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
126 #endif
127    LWIP_NETIF_CLIENT_DATA_INDEX_MAX
128 };
129 
130 #if LWIP_CHECKSUM_CTRL_PER_NETIF
131 #define NETIF_CHECKSUM_GEN_IP       0x0001
132 #define NETIF_CHECKSUM_GEN_UDP      0x0002
133 #define NETIF_CHECKSUM_GEN_TCP      0x0004
134 #define NETIF_CHECKSUM_GEN_ICMP     0x0008
135 #define NETIF_CHECKSUM_GEN_ICMP6    0x0010
136 #define NETIF_CHECKSUM_CHECK_IP     0x0100
137 #define NETIF_CHECKSUM_CHECK_UDP    0x0200
138 #define NETIF_CHECKSUM_CHECK_TCP    0x0400
139 #define NETIF_CHECKSUM_CHECK_ICMP   0x0800
140 #define NETIF_CHECKSUM_CHECK_ICMP6  0x1000
141 #define NETIF_CHECKSUM_ENABLE_ALL   0xFFFF
142 #define NETIF_CHECKSUM_DISABLE_ALL  0x0000
143 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
144 
145 struct netif;
146 
147 /** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or
148  * mld_mac_filter callback function. */
149 enum netif_mac_filter_action {
150   /** Delete a filter entry */
151   NETIF_DEL_MAC_FILTER = 0,
152   /** Add a filter entry */
153   NETIF_ADD_MAC_FILTER = 1
154 };
155 
156 /** Function prototype for netif init functions. Set up flags and output/linkoutput
157  * callback functions in this function.
158  *
159  * @param netif The netif to initialize
160  */
161 typedef err_t (*netif_init_fn)(struct netif *netif);
162 /** Function prototype for netif->input functions. This function is saved as 'input'
163  * callback function in the netif struct. Call it when a packet has been received.
164  *
165  * @param p The received packet, copied into a pbuf
166  * @param inp The netif which received the packet
167  */
168 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
169 
170 #if LWIP_IPV4
171 /** Function prototype for netif->output functions. Called by lwIP when a packet
172  * shall be sent. For ethernet netif, set this to 'etharp_output' and set
173  * 'linkoutput'.
174  *
175  * @param netif The netif which shall send a packet
176  * @param p The packet to send (p->payload points to IP header)
177  * @param ipaddr The IP address to which the packet shall be sent
178  */
179 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
180        const ip4_addr_t *ipaddr);
181 #endif /* LWIP_IPV4*/
182 
183 #if LWIP_IPV6
184 /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet
185  * shall be sent. For ethernet netif, set this to 'ethip6_output' and set
186  * 'linkoutput'.
187  *
188  * @param netif The netif which shall send a packet
189  * @param p The packet to send (p->payload points to IP header)
190  * @param ipaddr The IPv6 address to which the packet shall be sent
191  */
192 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
193        const ip6_addr_t *ipaddr);
194 #endif /* LWIP_IPV6 */
195 
196 /** Function prototype for netif->linkoutput functions. Only used for ethernet
197  * netifs. This function is called by ARP when a packet shall be sent.
198  *
199  * @param netif The netif which shall send a packet
200  * @param p The packet to send (raw ethernet packet)
201  */
202 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
203 /** Function prototype for netif status- or link-callback functions. */
204 typedef void (*netif_status_callback_fn)(struct netif *netif);
205 #if LWIP_IPV4 && LWIP_IGMP
206 /** Function prototype for netif igmp_mac_filter functions */
207 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
208        const ip4_addr_t *group, enum netif_mac_filter_action action);
209 #endif /* LWIP_IPV4 && LWIP_IGMP */
210 #if LWIP_IPV6 && LWIP_IPV6_MLD
211 /** Function prototype for netif mld_mac_filter functions */
212 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
213        const ip6_addr_t *group, enum netif_mac_filter_action action);
214 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
215 
216 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
217 u8_t netif_alloc_client_data_id(void);
218 /** @ingroup netif_cd
219  * Set client data. Obtain ID from netif_alloc_client_data_id().
220  */
221 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
222 /** @ingroup netif_cd
223  * Get client data. Obtain ID from netif_alloc_client_data_id().
224  */
225 #define netif_get_client_data(netif, id)       (netif)->client_data[(id)]
226 #endif
227 
228 /** Generic data structure used for all lwIP network interfaces.
229  *  The following fields should be filled in by the initialization
230  *  function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
231 struct netif {
232 #if !LWIP_SINGLE_NETIF
233   /** pointer to next in linked list */
234   struct netif *next;
235 #endif
236 
237 #if LWIP_IPV4
238   /** IP address configuration in network byte order */
239   ip_addr_t ip_addr;
240   ip_addr_t netmask;
241   ip_addr_t gw;
242 #endif /* LWIP_IPV4 */
243 #if LWIP_IPV6
244   /** Array of IPv6 addresses for this netif. */
245   ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
246   /** The state of each IPv6 address (Tentative, Preferred, etc).
247    * @see ip6_addr.h */
248   u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
249 #if LWIP_IPV6_ADDRESS_LIFETIMES
250   /** Remaining valid and preferred lifetime of each IPv6 address, in seconds.
251    * For valid lifetimes, the special value of IP6_ADDR_LIFE_STATIC (0)
252    * indicates the address is static and has no lifetimes. */
253   u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES];
254   u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES];
255 #endif /* LWIP_IPV6_ADDRESS_LIFETIMES */
256 #endif /* LWIP_IPV6 */
257   /** This function is called by the network device driver
258    *  to pass a packet up the TCP/IP stack. */
259   netif_input_fn input;
260 #if LWIP_IPV4
261   /** This function is called by the IP module when it wants
262    *  to send a packet on the interface. This function typically
263    *  first resolves the hardware address, then sends the packet.
264    *  For ethernet physical layer, this is usually etharp_output() */
265   netif_output_fn output;
266 #endif /* LWIP_IPV4 */
267   /** This function is called by ethernet_output() when it wants
268    *  to send a packet on the interface. This function outputs
269    *  the pbuf as-is on the link medium. */
270   netif_linkoutput_fn linkoutput;
271 #if LWIP_IPV6
272   /** This function is called by the IPv6 module when it wants
273    *  to send a packet on the interface. This function typically
274    *  first resolves the hardware address, then sends the packet.
275    *  For ethernet physical layer, this is usually ethip6_output() */
276   netif_output_ip6_fn output_ip6;
277 #endif /* LWIP_IPV6 */
278 #if LWIP_NETIF_STATUS_CALLBACK
279   /** This function is called when the netif state is set to up or down
280    */
281   netif_status_callback_fn status_callback;
282 #endif /* LWIP_NETIF_STATUS_CALLBACK */
283 #if LWIP_NETIF_LINK_CALLBACK
284   /** This function is called when the netif link is set to up or down
285    */
286   netif_status_callback_fn link_callback;
287 #endif /* LWIP_NETIF_LINK_CALLBACK */
288 #if LWIP_NETIF_REMOVE_CALLBACK
289   /** This function is called when the netif has been removed */
290   netif_status_callback_fn remove_callback;
291 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
292   /** This field can be set by the device driver and could point
293    *  to state information for the device. */
294   void *state;
295 #ifdef netif_get_client_data
296   void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA];
297 #endif
298 #if LWIP_NETIF_HOSTNAME
299   /* the hostname for this netif, NULL is a valid value */
300   const char*  hostname;
301 #endif /* LWIP_NETIF_HOSTNAME */
302 #if LWIP_CHECKSUM_CTRL_PER_NETIF
303   u16_t chksum_flags;
304 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
305   /** maximum transfer unit (in bytes) */
306   u16_t mtu;
307   /** link level hardware address of this interface */
308   /* Ensure hwaddr is 16-bit aligned by placing it behind u16_t value
309    * because it is accessed via ETHADDR16_COPY() macro in etharp.c and autoip.c */
310   u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
311   /** number of bytes used in hwaddr */
312   u8_t hwaddr_len;
313   /** flags (@see @ref netif_flags) */
314   u8_t flags;
315   /** descriptive abbreviation */
316   char name[2];
317   /** number of this interface. Used for @ref if_api and @ref netifapi_netif,
318    * as well as for IPv6 zones */
319   u8_t num;
320 #if LWIP_IPV6_AUTOCONFIG
321   /** is this netif enabled for IPv6 autoconfiguration */
322   u8_t ip6_autoconfig_enabled;
323 #endif /* LWIP_IPV6_AUTOCONFIG */
324 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
325   /** Number of Router Solicitation messages that remain to be sent. */
326   u8_t rs_count;
327 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
328 #if MIB2_STATS
329   /** link type (from "snmp_ifType" enum from snmp_mib2.h) */
330   u8_t link_type;
331   /** (estimate) link speed */
332   u32_t link_speed;
333   /** timestamp at last change made (up/down) */
334   u32_t ts;
335   /** counters */
336   struct stats_mib2_netif_ctrs mib2_counters;
337 #endif /* MIB2_STATS */
338 #if LWIP_IPV4 && LWIP_IGMP
339   /** This function could be called to add or delete an entry in the multicast
340       filter table of the ethernet MAC.*/
341   netif_igmp_mac_filter_fn igmp_mac_filter;
342 #endif /* LWIP_IPV4 && LWIP_IGMP */
343 #if LWIP_IPV6 && LWIP_IPV6_MLD
344   /** This function could be called to add or delete an entry in the IPv6 multicast
345       filter table of the ethernet MAC. */
346   netif_mld_mac_filter_fn mld_mac_filter;
347 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
348 #if LWIP_NETIF_HWADDRHINT
349   u8_t *addr_hint;
350 #endif /* LWIP_NETIF_HWADDRHINT */
351 #if ENABLE_LOOPBACK
352   /* List of packets to be queued for ourselves. */
353   struct pbuf *loop_first;
354   struct pbuf *loop_last;
355 #if LWIP_LOOPBACK_MAX_PBUFS
356   u16_t loop_cnt_current;
357 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
358 #endif /* ENABLE_LOOPBACK */
359 };
360 
361 #if LWIP_CHECKSUM_CTRL_PER_NETIF
362 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
363   (netif)->chksum_flags = chksumflags; } while(0)
364 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
365 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
366 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
367 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
368 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
369 
370 #if LWIP_SINGLE_NETIF
371 #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL)
372 #else /* LWIP_SINGLE_NETIF */
373 /** The list of network interfaces. */
374 extern struct netif *netif_list;
375 #define NETIF_FOREACH(netif) for (netif = netif_list; netif != NULL; netif = netif->next)
376 #endif /* LWIP_SINGLE_NETIF */
377 /** The default network interface. */
378 extern struct netif *netif_default;
379 
380 void netif_init(void);
381 
382 struct netif *netif_add(struct netif *netif,
383 #if LWIP_IPV4
384                         const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
385 #endif /* LWIP_IPV4 */
386                         void *state, netif_init_fn init, netif_input_fn input);
387 #if LWIP_IPV4
388 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
389                     const ip4_addr_t *gw);
390 #endif /* LWIP_IPV4 */
391 void netif_remove(struct netif * netif);
392 
393 /* Returns a network interface given its name. The name is of the form
394    "et0", where the first two letters are the "name" field in the
395    netif structure, and the digit is in the num field in the same
396    structure. */
397 struct netif *netif_find(const char *name);
398 
399 void netif_set_default(struct netif *netif);
400 
401 #if LWIP_IPV4
402 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
403 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
404 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
405 /** @ingroup netif_ip4 */
406 #define netif_ip4_addr(netif)    ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
407 /** @ingroup netif_ip4 */
408 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
409 /** @ingroup netif_ip4 */
410 #define netif_ip4_gw(netif)      ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
411 /** @ingroup netif_ip4 */
412 #define netif_ip_addr4(netif)    ((const ip_addr_t*)&((netif)->ip_addr))
413 /** @ingroup netif_ip4 */
414 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
415 /** @ingroup netif_ip4 */
416 #define netif_ip_gw4(netif)      ((const ip_addr_t*)&((netif)->gw))
417 #endif /* LWIP_IPV4 */
418 
419 void netif_set_up(struct netif *netif);
420 void netif_set_down(struct netif *netif);
421 /** @ingroup netif
422  * Ask if an interface is up
423  */
424 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
425 
426 #if LWIP_NETIF_STATUS_CALLBACK
427 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
428 #endif /* LWIP_NETIF_STATUS_CALLBACK */
429 #if LWIP_NETIF_REMOVE_CALLBACK
430 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
431 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
432 
433 void netif_set_link_up(struct netif *netif);
434 void netif_set_link_down(struct netif *netif);
435 /** Ask if a link is up */
436 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
437 
438 #if LWIP_NETIF_LINK_CALLBACK
439 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
440 #endif /* LWIP_NETIF_LINK_CALLBACK */
441 
442 #if LWIP_NETIF_HOSTNAME
443 /** @ingroup netif */
444 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
445 /** @ingroup netif */
446 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
447 #endif /* LWIP_NETIF_HOSTNAME */
448 
449 #if LWIP_IGMP
450 /** @ingroup netif */
451 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
452 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
453 #endif /* LWIP_IGMP */
454 
455 #if LWIP_IPV6 && LWIP_IPV6_MLD
456 /** @ingroup netif */
457 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
458 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
459 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0)
460 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
461 
462 #if ENABLE_LOOPBACK
463 err_t netif_loop_output(struct netif *netif, struct pbuf *p);
464 void netif_poll(struct netif *netif);
465 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
466 void netif_poll_all(void);
467 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
468 #endif /* ENABLE_LOOPBACK */
469 
470 err_t netif_input(struct pbuf *p, struct netif *inp);
471 
472 #if LWIP_IPV6
473 /** @ingroup netif_ip6 */
474 #define netif_ip_addr6(netif, i)  ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
475 /** @ingroup netif_ip6 */
476 #define netif_ip6_addr(netif, i)  ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
477 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
478 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);
479 #define netif_ip6_addr_state(netif, i)  ((netif)->ip6_addr_state[i])
480 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state);
481 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr);
482 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit);
483 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx);
484 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0)
485 #if LWIP_IPV6_ADDRESS_LIFETIMES
486 #define netif_ip6_addr_valid_life(netif, i)  \
487     (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC)
488 #define netif_ip6_addr_set_valid_life(netif, i, secs) \
489     do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0)
490 #define netif_ip6_addr_pref_life(netif, i)  \
491     (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC)
492 #define netif_ip6_addr_set_pref_life(netif, i, secs) \
493     do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0)
494 #define netif_ip6_addr_isstatic(netif, i)  \
495     (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC)
496 #else /* !LWIP_IPV6_ADDRESS_LIFETIMES */
497 #define netif_ip6_addr_isstatic(netif, i)  (1) /* all addresses are static */
498 #endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */
499 #endif /* LWIP_IPV6 */
500 
501 #if LWIP_NETIF_HWADDRHINT
502 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
503 #else /* LWIP_NETIF_HWADDRHINT */
504 #define NETIF_SET_HWADDRHINT(netif, hint)
505 #endif /* LWIP_NETIF_HWADDRHINT */
506 
507 u8_t netif_name_to_index(const char *name);
508 char * netif_index_to_name(u8_t idx, char *name);
509 struct netif* netif_get_by_index(u8_t idx);
510 
511 /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 */
512 #define netif_get_index(netif)      ((netif)->num + 1)
513 #define NETIF_NO_INDEX              (0)
514 
515 /**
516  * @ingroup netif
517  * Extended netif status callback (NSC) reasons enumeration.
518  * May be extended in the future!
519  */
520 typedef enum
521 {
522   /** netif was added. arg: NULL. Called AFTER netif was added. */
523   LWIP_NSC_NETIF_ADDED,
524   /** netif was removed. arg: NULL. Called BEFORE netif is removed. */
525   LWIP_NSC_NETIF_REMOVED,
526   /** link changed */
527   LWIP_NSC_LINK_CHANGED,
528   /** netif administrative status changed.\n
529    * up is called AFTER netif is set up.\n
530    * down is called BEFORE the netif is actually set down. */
531   LWIP_NSC_STATUS_CHANGED,
532   /** IPv4 address has changed */
533   LWIP_NSC_IPV4_ADDRESS_CHANGED,
534   /** IPv4 gateway has changed */
535   LWIP_NSC_IPV4_GATEWAY_CHANGED,
536   /** IPv4 netmask has changed */
537   LWIP_NSC_IPV4_NETMASK_CHANGED,
538   /** called AFTER IPv4 address/gateway/netmask changes have been applied. arg: NULL */
539   LWIP_NSC_IPV4_SETTINGS_CHANGED,
540   /** IPv6 address was added */
541   LWIP_NSC_IPV6_SET,
542   /** IPv6 address state has changed */
543   LWIP_NSC_IPV6_ADDR_STATE_CHANGED
544 } netif_nsc_reason_t;
545 
546 /** @ingroup netif
547  * Argument supplied to netif_ext_callback_fn.
548  */
549 typedef union
550 {
551   /** Args to LWIP_NSC_LINK_CHANGED callback */
552   struct link_changed_s
553   {
554     /** 1: up; 0: down */
555     u8_t state;
556   } link_changed;
557   /** Args to LWIP_NSC_STATUS_CHANGED callback */
558   struct status_changed_s
559   {
560     /** 1: up; 0: down */
561     u8_t state;
562   } status_changed;
563   /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED callback */
564   struct ipv4_changed_s
565   {
566     /** Old IPv4 address */
567     const ip_addr_t* old_address;
568   } ipv4_changed;
569   /** Args to LWIP_NSC_IPV4_GATEWAY_CHANGED callback */
570   struct ipv4_gw_changed_s
571   {
572     /** Old IPv4 gateway */
573     const ip_addr_t* old_address;
574   } ipv4_gw_changed;
575   /** Args to LWIP_NSC_IPV4_NETMASK_CHANGED callback */
576   struct ipv4_nm_changed_s
577   {
578     /** Old IPv4 netmask */
579     const ip_addr_t* old_address;
580   } ipv4_nm_changed;
581   /** Args to LWIP_NSC_IPV6_SET callback */
582   struct ipv6_set_s
583   {
584     /** Index of changed IPv6 address */
585     s8_t addr_index;
586     /** Old IPv6 address */
587     const ip_addr_t* old_address;
588   } ipv6_set;
589   /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */
590   struct ipv6_addr_state_changed_s
591   {
592     /** Index of affected IPv6 address */
593     s8_t addr_index;
594     /** Affected IPv6 address */
595     const ip_addr_t* address;
596   } ipv6_addr_state_changed;
597 } netif_ext_callback_args_t;
598 
599 /**
600  * @ingroup netif
601  * Function used for extended netif status callbacks
602  * Note: When parsing reason argument, keep in mind that more reasons may be added in the future!
603  * @param netif netif that is affected by change
604  * @param reason change reason
605  * @param args depends on reason, see reason description
606  */
607 typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args);
608 
609 #if LWIP_NETIF_EXT_STATUS_CALLBACK
610 struct netif_ext_callback;
611 typedef struct netif_ext_callback
612 {
613   netif_ext_callback_fn callback_fn;
614   struct netif_ext_callback* next;
615 } netif_ext_callback_t;
616 
617 #define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name;
618 void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn);
619 void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args);
620 #else
621 #define NETIF_DECLARE_EXT_CALLBACK(name)
622 #define netif_add_ext_callback(callback, fn)
623 #define netif_invoke_ext_callback(netif, reason, args)
624 #endif
625 
626 #ifdef __cplusplus
627 }
628 #endif
629 
630 #endif /* LWIP_HDR_NETIF_H */
631