BadVPN – Blame information for rev 1

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