ReactOS 0.4.16-dev-456-ga97fcf1
ip.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_IP_H
38#define LWIP_HDR_IP_H
39
40#include "lwip/opt.h"
41
42#include "lwip/def.h"
43#include "lwip/pbuf.h"
44#include "lwip/ip_addr.h"
45#include "lwip/err.h"
46#include "lwip/netif.h"
47#include "lwip/ip4.h"
48#include "lwip/ip6.h"
49#include "lwip/prot/ip.h"
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/* This is passed as the destination address to ip_output_if (not
56 to ip_output), meaning that an IP header already is constructed
57 in the pbuf. This is used when TCP retransmits. */
58#define LWIP_IP_HDRINCL NULL
59
62#ifndef LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX
63#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p) LWIP_ASSERT("p->ref == 1", (p)->ref == 1)
64#endif
65
66#if LWIP_NETIF_USE_HINTS
67#define IP_PCB_NETIFHINT ;struct netif_hint netif_hints
68#else /* LWIP_NETIF_USE_HINTS */
69#define IP_PCB_NETIFHINT
70#endif /* LWIP_NETIF_USE_HINTS */
71
76#define IP_PCB \
77 /* ip addresses in network byte order */ \
78 ip_addr_t local_ip; \
79 ip_addr_t remote_ip; \
80 /* Bound netif index */ \
81 u8_t netif_idx; \
82 /* Socket options */ \
83 u8_t so_options; \
84 /* Type Of Service */ \
85 u8_t tos; \
86 /* Time To Live */ \
87 u8_t ttl \
88 /* link layer address resolution hint */ \
89 IP_PCB_NETIFHINT
90
91struct ip_pcb {
92 /* Common members of all PCB types */
94};
95
96#if LWIP_VLAN_PCP
97#define pcb_has_tci(pcb) ((pcb)->netif_hints.tci >= 0)
98#define pcb_tci_get(pcb) ((pcb)->netif_hints.tci)
99#define pcb_tci_clear(pcb) do { (pcb)->netif_hints.tci = -1; } while(0)
100#define pcb_tci_set(pcb, tci_val) do { (pcb)->netif_hints.tci = (tci_val) & 0xffff; } while(0)
101#define pcb_tci_set_pcp_dei_vid(pcb, pcp, dei, vid) pcb_tci_set(pcb, (((pcp) & 7) << 13) | (((dei) & 1) << 12) | ((vid) & 0xFFF))
102#define pcb_tci_init(pcb) pcb_tci_clear(pcb)
103#else
104#define pcb_tci_init(pcb)
105#endif
106
107/*
108 * Option flags per-socket. These are the same like SO_XXX in sockets.h
109 */
110#define SOF_REUSEADDR 0x04U /* allow local address reuse */
111#define SOF_KEEPALIVE 0x08U /* keep connections alive */
112#define SOF_BROADCAST 0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
113
114/* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
115#define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE)
116
119{
124#if LWIP_IPV4
126 const struct ip_hdr *current_ip4_header;
127#endif /* LWIP_IPV4 */
128#if LWIP_IPV6
130 struct ip6_hdr *current_ip6_header;
131#endif /* LWIP_IPV6 */
138};
139extern struct ip_globals ip_data;
140
141
146#define ip_current_netif() (ip_data.current_netif)
150#define ip_current_input_netif() (ip_data.current_input_netif)
152#define ip_current_header_tot_len() (ip_data.current_ip_header_tot_len)
154#define ip_current_src_addr() (&ip_data.current_iphdr_src)
156#define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
157
158#if LWIP_IPV4 && LWIP_IPV6
162#define ip4_current_header() ip_data.current_ip4_header
166#define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header))
168#define ip_current_is_v6() (ip6_current_header() != NULL)
170#define ip6_current_src_addr() (ip_2_ip6(&ip_data.current_iphdr_src))
172#define ip6_current_dest_addr() (ip_2_ip6(&ip_data.current_iphdr_dest))
174#define ip_current_header_proto() (ip_current_is_v6() ? \
175 IP6H_NEXTH(ip6_current_header()) :\
176 IPH_PROTO(ip4_current_header()))
178#define ip_next_header_ptr() ((const void*)((ip_current_is_v6() ? \
179 (const u8_t*)ip6_current_header() : (const u8_t*)ip4_current_header()) + ip_current_header_tot_len()))
180
182#define ip4_current_src_addr() (ip_2_ip4(&ip_data.current_iphdr_src))
184#define ip4_current_dest_addr() (ip_2_ip4(&ip_data.current_iphdr_dest))
185
186#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
187
191#define ip4_current_header() ip_data.current_ip4_header
193#define ip_current_is_v6() 0
195#define ip_current_header_proto() IPH_PROTO(ip4_current_header())
197#define ip_next_header_ptr() ((const void*)((const u8_t*)ip4_current_header() + ip_current_header_tot_len()))
199#define ip4_current_src_addr() (&ip_data.current_iphdr_src)
201#define ip4_current_dest_addr() (&ip_data.current_iphdr_dest)
202
203#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
204
208#define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header))
210#define ip_current_is_v6() 1
212#define ip_current_header_proto() IP6H_NEXTH(ip6_current_header())
214#define ip_next_header_ptr() ((const void*)(((const u8_t*)ip6_current_header()) + ip_current_header_tot_len()))
216#define ip6_current_src_addr() (&ip_data.current_iphdr_src)
218#define ip6_current_dest_addr() (&ip_data.current_iphdr_dest)
219
220#endif /* LWIP_IPV6 */
221
223#define ip_current_src_addr() (&ip_data.current_iphdr_src)
225#define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
226
228#define ip_get_option(pcb, opt) ((pcb)->so_options & (opt))
230#define ip_set_option(pcb, opt) ((pcb)->so_options = (u8_t)((pcb)->so_options | (opt)))
232#define ip_reset_option(pcb, opt) ((pcb)->so_options = (u8_t)((pcb)->so_options & ~(opt)))
233
234#if LWIP_IPV4 && LWIP_IPV6
239#define ip_output(p, src, dest, ttl, tos, proto) \
240 (IP_IS_V6(dest) ? \
241 ip6_output(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto) : \
242 ip4_output(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto))
247#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \
248 (IP_IS_V6(dest) ? \
249 ip6_output_if(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
250 ip4_output_if(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
255#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \
256 (IP_IS_V6(dest) ? \
257 ip6_output_if_src(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
258 ip4_output_if_src(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
260#define ip_output_if_hdrincl(p, src, dest, netif) \
261 (IP_IS_V6(dest) ? \
262 ip6_output_if(p, ip_2_ip6(src), LWIP_IP_HDRINCL, 0, 0, 0, netif) : \
263 ip4_output_if(p, ip_2_ip4(src), LWIP_IP_HDRINCL, 0, 0, 0, netif))
265#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \
266 (IP_IS_V6(dest) ? \
267 ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif_hint) : \
268 ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif_hint))
273#define ip_route(src, dest) \
274 (IP_IS_V6(dest) ? \
275 ip6_route(ip_2_ip6(src), ip_2_ip6(dest)) : \
276 ip4_route_src(ip_2_ip4(src), ip_2_ip4(dest)))
281#define ip_netif_get_local_ip(netif, dest) (IP_IS_V6(dest) ? \
282 ip6_netif_get_local_ip(netif, ip_2_ip6(dest)) : \
283 ip4_netif_get_local_ip(netif))
284#define ip_debug_print(is_ipv6, p) ((is_ipv6) ? ip6_debug_print(p) : ip4_debug_print(p))
285
286err_t ip_input(struct pbuf *p, struct netif *inp);
287
288#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
289
290#define ip_output(p, src, dest, ttl, tos, proto) \
291 ip4_output(p, src, dest, ttl, tos, proto)
292#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \
293 ip4_output_if(p, src, dest, ttl, tos, proto, netif)
294#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \
295 ip4_output_if_src(p, src, dest, ttl, tos, proto, netif)
296#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \
297 ip4_output_hinted(p, src, dest, ttl, tos, proto, netif_hint)
298#define ip_output_if_hdrincl(p, src, dest, netif) \
299 ip4_output_if(p, src, LWIP_IP_HDRINCL, 0, 0, 0, netif)
300#define ip_route(src, dest) \
301 ip4_route_src(src, dest)
302#define ip_netif_get_local_ip(netif, dest) \
303 ip4_netif_get_local_ip(netif)
304#define ip_debug_print(is_ipv6, p) ip4_debug_print(p)
305
306#define ip_input ip4_input
307
308#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
309
310#define ip_output(p, src, dest, ttl, tos, proto) \
311 ip6_output(p, src, dest, ttl, tos, proto)
312#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \
313 ip6_output_if(p, src, dest, ttl, tos, proto, netif)
314#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \
315 ip6_output_if_src(p, src, dest, ttl, tos, proto, netif)
316#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \
317 ip6_output_hinted(p, src, dest, ttl, tos, proto, netif_hint)
318#define ip_output_if_hdrincl(p, src, dest, netif) \
319 ip6_output_if(p, src, LWIP_IP_HDRINCL, 0, 0, 0, netif)
320#define ip_route(src, dest) \
321 ip6_route(src, dest)
322#define ip_netif_get_local_ip(netif, dest) \
323 ip6_netif_get_local_ip(netif, dest)
324#define ip_debug_print(is_ipv6, p) ip6_debug_print(p)
325
326#define ip_input ip6_input
327
328#endif /* LWIP_IPV6 */
329
330#define ip_route_get_local_ip(src, dest, netif, ipaddr) do { \
331 (netif) = ip_route(src, dest); \
332 (ipaddr) = ip_netif_get_local_ip(netif, dest); \
333}while(0)
334
335#ifdef __cplusplus
336}
337#endif
338
339#endif /* LWIP_HDR_IP_H */
struct ip_globals ip_data
GLfloat GLfloat p
Definition: glext.h:8902
uint16_t u16_t
Definition: arch.h:127
s8_t err_t
Definition: err.h:96
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
Definition: ip6.h:82
Definition: ip.h:119
ip_addr_t current_iphdr_src
Definition: ip.h:135
ip_addr_t current_iphdr_dest
Definition: ip.h:137
u16_t current_ip_header_tot_len
Definition: ip.h:133
struct netif * current_netif
Definition: ip.h:121
struct netif * current_input_netif
Definition: ip.h:123
Definition: ip4.h:73
Definition: ip.h:91
IP_PCB
Definition: ip.h:93
Definition: netif.h:269
Definition: pbuf.h:186