ReactOS 0.4.15-dev-8235-gcd88a97
ip6.c File Reference
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/ip.h"
#include "lwip/inet.h"
#include "lwip/netif.h"
#include "lwip/icmp.h"
#include "lwip/udp.h"
#include "lwip/tcp_impl.h"
#include "lwip/stats.h"
#include "arch/perf.h"
Include dependency graph for ip6.c:

Go to the source code of this file.

Functions

void ip_init (void)
 
struct netifip_route (struct ip_addr *dest)
 
static void ip_forward (struct pbuf *p, struct ip_hdr *iphdr)
 
void ip_input (struct pbuf *p, struct netif *inp)
 
err_t ip_output_if (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto, struct netif *netif)
 
err_t ip_output (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto)
 

Function Documentation

◆ ip_forward()

static void ip_forward ( struct pbuf p,
struct ip_hdr iphdr 
)
static

Definition at line 96 of file ip6.c.

97{
98 struct netif *netif;
99
101
102 if ((netif = ip_route((struct ip_addr *)&(iphdr->dest))) == NULL) {
103
104 LWIP_DEBUGF(IP_DEBUG, ("ip_input: no forwarding route found for "));
105#if IP_DEBUG
106 ip_addr_debug_print(IP_DEBUG, ((struct ip_addr *)&(iphdr->dest)));
107#endif /* IP_DEBUG */
108 LWIP_DEBUGF(IP_DEBUG, ("\n"));
109 pbuf_free(p);
110 return;
111 }
112 /* Decrement TTL and send ICMP if ttl == 0. */
113 if (--iphdr->hoplim == 0) {
114#if LWIP_ICMP
115 /* Don't send ICMP messages in response to ICMP messages */
116 if (iphdr->nexthdr != IP_PROTO_ICMP) {
117 icmp_time_exceeded(p, ICMP_TE_TTL);
118 }
119#endif /* LWIP_ICMP */
120 pbuf_free(p);
121 return;
122 }
123
124 /* Incremental update of the IP checksum. */
125 /* if (iphdr->chksum >= htons(0xffff - 0x100)) {
126 iphdr->chksum += htons(0x100) + 1;
127 } else {
128 iphdr->chksum += htons(0x100);
129 }*/
130
131
132 LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to "));
133#if IP_DEBUG
134 ip_addr_debug_print(IP_DEBUG, ((struct ip_addr *)&(iphdr->dest)));
135#endif /* IP_DEBUG */
136 LWIP_DEBUGF(IP_DEBUG, ("\n"));
137
138 IP_STATS_INC(ip.fw);
139 IP_STATS_INC(ip.xmit);
140
141 PERF_STOP("ip_forward");
142
143 netif->output(netif, p, (struct ip_addr *)&(iphdr->dest));
144}
#define NULL
Definition: types.h:112
struct netif * ip_route(struct ip_addr *dest)
Definition: ip6.c:75
#define IP_PROTO_ICMP
Definition: ip.h:52
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:95
GLfloat GLfloat p
Definition: glext.h:8902
#define IP_DEBUG
Definition: lwipopts.h:135
#define ip_addr_debug_print(debug, ipaddr)
Definition: ip_addr.h:212
@ ICMP_TE_TTL
Definition: icmp.h:66
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:618
#define PERF_START
Definition: perf.h:3
#define PERF_STOP
Definition: perf.h:4
#define IP_STATS_INC(x)
Definition: stats.h:203
struct ip_addr src dest
Definition: ip.h:96
u8_t hoplim
Definition: ip.h:95
u8_t nexthdr
Definition: ip.h:94
Definition: dhcpd.h:62
Definition: netif.h:136
netif_output_fn output
Definition: netif.h:151

Referenced by ip_input().

◆ ip_init()

void ip_init ( void  )

Definition at line 63 of file ip6.c.

64{
65}

◆ ip_input()

void ip_input ( struct pbuf p,
struct netif inp 
)

This function is called by the network interface device driver when an IP packet is received. The function does the basic checks of the IP header such as packet size being at least larger than the header size etc. If the packet was not destined for us, the packet is forwarded (using ip_forward). The IP checksum is always checked.

Finally, the packet is sent to the upper layer protocol input function.

Parameters
pthe received IP packet (p->payload points to IP header)
inpthe netif on which this packet was received
Returns
ERR_OK if the packet was processed (could return ERR_* if it wasn't processed, but currently always returns ERR_OK)

Definition at line 157 of file ip6.c.

157 {
158 struct ip_hdr *iphdr;
159 struct netif *netif;
160
161
163
164#if IP_DEBUG
166#endif /* IP_DEBUG */
167
168
169 IP_STATS_INC(ip.recv);
170
171 /* identify the IP header */
172 iphdr = p->payload;
173
174
175 if (iphdr->v != 6) {
176 LWIP_DEBUGF(IP_DEBUG, ("IP packet dropped due to bad version number\n"));
177#if IP_DEBUG
179#endif /* IP_DEBUG */
180 pbuf_free(p);
181 IP_STATS_INC(ip.err);
182 IP_STATS_INC(ip.drop);
183 return;
184 }
185
186 /* is this packet for us? */
187 for(netif = netif_list; netif != NULL; netif = netif->next) {
188#if IP_DEBUG
189 LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest "));
190 ip_addr_debug_print(IP_DEBUG, ((struct ip_addr *)&(iphdr->dest)));
191 LWIP_DEBUGF(IP_DEBUG, ("netif->ip_addr "));
192 ip_addr_debug_print(IP_DEBUG, ((struct ip_addr *)&(iphdr->dest)));
193 LWIP_DEBUGF(IP_DEBUG, ("\n"));
194#endif /* IP_DEBUG */
195 if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr))) {
196 break;
197 }
198 }
199
200
201 if (netif == NULL) {
202 /* packet not for us, route or discard */
203#if IP_FORWARD
204 ip_forward(p, iphdr);
205#endif
206 pbuf_free(p);
207 return;
208 }
209
210 pbuf_realloc(p, IP_HLEN + ntohs(iphdr->len));
211
212 /* send to upper layers */
213#if IP_DEBUG
214 /* LWIP_DEBUGF("ip_input: \n");
215 ip_debug_print(p);
216 LWIP_DEBUGF("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len);*/
217#endif /* IP_DEBUG */
218
219 if(pbuf_header(p, -IP_HLEN)) {
220 LWIP_ASSERT("Can't move over header in packet", 0);
221 return;
222 }
223
224 switch (iphdr->nexthdr) {
225 case IP_PROTO_UDP:
226 udp_input(p, inp);
227 break;
228 case IP_PROTO_TCP:
229 tcp_input(p, inp);
230 break;
231#if LWIP_ICMP
232 case IP_PROTO_ICMP:
233 icmp_input(p, inp);
234 break;
235#endif /* LWIP_ICMP */
236 default:
237#if LWIP_ICMP
238 /* send ICMP destination protocol unreachable */
239 icmp_dest_unreach(p, ICMP_DUR_PROTO);
240#endif /* LWIP_ICMP */
241 pbuf_free(p);
242 LWIP_DEBUGF(IP_DEBUG, ("Unsupported transport protocol %"U16_F"\n",
243 iphdr->nexthdr));
244
245 IP_STATS_INC(ip.proterr);
246 IP_STATS_INC(ip.drop);
247 }
248 PERF_STOP("ip_input");
249}
#define U16_F
Definition: cc.h:36
static void ip_forward(struct pbuf *p, struct ip_hdr *iphdr)
Definition: ip6.c:96
#define IP_PROTO_TCP
Definition: ip.h:56
#define IP_PROTO_UDP
Definition: ip.h:54
#define ip_debug_print(p)
Definition: ip.h:214
#define IP_HLEN
Definition: ip.h:50
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:66
#define ip_addr_cmp(addr1, addr2)
Definition: ip_addr.h:198
@ ICMP_DUR_PROTO
Definition: icmp.h:59
#define ntohs(x)
Definition: module.h:210
struct netif * netif_list
Definition: netif.c:75
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
Definition: pbuf.c:511
void pbuf_realloc(struct pbuf *p, u16_t new_len)
Definition: pbuf.c:430
Definition: ip.h:116
u8_t v
Definition: ip.h:86
u16_t len
Definition: ip.h:93
ip_addr_t ip_addr
Definition: netif.h:141
struct netif * next
Definition: netif.h:138

◆ ip_output()

err_t ip_output ( struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
u8_t  ttl,
u8_t  proto 
)

Definition at line 317 of file ip6.c.

319{
320 struct netif *netif;
321 if ((netif = ip_route(dest)) == NULL) {
322 LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%"X32_F"\n", dest->addr));
323 IP_STATS_INC(ip.rterr);
324 return ERR_RTE;
325 }
326
327 return ip_output_if (p, src, dest, ttl, proto, netif);
328}
#define X32_F
Definition: cc.h:41
err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto, struct netif *netif)
Definition: ip6.c:260
#define ERR_RTE
Definition: err.h:56
GLenum src
Definition: glext.h:6340
static char * dest
Definition: rtl.c:135

◆ ip_output_if()

err_t ip_output_if ( struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
u8_t  ttl,
u8_t  proto,
struct netif netif 
)

Definition at line 260 of file ip6.c.

263{
264 struct ip_hdr *iphdr;
265
267
268 LWIP_DEBUGF(IP_DEBUG, ("len %"U16_F" tot_len %"U16_F"\n", p->len, p->tot_len));
269 if (pbuf_header(p, IP_HLEN)) {
270 LWIP_DEBUGF(IP_DEBUG, ("ip_output: not enough room for IP header in pbuf\n"));
271 IP_STATS_INC(ip.err);
272
273 return ERR_BUF;
274 }
275 LWIP_DEBUGF(IP_DEBUG, ("len %"U16_F" tot_len %"U16_F"\n", p->len, p->tot_len));
276
277 iphdr = p->payload;
278
279
280 if (dest != IP_HDRINCL) {
281 LWIP_DEBUGF(IP_DEBUG, ("!IP_HDRLINCL\n"));
282 iphdr->hoplim = ttl;
283 iphdr->nexthdr = proto;
284 iphdr->len = htons(p->tot_len - IP_HLEN);
285 ip_addr_set(&(iphdr->dest), dest);
286
287 iphdr->v = 6;
288
289 if (ip_addr_isany(src)) {
290 ip_addr_set(&(iphdr->src), &(netif->ip_addr));
291 } else {
292 ip_addr_set(&(iphdr->src), src);
293 }
294
295 } else {
296 dest = &(iphdr->dest);
297 }
298
299 IP_STATS_INC(ip.xmit);
300
301 LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c (len %"U16_F")\n", netif->name[0], netif->name[1], p->tot_len));
302#if IP_DEBUG
304#endif /* IP_DEBUG */
305
306 PERF_STOP("ip_output_if");
307 return netif->output(netif, p, dest);
308}
#define IP_HDRINCL
Definition: ip.h:64
#define ERR_BUF
Definition: err.h:54
#define ip_addr_isany(addr1)
Definition: ip_addr.h:200
#define ip_addr_set(dest, src)
Definition: ip_addr.h:164
#define htons(x)
Definition: module.h:215
char name[2]
Definition: netif.h:194

Referenced by ip_output().

◆ ip_route()

struct netif * ip_route ( struct ip_addr dest)

Definition at line 75 of file ip6.c.

76{
77 struct netif *netif;
78
79 for(netif = netif_list; netif != NULL; netif = netif->next) {
81 return netif;
82 }
83 }
84
85 return netif_default;
86}
#define ip_addr_netcmp(addr1, addr2, mask)
Definition: ip_addr.h:194
struct netif * netif_default
Definition: netif.c:76
ip_addr_t netmask
Definition: netif.h:142

Referenced by ip_forward(), and ip_output().