57 #include "contiki-conf.h"
62 #ifdef AODV_COMPLIANCE
86 uip_ipaddr_t srcipaddr, destipaddr;
111 uip_ipaddr_t srcipaddr, destipaddr;
128 #define BUF ((struct tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
133 #define ICMPBUF ((struct icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
139 struct fwcache_entry {
142 uip_ipaddr_t srcipaddr;
143 uip_ipaddr_t destipaddr;
152 #if UIP_REASSEMBLY > 0
153 uint16_t len, offset;
160 #ifdef UIP_CONF_FWCACHE_SIZE
161 #define FWCACHE_SIZE UIP_CONF_FWCACHE_SIZE
163 #define FWCACHE_SIZE 2
171 static struct fwcache_entry fwcache[FWCACHE_SIZE];
189 while(netifs !=
NULL) {
191 netifs = netifs->
next;
209 ipaddr_maskcmp(uip_ipaddr_t *
ipaddr,
210 uip_ipaddr_t *netipaddr,
213 return (ipaddr->u16[0] & netmask->u16[0]) == (netipaddr->u16[0] & netmask->u16[0]) &&
214 (ipaddr->u16[1] & netmask->u16[1]) == (netipaddr->u16[1] & netmask->u16[1]);
230 if(ICMPBUF->proto == UIP_PROTO_ICMP &&
231 ICMPBUF->type != ICMP_ECHO) {
236 memcpy(&(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8);
239 ICMPBUF->type = ICMP_TE;
243 ICMPBUF->icmpchksum = 0;
244 ICMPBUF->icmpchksum = ~
uip_chksum((uint16_t *)&(ICMPBUF->type), 36);
257 ICMPBUF->len[1] = (uint8_t)
uip_len;
262 ICMPBUF->ipoffset[0] = ICMPBUF->ipoffset[1] = 0;
264 ICMPBUF->proto = UIP_PROTO_ICMP;
267 ICMPBUF->ipchksum = 0;
280 fwcache_register(
void)
282 struct fwcache_entry *fw;
289 for(i = 0; i < FWCACHE_SIZE; ++i) {
290 if(fwcache[i].
timer == 0) {
293 }
else if(fwcache[i].
timer <= oldest) {
295 oldest = fwcache[i].timer;
300 fw->ipid = BUF->ipid;
303 fw->proto = BUF->proto;
305 fw->payload[0] = BUF->srcport;
306 fw->payload[1] = BUF->destport;
308 #if UIP_REASSEMBLY > 0
310 fw->offset = BUF->ipoffset;
325 for(netif = netifs; netif !=
NULL; netif = netif->
next) {
326 if(ipaddr_maskcmp(&BUF->destipaddr, &netif->
ipaddr,
358 const struct uip_udpip_hdr *udp = (
void *)BUF;
369 if(uip_ipaddr_cmp(&udp->destipaddr, &uip_broadcast_addr)) {
370 if(defaultnetif !=
NULL) {
373 for(netif = netifs; netif !=
NULL; netif = netif->
next) {
380 netif = find_netif();
405 struct fwcache_entry *fw;
409 if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
413 #ifdef AODV_COMPLIANCE
414 #define udp ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
415 if(udp->proto == UIP_PROTO_UDP && udp->destport ==
UIP_HTONS(UAODV_UDPPORT)) {
423 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) &&
424 BUF->proto == UIP_PROTO_ICMP &&
425 ICMPBUF->type == ICMP_ECHO) {
433 for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
436 fw->len == BUF->len &&
437 fw->offset == BUF->ipoffset &&
439 fw->ipid == BUF->ipid &&
440 uip_ipaddr_cmp(&fw->srcipaddr, &BUF->srcipaddr) &&
441 uip_ipaddr_cmp(&fw->destipaddr, &BUF->destipaddr) &&
443 fw->payload[0] == BUF->srcport &&
444 fw->payload[1] == BUF->destport &&
446 fw->proto == BUF->proto) {
458 if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
465 BUF->ttl = BUF->ttl - 1;
468 if(BUF->ipchksum >=
UIP_HTONS(0xffff - 0x0100)) {
469 BUF->ipchksum = BUF->ipchksum +
UIP_HTONS(0x0100) + 1;
471 BUF->ipchksum = BUF->ipchksum +
UIP_HTONS(0x0100);
480 if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
500 netif->
next = netifs;
517 defaultnetif = netif;
527 struct fwcache_entry *fw;
528 for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
uint16_t uip_ipchksum(void)
Calculate the IP header checksum of the packet header in uip_buf.
uip_len
The length of the packet in the uip_buf buffer.
uIP packet forwarding header file.
Representation of a uIP network interface.
struct uip_fw_netif * next
Pointer to the next interface when linked in a list.
uint8_t(* output)(void)
A pointer to the function that sends a packet.
uip_ipaddr_t ipaddr
The IP address of this interface.
Header file for the uIP TCP/IP stack.
void uip_fw_init(void)
Initialize the uIP packet forwarding module.
#define UIP_REASSEMBLY
Turn on support for IP packet reassembly.
uint16_t uip_chksum(uint16_t *buf, uint16_t len)
Calculate the Internet checksum over a buffer.
#define NULL
The null pointer.
#define UIP_FW_ZEROLEN
A non-error message that indicates that a zero-length packet transmission was attempted, and that no packet was sent.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
uint8_t uip_fw_forward(void)
Forward an IP packet in the uip_buf buffer.
#define UIP_LLH_LEN
The link level header length.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
void uip_fw_default(struct uip_fw_netif *netif)
Register a default network interface.
void uip_fw_register(struct uip_fw_netif *netif)
Register a network interface with the forwarding module.
uint8_t uip_fw_output(void)
Output an IP packet on the correct network interface.
uip_ipaddr_t netmask
The netmask of the interface.
#define UIP_FW_FORWARDED
A non-error message that indicates that a packet was forwarded.
void uip_fw_periodic(void)
Perform periodic processing.
Definitions for the micro implementation of the AODV ad hoc routing protocol ...
#define UIP_TTL
The IP TTL (time to live) of IP packets sent by uIP.
#define UIP_FW_LOCAL
A non-error message that indicates that a packet should be processed locally.
#define UIP_FW_OK
A non-error message that indicates that something went OK.
Declarations of architecture specific functions.
uip_appdata
Pointer to the application data in the packet buffer.
#define UIP_FW_NOROUTE
An error message that indicates that no suitable interface could be found for an outbound packet...