ReactOS  0.4.14-dev-606-g14ebc0b
netif.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef __LWIP_NETIF_H__
33 #define __LWIP_NETIF_H__
34 
35 #include "lwip/opt.h"
36 
37 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
38 
39 #include "lwip/err.h"
40 
41 #include "lwip/ip_addr.h"
42 
43 #include "lwip/def.h"
44 #include "lwip/pbuf.h"
45 #if LWIP_DHCP
46 struct dhcp;
47 #endif
48 #if LWIP_AUTOIP
49 struct autoip;
50 #endif
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 
61 #define NETIF_MAX_HWADDR_LEN 6U
62 
69 #define NETIF_FLAG_UP 0x01U
70 
72 #define NETIF_FLAG_BROADCAST 0x02U
73 
75 #define NETIF_FLAG_POINTTOPOINT 0x04U
76 
78 #define NETIF_FLAG_DHCP 0x08U
79 
84 #define NETIF_FLAG_LINK_UP 0x10U
85 
88 #define NETIF_FLAG_ETHARP 0x20U
89 
92 #define NETIF_FLAG_ETHERNET 0x40U
93 
95 #define NETIF_FLAG_IGMP 0x80U
96 
102 typedef err_t (*netif_init_fn)(struct netif *netif);
109 typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
118 typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
119  ip_addr_t *ipaddr);
126 typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
132 
136 struct netif {
138  struct netif *next;
139 
144 
156 #if LWIP_NETIF_STATUS_CALLBACK
157 
160 #endif /* LWIP_NETIF_STATUS_CALLBACK */
161 #if LWIP_NETIF_LINK_CALLBACK
162 
164  netif_status_callback_fn link_callback;
165 #endif /* LWIP_NETIF_LINK_CALLBACK */
166 #if LWIP_NETIF_REMOVE_CALLBACK
167 
168  netif_status_callback_fn remove_callback;
169 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
170 
172  void *state;
173 #if LWIP_DHCP
174 
175  struct dhcp *dhcp;
176 #endif /* LWIP_DHCP */
177 #if LWIP_AUTOIP
178 
179  struct autoip *autoip;
180 #endif
181 #if LWIP_NETIF_HOSTNAME
182  /* the hostname for this netif, NULL is a valid value */
183  char* hostname;
184 #endif /* LWIP_NETIF_HOSTNAME */
185 
194  char name[2];
197 #if LWIP_SNMP
198 
199  u8_t link_type;
201  u32_t link_speed;
203  u32_t ts;
205  u32_t ifinoctets;
206  u32_t ifinucastpkts;
207  u32_t ifinnucastpkts;
208  u32_t ifindiscards;
209  u32_t ifoutoctets;
210  u32_t ifoutucastpkts;
211  u32_t ifoutnucastpkts;
212  u32_t ifoutdiscards;
213 #endif /* LWIP_SNMP */
214 #if LWIP_IGMP
215 
217  netif_igmp_mac_filter_fn igmp_mac_filter;
218 #endif /* LWIP_IGMP */
219 #if LWIP_NETIF_HWADDRHINT
220  u8_t *addr_hint;
221 #endif /* LWIP_NETIF_HWADDRHINT */
222 #if ENABLE_LOOPBACK
223  /* List of packets to be queued for ourselves. */
224  struct pbuf *loop_first;
225  struct pbuf *loop_last;
226 #if LWIP_LOOPBACK_MAX_PBUFS
227  u16_t loop_cnt_current;
228 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
229 #endif /* ENABLE_LOOPBACK */
230 };
231 
232 #if LWIP_SNMP
233 #define NETIF_INIT_SNMP(netif, type, speed) \
234  /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
235  (netif)->link_type = (type); \
236  /* your link speed here (units: bits per second) */ \
237  (netif)->link_speed = (speed); \
238  (netif)->ts = 0; \
239  (netif)->ifinoctets = 0; \
240  (netif)->ifinucastpkts = 0; \
241  (netif)->ifinnucastpkts = 0; \
242  (netif)->ifindiscards = 0; \
243  (netif)->ifoutoctets = 0; \
244  (netif)->ifoutucastpkts = 0; \
245  (netif)->ifoutnucastpkts = 0; \
246  (netif)->ifoutdiscards = 0
247 #else /* LWIP_SNMP */
248 #define NETIF_INIT_SNMP(netif, type, speed)
249 #endif /* LWIP_SNMP */
250 
251 
253 extern struct netif *netif_list;
255 extern struct netif *netif_default;
256 
257 void netif_init(void);
258 
259 struct netif *netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
261 
262 void
264  ip_addr_t *gw);
265 void netif_remove(struct netif * netif);
266 
267 /* Returns a network interface given its name. The name is of the form
268  "et0", where the first two letters are the "name" field in the
269  netif structure, and the digit is in the num field in the same
270  structure. */
271 struct netif *netif_find(char *name);
272 
273 void netif_set_default(struct netif *netif);
274 
275 void netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr);
277 void netif_set_gw(struct netif *netif, ip_addr_t *gw);
278 
279 void netif_set_up(struct netif *netif);
280 void netif_set_down(struct netif *netif);
282 #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0)
283 
284 #if LWIP_NETIF_STATUS_CALLBACK
285 void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback);
286 #endif /* LWIP_NETIF_STATUS_CALLBACK */
287 #if LWIP_NETIF_REMOVE_CALLBACK
288 void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback);
289 #endif /* LWIP_NETIF_REMOVE_CALLBACK */
290 
291 void netif_set_link_up(struct netif *netif);
292 void netif_set_link_down(struct netif *netif);
294 #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0)
295 
296 #if LWIP_NETIF_LINK_CALLBACK
297 void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback);
298 #endif /* LWIP_NETIF_LINK_CALLBACK */
299 
300 #if LWIP_NETIF_HOSTNAME
301 #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
302 #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
303 #endif /* LWIP_NETIF_HOSTNAME */
304 
305 #if LWIP_IGMP
306 #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
307 #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
308 #endif /* LWIP_IGMP */
309 
310 #if ENABLE_LOOPBACK
311 err_t netif_loop_output(struct netif *netif, struct pbuf *p, ip_addr_t *dest_ip);
312 void netif_poll(struct netif *netif);
313 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
314 void netif_poll_all(void);
315 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
316 #endif /* ENABLE_LOOPBACK */
317 
318 #if LWIP_NETIF_HWADDRHINT
319 #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
320 #else /* LWIP_NETIF_HWADDRHINT */
321 #define NETIF_SET_HWADDRHINT(netif, hint)
322 #endif /* LWIP_NETIF_HWADDRHINT */
323 
324 #ifdef __cplusplus
325 }
326 #endif
327 
328 #endif /* __LWIP_NETIF_H__ */
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
Definition: netif.h:109
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:190
void(* netif_status_callback_fn)(struct netif *netif)
Definition: netif.h:128
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
void netif_init(void)
Definition: netif.c:106
err_t(* netif_igmp_mac_filter_fn)(struct netif *netif, ip_addr_t *group, u8_t action)
Definition: netif.h:130
void netif_set_down(struct netif *netif)
Definition: netif.c:490
struct netif * netif_list
Definition: netif.c:75
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
Definition: ip_addr.h:64
netif_output_fn output
Definition: netif.h:151
u8_t num
Definition: netif.h:196
static int init
Definition: wintirpc.c:33
static void WINAPI status_callback(HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD info_len)
Definition: ftp.c:950
void netif_set_default(struct netif *netif)
Definition: netif.c:430
char * hostname
Definition: ftp.c:88
struct netif * netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:139
#define NETIF_MAX_HWADDR_LEN
Definition: netif.h:61
u8_t hwaddr_len
Definition: netif.h:188
void netif_set_up(struct netif *netif)
Definition: netif.c:453
static const char * ts(int t)
s8_t err_t
Definition: err.h:47
void netif_set_link_up(struct netif *netif)
Definition: netif.c:535
ip_addr_t gw
Definition: netif.h:143
struct netif * next
Definition: netif.h:138
GLboolean GLuint group
Definition: glext.h:11120
void netif_set_gw(struct netif *netif, ip_addr_t *gw)
Definition: netif.c:388
Definition: pbuf.h:79
struct netif * netif_default
Definition: netif.c:76
unsigned long u32_t
Definition: cc.h:25
u8_t flags
Definition: netif.h:192
Definition: netif.h:136
err_t(* netif_init_fn)(struct netif *netif)
Definition: netif.h:102
ip_addr_t ip_addr
Definition: netif.h:141
static int state
Definition: maze.c:121
u16_t mtu
Definition: netif.h:186
err_t(* netif_output_fn)(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
Definition: netif.h:118
void netif_set_ipaddr(struct netif *netif, ip_addr_t *ipaddr)
Definition: netif.c:323
void netif_set_netmask(struct netif *netif, ip_addr_t *netmask)
Definition: netif.c:409
void netif_remove(struct netif *netif)
Definition: netif.c:235
const WCHAR * action
Definition: action.c:7783
GLenum GLenum GLenum input
Definition: glext.h:9031
void * state
Definition: netif.h:172
void netif_set_link_down(struct netif *netif)
Definition: netif.c:574
unsigned char u8_t
Definition: cc.h:23
netif_input_fn input
Definition: netif.h:147
Definition: name.c:38
void dhcp(struct packet *packet)
Definition: dhclient.c:682
ip_addr_t netmask
Definition: netif.h:142
unsigned short u16_t
Definition: cc.h:24
GLfloat GLfloat p
Definition: glext.h:8902
void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw)
Definition: netif.c:221
netif_linkoutput_fn linkoutput
Definition: netif.h:155
err_t(* netif_linkoutput_fn)(struct netif *netif, struct pbuf *p)
Definition: netif.h:126
struct netif * netif_find(char *name)
Definition: netif.c:290