STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
ip.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_HDR_IP_H__
33 #define LWIP_HDR_IP_H__
34 
35 #include "lwip/opt.h"
36 
37 #include "lwip/def.h"
38 #include "lwip/pbuf.h"
39 #include "lwip/ip_addr.h"
40 #include "lwip/err.h"
41 #include "lwip/netif.h"
42 #include "lwip/ip4.h"
43 #include "lwip/ip6.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define IP_PROTO_ICMP 1
50 #define IP_PROTO_IGMP 2
51 #define IP_PROTO_UDP 17
52 #define IP_PROTO_UDPLITE 136
53 #define IP_PROTO_TCP 6
54 
56 #define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4)
57 
58 /* This is passed as the destination address to ip_output_if (not
59  to ip_output), meaning that an IP header already is constructed
60  in the pbuf. This is used when TCP retransmits. */
61 #ifdef IP_HDRINCL
62 #undef IP_HDRINCL
63 #endif /* IP_HDRINCL */
64 #define IP_HDRINCL NULL
65 
68 #ifndef LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX
69 #define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p) LWIP_ASSERT("p->ref == 1", (p)->ref == 1)
70 #endif
71 
72 #if LWIP_NETIF_HWADDRHINT
73 #define IP_PCB_ADDRHINT ;u8_t addr_hint
74 #else
75 #define IP_PCB_ADDRHINT
76 #endif /* LWIP_NETIF_HWADDRHINT */
77 
78 #if LWIP_IPV6 && LWIP_IPV4
79 #define IP_PCB_ISIPV6_MEMBER u8_t isipv6;
80 #define IP_PCB_IPVER_EQ(pcb1, pcb2) ((pcb1)->isipv6 == (pcb2)->isipv6)
81 #define IP_PCB_IPVER_INPUT_MATCH(pcb) (ip_current_is_v6() ? \
82  ((pcb)->isipv6 != 0) : \
83  ((pcb)->isipv6 == 0))
84 #define PCB_ISIPV6(pcb) ((pcb)->isipv6)
85 #else
86 #define IP_PCB_ISIPV6_MEMBER
87 #define IP_PCB_IPVER_EQ(pcb1, pcb2) 1
88 #define IP_PCB_IPVER_INPUT_MATCH(pcb) 1
89 #define PCB_ISIPV6(pcb) LWIP_IPV6
90 #endif /* LWIP_IPV6 */
91 
92 /* This is the common part of all PCB types. It needs to be at the
93  beginning of a PCB type definition. It is located here so that
94  changes to this common part are made in one location instead of
95  having to change all PCB structs. */
96 #define IP_PCB \
97  IP_PCB_ISIPV6_MEMBER \
98  /* ip addresses in network byte order */ \
99  ip_addr_t local_ip; \
100  ip_addr_t remote_ip; \
101  /* Socket options */ \
102  u8_t so_options; \
103  /* Type Of Service */ \
104  u8_t tos; \
105  /* Time To Live */ \
106  u8_t ttl \
107  /* link layer address resolution hint */ \
108  IP_PCB_ADDRHINT
109 
110 struct ip_pcb {
111 /* Common members of all PCB types */
113 };
114 
115 /*
116  * Option flags per-socket. These are the same like SO_XXX in sockets.h
117  */
118 #define SOF_REUSEADDR 0x04U /* allow local address reuse */
119 #define SOF_KEEPALIVE 0x08U /* keep connections alive */
120 #define SOF_BROADCAST 0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
121 
122 /* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
123 #define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE)
124 
125 /* Global variables of this module, kept in a struct for efficient access using base+index. */
127 {
132 #if LWIP_IPV4
133 
134  struct ip_hdr *current_ip4_header;
135 #endif /* LWIP_IPV4 */
136 #if LWIP_IPV6
137 
138  struct ip6_hdr *current_ip6_header;
139 #endif /* LWIP_IPV6 */
140 
146 };
147 extern struct ip_globals ip_data;
148 
149 
154 #define ip_current_netif() (ip_data.current_netif)
155 
158 #define ip_current_input_netif() (ip_data.current_input_netif)
159 
160 #define ip_current_header_tot_len() (ip_data.current_ip_header_tot_len)
161 
162 #define ip_current_src_addr() (&ip_data.current_iphdr_src)
163 
164 #define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
165 
166 #if LWIP_IPV4 && LWIP_IPV6
167 
170 #define ip4_current_header() ((const struct ip_hdr*)(ip_data.current_ip4_header))
171 
174 #define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header))
175 
176 #define ip_current_is_v6() (ip6_current_header() != NULL)
177 
178 #define ip6_current_src_addr() (ip_2_ip6(&ip_data.current_iphdr_src))
179 
180 #define ip6_current_dest_addr() (ip_2_ip6(&ip_data.current_iphdr_dest))
181 
182 #define ip_current_header_proto() (ip_current_is_v6() ? \
183  IP6H_NEXTH(ip6_current_header()) :\
184  IPH_PROTO(ip4_current_header()))
185 
186 #define ip_next_header_ptr() ((const void*)((ip_current_is_v6() ? \
187  (const u8_t*)ip6_current_header() : (const u8_t*)ip4_current_header()) + ip_current_header_tot_len()))
188 
190 #define ip_set_v6(pcb, val) do{if(pcb != NULL) { pcb->isipv6 = val; \
191  IP_SET_TYPE(&(pcb)->local_ip, (val)?IPADDR_TYPE_V6:IPADDR_TYPE_V4); \
192  IP_SET_TYPE(&(pcb)->remote_ip, (val)?IPADDR_TYPE_V6:IPADDR_TYPE_V4); }}while(0)
193 
195 #define ip4_current_src_addr() (ip_2_ip4(&ip_data.current_iphdr_src))
196 
197 #define ip4_current_dest_addr() (ip_2_ip4(&ip_data.current_iphdr_dest))
198 
199 #elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
200 
204 #define ip4_current_header() ((const struct ip_hdr*)(ip_data.current_ip4_header))
205 
206 #define ip_current_is_v6() 0
207 
208 #define ip_current_header_proto() IPH_PROTO(ip4_current_header())
209 
210 #define ip_next_header_ptr() ((const void*)((const u8_t*)ip4_current_header() + ip_current_header_tot_len()))
211 
212 #define ip4_current_src_addr() (&ip_data.current_iphdr_src)
213 
214 #define ip4_current_dest_addr() (&ip_data.current_iphdr_dest)
215 
216 #elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
217 
221 #define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header))
222 
223 #define ip_current_is_v6() 1
224 
225 #define ip_current_header_proto() IP6H_NEXTH(ip6_current_header())
226 
227 #define ip_next_header_ptr() ((const void*)((const u8_t*)ip6_current_header()))
228 
229 #define ip6_current_src_addr() (&ip_data.current_iphdr_src)
230 
231 #define ip6_current_dest_addr() (&ip_data.current_iphdr_dest)
232 
233 #endif /* LWIP_IPV6 */
234 
236 #define ip_current_src_addr() (&ip_data.current_iphdr_src)
237 
238 #define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
239 
241 #define ip_get_option(pcb, opt) ((pcb)->so_options & (opt))
242 
243 #define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
244 
245 #define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
246 
247 #if LWIP_IPV4 && LWIP_IPV6
248 #define ip_output(isipv6, p, src, dest, ttl, tos, proto) \
249  ((isipv6) ? \
250  ip6_output(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto) : \
251  ip4_output(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto))
252 #define ip_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
253  ((isipv6) ? \
254  ip6_output_if(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
255  ip4_output_if(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
256 #define ip_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
257  ((isipv6) ? \
258  ip6_output_if_src(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
259  ip4_output_if_src(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
260 #define ip_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
261  ((isipv6) ? \
262  ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, addr_hint) : \
263  ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, addr_hint))
264 #define ip_route(isipv6, src, dest) \
265  ((isipv6) ? \
266  ip6_route(ip_2_ip6(src), ip_2_ip6(dest)) : \
267  ip4_route_src(ip_2_ip4(dest), ip_2_ip4(src)))
268 #define ip_netif_get_local_ip(isipv6, netif, dest) ((isipv6) ? \
269  ip6_netif_get_local_ip(netif, ip_2_ip6(dest)) : \
270  ip4_netif_get_local_ip(netif))
271 #define ip_debug_print(is_ipv6, p) ((is_ipv6) ? ip6_debug_print(p) : ip4_debug_print(p))
272 #elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
273 #define ip_output(isipv6, p, src, dest, ttl, tos, proto) \
274  ip4_output(p, src, dest, ttl, tos, proto)
275 #define ip_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
276  ip4_output_if(p, src, dest, ttl, tos, proto, netif)
277 #define ip_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
278  ip4_output_if_src(p, src, dest, ttl, tos, proto, netif)
279 #define ip_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
280  ip4_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
281 #define ip_route(isipv6, src, dest) \
282  ip4_route_src(dest, src)
283 #define ip_netif_get_local_ip(isipv6, netif, dest) \
284  ip4_netif_get_local_ip(netif)
285 #define ip_debug_print(is_ipv6, p) ip4_debug_print(p)
286 #elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
287 #define ip_output(isipv6, p, src, dest, ttl, tos, proto) \
288  ip6_output(p, src, dest, ttl, tos, proto)
289 #define ip_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
290  ip6_output_if(p, src, dest, ttl, tos, proto, netif)
291 #define ip_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
292  ip6_output_if_src(p, src, dest, ttl, tos, proto, netif)
293 #define ip_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
294  ip6_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
295 #define ip_route(isipv6, src, dest) \
296  ip6_route(src, dest)
297 #define ip_netif_get_local_ip(isipv6, netif, dest) \
298  ip6_netif_get_local_ip(netif, dest)
299 #define ip_debug_print(is_ipv6, p) ip6_debug_print(p)
300 #endif /* LWIP_IPV6 */
301 
302 #define ip_route_get_local_ip(isipv6, src, dest, netif, ipaddr) do { \
303  (netif) = ip_route(isipv6, src, dest); \
304  (ipaddr) = ip_netif_get_local_ip(isipv6, netif, dest); \
305 }while(0)
306 
307 err_t ip_input(struct pbuf *p, struct netif *inp);
308 
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 #endif /* LWIP_HDR_IP_H__ */
314 
ip_addr_t current_iphdr_dest
Definition: ip.h:145
err_t ip_input(struct pbuf *p, struct netif *inp)
u16_t current_ip_header_tot_len
Definition: ip.h:141
ip_addr_t current_iphdr_src
Definition: ip.h:143
struct netif * current_netif
Definition: ip.h:129
Definition: pbuf.h:108
IP_PCB
Definition: ip.h:112
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
struct ip_globals ip_data
Definition: ip.h:126
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
struct netif * current_input_netif
Definition: ip.h:131
Definition: ip.h:110
unsigned short u16_t
Definition: cc.h:40