31 |
*/ |
*/ |
32 |
|
|
33 |
|
|
34 |
/*-----------------------------------------------------------------------------------*/ |
|
35 |
/* ip.c |
/* ip.c |
36 |
* |
* |
37 |
* This is the code for the IP layer. |
* This is the code for the IP layer. |
38 |
* |
* |
39 |
*/ |
*/ |
40 |
/*-----------------------------------------------------------------------------------*/ |
|
41 |
|
|
42 |
#include "lwip/opt.h" |
#include "lwip/opt.h" |
43 |
|
|
62 |
# include "lwip/dhcp.h" |
# include "lwip/dhcp.h" |
63 |
#endif /* LWIP_DHCP */ |
#endif /* LWIP_DHCP */ |
64 |
|
|
65 |
/*-----------------------------------------------------------------------------------*/ |
|
66 |
/* ip_init: |
/* ip_init: |
67 |
* |
* |
68 |
* Initializes the IP layer. |
* Initializes the IP layer. |
69 |
*/ |
*/ |
70 |
/*-----------------------------------------------------------------------------------*/ |
|
71 |
void |
void |
72 |
ip_init(void) |
ip_init(void) |
73 |
{ |
{ |
74 |
} |
} |
75 |
/*-----------------------------------------------------------------------------------*/ |
|
76 |
/* ip_lookup: |
/* ip_lookup: |
77 |
* |
* |
78 |
* An experimental feature that will be changed in future versions. Do |
* An experimental feature that will be changed in future versions. Do |
79 |
* not depend on it yet... |
* not depend on it yet... |
80 |
*/ |
*/ |
81 |
/*-----------------------------------------------------------------------------------*/ |
|
82 |
#ifdef LWIP_DEBUG |
#ifdef LWIP_DEBUG |
83 |
u8_t |
u8_t |
84 |
ip_lookup(void *header, struct netif *inp) |
ip_lookup(void *header, struct netif *inp) |
123 |
} |
} |
124 |
} |
} |
125 |
#endif /* LWIP_DEBUG */ |
#endif /* LWIP_DEBUG */ |
126 |
/*-----------------------------------------------------------------------------------*/ |
|
127 |
/* ip_route: |
/* ip_route: |
128 |
* |
* |
129 |
* Finds the appropriate network interface for a given IP address. It |
* Finds the appropriate network interface for a given IP address. It |
131 |
* if the masked IP address of the network interface equals the masked |
* if the masked IP address of the network interface equals the masked |
132 |
* IP address given to the function. |
* IP address given to the function. |
133 |
*/ |
*/ |
134 |
/*-----------------------------------------------------------------------------------*/ |
|
135 |
struct netif * |
struct netif * |
136 |
ip_route(struct ip_addr *dest) |
ip_route(struct ip_addr *dest) |
137 |
{ |
{ |
149 |
return netif_default; |
return netif_default; |
150 |
} |
} |
151 |
#if IP_FORWARD |
#if IP_FORWARD |
152 |
/*-----------------------------------------------------------------------------------*/ |
|
153 |
/* ip_forward: |
/* ip_forward: |
154 |
* |
* |
155 |
* Forwards an IP packet. It finds an appropriate route for the |
* Forwards an IP packet. It finds an appropriate route for the |
156 |
* packet, decrements the TTL value of the packet, adjusts the |
* packet, decrements the TTL value of the packet, adjusts the |
157 |
* checksum and outputs the packet on the appropriate interface. |
* checksum and outputs the packet on the appropriate interface. |
158 |
*/ |
*/ |
159 |
/*-----------------------------------------------------------------------------------*/ |
|
160 |
static void |
static void |
161 |
ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) |
ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) |
162 |
{ |
{ |
210 |
netif->output(netif, p, (struct ip_addr *)&(iphdr->dest)); |
netif->output(netif, p, (struct ip_addr *)&(iphdr->dest)); |
211 |
} |
} |
212 |
#endif /* IP_FORWARD */ |
#endif /* IP_FORWARD */ |
213 |
/*-----------------------------------------------------------------------------------*/ |
|
214 |
/* ip_input: |
/* ip_input: |
215 |
* |
* |
216 |
* This function is called by the network interface device driver when |
* This function is called by the network interface device driver when |
221 |
* |
* |
222 |
* Finally, the packet is sent to the upper layer protocol input function. |
* Finally, the packet is sent to the upper layer protocol input function. |
223 |
*/ |
*/ |
224 |
/*-----------------------------------------------------------------------------------*/ |
|
225 |
err_t |
err_t |
226 |
ip_input(struct pbuf *p, struct netif *inp) { |
ip_input(struct pbuf *p, struct netif *inp) { |
227 |
static struct ip_hdr *iphdr; |
static struct ip_hdr *iphdr; |
418 |
return ERR_OK; |
return ERR_OK; |
419 |
} |
} |
420 |
|
|
421 |
/*-----------------------------------------------------------------------------------*/ |
|
422 |
/* ip_output_if: |
/* ip_output_if: |
423 |
* |
* |
424 |
* Sends an IP packet on a network interface. This function constructs |
* Sends an IP packet on a network interface. This function constructs |
426 |
* IP address is NULL, the IP address of the outgoing network |
* IP address is NULL, the IP address of the outgoing network |
427 |
* interface is filled in as source address. |
* interface is filled in as source address. |
428 |
*/ |
*/ |
429 |
/*-----------------------------------------------------------------------------------*/ |
|
430 |
err_t |
err_t |
431 |
ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, |
ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, |
432 |
u8_t ttl, u8_t tos, |
u8_t ttl, u8_t tos, |
487 |
|
|
488 |
return netif->output(netif, p, dest); |
return netif->output(netif, p, dest); |
489 |
} |
} |
490 |
/*-----------------------------------------------------------------------------------*/ |
|
491 |
/* ip_output: |
/* ip_output: |
492 |
* |
* |
493 |
* Simple interface to ip_output_if. It finds the outgoing network |
* Simple interface to ip_output_if. It finds the outgoing network |
494 |
* interface and calls upon ip_output_if to do the actual work. |
* interface and calls upon ip_output_if to do the actual work. |
495 |
*/ |
*/ |
496 |
/*-----------------------------------------------------------------------------------*/ |
|
497 |
err_t |
err_t |
498 |
ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, |
ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, |
499 |
u8_t ttl, u8_t tos, u8_t proto) |
u8_t ttl, u8_t tos, u8_t proto) |
510 |
|
|
511 |
return ip_output_if(p, src, dest, ttl, tos, proto, netif); |
return ip_output_if(p, src, dest, ttl, tos, proto, netif); |
512 |
} |
} |
513 |
/*-----------------------------------------------------------------------------------*/ |
|
514 |
#if IP_DEBUG |
#if IP_DEBUG |
515 |
void |
void |
516 |
ip_debug_print(struct pbuf *p) |
ip_debug_print(struct pbuf *p) |
554 |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
555 |
} |
} |
556 |
#endif /* IP_DEBUG */ |
#endif /* IP_DEBUG */ |
557 |
/*-----------------------------------------------------------------------------------*/ |
|
558 |
|
|
559 |
|
|
560 |
|
|