ConOpSys V2970  P004.07
ANVILEX control operating system
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 "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 
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 */
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. */
157  /** Delete a filter entry */
159  /** Add a filter entry */
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 initialise
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
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 initialisation
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. */
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. */
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. */
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
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) */
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 */
342  /** number of bytes used in hwaddr */
344  /** flags (@see @ref netif_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 */
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 #endif /* ENABLE_LOOPBACK */
390 };
391 
392 #if LWIP_CHECKSUM_CTRL_PER_NETIF
393 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
394  (netif)->chksum_flags = chksumflags; } while(0)
395 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
396 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
397 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
398 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
399 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
400 
401 #if LWIP_SINGLE_NETIF
402 #define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL)
403 #else /* LWIP_SINGLE_NETIF */
404 /** The list of network interfaces. */
405 extern struct netif *netif_list;
406 #define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next)
407 #endif /* LWIP_SINGLE_NETIF */
408 /** The default network interface. */
409 extern struct netif *netif_default;
410 
411 void netif_init(void);
412 
414 
415 #if LWIP_IPV4
416 struct netif *netif_add(struct netif *netif,
417  const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
418  void *state, netif_init_fn init, netif_input_fn input);
419 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
420  const ip4_addr_t *gw);
421 #else /* LWIP_IPV4 */
422 struct netif *netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input);
423 #endif /* LWIP_IPV4 */
424 void netif_remove(struct netif * netif);
425 
426 /* Returns a network interface given its name. The name is of the form
427  "et0", where the first two letters are the "name" field in the
428  netif structure, and the digit is in the num field in the same
429  structure. */
430 struct netif *netif_find(const char *name);
431 
432 void netif_set_default(struct netif *netif);
433 
434 #if LWIP_IPV4
435 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
436 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
437 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
438 /** @ingroup netif_ip4 */
439 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
440 /** @ingroup netif_ip4 */
441 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
442 /** @ingroup netif_ip4 */
443 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
444 /** @ingroup netif_ip4 */
445 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
446 /** @ingroup netif_ip4 */
447 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
448 /** @ingroup netif_ip4 */
449 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
450 #endif /* LWIP_IPV4 */
451 
452 #define netif_set_flags(netif, set_flags) do { (netif)->flags = (u8_t)((netif)->flags | (set_flags)); } while(0)
453 #define netif_clear_flags(netif, clr_flags) do { (netif)->flags = (u8_t)((netif)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
454 #define netif_is_flag_set(nefif, flag) (((netif)->flags & (flag)) != 0)
455 
456 void netif_set_up(struct netif *netif);
457 void netif_set_down(struct netif *netif);
458 /** @ingroup netif
459  * Ask if an interface is up
460  */
461 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
462 
463 #if LWIP_NETIF_STATUS_CALLBACK
464 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
465 #endif /* LWIP_NETIF_STATUS_CALLBACK */
466 #if LWIP_NETIF_REMOVE_CALLBACK
467 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
468 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
469 
470 void netif_set_link_up(struct netif *netif);
471 void netif_set_link_down(struct netif *netif);
472 /** Ask if a link is up */
473 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
474 
475 #if LWIP_NETIF_LINK_CALLBACK
476 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
477 #endif /* LWIP_NETIF_LINK_CALLBACK */
478 
479 #if LWIP_NETIF_HOSTNAME
480 /** @ingroup netif */
481 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
482 /** @ingroup netif */
483 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
484 #endif /* LWIP_NETIF_HOSTNAME */
485 
486 #if LWIP_IGMP
487 /** @ingroup netif */
488 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
489 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
490 #endif /* LWIP_IGMP */
491 
492 #if LWIP_IPV6 && LWIP_IPV6_MLD
493 /** @ingroup netif */
494 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
495 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
496 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0)
497 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
498 
499 #if ENABLE_LOOPBACK
500 err_t netif_loop_output(struct netif *netif, struct pbuf *p);
501 void netif_poll(struct netif *netif);
502 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
503 void netif_poll_all(void);
504 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
505 #endif /* ENABLE_LOOPBACK */
506 
507 err_t netif_input(struct pbuf *p, struct netif *inp);
508 
509 #if LWIP_IPV6
510 /** @ingroup netif_ip6 */
511 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
512 /** @ingroup netif_ip6 */
513 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
514 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
515 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);
516 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
517 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state);
518 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr);
519 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit);
520 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx);
521 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0)
522 #if LWIP_IPV6_ADDRESS_LIFETIMES
523 #define netif_ip6_addr_valid_life(netif, i) \
524  (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC)
525 #define netif_ip6_addr_set_valid_life(netif, i, secs) \
526  do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0)
527 #define netif_ip6_addr_pref_life(netif, i) \
528  (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC)
529 #define netif_ip6_addr_set_pref_life(netif, i, secs) \
530  do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0)
531 #define netif_ip6_addr_isstatic(netif, i) \
532  (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC)
533 #else /* !LWIP_IPV6_ADDRESS_LIFETIMES */
534 #define netif_ip6_addr_isstatic(netif, i) (1) /* all addresses are static */
535 #endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */
536 #if LWIP_ND6_ALLOW_RA_UPDATES
537 #define netif_mtu6(netif) ((netif)->mtu6)
538 #else /* LWIP_ND6_ALLOW_RA_UPDATES */
539 #define netif_mtu6(netif) ((netif)->mtu)
540 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */
541 #endif /* LWIP_IPV6 */
542 
543 #if LWIP_NETIF_USE_HINTS
544 #define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint)
545 #define NETIF_RESET_HINTS(netif) (netif)->hints = NULL
546 #else /* LWIP_NETIF_USE_HINTS */
547 #define NETIF_SET_HINTS(netif, netifhint)
548 #define NETIF_RESET_HINTS(netif)
549 #endif /* LWIP_NETIF_USE_HINTS */
550 
551 u8_t netif_name_to_index(const char *name);
552 char * netif_index_to_name(u8_t idx, char *name);
553 struct netif* netif_get_by_index(u8_t idx);
554 
555 /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/
556 #define netif_get_index(netif) ((u8_t)((netif)->num + 1))
557 #define NETIF_NO_INDEX (0)
558 
559 /**
560  * @ingroup netif
561  * Extended netif status callback (NSC) reasons flags.
562  * May be extended in the future!
563  */
565 
566 /* used for initialisation only */
567 #define LWIP_NSC_NONE 0x0000
568 /** netif was added. arg: NULL. Called AFTER netif was added. */
569 #define LWIP_NSC_NETIF_ADDED 0x0001
570 /** netif was removed. arg: NULL. Called BEFORE netif is removed. */
571 #define LWIP_NSC_NETIF_REMOVED 0x0002
572 /** link changed */
573 #define LWIP_NSC_LINK_CHANGED 0x0004
574 /** netif administrative status changed.\n
575  * up is called AFTER netif is set up.\n
576  * down is called BEFORE the netif is actually set down. */
577 #define LWIP_NSC_STATUS_CHANGED 0x0008
578 /** IPv4 address has changed */
579 #define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010
580 /** IPv4 gateway has changed */
581 #define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020
582 /** IPv4 netmask has changed */
583 #define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040
584 /** called AFTER IPv4 address/gateway/netmask changes have been applied */
585 #define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080
586 /** IPv6 address was added */
587 #define LWIP_NSC_IPV6_SET 0x0100
588 /** IPv6 address state has changed */
589 #define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200
590 
591 /** @ingroup netif
592  * Argument supplied to netif_ext_callback_fn.
593  */
594 typedef union
595 {
596  /** Args to LWIP_NSC_LINK_CHANGED callback */
598  {
599  /** 1: up; 0: down */
601  } link_changed;
602  /** Args to LWIP_NSC_STATUS_CHANGED callback */
604  {
605  /** 1: up; 0: down */
607  } status_changed;
608  /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWIP_NSC_IPV4_SETTINGS_CHANGED callback */
610  {
611  /** Old IPv4 address */
615  } ipv4_changed;
616  /** Args to LWIP_NSC_IPV6_SET callback */
617  struct ipv6_set_s
618  {
619  /** Index of changed IPv6 address */
621  /** Old IPv6 address */
623  } ipv6_set;
624  /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */
626  {
627  /** Index of affected IPv6 address */
629  /** Old IPv6 address state */
631  /** Affected IPv6 address */
633  } ipv6_addr_state_changed;
635 
636 /**
637  * @ingroup netif
638  * Function used for extended netif status callbacks
639  * Note: When parsing reason argument, keep in mind that more reasons may be added in the future!
640  * @param netif netif that is affected by change
641  * @param reason change reason
642  * @param args depends on reason, see reason description
643  */
644 typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args);
645 
646 #if LWIP_NETIF_EXT_STATUS_CALLBACK
647 struct netif_ext_callback;
648 typedef struct netif_ext_callback
649 {
650  netif_ext_callback_fn callback_fn;
651  struct netif_ext_callback* next;
652 } netif_ext_callback_t;
653 
654 #define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name;
655 void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn);
656 void netif_remove_ext_callback(netif_ext_callback_t* callback);
658 #else
659 #define NETIF_DECLARE_EXT_CALLBACK(name)
660 #define netif_add_ext_callback(callback, fn)
661 #define netif_remove_ext_callback(callback)
662 #define netif_invoke_ext_callback(netif, reason, args)
663 #endif
664 
665 #ifdef __cplusplus
666 }
667 #endif
668 
669 #endif /* LWIP_HDR_NETIF_H */
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
int8_t s8_t
Definition: arch.h:126
s8_t err_t
Definition: err.h:96
#define LWIP_IPV6_NUM_ADDRESSES
Definition: opt.h:2420
#define LWIP_NUM_NETIF_CLIENT_DATA
Definition: opt.h:1666
void netif_set_link_down(struct netif *netif)
Definition: netif.c:1026
char * netif_index_to_name(u8_t idx, char *name)
Definition: netif.c:1656
void(* netif_ext_callback_fn)(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
Definition: netif.h:644
void netif_set_down(struct netif *netif)
Definition: netif.c:919
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:276
struct netif * netif_find(const char *name)
Definition: netif.c:1701
void netif_remove(struct netif *netif)
Definition: netif.c:737
u16_t netif_nsc_reason_t
Definition: netif.h:564
struct netif * netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:239
u8_t netif_name_to_index(const char *name)
Definition: netif.c:1637
void netif_set_default(struct netif *netif)
Definition: netif.c:822
void netif_set_link_up(struct netif *netif)
Definition: netif.c:988
struct netif * netif_get_by_index(u8_t idx)
Definition: netif.c:1676
void netif_set_up(struct netif *netif)
Definition: netif.c:844
ip6_addr_t ip_addr_t
Definition: ip_addr.h:318
void netif_init(void)
Definition: netif.c:177
struct netif * netif_list
Definition: netif.c:110
err_t(* netif_init_fn)(struct netif *netif)
Definition: netif.h:168
struct netif * netif_default
Definition: netif.c:112
void(* netif_status_callback_fn)(struct netif *netif)
Definition: netif.h:214
lwip_internal_netif_client_data_index
Definition: netif.h:114
@ LWIP_NETIF_CLIENT_DATA_INDEX_MAX
Definition: netif.h:134
err_t netif_input(struct pbuf *p, struct netif *inp)
Definition: netif.c:217
#define netif_invoke_ext_callback(netif, reason, args)
Definition: netif.h:662
#define netif_add_ext_callback(callback, fn)
Definition: netif.h:660
netif_mac_filter_action
Definition: netif.h:156
@ NETIF_ADD_MAC_FILTER
Definition: netif.h:160
@ NETIF_DEL_MAC_FILTER
Definition: netif.h:158
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: netif.h:178
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition: netif.h:212
#define NETIF_MAX_HWADDR_LEN
Definition: netif.h:63
u8_t netif_addr_idx_t
Definition: netif.h:244
#define netif_remove_ext_callback(callback)
Definition: netif.h:661
const ip_addr_t * old_address
Definition: netif.h:612
const ip_addr_t * old_gw
Definition: netif.h:614
const ip_addr_t * old_netmask
Definition: netif.h:613
const ip_addr_t * address
Definition: netif.h:632
const ip_addr_t * old_address
Definition: netif.h:622
s8_t addr_index
Definition: netif.h:620
Definition: netif.h:260
u8_t flags
Definition: netif.h:345
char name[2]
Definition: netif.h:347
void * state
Definition: netif.h:323
netif_input_fn input
Definition: netif.h:288
u8_t num
Definition: netif.h:350
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:341
u16_t mtu
Definition: netif.h:335
netif_linkoutput_fn linkoutput
Definition: netif.h:299
struct netif * next
Definition: netif.h:263
u8_t hwaddr_len
Definition: netif.h:343
Definition: pbuf.h:186
Definition: netif.h:595