Changeset 262 for uKadecot/trunk/uip/net/ipv4/uip-fw.c
- Timestamp:
- Nov 18, 2016, 2:58:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uKadecot/trunk/uip/net/ipv4/uip-fw.c
r158 r262 86 86 proto; 87 87 uint16_t ipchksum; 88 uint16_t srcipaddr[2], 89 destipaddr[2]; 88 uip_ipaddr_t srcipaddr, destipaddr; 90 89 91 90 /* TCP header. */ … … 112 111 proto; 113 112 uint16_t ipchksum; 114 uint16_t srcipaddr[2], 115 destipaddr[2]; 113 uip_ipaddr_t srcipaddr, destipaddr; 116 114 /* ICMP (echo) header. */ 117 115 uint8_t type, icode; … … 144 142 uint16_t timer; 145 143 146 ui nt16_t srcipaddr[2];147 ui nt16_t destipaddr[2];144 uip_ipaddr_t srcipaddr; 145 uip_ipaddr_t destipaddr; 148 146 uint16_t ipid; 149 147 uint8_t proto; … … 217 215 /*------------------------------------------------------------------------------*/ 218 216 static unsigned char 219 ipaddr_maskcmp(uint16_t *ipaddr, uint16_t *netipaddr, uint16_t *netmask) 220 { 221 return (ipaddr[0] & netmask [0]) == (netipaddr[0] & netmask[0]) && 222 (ipaddr[1] & netmask[1]) == (netipaddr[1] & netmask[1]); 217 ipaddr_maskcmp(uip_ipaddr_t *ipaddr, 218 uip_ipaddr_t *netipaddr, 219 uip_ipaddr_t *netmask) 220 { 221 return (ipaddr->u16[0] & netmask->u16[0]) == (netipaddr->u16[0] & netmask->u16[0]) && 222 (ipaddr->u16[1] & netmask->u16[1]) == (netipaddr->u16[1] & netmask->u16[1]); 223 223 } 224 224 /*------------------------------------------------------------------------------*/ … … 254 254 /* Set the IP destination address to be the source address of the 255 255 original packet. */ 256 tmp16= BUF->destipaddr[0]; 257 BUF->destipaddr[0] = BUF->srcipaddr[0]; 258 BUF->srcipaddr[0] = tmp16; 259 tmp16 = BUF->destipaddr[1]; 260 BUF->destipaddr[1] = BUF->srcipaddr[1]; 261 BUF->srcipaddr[1] = tmp16; 256 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr); 262 257 263 258 /* Set our IP address as the source address. */ 264 BUF->srcipaddr[0] = uip_hostaddr[0]; 265 BUF->srcipaddr[1] = uip_hostaddr[1]; 259 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr); 266 260 267 261 /* The size of the ICMP time exceeded packet is 36 + the size of the … … 269 263 uip_len = 56; 270 264 ICMPBUF->len[0] = 0; 271 ICMPBUF->len[1] = uip_len;265 ICMPBUF->len[1] = (uint8_t)uip_len; 272 266 273 267 /* Fill in the other fields in the IP header. */ … … 313 307 fw->timer = FW_TIME; 314 308 fw->ipid = BUF->ipid; 315 fw->srcipaddr[0] = BUF->srcipaddr[0]; 316 fw->srcipaddr[1] = BUF->srcipaddr[1]; 317 fw->destipaddr[0] = BUF->destipaddr[0]; 318 fw->destipaddr[1] = BUF->destipaddr[1]; 309 uip_ipaddr_copy(&fw->srcipaddr, &BUF->srcipaddr); 310 uip_ipaddr_copy(&fw->destipaddr, &BUF->destipaddr); 319 311 fw->proto = BUF->proto; 320 312 #if notdef … … 340 332 /* Walk through every network interface to check for a match. */ 341 333 for(netif = netifs; netif != NULL; netif = netif->next) { 342 if(ipaddr_maskcmp( BUF->destipaddr,netif->ipaddr,343 netif->netmask)) {334 if(ipaddr_maskcmp(&BUF->destipaddr, &netif->ipaddr, 335 &netif->netmask)) { 344 336 /* If there was a match, we break the loop. */ 345 337 return netif; … … 371 363 { 372 364 struct uip_fw_netif *netif; 365 #if UIP_BROADCAST 366 const struct uip_udpip_hdr *udp = (void *)BUF; 367 #endif /* UIP_BROADCAST */ 373 368 374 369 if(uip_len == 0) { … … 380 375 #if UIP_BROADCAST 381 376 /* Link local broadcasts go out on all interfaces. */ 382 if(/*BUF->proto == UIP_PROTO_UDP &&*/ 383 BUF->destipaddr[0] == 0xffff && 384 BUF->destipaddr[1] == 0xffff) { 377 if(uip_ipaddr_cmp(&udp->destipaddr, &uip_broadcast_addr)) { 385 378 if(defaultnetif != NULL) { 386 379 defaultnetif->output(); … … 422 415 /* First check if the packet is destined for ourselves and return 0 423 416 to indicate that the packet should be processed locally. */ 424 if(BUF->destipaddr[0] == uip_hostaddr[0] && 425 BUF->destipaddr[1] == uip_hostaddr[1]) { 417 if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) { 426 418 return UIP_FW_LOCAL; 427 419 } … … 430 422 not yet configured, we should intercept all ICMP echo packets. */ 431 423 #if UIP_PINGADDRCONF 432 if( (uip_hostaddr[0] | uip_hostaddr[1]) == 0&&424 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) && 433 425 BUF->proto == UIP_PROTO_ICMP && 434 426 ICMPBUF->type == ICMP_ECHO) { … … 447 439 #endif 448 440 fw->ipid == BUF->ipid && 449 fw->srcipaddr[0] == BUF->srcipaddr[0] && 450 fw->srcipaddr[1] == BUF->srcipaddr[1] && 451 fw->destipaddr[0] == BUF->destipaddr[0] && 452 fw->destipaddr[1] == BUF->destipaddr[1] && 441 uip_ipaddr_cmp(&fw->srcipaddr, &BUF->srcipaddr) && 442 uip_ipaddr_cmp(&fw->destipaddr, &BUF->destipaddr) && 453 443 #if notdef 454 444 fw->payload[0] == BUF->srcport && … … 464 454 in the uip_buf buffer and forward that packet back to the sender 465 455 of the packet. */ 456 466 457 if(BUF->ttl <= 1) { 467 458 /* No time exceeded for broadcasts and multicasts! */ 468 if( BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {459 if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) { 469 460 return UIP_FW_LOCAL; 470 461 } … … 476 467 477 468 /* Update the IP checksum. */ 478 if(BUF->ipchksum >= HTONS(0xffff - 0x0100)) {479 BUF->ipchksum = BUF->ipchksum + HTONS(0x0100) + 1;469 if(BUF->ipchksum >= UIP_HTONS(0xffff - 0x0100)) { 470 BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100) + 1; 480 471 } else { 481 BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);472 BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100); 482 473 } 483 474 … … 488 479 489 480 #if UIP_BROADCAST 490 if( BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {481 if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) { 491 482 return UIP_FW_LOCAL; 492 483 }
Note:
See TracChangeset
for help on using the changeset viewer.