The Pedigree Project 0.1
netif.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
25/*
26 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without modification,
30 * are permitted provided that the following conditions are met:
31 *
32 * 1. Redistributions of source code must retain the above copyright notice,
33 * this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following disclaimer in the documentation
36 * and/or other materials provided with the distribution.
37 * 3. The name of the author may not be used to endorse or promote products
38 * derived from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49 * OF SUCH DAMAGE.
50 *
51 * This file is part of the lwIP TCP/IP stack.
52 *
53 * Author: Adam Dunkels <adam@sics.se>
54 *
55 */
56#ifndef LWIP_HDR_NETIF_H
57#define LWIP_HDR_NETIF_H
58
59#include "lwip/opt.h"
60
61#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
62
63#include "lwip/err.h"
64
65#include "lwip/ip_addr.h"
66
67#include "lwip/def.h"
68#include "lwip/pbuf.h"
69#include "lwip/stats.h"
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75/* Throughout this file, IP addresses are expected to be in
76 * the same byte order as in IP_PCB. */
77
81#ifndef NETIF_MAX_HWADDR_LEN
82#define NETIF_MAX_HWADDR_LEN 6U
83#endif
84
97#define NETIF_FLAG_UP 0x01U
100#define NETIF_FLAG_BROADCAST 0x02U
106#define NETIF_FLAG_LINK_UP 0x04U
110#define NETIF_FLAG_ETHARP 0x08U
114#define NETIF_FLAG_ETHERNET 0x10U
117#define NETIF_FLAG_IGMP 0x20U
120#define NETIF_FLAG_MLD6 0x40U
121
126enum lwip_internal_netif_client_data_index
127{
128#if LWIP_DHCP
129 LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
130#endif
131#if LWIP_AUTOIP
132 LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
133#endif
134#if LWIP_IGMP
135 LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
136#endif
137#if LWIP_IPV6_MLD
138 LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
139#endif
140 LWIP_NETIF_CLIENT_DATA_INDEX_MAX
141};
142
143#if LWIP_CHECKSUM_CTRL_PER_NETIF
144#define NETIF_CHECKSUM_GEN_IP 0x0001
145#define NETIF_CHECKSUM_GEN_UDP 0x0002
146#define NETIF_CHECKSUM_GEN_TCP 0x0004
147#define NETIF_CHECKSUM_GEN_ICMP 0x0008
148#define NETIF_CHECKSUM_GEN_ICMP6 0x0010
149#define NETIF_CHECKSUM_CHECK_IP 0x0100
150#define NETIF_CHECKSUM_CHECK_UDP 0x0200
151#define NETIF_CHECKSUM_CHECK_TCP 0x0400
152#define NETIF_CHECKSUM_CHECK_ICMP 0x0800
153#define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
154#define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
155#define NETIF_CHECKSUM_DISABLE_ALL 0x0000
156#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
157
158struct netif;
159
168
174typedef err_t (*netif_init_fn)(struct netif *netif);
181typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
182
183#if LWIP_IPV4
192typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
193 const ip4_addr_t *ipaddr);
194#endif /* LWIP_IPV4*/
195
196#if LWIP_IPV6
205typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
206 const ip6_addr_t *ipaddr);
207#endif /* LWIP_IPV6 */
208
215typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
217typedef void (*netif_status_callback_fn)(struct netif *netif);
218#if LWIP_IPV4 && LWIP_IGMP
220typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
221 const ip4_addr_t *group, enum netif_mac_filter_action action);
222#endif /* LWIP_IPV4 && LWIP_IGMP */
223#if LWIP_IPV6 && LWIP_IPV6_MLD
225typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
226 const ip6_addr_t *group, enum netif_mac_filter_action action);
227#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
228
229#if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
230u8_t netif_alloc_client_data_id(void);
234#define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
238#define netif_get_client_data(netif, id) (netif)->client_data[(id)]
239#endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */
240
244struct netif {
246 struct netif *next;
247
248#if LWIP_IPV4
250 ip_addr_t ip_addr;
251 ip_addr_t netmask;
252 ip_addr_t gw;
253#endif /* LWIP_IPV4 */
254#if LWIP_IPV6
256 ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
259 u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
260#endif /* LWIP_IPV6 */
264#if LWIP_IPV4
269 netif_output_fn output;
270#endif /* LWIP_IPV4 */
275#if LWIP_IPV6
280 netif_output_ip6_fn output_ip6;
281#endif /* LWIP_IPV6 */
282#if LWIP_NETIF_STATUS_CALLBACK
285 netif_status_callback_fn status_callback;
286#endif /* LWIP_NETIF_STATUS_CALLBACK */
287#if LWIP_NETIF_LINK_CALLBACK
290 netif_status_callback_fn link_callback;
291#endif /* LWIP_NETIF_LINK_CALLBACK */
292#if LWIP_NETIF_REMOVE_CALLBACK
294 netif_status_callback_fn remove_callback;
295#endif /* LWIP_NETIF_REMOVE_CALLBACK */
298 void *state;
299#ifdef netif_get_client_data
300 void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA];
301#endif
302#if LWIP_IPV6_AUTOCONFIG
304 u8_t ip6_autoconfig_enabled;
305#endif /* LWIP_IPV6_AUTOCONFIG */
306#if LWIP_IPV6_SEND_ROUTER_SOLICIT
308 u8_t rs_count;
309#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
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*/
318 u16_t mtu;
324 u8_t flags;
326 char name[2];
328 u8_t num;
329#if MIB2_STATS
331 u8_t link_type;
333 u32_t link_speed;
335 u32_t ts;
337 struct stats_mib2_netif_ctrs mib2_counters;
338#endif /* MIB2_STATS */
339#if LWIP_IPV4 && LWIP_IGMP
342 netif_igmp_mac_filter_fn igmp_mac_filter;
343#endif /* LWIP_IPV4 && LWIP_IGMP */
344#if LWIP_IPV6 && LWIP_IPV6_MLD
347 netif_mld_mac_filter_fn mld_mac_filter;
348#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
349#if LWIP_NETIF_HWADDRHINT
350 u8_t *addr_hint;
351#endif /* LWIP_NETIF_HWADDRHINT */
352#if ENABLE_LOOPBACK
353 /* List of packets to be queued for ourselves. */
354 struct pbuf *loop_first;
355 struct pbuf *loop_last;
356#if LWIP_LOOPBACK_MAX_PBUFS
357 u16_t loop_cnt_current;
358#endif /* LWIP_LOOPBACK_MAX_PBUFS */
359#endif /* ENABLE_LOOPBACK */
360};
361
362#if LWIP_CHECKSUM_CTRL_PER_NETIF
363#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
364 (netif)->chksum_flags = chksumflags; } while(0)
365#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
366#else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
367#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
368#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
369#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
370
372extern struct netif *netif_list;
374extern struct netif *netif_default;
375
376void netif_init(void);
377
378struct netif *netif_add(struct netif *netif,
379#if LWIP_IPV4
380 const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
381#endif /* LWIP_IPV4 */
383#if LWIP_IPV4
384void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
385 const ip4_addr_t *gw);
386#endif /* LWIP_IPV4 */
387void netif_remove(struct netif * netif);
388
389/* Returns a network interface given its name. The name is of the form
390 "et0", where the first two letters are the "name" field in the
391 netif structure, and the digit is in the num field in the same
392 structure. */
393struct netif *netif_find(const char *name);
394
395void netif_set_default(struct netif *netif);
396
397#if LWIP_IPV4
398void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
399void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
400void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
402#define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
404#define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
406#define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
408#define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
410#define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
412#define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
413#endif /* LWIP_IPV4 */
414
415void netif_set_up(struct netif *netif);
416void netif_set_down(struct netif *netif);
420#define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
421
422#if LWIP_NETIF_STATUS_CALLBACK
423void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
424#endif /* LWIP_NETIF_STATUS_CALLBACK */
425#if LWIP_NETIF_REMOVE_CALLBACK
426void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
427#endif /* LWIP_NETIF_REMOVE_CALLBACK */
428
429void netif_set_link_up(struct netif *netif);
430void netif_set_link_down(struct netif *netif);
432#define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
433
434#if LWIP_NETIF_LINK_CALLBACK
435void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
436#endif /* LWIP_NETIF_LINK_CALLBACK */
437
438#if LWIP_NETIF_HOSTNAME
440#define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
442#define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
443#endif /* LWIP_NETIF_HOSTNAME */
444
445#if LWIP_IGMP
447#define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
448#define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
449#endif /* LWIP_IGMP */
450
451#if LWIP_IPV6 && LWIP_IPV6_MLD
453#define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
454#define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
455#define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0)
456#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
457
458#if ENABLE_LOOPBACK
459err_t netif_loop_output(struct netif *netif, struct pbuf *p);
460void netif_poll(struct netif *netif);
461#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
462void netif_poll_all(void);
463#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
464#endif /* ENABLE_LOOPBACK */
465
466err_t netif_input(struct pbuf *p, struct netif *inp);
467
468#if LWIP_IPV6
470#define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
472#define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
473void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
474void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3);
475#define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
476void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state);
477s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr);
478void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit);
479err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx);
480#define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0)
481#endif /* LWIP_IPV6 */
482
483#if LWIP_NETIF_HWADDRHINT
484#define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
485#else /* LWIP_NETIF_HWADDRHINT */
486#define NETIF_SET_HWADDRHINT(netif, hint)
487#endif /* LWIP_NETIF_HWADDRHINT */
488
489#ifdef __cplusplus
490}
491#endif
492
493#endif /* LWIP_HDR_NETIF_H */
s8_t err_t
Definition err.h:76
#define LWIP_IPV4
Definition opt.h:659
#define LWIP_IPV6_NUM_ADDRESSES
Definition opt.h:2179
#define LWIP_NUM_NETIF_CLIENT_DATA
Definition opt.h:1476
void netif_set_link_down(struct netif *netif)
Definition netif.c:779
struct netif * netif_find(const char *name)
Definition netif.c:491
void netif_set_down(struct netif *netif)
Definition netif.c:701
void netif_remove(struct netif *netif)
Definition netif.c:396
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition netif.c:260
void netif_set_default(struct netif *netif)
Definition netif.c:623
void netif_set_link_up(struct netif *netif)
Definition netif.c:754
void netif_set_up(struct netif *netif)
Definition netif.c:643
struct netif * netif_list
Definition netif.c:123
err_t(* netif_init_fn)(struct netif *netif)
Definition netif.h:174
struct netif * netif_default
Definition netif.c:124
void(* netif_status_callback_fn)(struct netif *netif)
Definition netif.h:217
err_t netif_input(struct pbuf *p, struct netif *inp)
Definition netif.c:222
netif_mac_filter_action
Definition netif.h:162
@ NETIF_ADD_MAC_FILTER
Definition netif.h:166
@ NETIF_DEL_MAC_FILTER
Definition netif.h:164
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition netif.h:181
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition netif.h:215
#define NETIF_MAX_HWADDR_LEN
Definition netif.h:82
Definition netif.h:244
u8_t flags
Definition netif.h:324
char name[2]
Definition netif.h:326
void * state
Definition netif.h:298
netif_input_fn input
Definition netif.h:263
u8_t num
Definition netif.h:328
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition netif.h:322
u16_t mtu
Definition netif.h:318
netif_linkoutput_fn linkoutput
Definition netif.h:274
struct netif * next
Definition netif.h:246
u8_t hwaddr_len
Definition netif.h:320
Definition pbuf.h:161