User | Revision | Line number | New contents of line |
mbed714 |
0:d616ece2d859
|
1
|
/*
|
mbed714 |
0:d616ece2d859
|
2
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
mbed714 |
0:d616ece2d859
|
3
|
* All rights reserved.
|
mbed714 |
0:d616ece2d859
|
4
|
*
|
mbed714 |
0:d616ece2d859
|
5
|
* Redistribution and use in source and binary forms, with or without modification,
|
mbed714 |
0:d616ece2d859
|
6
|
* are permitted provided that the following conditions are met:
|
mbed714 |
0:d616ece2d859
|
7
|
*
|
mbed714 |
0:d616ece2d859
|
8
|
* 1. Redistributions of source code must retain the above copyright notice,
|
mbed714 |
0:d616ece2d859
|
9
|
* this list of conditions and the following disclaimer.
|
mbed714 |
0:d616ece2d859
|
10
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
mbed714 |
0:d616ece2d859
|
11
|
* this list of conditions and the following disclaimer in the documentation
|
mbed714 |
0:d616ece2d859
|
12
|
* and/or other materials provided with the distribution.
|
mbed714 |
0:d616ece2d859
|
13
|
* 3. The name of the author may not be used to endorse or promote products
|
mbed714 |
0:d616ece2d859
|
14
|
* derived from this software without specific prior written permission.
|
mbed714 |
0:d616ece2d859
|
15
|
*
|
mbed714 |
0:d616ece2d859
|
16
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
mbed714 |
0:d616ece2d859
|
17
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
mbed714 |
0:d616ece2d859
|
18
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
mbed714 |
0:d616ece2d859
|
19
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
mbed714 |
0:d616ece2d859
|
20
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
mbed714 |
0:d616ece2d859
|
21
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
mbed714 |
0:d616ece2d859
|
22
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
mbed714 |
0:d616ece2d859
|
23
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
mbed714 |
0:d616ece2d859
|
24
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
mbed714 |
0:d616ece2d859
|
25
|
* OF SUCH DAMAGE.
|
mbed714 |
0:d616ece2d859
|
26
|
*
|
mbed714 |
0:d616ece2d859
|
27
|
* This file is part of the lwIP TCP/IP stack.
|
mbed714 |
0:d616ece2d859
|
28
|
*
|
mbed714 |
0:d616ece2d859
|
29
|
* Author: Adam Dunkels <adam@sics.se>
|
mbed714 |
0:d616ece2d859
|
30
|
*
|
mbed714 |
0:d616ece2d859
|
31
|
*/
|
mbed714 |
0:d616ece2d859
|
32
|
#ifndef __LWIP_IP_H__
|
mbed714 |
0:d616ece2d859
|
33
|
#define __LWIP_IP_H__
|
mbed714 |
0:d616ece2d859
|
34
|
|
mbed714 |
0:d616ece2d859
|
35
|
#include "lwip/opt.h"
|
mbed714 |
0:d616ece2d859
|
36
|
|
mbed714 |
0:d616ece2d859
|
37
|
#include "lwip/def.h"
|
mbed714 |
0:d616ece2d859
|
38
|
#include "lwip/pbuf.h"
|
mbed714 |
0:d616ece2d859
|
39
|
#include "lwip/ip_addr.h"
|
mbed714 |
0:d616ece2d859
|
40
|
#include "lwip/err.h"
|
mbed714 |
0:d616ece2d859
|
41
|
#include "lwip/netif.h"
|
mbed714 |
0:d616ece2d859
|
42
|
|
mbed714 |
0:d616ece2d859
|
43
|
#ifdef __cplusplus
|
mbed714 |
0:d616ece2d859
|
44
|
extern "C" {
|
mbed714 |
0:d616ece2d859
|
45
|
#endif
|
mbed714 |
0:d616ece2d859
|
46
|
|
mbed714 |
0:d616ece2d859
|
47
|
/** Currently, the function ip_output_if_opt() is only used with IGMP */
|
mbed714 |
0:d616ece2d859
|
48
|
#define IP_OPTIONS_SEND LWIP_IGMP
|
mbed714 |
0:d616ece2d859
|
49
|
|
mbed714 |
0:d616ece2d859
|
50
|
#define IP_HLEN 20
|
mbed714 |
0:d616ece2d859
|
51
|
|
mbed714 |
0:d616ece2d859
|
52
|
#define IP_PROTO_ICMP 1
|
mbed714 |
0:d616ece2d859
|
53
|
#define IP_PROTO_IGMP 2
|
mbed714 |
0:d616ece2d859
|
54
|
#define IP_PROTO_UDP 17
|
mbed714 |
0:d616ece2d859
|
55
|
#define IP_PROTO_UDPLITE 136
|
mbed714 |
0:d616ece2d859
|
56
|
#define IP_PROTO_TCP 6
|
mbed714 |
0:d616ece2d859
|
57
|
|
mbed714 |
0:d616ece2d859
|
58
|
/* This is passed as the destination address to ip_output_if (not
|
mbed714 |
0:d616ece2d859
|
59
|
to ip_output), meaning that an IP header already is constructed
|
mbed714 |
0:d616ece2d859
|
60
|
in the pbuf. This is used when TCP retransmits. */
|
mbed714 |
0:d616ece2d859
|
61
|
#ifdef IP_HDRINCL
|
mbed714 |
0:d616ece2d859
|
62
|
#undef IP_HDRINCL
|
mbed714 |
0:d616ece2d859
|
63
|
#endif /* IP_HDRINCL */
|
mbed714 |
0:d616ece2d859
|
64
|
#define IP_HDRINCL NULL
|
mbed714 |
0:d616ece2d859
|
65
|
|
mbed714 |
0:d616ece2d859
|
66
|
#if LWIP_NETIF_HWADDRHINT
|
mbed714 |
0:d616ece2d859
|
67
|
#define IP_PCB_ADDRHINT ;u8_t addr_hint
|
mbed714 |
0:d616ece2d859
|
68
|
#else
|
mbed714 |
0:d616ece2d859
|
69
|
#define IP_PCB_ADDRHINT
|
mbed714 |
0:d616ece2d859
|
70
|
#endif /* LWIP_NETIF_HWADDRHINT */
|
mbed714 |
0:d616ece2d859
|
71
|
|
mbed714 |
0:d616ece2d859
|
72
|
/* This is the common part of all PCB types. It needs to be at the
|
mbed714 |
0:d616ece2d859
|
73
|
beginning of a PCB type definition. It is located here so that
|
mbed714 |
0:d616ece2d859
|
74
|
changes to this common part are made in one location instead of
|
mbed714 |
0:d616ece2d859
|
75
|
having to change all PCB structs. */
|
mbed714 |
0:d616ece2d859
|
76
|
#define IP_PCB \
|
mbed714 |
0:d616ece2d859
|
77
|
/* ip addresses in network byte order */ \
|
mbed714 |
0:d616ece2d859
|
78
|
ip_addr_t local_ip; \
|
mbed714 |
0:d616ece2d859
|
79
|
ip_addr_t remote_ip; \
|
mbed714 |
0:d616ece2d859
|
80
|
/* Socket options */ \
|
mbed714 |
0:d616ece2d859
|
81
|
u8_t so_options; \
|
mbed714 |
0:d616ece2d859
|
82
|
/* Type Of Service */ \
|
mbed714 |
0:d616ece2d859
|
83
|
u8_t tos; \
|
mbed714 |
0:d616ece2d859
|
84
|
/* Time To Live */ \
|
mbed714 |
0:d616ece2d859
|
85
|
u8_t ttl \
|
mbed714 |
0:d616ece2d859
|
86
|
/* link layer address resolution hint */ \
|
mbed714 |
0:d616ece2d859
|
87
|
IP_PCB_ADDRHINT
|
mbed714 |
0:d616ece2d859
|
88
|
|
mbed714 |
0:d616ece2d859
|
89
|
struct ip_pcb {
|
mbed714 |
0:d616ece2d859
|
90
|
/* Common members of all PCB types */
|
mbed714 |
0:d616ece2d859
|
91
|
IP_PCB;
|
mbed714 |
0:d616ece2d859
|
92
|
};
|
mbed714 |
0:d616ece2d859
|
93
|
|
mbed714 |
0:d616ece2d859
|
94
|
/*
|
mbed714 |
0:d616ece2d859
|
95
|
* Option flags per-socket. These are the same like SO_XXX.
|
mbed714 |
0:d616ece2d859
|
96
|
*/
|
mbed714 |
0:d616ece2d859
|
97
|
/*#define SOF_DEBUG (u8_t)0x01U Unimplemented: turn on debugging info recording */
|
mbed714 |
0:d616ece2d859
|
98
|
#define SOF_ACCEPTCONN (u8_t)0x02U /* socket has had listen() */
|
mbed714 |
0:d616ece2d859
|
99
|
#define SOF_REUSEADDR (u8_t)0x04U /* allow local address reuse */
|
mbed714 |
0:d616ece2d859
|
100
|
#define SOF_KEEPALIVE (u8_t)0x08U /* keep connections alive */
|
mbed714 |
0:d616ece2d859
|
101
|
/*#define SOF_DONTROUTE (u8_t)0x10U Unimplemented: just use interface addresses */
|
mbed714 |
0:d616ece2d859
|
102
|
#define SOF_BROADCAST (u8_t)0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
|
mbed714 |
0:d616ece2d859
|
103
|
/*#define SOF_USELOOPBACK (u8_t)0x40U Unimplemented: bypass hardware when possible */
|
mbed714 |
0:d616ece2d859
|
104
|
#define SOF_LINGER (u8_t)0x80U /* linger on close if data present */
|
mbed714 |
0:d616ece2d859
|
105
|
/*#define SOF_OOBINLINE (u16_t)0x0100U Unimplemented: leave received OOB data in line */
|
mbed714 |
0:d616ece2d859
|
106
|
/*#define SOF_REUSEPORT (u16_t)0x0200U Unimplemented: allow local address & port reuse */
|
mbed714 |
0:d616ece2d859
|
107
|
|
mbed714 |
0:d616ece2d859
|
108
|
/* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
|
mbed714 |
0:d616ece2d859
|
109
|
#define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE|SOF_LINGER/*|SOF_DEBUG|SOF_DONTROUTE|SOF_OOBINLINE*/)
|
mbed714 |
0:d616ece2d859
|
110
|
|
mbed714 |
0:d616ece2d859
|
111
|
|
mbed714 |
0:d616ece2d859
|
112
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
mbed714 |
0:d616ece2d859
|
113
|
# include "arch/bpstruct.h"
|
mbed714 |
0:d616ece2d859
|
114
|
#endif
|
mbed714 |
0:d616ece2d859
|
115
|
PACK_STRUCT_BEGIN
|
mbed714 |
0:d616ece2d859
|
116
|
struct ip_hdr {
|
mbed714 |
0:d616ece2d859
|
117
|
/* version / header length / type of service */
|
mbed714 |
0:d616ece2d859
|
118
|
PACK_STRUCT_FIELD(u16_t _v_hl_tos);
|
mbed714 |
0:d616ece2d859
|
119
|
/* total length */
|
mbed714 |
0:d616ece2d859
|
120
|
PACK_STRUCT_FIELD(u16_t _len);
|
mbed714 |
0:d616ece2d859
|
121
|
/* identification */
|
mbed714 |
0:d616ece2d859
|
122
|
PACK_STRUCT_FIELD(u16_t _id);
|
mbed714 |
0:d616ece2d859
|
123
|
/* fragment offset field */
|
mbed714 |
0:d616ece2d859
|
124
|
PACK_STRUCT_FIELD(u16_t _offset);
|
mbed714 |
0:d616ece2d859
|
125
|
#define IP_RF 0x8000 /* reserved fragment flag */
|
mbed714 |
0:d616ece2d859
|
126
|
#define IP_DF 0x4000 /* dont fragment flag */
|
mbed714 |
0:d616ece2d859
|
127
|
#define IP_MF 0x2000 /* more fragments flag */
|
mbed714 |
0:d616ece2d859
|
128
|
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
mbed714 |
0:d616ece2d859
|
129
|
/* time to live */
|
mbed714 |
0:d616ece2d859
|
130
|
PACK_STRUCT_FIELD(u8_t _ttl);
|
mbed714 |
0:d616ece2d859
|
131
|
/* protocol*/
|
mbed714 |
0:d616ece2d859
|
132
|
PACK_STRUCT_FIELD(u8_t _proto);
|
mbed714 |
0:d616ece2d859
|
133
|
/* checksum */
|
mbed714 |
0:d616ece2d859
|
134
|
PACK_STRUCT_FIELD(u16_t _chksum);
|
mbed714 |
0:d616ece2d859
|
135
|
/* source and destination IP addresses */
|
mbed714 |
0:d616ece2d859
|
136
|
PACK_STRUCT_FIELD(ip_addr_p_t src);
|
mbed714 |
0:d616ece2d859
|
137
|
PACK_STRUCT_FIELD(ip_addr_p_t dest);
|
mbed714 |
0:d616ece2d859
|
138
|
} PACK_STRUCT_STRUCT;
|
mbed714 |
0:d616ece2d859
|
139
|
PACK_STRUCT_END
|
mbed714 |
0:d616ece2d859
|
140
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
mbed714 |
0:d616ece2d859
|
141
|
# include "arch/epstruct.h"
|
mbed714 |
0:d616ece2d859
|
142
|
#endif
|
mbed714 |
0:d616ece2d859
|
143
|
|
mbed714 |
0:d616ece2d859
|
144
|
#define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
|
mbed714 |
0:d616ece2d859
|
145
|
#define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
|
mbed714 |
0:d616ece2d859
|
146
|
#define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
|
mbed714 |
0:d616ece2d859
|
147
|
#define IPH_LEN(hdr) ((hdr)->_len)
|
mbed714 |
0:d616ece2d859
|
148
|
#define IPH_ID(hdr) ((hdr)->_id)
|
mbed714 |
0:d616ece2d859
|
149
|
#define IPH_OFFSET(hdr) ((hdr)->_offset)
|
mbed714 |
0:d616ece2d859
|
150
|
#define IPH_TTL(hdr) ((hdr)->_ttl)
|
mbed714 |
0:d616ece2d859
|
151
|
#define IPH_PROTO(hdr) ((hdr)->_proto)
|
mbed714 |
0:d616ece2d859
|
152
|
#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
|
mbed714 |
0:d616ece2d859
|
153
|
|
mbed714 |
0:d616ece2d859
|
154
|
#define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
|
mbed714 |
0:d616ece2d859
|
155
|
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
|
mbed714 |
0:d616ece2d859
|
156
|
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
|
mbed714 |
0:d616ece2d859
|
157
|
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
|
mbed714 |
0:d616ece2d859
|
158
|
#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
|
mbed714 |
0:d616ece2d859
|
159
|
#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
|
mbed714 |
0:d616ece2d859
|
160
|
#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
|
mbed714 |
0:d616ece2d859
|
161
|
|
mbed714 |
0:d616ece2d859
|
162
|
/** The interface that provided the packet for the current callback invocation. */
|
mbed714 |
0:d616ece2d859
|
163
|
extern struct netif *current_netif;
|
mbed714 |
0:d616ece2d859
|
164
|
/** Header of the input packet currently being processed. */
|
mbed714 |
0:d616ece2d859
|
165
|
extern const struct ip_hdr *current_header;
|
mbed714 |
0:d616ece2d859
|
166
|
/** Source IP address of current_header */
|
mbed714 |
0:d616ece2d859
|
167
|
extern ip_addr_t current_iphdr_src;
|
mbed714 |
0:d616ece2d859
|
168
|
/** Destination IP address of current_header */
|
mbed714 |
0:d616ece2d859
|
169
|
extern ip_addr_t current_iphdr_dest;
|
mbed714 |
0:d616ece2d859
|
170
|
|
mbed714 |
0:d616ece2d859
|
171
|
#define ip_init() /* Compatibility define, not init needed. */
|
mbed714 |
0:d616ece2d859
|
172
|
struct netif *ip_route(ip_addr_t *dest);
|
mbed714 |
0:d616ece2d859
|
173
|
err_t ip_input(struct pbuf *p, struct netif *inp);
|
mbed714 |
0:d616ece2d859
|
174
|
err_t ip_output(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
|
mbed714 |
0:d616ece2d859
|
175
|
u8_t ttl, u8_t tos, u8_t proto);
|
mbed714 |
0:d616ece2d859
|
176
|
err_t ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
|
mbed714 |
0:d616ece2d859
|
177
|
u8_t ttl, u8_t tos, u8_t proto,
|
mbed714 |
0:d616ece2d859
|
178
|
struct netif *netif);
|
mbed714 |
0:d616ece2d859
|
179
|
#if LWIP_NETIF_HWADDRHINT
|
mbed714 |
0:d616ece2d859
|
180
|
err_t ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
|
mbed714 |
0:d616ece2d859
|
181
|
u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
|
mbed714 |
0:d616ece2d859
|
182
|
#endif /* LWIP_NETIF_HWADDRHINT */
|
mbed714 |
0:d616ece2d859
|
183
|
#if IP_OPTIONS_SEND
|
mbed714 |
0:d616ece2d859
|
184
|
err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
|
mbed714 |
0:d616ece2d859
|
185
|
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
|
mbed714 |
0:d616ece2d859
|
186
|
u16_t optlen);
|
mbed714 |
0:d616ece2d859
|
187
|
#endif /* IP_OPTIONS_SEND */
|
mbed714 |
0:d616ece2d859
|
188
|
/** Get the interface that received the current packet.
|
mbed714 |
0:d616ece2d859
|
189
|
* This function must only be called from a receive callback (udp_recv,
|
mbed714 |
0:d616ece2d859
|
190
|
* raw_recv, tcp_accept). It will return NULL otherwise. */
|
mbed714 |
0:d616ece2d859
|
191
|
#define ip_current_netif() (current_netif)
|
mbed714 |
0:d616ece2d859
|
192
|
/** Get the IP header of the current packet.
|
mbed714 |
0:d616ece2d859
|
193
|
* This function must only be called from a receive callback (udp_recv,
|
mbed714 |
0:d616ece2d859
|
194
|
* raw_recv, tcp_accept). It will return NULL otherwise. */
|
mbed714 |
0:d616ece2d859
|
195
|
#define ip_current_header() (current_header)
|
mbed714 |
0:d616ece2d859
|
196
|
/** Source IP address of current_header */
|
mbed714 |
0:d616ece2d859
|
197
|
#define ip_current_src_addr() (¤t_iphdr_src)
|
mbed714 |
0:d616ece2d859
|
198
|
/** Destination IP address of current_header */
|
mbed714 |
0:d616ece2d859
|
199
|
#define ip_current_dest_addr() (¤t_iphdr_dest)
|
mbed714 |
0:d616ece2d859
|
200
|
|
mbed714 |
0:d616ece2d859
|
201
|
#if IP_DEBUG
|
mbed714 |
0:d616ece2d859
|
202
|
void ip_debug_print(struct pbuf *p);
|
mbed714 |
0:d616ece2d859
|
203
|
#else
|
mbed714 |
0:d616ece2d859
|
204
|
#define ip_debug_print(p)
|
mbed714 |
0:d616ece2d859
|
205
|
#endif /* IP_DEBUG */
|
mbed714 |
0:d616ece2d859
|
206
|
|
mbed714 |
0:d616ece2d859
|
207
|
#ifdef __cplusplus
|
mbed714 |
0:d616ece2d859
|
208
|
}
|
mbed714 |
0:d616ece2d859
|
209
|
#endif
|
mbed714 |
0:d616ece2d859
|
210
|
|
mbed714 |
0:d616ece2d859
|
211
|
#endif /* __LWIP_IP_H__ */
|
mbed714 |
0:d616ece2d859
|
212
|
|
mbed714 |
0:d616ece2d859
|
213
|
|