Change typedef of uip_ipaddr_t from a vector type to a union.
typedef union uip_ip4addr_t { u16_t u16[2]; u8_t u8[4]; } uip_ip4addr_t; typedef uip_ip4addr_t uip_ipaddr_t; This implies that one must consistently pass pointers to uip_ipaddr_t:s and not mix and match pointers with uip_ipaddr_t:s as was done earlier.
This commit is contained in:
parent
2fe1ccf8c5
commit
fb94d50410
30 changed files with 253 additions and 270 deletions
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: uip-fw.c,v 1.1 2006/06/17 22:41:19 adamdunkels Exp $
|
||||
* $Id: uip-fw.c,v 1.2 2006/08/09 16:13:39 bg- Exp $
|
||||
*/
|
||||
/**
|
||||
* \addtogroup uip
|
||||
|
@ -80,8 +80,7 @@ struct tcpip_hdr {
|
|||
u8_t ttl,
|
||||
proto;
|
||||
u16_t ipchksum;
|
||||
u16_t srcipaddr[2],
|
||||
destipaddr[2];
|
||||
uip_ipaddr_t srcipaddr, destipaddr;
|
||||
|
||||
/* TCP header. */
|
||||
u16_t srcport,
|
||||
|
@ -106,8 +105,7 @@ struct icmpip_hdr {
|
|||
ttl,
|
||||
proto;
|
||||
u16_t ipchksum;
|
||||
u16_t srcipaddr[2],
|
||||
destipaddr[2];
|
||||
uip_ipaddr_t srcipaddr, destipaddr;
|
||||
/* ICMP (echo) header. */
|
||||
u8_t type, icode;
|
||||
u16_t icmpchksum;
|
||||
|
@ -138,8 +136,8 @@ struct icmpip_hdr {
|
|||
struct fwcache_entry {
|
||||
u16_t timer;
|
||||
|
||||
u16_t srcipaddr[2];
|
||||
u16_t destipaddr[2];
|
||||
uip_ipaddr_t srcipaddr;
|
||||
uip_ipaddr_t destipaddr;
|
||||
u16_t ipid;
|
||||
u8_t proto;
|
||||
u8_t unused;
|
||||
|
@ -205,10 +203,12 @@ uip_fw_init(void)
|
|||
*/
|
||||
/*------------------------------------------------------------------------------*/
|
||||
static unsigned char
|
||||
ipaddr_maskcmp(u16_t *ipaddr, u16_t *netipaddr, u16_t *netmask)
|
||||
ipaddr_maskcmp(uip_ipaddr_t *ipaddr,
|
||||
uip_ipaddr_t *netipaddr,
|
||||
uip_ipaddr_t *netmask)
|
||||
{
|
||||
return (ipaddr[0] & netmask [0]) == (netipaddr[0] & netmask[0]) &&
|
||||
(ipaddr[1] & netmask[1]) == (netipaddr[1] & netmask[1]);
|
||||
return (ipaddr->u16[0] & netmask->u16[0]) == (netipaddr->u16[0] & netmask->u16[0]) &&
|
||||
(ipaddr->u16[1] & netmask->u16[1]) == (netipaddr->u16[1] & netmask->u16[1]);
|
||||
}
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -222,7 +222,7 @@ ipaddr_maskcmp(u16_t *ipaddr, u16_t *netipaddr, u16_t *netmask)
|
|||
static void
|
||||
time_exceeded(void)
|
||||
{
|
||||
u16_t tmp16;
|
||||
uip_ipaddr_t tmpip;
|
||||
|
||||
/* We don't send out ICMP errors for ICMP messages. */
|
||||
if(ICMPBUF->proto == UIP_PROTO_ICMP) {
|
||||
|
@ -242,16 +242,15 @@ time_exceeded(void)
|
|||
|
||||
/* Set the IP destination address to be the source address of the
|
||||
original packet. */
|
||||
tmp16= BUF->destipaddr[0];
|
||||
BUF->destipaddr[0] = BUF->srcipaddr[0];
|
||||
BUF->srcipaddr[0] = tmp16;
|
||||
tmp16 = BUF->destipaddr[1];
|
||||
BUF->destipaddr[1] = BUF->srcipaddr[1];
|
||||
BUF->srcipaddr[1] = tmp16;
|
||||
tmpip = BUF->destipaddr;
|
||||
BUF->destipaddr = BUF->srcipaddr;
|
||||
BUF->srcipaddr = tmpip;
|
||||
tmpip = BUF->destipaddr;
|
||||
BUF->destipaddr = BUF->srcipaddr;
|
||||
BUF->srcipaddr = tmpip;
|
||||
|
||||
/* Set our IP address as the source address. */
|
||||
BUF->srcipaddr[0] = uip_hostaddr[0];
|
||||
BUF->srcipaddr[1] = uip_hostaddr[1];
|
||||
BUF->srcipaddr = uip_hostaddr;
|
||||
|
||||
/* The size of the ICMP time exceeded packet is 36 + the size of the
|
||||
IP header (20) = 56. */
|
||||
|
@ -301,10 +300,8 @@ fwcache_register(void)
|
|||
|
||||
fw->timer = FW_TIME;
|
||||
fw->ipid = BUF->ipid;
|
||||
fw->srcipaddr[0] = BUF->srcipaddr[0];
|
||||
fw->srcipaddr[1] = BUF->srcipaddr[1];
|
||||
fw->destipaddr[0] = BUF->destipaddr[0];
|
||||
fw->destipaddr[1] = BUF->destipaddr[1];
|
||||
fw->srcipaddr = BUF->srcipaddr;
|
||||
fw->destipaddr = BUF->destipaddr;
|
||||
fw->proto = BUF->proto;
|
||||
#if notdef
|
||||
fw->payload[0] = BUF->srcport;
|
||||
|
@ -328,8 +325,8 @@ find_netif(void)
|
|||
|
||||
/* Walk through every network interface to check for a match. */
|
||||
for(netif = netifs; netif != NULL; netif = netif->next) {
|
||||
if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
|
||||
netif->netmask)) {
|
||||
if(ipaddr_maskcmp(&BUF->destipaddr, &netif->ipaddr,
|
||||
&netif->netmask)) {
|
||||
/* If there was a match, we break the loop. */
|
||||
return netif;
|
||||
}
|
||||
|
@ -369,8 +366,7 @@ uip_fw_output(void)
|
|||
#if UIP_BROADCAST
|
||||
/* Link local broadcasts go out on all interfaces. */
|
||||
if(/*BUF->proto == UIP_PROTO_UDP &&*/
|
||||
BUF->destipaddr[0] == 0xffff &&
|
||||
BUF->destipaddr[1] == 0xffff) {
|
||||
uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
|
||||
if(defaultnetif != NULL) {
|
||||
defaultnetif->output();
|
||||
}
|
||||
|
@ -410,15 +406,14 @@ uip_fw_forward(void)
|
|||
|
||||
/* First check if the packet is destined for ourselves and return 0
|
||||
to indicate that the packet should be processed locally. */
|
||||
if(BUF->destipaddr[0] == uip_hostaddr[0] &&
|
||||
BUF->destipaddr[1] == uip_hostaddr[1]) {
|
||||
if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
|
||||
return UIP_FW_LOCAL;
|
||||
}
|
||||
|
||||
/* If we use ping IP address configuration, and our IP address is
|
||||
not yet configured, we should intercept all ICMP echo packets. */
|
||||
#if UIP_PINGADDRCONF
|
||||
if((uip_hostaddr[0] | uip_hostaddr[1]) == 0 &&
|
||||
if(uip_ipaddr_cmp(&uip_hostaddr, &all_zeroes_addr) &&
|
||||
BUF->proto == UIP_PROTO_ICMP &&
|
||||
ICMPBUF->type == ICMP_ECHO) {
|
||||
return UIP_FW_LOCAL;
|
||||
|
@ -435,10 +430,8 @@ uip_fw_forward(void)
|
|||
fw->offset == BUF->ipoffset &&
|
||||
#endif
|
||||
fw->ipid == BUF->ipid &&
|
||||
fw->srcipaddr[0] == BUF->srcipaddr[0] &&
|
||||
fw->srcipaddr[1] == BUF->srcipaddr[1] &&
|
||||
fw->destipaddr[0] == BUF->destipaddr[0] &&
|
||||
fw->destipaddr[1] == BUF->destipaddr[1] &&
|
||||
uip_ipaddr_cmp(&fw->srcipaddr, &BUF->srcipaddr) &&
|
||||
uip_ipaddr_cmp(&fw->destipaddr, &BUF->destipaddr) &&
|
||||
#if notdef
|
||||
fw->payload[0] == BUF->srcport &&
|
||||
fw->payload[1] == BUF->destport &&
|
||||
|
@ -454,7 +447,7 @@ uip_fw_forward(void)
|
|||
of the packet. */
|
||||
if(BUF->ttl <= 1) {
|
||||
/* No time exceeded for broadcasts and multicasts! */
|
||||
if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
|
||||
if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
|
||||
return UIP_FW_LOCAL;
|
||||
}
|
||||
time_exceeded();
|
||||
|
@ -476,7 +469,7 @@ uip_fw_forward(void)
|
|||
}
|
||||
|
||||
#if UIP_BROADCAST
|
||||
if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
|
||||
if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
|
||||
return UIP_FW_LOCAL;
|
||||
}
|
||||
#endif /* UIP_BROADCAST */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue