The Pedigree Project 0.1
ip.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_IP_H
57#define LWIP_HDR_IP_H
58
59#include "lwip/opt.h"
60
61#include "lwip/def.h"
62#include "lwip/pbuf.h"
63#include "lwip/ip_addr.h"
64#include "lwip/err.h"
65#include "lwip/netif.h"
66#include "lwip/ip4.h"
67#include "lwip/ip6.h"
68#include "lwip/prot/ip.h"
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74/* This is passed as the destination address to ip_output_if (not
75 to ip_output), meaning that an IP header already is constructed
76 in the pbuf. This is used when TCP retransmits. */
77#define LWIP_IP_HDRINCL NULL
78
81#ifndef LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX
82#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p) LWIP_ASSERT("p->ref == 1", (p)->ref == 1)
83#endif
84
85#if LWIP_NETIF_HWADDRHINT
86#define IP_PCB_ADDRHINT ;u8_t addr_hint
87#else
88#define IP_PCB_ADDRHINT
89#endif /* LWIP_NETIF_HWADDRHINT */
90
95#define IP_PCB \
96 /* ip addresses in network byte order */ \
97 ip_addr_t local_ip; \
98 ip_addr_t remote_ip; \
99 /* Socket options */ \
100 u8_t so_options; \
101 /* Type Of Service */ \
102 u8_t tos; \
103 /* Time To Live */ \
104 u8_t ttl \
105 /* link layer address resolution hint */ \
106 IP_PCB_ADDRHINT
107
108struct ip_pcb {
109/* Common members of all PCB types */
110 IP_PCB;
111};
112
113/*
114 * Option flags per-socket. These are the same like SO_XXX in sockets.h
115 */
116#define SOF_REUSEADDR 0x04U /* allow local address reuse */
117#define SOF_KEEPALIVE 0x08U /* keep connections alive */
118#define SOF_BROADCAST 0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
119
120/* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
121#define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE)
122
125{
130#if LWIP_IPV4
132 struct ip_hdr *current_ip4_header;
133#endif /* LWIP_IPV4 */
134#if LWIP_IPV6
136 struct ip6_hdr *current_ip6_header;
137#endif /* LWIP_IPV6 */
144};
145extern struct ip_globals ip_data;
146
147
152#define ip_current_netif() (ip_data.current_netif)
156#define ip_current_input_netif() (ip_data.current_input_netif)
158#define ip_current_header_tot_len() (ip_data.current_ip_header_tot_len)
160#define ip_current_src_addr() (&ip_data.current_iphdr_src)
162#define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
163
164#if LWIP_IPV4 && LWIP_IPV6
168#define ip4_current_header() ((const struct ip_hdr*)(ip_data.current_ip4_header))
172#define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header))
174#define ip_current_is_v6() (ip6_current_header() != NULL)
176#define ip6_current_src_addr() (ip_2_ip6(&ip_data.current_iphdr_src))
178#define ip6_current_dest_addr() (ip_2_ip6(&ip_data.current_iphdr_dest))
180#define ip_current_header_proto() (ip_current_is_v6() ? \
181 IP6H_NEXTH(ip6_current_header()) :\
182 IPH_PROTO(ip4_current_header()))
184#define ip_next_header_ptr() ((const void*)((ip_current_is_v6() ? \
185 (const u8_t*)ip6_current_header() : (const u8_t*)ip4_current_header()) + ip_current_header_tot_len()))
186
188#define ip4_current_src_addr() (ip_2_ip4(&ip_data.current_iphdr_src))
190#define ip4_current_dest_addr() (ip_2_ip4(&ip_data.current_iphdr_dest))
191
192#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
193
197#define ip4_current_header() ((const struct ip_hdr*)(ip_data.current_ip4_header))
199#define ip_current_is_v6() 0
201#define ip_current_header_proto() IPH_PROTO(ip4_current_header())
203#define ip_next_header_ptr() ((const void*)((const u8_t*)ip4_current_header() + ip_current_header_tot_len()))
205#define ip4_current_src_addr() (&ip_data.current_iphdr_src)
207#define ip4_current_dest_addr() (&ip_data.current_iphdr_dest)
208
209#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
210
214#define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header))
216#define ip_current_is_v6() 1
218#define ip_current_header_proto() IP6H_NEXTH(ip6_current_header())
220#define ip_next_header_ptr() ((const void*)((const u8_t*)ip6_current_header()))
222#define ip6_current_src_addr() (&ip_data.current_iphdr_src)
224#define ip6_current_dest_addr() (&ip_data.current_iphdr_dest)
225
226#endif /* LWIP_IPV6 */
227
229#define ip_current_src_addr() (&ip_data.current_iphdr_src)
231#define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
232
234#define ip_get_option(pcb, opt) ((pcb)->so_options & (opt))
236#define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
238#define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
239
240#if LWIP_IPV4 && LWIP_IPV6
245#define ip_output(p, src, dest, ttl, tos, proto) \
246 (IP_IS_V6(dest) ? \
247 ip6_output(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto) : \
248 ip4_output(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto))
253#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \
254 (IP_IS_V6(dest) ? \
255 ip6_output_if(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
256 ip4_output_if(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
261#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \
262 (IP_IS_V6(dest) ? \
263 ip6_output_if_src(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
264 ip4_output_if_src(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
266#define ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) \
267 (IP_IS_V6(dest) ? \
268 ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, addr_hint) : \
269 ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, addr_hint))
274#define ip_route(src, dest) \
275 (IP_IS_V6(dest) ? \
276 ip6_route(ip_2_ip6(src), ip_2_ip6(dest)) : \
277 ip4_route_src(ip_2_ip4(dest), ip_2_ip4(src)))
282#define ip_netif_get_local_ip(netif, dest) (IP_IS_V6(dest) ? \
283 ip6_netif_get_local_ip(netif, ip_2_ip6(dest)) : \
284 ip4_netif_get_local_ip(netif))
285#define ip_debug_print(is_ipv6, p) ((is_ipv6) ? ip6_debug_print(p) : ip4_debug_print(p))
286
287err_t ip_input(struct pbuf *p, struct netif *inp);
288
289#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
290
291#define ip_output(p, src, dest, ttl, tos, proto) \
292 ip4_output(p, src, dest, ttl, tos, proto)
293#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \
294 ip4_output_if(p, src, dest, ttl, tos, proto, netif)
295#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \
296 ip4_output_if_src(p, src, dest, ttl, tos, proto, netif)
297#define ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) \
298 ip4_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
299#define ip_route(src, dest) \
300 ip4_route_src(dest, src)
301#define ip_netif_get_local_ip(netif, dest) \
302 ip4_netif_get_local_ip(netif)
303#define ip_debug_print(is_ipv6, p) ip4_debug_print(p)
304
305#define ip_input ip4_input
306
307#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
308
309#define ip_output(p, src, dest, ttl, tos, proto) \
310 ip6_output(p, src, dest, ttl, tos, proto)
311#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \
312 ip6_output_if(p, src, dest, ttl, tos, proto, netif)
313#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \
314 ip6_output_if_src(p, src, dest, ttl, tos, proto, netif)
315#define ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) \
316 ip6_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
317#define ip_route(src, dest) \
318 ip6_route(src, dest)
319#define ip_netif_get_local_ip(netif, dest) \
320 ip6_netif_get_local_ip(netif, dest)
321#define ip_debug_print(is_ipv6, p) ip6_debug_print(p)
322
323#define ip_input ip6_input
324
325#endif /* LWIP_IPV6 */
326
327#define ip_route_get_local_ip(src, dest, netif, ipaddr) do { \
328 (netif) = ip_route(src, dest); \
329 (ipaddr) = ip_netif_get_local_ip(netif, dest); \
330}while(0)
331
332#ifdef __cplusplus
333}
334#endif
335
336#endif /* LWIP_HDR_IP_H */
337
338
s8_t err_t
Definition err.h:76
ip_addr_t current_iphdr_src
Definition ip.h:141
ip_addr_t current_iphdr_dest
Definition ip.h:143
u16_t current_ip_header_tot_len
Definition ip.h:139
struct netif * current_netif
Definition ip.h:127
struct netif * current_input_netif
Definition ip.h:129
Definition ip.h:108
Definition netif.h:244
Definition pbuf.h:161