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