UbixOS V2  2.0
netif.h
Go to the documentation of this file.
1 
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 <net/opt.h>
41 
42 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
43 
44 #include <net/err.h>
45 
46 #include <net/ip_addr.h>
47 
48 #include <net/def.h>
49 #include <net/pbuf.h>
50 #include <net/stats.h>
51 
52 struct nicBuffer {
53  struct nicBuffer *next;
54  int length;
55  char *buffer;
56 };
57 
58 extern struct nicBuffer *tmpBuf;
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /* Throughout this file, IP addresses are expected to be in
65  * the same byte order as in IP_PCB. */
66 
70 #ifndef NETIF_MAX_HWADDR_LEN
71 #define NETIF_MAX_HWADDR_LEN 6U
72 #endif
73 
86 #define NETIF_FLAG_UP 0x01U
87 
89 #define NETIF_FLAG_BROADCAST 0x02U
90 
95 #define NETIF_FLAG_LINK_UP 0x04U
96 
99 #define NETIF_FLAG_ETHARP 0x08U
100 
103 #define NETIF_FLAG_ETHERNET 0x10U
104 
106 #define NETIF_FLAG_IGMP 0x20U
107 
109 #define NETIF_FLAG_MLD6 0x40U
110 
116 {
117 #if LWIP_DHCP
118  LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
119 #endif
120 #if LWIP_AUTOIP
121  LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
122 #endif
123 #if LWIP_IGMP
124  LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
125 #endif
126 #if LWIP_IPV6_MLD
127  LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
128 #endif
130 };
131 
132 #if LWIP_CHECKSUM_CTRL_PER_NETIF
133 #define NETIF_CHECKSUM_GEN_IP 0x0001
134 #define NETIF_CHECKSUM_GEN_UDP 0x0002
135 #define NETIF_CHECKSUM_GEN_TCP 0x0004
136 #define NETIF_CHECKSUM_GEN_ICMP 0x0008
137 #define NETIF_CHECKSUM_GEN_ICMP6 0x0010
138 #define NETIF_CHECKSUM_CHECK_IP 0x0100
139 #define NETIF_CHECKSUM_CHECK_UDP 0x0200
140 #define NETIF_CHECKSUM_CHECK_TCP 0x0400
141 #define NETIF_CHECKSUM_CHECK_ICMP 0x0800
142 #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
143 #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
144 #define NETIF_CHECKSUM_DISABLE_ALL 0x0000
145 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
146 
147 struct netif;
148 
156 };
157 
163 typedef err_t (*netif_init_fn)(struct netif *netif);
170 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
171 
172 #if LWIP_IPV4
173 
181 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
182  const ip4_addr_t *ipaddr);
183 #endif /* LWIP_IPV4*/
184 
185 #if LWIP_IPV6
186 
194 typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
195  const ip6_addr_t *ipaddr);
196 #endif /* LWIP_IPV6 */
197 
204 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
206 typedef void (*netif_status_callback_fn)(struct netif *netif);
207 #if LWIP_IPV4 && LWIP_IGMP
208 
209 typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
210  const ip4_addr_t *group, enum netif_mac_filter_action action);
211 #endif /* LWIP_IPV4 && LWIP_IGMP */
212 #if LWIP_IPV6 && LWIP_IPV6_MLD
213 
214 typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
215  const ip6_addr_t *group, enum netif_mac_filter_action action);
216 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
217 
218 #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
219 u8_t netif_alloc_client_data_id(void);
223 #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
224 
227 #define netif_get_client_data(netif, id) (netif)->client_data[(id)]
228 #endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */
229 
233 struct netif {
235  struct netif *next;
236 
237 #if LWIP_IPV4
238 
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 
248  u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
249 #endif /* LWIP_IPV6 */
250 
253 #if LWIP_IPV4
254 
258  netif_output_fn output;
259 #endif /* LWIP_IPV4 */
260 
264 #if LWIP_IPV6
265 
269  netif_output_ip6_fn output_ip6;
270 #endif /* LWIP_IPV6 */
271 #if LWIP_NETIF_STATUS_CALLBACK
272 
274  netif_status_callback_fn status_callback;
275 #endif /* LWIP_NETIF_STATUS_CALLBACK */
276 #if LWIP_NETIF_LINK_CALLBACK
277 
279  netif_status_callback_fn link_callback;
280 #endif /* LWIP_NETIF_LINK_CALLBACK */
281 #if LWIP_NETIF_REMOVE_CALLBACK
282 
283  netif_status_callback_fn remove_callback;
284 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
285 
287  void *state;
288 #ifdef netif_get_client_data
290 #endif
291 #if LWIP_IPV6_AUTOCONFIG
292 
293  u8_t ip6_autoconfig_enabled;
294 #endif /* LWIP_IPV6_AUTOCONFIG */
295 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
296 
297  u8_t rs_count;
298 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
299 #if LWIP_NETIF_HOSTNAME
300  /* the hostname for this netif, NULL is a valid value */
301  const char* hostname;
302 #endif /* LWIP_NETIF_HOSTNAME */
303 #if LWIP_CHECKSUM_CTRL_PER_NETIF
304  u16_t chksum_flags;
305 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
306 
315  char name[2];
318 #if MIB2_STATS
319 
320  u8_t link_type;
322  u32_t link_speed;
324  u32_t ts;
326  struct stats_mib2_netif_ctrs mib2_counters;
327 #endif /* MIB2_STATS */
328 #if LWIP_IPV4 && LWIP_IGMP
329 
331  netif_igmp_mac_filter_fn igmp_mac_filter;
332 #endif /* LWIP_IPV4 && LWIP_IGMP */
333 #if LWIP_IPV6 && LWIP_IPV6_MLD
334 
336  netif_mld_mac_filter_fn mld_mac_filter;
337 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
338 #if LWIP_NETIF_HWADDRHINT
339  u8_t *addr_hint;
340 #endif /* LWIP_NETIF_HWADDRHINT */
341 #if ENABLE_LOOPBACK
342  /* List of packets to be queued for ourselves. */
343  struct pbuf *loop_first;
344  struct pbuf *loop_last;
345 #if LWIP_LOOPBACK_MAX_PBUFS
346  u16_t loop_cnt_current;
347 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
348 #endif /* ENABLE_LOOPBACK */
349 };
350 
351 #if LWIP_CHECKSUM_CTRL_PER_NETIF
352 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
353  (netif)->chksum_flags = chksumflags; } while(0)
354 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
355 #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
356 #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
357 #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
358 #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
359 
361 extern struct netif *netif_list;
363 extern struct netif *netif_default;
364 
365 void netif_init(void);
366 
367 struct netif *netif_add(struct netif *netif,
368 #if LWIP_IPV4
369  const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
370 #endif /* LWIP_IPV4 */
371  void *state, netif_init_fn init, netif_input_fn input);
372 #if LWIP_IPV4
373 void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
374  const ip4_addr_t *gw);
375 #endif /* LWIP_IPV4 */
376 void netif_remove(struct netif * netif);
377 
378 /* Returns a network interface given its name. The name is of the form
379  "et0", where the first two letters are the "name" field in the
380  netif structure, and the digit is in the num field in the same
381  structure. */
382 struct netif *netif_find(const char *name);
383 
384 void netif_set_default(struct netif *netif);
385 
386 #if LWIP_IPV4
387 void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
388 void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
389 void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
391 #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
392 
393 #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
394 
395 #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
396 
397 #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
398 
399 #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
400 
401 #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
402 #endif /* LWIP_IPV4 */
403 
404 void netif_set_up(struct netif *netif);
405 void netif_set_down(struct netif *netif);
409 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
410 
411 #if LWIP_NETIF_STATUS_CALLBACK
412 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
413 #endif /* LWIP_NETIF_STATUS_CALLBACK */
414 #if LWIP_NETIF_REMOVE_CALLBACK
415 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
416 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
417 
418 void netif_set_link_up(struct netif *netif);
419 void netif_set_link_down(struct netif *netif);
421 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
422 
423 #if LWIP_NETIF_LINK_CALLBACK
424 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
425 #endif /* LWIP_NETIF_LINK_CALLBACK */
426 
427 #if LWIP_NETIF_HOSTNAME
428 
429 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
430 
431 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
432 #endif /* LWIP_NETIF_HOSTNAME */
433 
434 #if LWIP_IGMP
435 
436 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
437 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
438 #endif /* LWIP_IGMP */
439 
440 #if LWIP_IPV6 && LWIP_IPV6_MLD
441 
442 #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
443 #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
444 #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0)
445 #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
446 
447 #if ENABLE_LOOPBACK
448 err_t netif_loop_output(struct netif *netif, struct pbuf *p);
449 void netif_poll(struct netif *netif);
450 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
451 void netif_poll_all(void);
452 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
453 #endif /* ENABLE_LOOPBACK */
454 
455 err_t netif_input(struct pbuf *p, struct netif *inp);
456 
457 #if LWIP_IPV6
458 
459 #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
460 
461 #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
462 void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
463 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);
464 #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
465 void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state);
466 s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr);
467 void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit);
468 err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx);
469 #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0)
470 #endif /* LWIP_IPV6 */
471 
472 #if LWIP_NETIF_HWADDRHINT
473 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
474 #else /* LWIP_NETIF_HWADDRHINT */
475 #define NETIF_SET_HWADDRHINT(netif, hint)
476 #endif /* LWIP_NETIF_HWADDRHINT */
477 
478 #ifdef __cplusplus
479 }
480 #endif
481 
482 /*MrOlsen 2017-12-17 LWIP */
483 void ethernetif_input(struct netif *);
484 
485 #endif /* LWIP_HDR_NETIF_H */
opt.h
def.h
NETIF_MAX_HWADDR_LEN
#define NETIF_MAX_HWADDR_LEN
Definition: netif.h:71
netif_set_up
void netif_set_up(struct netif *netif)
Definition: netif.c:624
netif_set_down
void netif_set_down(struct netif *netif)
Definition: netif.c:682
nicBuffer::next
struct nicBuffer * next
Definition: netif.h:53
pbuf.h
nicBuffer::buffer
char * buffer
Definition: netif.h:55
ethernetif_input
void ethernetif_input(struct netif *)
Definition: ethernetif.c:270
u16_t
uint16_t u16_t
Definition: arch.h:124
netif::input
netif_input_fn input
Definition: netif.h:252
netif_remove
void netif_remove(struct netif *netif)
Definition: netif.c:377
u32_t
uint32_t u32_t
Definition: arch.h:126
netif::state
void * state
Definition: netif.h:287
netif::mtu
u16_t mtu
Definition: netif.h:307
netif_input_fn
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: netif.h:170
netif::flags
u8_t flags
Definition: netif.h:313
netif_find
struct netif * netif_find(const char *name)
Definition: netif.c:472
netif_status_callback_fn
void(* netif_status_callback_fn)(struct netif *netif)
Definition: netif.h:206
NETIF_DEL_MAC_FILTER
Definition: netif.h:153
netif::linkoutput
netif_linkoutput_fn linkoutput
Definition: netif.h:263
netif_init
void netif_init(void)
Definition: netif.c:163
NETIF_ADD_MAC_FILTER
Definition: netif.h:155
stats.h
netif::hwaddr
u8_t hwaddr[6U]
Definition: netif.h:311
lwip_internal_netif_client_data_index
lwip_internal_netif_client_data_index
Definition: netif.h:115
netif::num
u8_t num
Definition: netif.h:317
u8_t
uint8_t u8_t
Definition: arch.h:122
err.h
ip_addr_t
ip6_addr_t ip_addr_t
Definition: ip_addr.h:290
netif_linkoutput_fn
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition: netif.h:204
nicBuffer
Definition: netif.h:52
netif
Definition: netif.h:233
netif::hwaddr_len
u8_t hwaddr_len
Definition: netif.h:309
netif::name
char name[2]
Definition: netif.h:315
netif::next
struct netif * next
Definition: netif.h:235
s8_t
int8_t s8_t
Definition: arch.h:123
netif_set_default
void netif_set_default(struct netif *netif)
Definition: netif.c:604
netif_list
struct netif * netif_list
Definition: netif.c:104
netif_add
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:241
err_t
s8_t err_t
Definition: err.h:57
name
const char * name
Definition: pci.c:37
nicBuffer::length
int length
Definition: netif.h:54
netif_input
err_t netif_input(struct pbuf *p, struct netif *inp)
Definition: netif.c:203
netif_set_link_down
void netif_set_link_down(struct netif *netif)
Definition: netif.c:760
netif_set_link_up
void netif_set_link_up(struct netif *netif)
Definition: netif.c:735
netif_init_fn
err_t(* netif_init_fn)(struct netif *netif)
Definition: netif.h:163
LWIP_IPV4
#define LWIP_IPV4
Definition: lwipopts.h:109
LWIP_NUM_NETIF_CLIENT_DATA
#define LWIP_NUM_NETIF_CLIENT_DATA
Definition: lwipopts.h:229
tmpBuf
struct nicBuffer * tmpBuf
Definition: ethernetif.c:63
pbuf
Definition: pbuf.h:142
ip_addr.h
LWIP_NETIF_CLIENT_DATA_INDEX_MAX
Definition: netif.h:129
LWIP_IPV6_NUM_ADDRESSES
#define LWIP_IPV6_NUM_ADDRESSES
Definition: lwipopts.h:367
netif_mac_filter_action
netif_mac_filter_action
Definition: netif.h:151
netif_default
struct netif * netif_default
Definition: netif.c:105