Changeset 262 for uKadecot/trunk/uip/net/ipv4
- Timestamp:
- Nov 18, 2016, 2:58:30 PM (8 years ago)
- Location:
- uKadecot/trunk/uip/net/ipv4
- Files:
-
- 7 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 } -
uKadecot/trunk/uip/net/ipv4/uip-fw.h
r158 r262 55 55 struct uip_fw_netif *next; /**< Pointer to the next interface when 56 56 linked in a list. */ 57 ui nt16_t ipaddr[2]; /**< The IP address of this interface. */58 ui nt16_t netmask[2]; /**< The netmask of the interface. */57 uip_ipaddr_t ipaddr; /**< The IP address of this interface. */ 58 uip_ipaddr_t netmask; /**< The netmask of the interface. */ 59 59 uint8_t (* output)(void); 60 60 /**< A pointer to the function that … … 63 63 64 64 /** 65 * In tantiating macro for a uIP network interface.65 * Instantiating macro for a uIP network interface. 66 66 * 67 67 * Example: … … 80 80 #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \ 81 81 NULL, \ 82 { HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \83 { HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \82 { {ip1, ip2, ip3, ip4} }, \ 83 { {nm1, nm2, nm3, nm4} }, \ 84 84 outputfunc 85 85 -
uKadecot/trunk/uip/net/ipv4/uip-neighbor.c
r158 r262 83 83 /*---------------------------------------------------------------------------*/ 84 84 void 85 uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)85 uip_neighbor_add(uip_ipaddr_t *ipaddr, struct uip_neighbor_addr *addr) 86 86 { 87 87 int i, oldest; … … 100 100 break; 101 101 } 102 if(uip_ipaddr_cmp( entries[i].ipaddr,addr)) {102 if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) { 103 103 oldest = i; 104 104 break; … … 113 113 "oldest" variable). */ 114 114 entries[oldest].time = 0; 115 uip_ipaddr_copy( entries[oldest].ipaddr, ipaddr);115 uip_ipaddr_copy(&entries[oldest].ipaddr, ipaddr); 116 116 memcpy(&entries[oldest].addr, addr, sizeof(struct uip_neighbor_addr)); 117 117 } 118 118 /*---------------------------------------------------------------------------*/ 119 119 static struct neighbor_entry * 120 find_entry(uip_ipaddr_t ipaddr)120 find_entry(uip_ipaddr_t *ipaddr) 121 121 { 122 122 int i; 123 123 124 124 for(i = 0; i < ENTRIES; ++i) { 125 if(uip_ipaddr_cmp( entries[i].ipaddr, ipaddr)) {125 if(uip_ipaddr_cmp(&entries[i].ipaddr, ipaddr)) { 126 126 return &entries[i]; 127 127 } … … 131 131 /*---------------------------------------------------------------------------*/ 132 132 void 133 uip_neighbor_update(uip_ipaddr_t ipaddr)133 uip_neighbor_update(uip_ipaddr_t *ipaddr) 134 134 { 135 135 struct neighbor_entry *e; … … 142 142 /*---------------------------------------------------------------------------*/ 143 143 struct uip_neighbor_addr * 144 uip_neighbor_lookup(uip_ipaddr_t ipaddr)144 uip_neighbor_lookup(uip_ipaddr_t *ipaddr) 145 145 { 146 146 struct neighbor_entry *e; -
uKadecot/trunk/uip/net/ipv4/uip-neighbor.h
r158 r262 54 54 55 55 void uip_neighbor_init(void); 56 void uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr);57 void uip_neighbor_update(uip_ipaddr_t ipaddr);58 struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t ipaddr);56 void uip_neighbor_add(uip_ipaddr_t *ipaddr, struct uip_neighbor_addr *addr); 57 void uip_neighbor_update(uip_ipaddr_t *ipaddr); 58 struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t *ipaddr); 59 59 void uip_neighbor_periodic(void); 60 60 -
uKadecot/trunk/uip/net/ipv4/uip.c
r158 r262 99 99 #if UIP_FIXEDADDR > 0 100 100 const uip_ipaddr_t uip_hostaddr = 101 {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1), 102 HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)}; 101 { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 }; 103 102 const uip_ipaddr_t uip_draddr = 104 {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1), 105 HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)}; 103 { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 }; 106 104 const uip_ipaddr_t uip_netmask = 107 {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1), 108 HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)}; 105 { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 }; 109 106 #else 110 107 uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask; 111 108 #endif /* UIP_FIXEDADDR */ 112 109 113 static const uip_ipaddr_t all_ones_addr =110 const uip_ipaddr_t uip_broadcast_addr = 114 111 #if UIP_CONF_IPV6 115 {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff}; 112 { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 113 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; 116 114 #else /* UIP_CONF_IPV6 */ 117 { 0xffff,0xffff};115 { { 0xff, 0xff, 0xff, 0xff } }; 118 116 #endif /* UIP_CONF_IPV6 */ 119 static const uip_ipaddr_t all_zeroes_addr = 120 #if UIP_CONF_IPV6 121 {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}; 122 #else /* UIP_CONF_IPV6 */ 123 {0x0000,0x0000}; 124 #endif /* UIP_CONF_IPV6 */ 125 117 const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, /* rest is 0 */ } }; 126 118 127 119 #if UIP_FIXEDETHADDR 128 const struct uip_eth_addr uip_ ethaddr = {{UIP_ETHADDR0,120 const struct uip_eth_addr uip_lladdr = {{UIP_ETHADDR0, 129 121 UIP_ETHADDR1, 130 122 UIP_ETHADDR2, … … 133 125 UIP_ETHADDR5}}; 134 126 #else 135 struct uip_eth_addr uip_ ethaddr = {{0,0,0,0,0,0}};127 struct uip_eth_addr uip_lladdr = {{0,0,0,0,0,0}}; 136 128 #endif 137 129 … … 311 303 uip_chksum(uint16_t *data, uint16_t len) 312 304 { 313 return htons(chksum(0, (uint8_t *)data, len));305 return uip_htons(chksum(0, (uint8_t *)data, len)); 314 306 } 315 307 /*---------------------------------------------------------------------------*/ … … 322 314 sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN); 323 315 DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum); 324 return (sum == 0) ? 0xffff : htons(sum);316 return (sum == 0) ? 0xffff : uip_htons(sum); 325 317 } 326 318 #endif … … 343 335 sum = upper_layer_len + proto; 344 336 /* Sum IP source and destination addresses. */ 345 sum = chksum(sum, (uint8_t *)&BUF->srcipaddr [0], 2 * sizeof(uip_ipaddr_t));337 sum = chksum(sum, (uint8_t *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t)); 346 338 347 339 /* Sum TCP header and data. */ … … 349 341 upper_layer_len); 350 342 351 return (sum == 0) ? 0xffff : htons(sum);343 return (sum == 0) ? 0xffff : uip_htons(sum); 352 344 } 353 345 /*---------------------------------------------------------------------------*/ … … 375 367 #endif /* UIP_UDP_CHECKSUMS */ 376 368 #endif /* UIP_ARCH_CHKSUM */ 377 uint8_t378 uip_ismulticast(uip_ipaddr_t ipaddr)379 {380 #if UIP_CONF_IPV6381 return 0;382 #else383 static const uint16_t multicast_ipaddr[2] = { 0x00e0, 0x0000 };384 static const uint16_t multicast_mask[2] = { 0x00f0, 0x0000 };385 return uip_ipaddr_maskcmp(ipaddr, multicast_ipaddr, multicast_mask);386 #endif387 }388 369 /*---------------------------------------------------------------------------*/ 389 370 void … … 433 414 conn = &uip_conns[c]; 434 415 if(conn->tcpstateflags != UIP_CLOSED && 435 conn->lport == htons(lastport)) {416 conn->lport == uip_htons(lastport)) { 436 417 goto again; 437 418 } … … 472 453 conn->sa = 0; 473 454 conn->sv = 16; /* Initial value of the RTT variance. */ 474 conn->lport = htons(lastport);455 conn->lport = uip_htons(lastport); 475 456 conn->rport = rport; 476 457 uip_ipaddr_copy(&conn->ripaddr, ripaddr); … … 482 463 #if UIP_UDP 483 464 struct uip_udp_conn * 484 uip_udp_new( uip_ipaddr_t *ripaddr, uint16_t rport)465 uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport) 485 466 { 486 467 register struct uip_udp_conn *conn; … … 495 476 496 477 for(c = 0; c < UIP_UDP_CONNS; ++c) { 497 if(uip_udp_conns[c].lport == htons(lastport)) {478 if(uip_udp_conns[c].lport == uip_htons(lastport)) { 498 479 goto again; 499 480 } … … 513 494 } 514 495 515 conn->lport = HTONS(lastport);496 conn->lport = UIP_HTONS(lastport); 516 497 conn->rport = rport; 517 498 if(ripaddr == NULL) { 518 memset( conn->ripaddr, 0, sizeof(uip_ipaddr_t));499 memset(&conn->ripaddr, 0, sizeof(uip_ipaddr_t)); 519 500 } else { 520 501 uip_ipaddr_copy(&conn->ripaddr, ripaddr); … … 748 729 connection's timer and see if it has reached the RTO value 749 730 in which case we retransmit. */ 731 750 732 if(uip_outstanding(uip_connr)) { 751 733 if(uip_connr->timer-- == 0) { … … 901 883 #endif /* UIP_CONF_IPV6 */ 902 884 903 if(uip_ipaddr_cmp( uip_hostaddr,all_zeroes_addr)) {885 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) { 904 886 /* If we are configured to use ping IP address configuration and 905 887 hasn't been assigned an IP address yet, we accept all ICMP … … 921 903 DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum()); 922 904 if(BUF->proto == UIP_PROTO_UDP && 923 (uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr) || 924 uip_ismulticast(BUF->destipaddr)) 925 /*&& 926 uip_ipchksum() == 0xffff*/) { 905 (uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) || 906 (BUF->destipaddr.u8[0] & 224) == 224)) { /* XXX this is a 907 hack to be able 908 to receive UDP 909 multicast 910 packets. We check 911 for the bit 912 pattern of the 913 multicast 914 prefix. */ 927 915 goto udp_input; 928 916 } … … 931 919 /* Check if the packet is destined for our IP address. */ 932 920 #if !UIP_CONF_IPV6 933 if(!uip_ipaddr_cmp( BUF->destipaddr,uip_hostaddr)) {921 if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) { 934 922 UIP_STAT(++uip_stat.ip.drop); 935 923 goto drop; … … 941 929 address) as well. However, we will cheat here and accept all 942 930 multicast packets that are sent to the ff02::/16 addresses. */ 943 if(!uip_ipaddr_cmp( BUF->destipaddr,uip_hostaddr) &&944 BUF->destipaddr [0] !=HTONS(0xff02)) {931 if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) && 932 BUF->destipaddr.u16[0] != UIP_HTONS(0xff02)) { 945 933 UIP_STAT(++uip_stat.ip.drop); 946 934 goto drop; … … 1000 988 ourself. */ 1001 989 #if UIP_PINGADDRCONF 1002 if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) { 1003 uip_hostaddr[0] = BUF->destipaddr[0]; 1004 uip_hostaddr[1] = BUF->destipaddr[1]; 990 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) { 991 uip_hostaddr = BUF->destipaddr; 1005 992 } 1006 993 #endif /* UIP_PINGADDRCONF */ … … 1008 995 ICMPBUF->type = ICMP_ECHO_REPLY; 1009 996 1010 if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) {1011 ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;997 if(ICMPBUF->icmpchksum >= UIP_HTONS(0xffff - (ICMP_ECHO << 8))) { 998 ICMPBUF->icmpchksum += UIP_HTONS(ICMP_ECHO << 8) + 1; 1012 999 } else { 1013 ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);1000 ICMPBUF->icmpchksum += UIP_HTONS(ICMP_ECHO << 8); 1014 1001 } 1015 1002 1016 1003 /* Swap IP addresses. */ 1017 uip_ipaddr_copy( BUF->destipaddr,BUF->srcipaddr);1018 uip_ipaddr_copy( BUF->srcipaddr,uip_hostaddr);1004 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr); 1005 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr); 1019 1006 1020 1007 UIP_STAT(++uip_stat.icmp.sent); 1021 goto send; 1008 BUF->ttl = UIP_TTL; 1009 goto ip_send_nolen; 1022 1010 1023 1011 /* End of IPv4 input header processing code. */ … … 1040 1028 a neighbor advertisement message back. */ 1041 1029 if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) { 1042 if(uip_ipaddr_cmp( ICMPBUF->icmp6data,uip_hostaddr)) {1030 if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) { 1043 1031 1044 1032 if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) { 1045 1033 /* Save the sender's address in our neighbor list. */ 1046 uip_neighbor_add( ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));1034 uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2])); 1047 1035 } 1048 1036 … … 1054 1042 ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0; 1055 1043 1056 uip_ipaddr_copy( ICMPBUF->destipaddr,ICMPBUF->srcipaddr);1057 uip_ipaddr_copy( ICMPBUF->srcipaddr,uip_hostaddr);1044 uip_ipaddr_copy(&ICMPBUF->destipaddr, &ICMPBUF->srcipaddr); 1045 uip_ipaddr_copy(&ICMPBUF->srcipaddr, &uip_hostaddr); 1058 1046 ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS; 1059 1047 ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */ 1060 memcpy(&(ICMPBUF->options[2]), &uip_ ethaddr, sizeof(uip_ethaddr));1048 memcpy(&(ICMPBUF->options[2]), &uip_lladdr, sizeof(uip_lladdr)); 1061 1049 ICMPBUF->icmpchksum = 0; 1062 1050 ICMPBUF->icmpchksum = ~uip_icmp6chksum(); 1051 1063 1052 goto send; 1064 1053 … … 1072 1061 ICMPBUF->type = ICMP6_ECHO_REPLY; 1073 1062 1074 uip_ipaddr_copy( BUF->destipaddr,BUF->srcipaddr);1075 uip_ipaddr_copy( BUF->srcipaddr,uip_hostaddr);1063 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr); 1064 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr); 1076 1065 ICMPBUF->icmpchksum = 0; 1077 1066 ICMPBUF->icmpchksum = ~uip_icmp6chksum(); … … 1110 1099 uip_len = uip_len - UIP_IPUDPH_LEN; 1111 1100 #endif /* UIP_UDP_CHECKSUMS */ 1101 1102 /* Make sure that the UDP destination port number is not zero. */ 1103 if(UDPBUF->destport == 0) { 1104 UIP_LOG("udp: zero port."); 1105 goto drop; 1106 } 1112 1107 1113 1108 /* Demultiplex this UDP packet between the UDP "connections". */ … … 1126 1121 (uip_udp_conn->rport == 0 || 1127 1122 UDPBUF->srcport == uip_udp_conn->rport) && 1128 (uip_ipaddr_cmp( uip_udp_conn->ripaddr,all_zeroes_addr) ||1129 uip_ipaddr_cmp( uip_udp_conn->ripaddr, all_ones_addr) ||1130 uip_ipaddr_cmp( BUF->srcipaddr,uip_udp_conn->ripaddr))) {1123 (uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_all_zeroes_addr) || 1124 uip_ipaddr_cmp(&uip_udp_conn->ripaddr, &uip_broadcast_addr) || 1125 uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->ripaddr))) { 1131 1126 goto udp_found; 1132 1127 } … … 1141 1136 uip_slen = 0; 1142 1137 UIP_UDP_APPCALL(); 1138 1143 1139 udp_send: 1144 1140 if(uip_slen == 0) { … … 1160 1156 BUF->proto = UIP_PROTO_UDP; 1161 1157 1162 UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN);1158 UDPBUF->udplen = UIP_HTONS(uip_slen + UIP_UDPH_LEN); 1163 1159 UDPBUF->udpchksum = 0; 1164 1160 … … 1166 1162 BUF->destport = uip_udp_conn->rport; 1167 1163 1168 uip_ipaddr_copy( BUF->srcipaddr,uip_hostaddr);1169 uip_ipaddr_copy( BUF->destipaddr,uip_udp_conn->ripaddr);1164 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr); 1165 uip_ipaddr_copy(&BUF->destipaddr, &uip_udp_conn->ripaddr); 1170 1166 1171 1167 uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN]; … … 1196 1192 } 1197 1193 1194 /* Make sure that the TCP port number is not zero. */ 1195 if(BUF->destport == 0 || BUF->srcport == 0) { 1196 UIP_LOG("tcp: zero port."); 1197 goto drop; 1198 } 1198 1199 1199 1200 /* Demultiplex this segment. */ … … 1204 1205 BUF->destport == uip_connr->lport && 1205 1206 BUF->srcport == uip_connr->rport && 1206 uip_ipaddr_cmp( BUF->srcipaddr,uip_connr->ripaddr)) {1207 uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->ripaddr)) { 1207 1208 goto found; 1208 1209 } … … 1220 1221 /* Next, check listening connections. */ 1221 1222 for(c = 0; c < UIP_LISTENPORTS; ++c) { 1222 if(tmp16 == uip_listenports[c]) 1223 if(tmp16 == uip_listenports[c]) { 1223 1224 goto found_listen; 1225 } 1224 1226 } 1225 1227 1226 1228 /* No matching connection found, so we send a RST packet. */ 1227 1229 UIP_STAT(++uip_stat.tcp.synrst); 1230 1228 1231 reset: 1229 1230 1232 /* We do not send resets in response to resets. */ 1231 1233 if(BUF->flags & TCP_RST) { … … 1273 1275 1274 1276 /* Swap IP addresses. */ 1275 uip_ipaddr_copy( BUF->destipaddr,BUF->srcipaddr);1276 uip_ipaddr_copy( BUF->srcipaddr,uip_hostaddr);1277 uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr); 1278 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr); 1277 1279 1278 1280 /* And send out the RST packet! */ … … 1283 1285 connection and send a SYNACK in return. */ 1284 1286 found_listen: 1285 /* First we check if there are any connections ava liable. Unused1287 /* First we check if there are any connections available. Unused 1286 1288 connections are kept in the same table as used connections, but 1287 1289 unused ones have the tcpstate set to CLOSED. Also, connections in … … 1320 1322 uip_connr->lport = BUF->destport; 1321 1323 uip_connr->rport = BUF->srcport; 1322 uip_ipaddr_copy( uip_connr->ripaddr,BUF->srcipaddr);1324 uip_ipaddr_copy(&uip_connr->ripaddr, &BUF->srcipaddr); 1323 1325 uip_connr->tcpstateflags = UIP_SYN_RCVD; 1324 1326 … … 1406 1408 goto drop; 1407 1409 } 1408 /* Calculate dthe length of the data, if the application has sent1410 /* Calculate the length of the data, if the application has sent 1409 1411 any data to us. */ 1410 1412 c = (BUF->tcpoffset >> 4) << 2; … … 1416 1418 /* First, check if the sequence number of the incoming packet is 1417 1419 what we're expecting next. If not, we send out an ACK with the 1418 correct numbers in. */ 1419 if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && 1420 ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) { 1420 correct numbers in, unless we are in the SYN_RCVD state and 1421 receive a SYN, in which case we should retransmit our SYNACK 1422 (which is done futher down). */ 1423 if(!((((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && 1424 ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) || 1425 (((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) && 1426 ((BUF->flags & TCP_CTL) == TCP_SYN)))) { 1421 1427 if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) && 1422 1428 (BUF->seqno[0] != uip_connr->rcv_nxt[0] || … … 1444 1450 uip_connr->snd_nxt[2] = uip_acc32[2]; 1445 1451 uip_connr->snd_nxt[3] = uip_acc32[3]; 1446 1447 1452 1448 1453 /* Do RTT estimation, unless we have done retransmissions. */ … … 1495 1500 goto appsend; 1496 1501 } 1502 /* We need to retransmit the SYNACK */ 1503 if((BUF->flags & TCP_CTL) == TCP_SYN) { 1504 goto tcp_send_synack; 1505 } 1497 1506 goto drop; 1498 1507 #if UIP_ACTIVE_OPEN … … 1798 1807 goto drop; 1799 1808 1800 1801 1809 /* We jump here when we are ready to send the packet, and just want 1802 1810 to set the appropriate TCP sequence numbers in the TCP header. */ 1803 1811 tcp_send_ack: 1804 1812 BUF->flags = TCP_ACK; 1813 1805 1814 tcp_send_nodata: 1806 1815 uip_len = UIP_IPTCPH_LEN; 1816 1807 1817 tcp_send_noopts: 1808 1818 BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4; 1809 tcp_send: 1819 1810 1820 /* We're done with the input processing. We are now ready to send a 1811 1821 reply. Our job is to fill in all the fields of the TCP and IP 1812 1822 headers before calculating the checksum and finally send the 1813 1823 packet. */ 1824 tcp_send: 1814 1825 BUF->ackno[0] = uip_connr->rcv_nxt[0]; 1815 1826 BUF->ackno[1] = uip_connr->rcv_nxt[1]; … … 1827 1838 BUF->destport = uip_connr->rport; 1828 1839 1829 uip_ipaddr_copy( BUF->srcipaddr,uip_hostaddr);1830 uip_ipaddr_copy( BUF->destipaddr,uip_connr->ripaddr);1840 uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr); 1841 uip_ipaddr_copy(&BUF->destipaddr, &uip_connr->ripaddr); 1831 1842 1832 1843 if(uip_connr->tcpstateflags & UIP_STOPPED) { … … 1858 1869 1859 1870 ip_send_nolen: 1860 1861 1871 #if UIP_CONF_IPV6 1862 1872 BUF->vtc = 0x60; … … 1875 1885 DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum()); 1876 1886 #endif /* UIP_CONF_IPV6 */ 1877 1878 1887 UIP_STAT(++uip_stat.tcp.sent); 1888 #if UIP_CONF_IPV6 1879 1889 send: 1890 #endif /* UIP_CONF_IPV6 */ 1880 1891 DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len, 1881 1892 (BUF->len[0] << 8) | BUF->len[1]); … … 1885 1896 uip_flags = 0; 1886 1897 return; 1898 1887 1899 drop: 1888 1900 uip_len = 0; … … 1892 1904 /*---------------------------------------------------------------------------*/ 1893 1905 uint16_t 1894 htons(uint16_t val)1906 uip_htons(uint16_t val) 1895 1907 { 1896 return HTONS(val);1908 return UIP_HTONS(val); 1897 1909 } 1898 1910 /*---------------------------------------------------------------------------*/ -
uKadecot/trunk/uip/net/ipv4/uip_arp.c
r158 r262 78 78 uint16_t opcode; 79 79 struct uip_eth_addr shwaddr; 80 ui nt16_t sipaddr[2];80 uip_ipaddr_t sipaddr; 81 81 struct uip_eth_addr dhwaddr; 82 ui nt16_t dipaddr[2];82 uip_ipaddr_t dipaddr; 83 83 }; 84 84 … … 94 94 proto; 95 95 uint16_t ipchksum; 96 uint16_t srcipaddr[2], 97 destipaddr[2]; 96 uip_ipaddr_t srcipaddr, destipaddr; 98 97 }; 99 98 … … 110 109 111 110 struct arp_entry { 112 ui nt16_t ipaddr[2];111 uip_ipaddr_t ipaddr; 113 112 struct uip_eth_addr ethaddr; 114 113 uint8_t time; … … 118 117 {{0xff,0xff,0xff,0xff,0xff,0xff}}; 119 118 static const uint16_t broadcast_ipaddr[2] = {0xffff,0xffff}; 120 static const uint16_t multicast_ipaddr[2] = { 0x00e0, 0x0000 };121 static const uint16_t multicast_mask[2] = { 0x00f0, 0x0000 };122 119 123 120 static struct arp_entry arp_table[UIP_ARPTAB_SIZE]; 124 static ui nt16_t ipaddr[2];121 static uip_ipaddr_t ipaddr; 125 122 static uint8_t i, c; 126 123 … … 140 137 { 141 138 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 142 memset( arp_table[i].ipaddr, 0, 4);139 memset(&arp_table[i].ipaddr, 0, 4); 143 140 } 144 141 } … … 161 158 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 162 159 tabptr = &arp_table[i]; 163 if( (tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0&&160 if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr) && 164 161 arptime - tabptr->time >= UIP_ARP_MAXAGE) { 165 memset(tabptr->ipaddr, 0, 4); 166 } 167 } 168 169 } 162 memset(&tabptr->ipaddr, 0, 4); 163 } 164 } 165 166 } 167 170 168 /*-----------------------------------------------------------------------------------*/ 171 169 static void 172 uip_arp_update(uint16_t *ipaddr, struct uip_eth_addr *ethaddr) 173 { 174 register struct arp_entry *tabptr = NULL; 170 uip_arp_update(uip_ipaddr_t *ipaddr, struct uip_eth_addr *ethaddr) 171 { 172 register struct arp_entry *tabptr = arp_table; 173 175 174 /* Walk through the ARP mapping table and try to find an entry to 176 175 update. If none is found, the IP -> MAC address mapping is 177 176 inserted in the ARP table. */ 178 177 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 179 180 178 tabptr = &arp_table[i]; 179 181 180 /* Only check those entries that are actually in use. */ 182 if(tabptr->ipaddr[0] != 0 && 183 tabptr->ipaddr[1] != 0) { 181 if(!uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) { 184 182 185 183 /* Check if the source IP address of the incoming packet matches 186 184 the IP address in this ARP table entry. */ 187 if(ipaddr[0] == tabptr->ipaddr[0] && 188 ipaddr[1] == tabptr->ipaddr[1]) { 185 if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) { 189 186 190 187 /* An old entry found, update this and return. */ … … 203 200 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 204 201 tabptr = &arp_table[i]; 205 if(tabptr->ipaddr[0] == 0 && 206 tabptr->ipaddr[1] == 0) { 202 if(uip_ipaddr_cmp(&tabptr->ipaddr, &uip_all_zeroes_addr)) { 207 203 break; 208 204 } … … 227 223 /* Now, i is the ARP table entry which we will fill with the new 228 224 information. */ 229 memcpy(tabptr->ipaddr, ipaddr, 4);225 uip_ipaddr_copy(&tabptr->ipaddr, ipaddr); 230 226 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6); 231 227 tabptr->time = arptime; … … 300 296 301 297 switch(BUF->opcode) { 302 case HTONS(ARP_REQUEST):298 case UIP_HTONS(ARP_REQUEST): 303 299 /* ARP request. If it asked for our address, we send out a 304 300 reply. */ 305 if(uip_ipaddr_cmp( BUF->dipaddr,uip_hostaddr)) {301 if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) { 306 302 /* First, we register the one who made the request in our ARP 307 303 table, since it is likely that we will do more communication 308 304 with this host in the future. */ 309 uip_arp_update( BUF->sipaddr, &BUF->shwaddr);305 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr); 310 306 311 307 /* The reply opcode is 2. */ 312 BUF->opcode = HTONS(2);308 BUF->opcode = UIP_HTONS(2); 313 309 314 310 memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); 315 memcpy(BUF->shwaddr.addr, uip_ ethaddr.addr, 6);316 memcpy(BUF->ethhdr.src.addr, uip_ ethaddr.addr, 6);311 memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6); 312 memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6); 317 313 memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); 318 314 319 BUF->dipaddr[0] = BUF->sipaddr[0]; 320 BUF->dipaddr[1] = BUF->sipaddr[1]; 321 BUF->sipaddr[0] = uip_hostaddr[0]; 322 BUF->sipaddr[1] = uip_hostaddr[1]; 323 324 BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); 315 uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr); 316 uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr); 317 318 BUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP); 325 319 uip_len = sizeof(struct arp_hdr); 326 320 } 327 321 break; 328 case HTONS(ARP_REPLY):322 case UIP_HTONS(ARP_REPLY): 329 323 /* ARP reply. We insert or update the ARP table if it was meant 330 324 for us. */ 331 if(uip_ipaddr_cmp( BUF->dipaddr,uip_hostaddr)) {332 uip_arp_update( BUF->sipaddr, &BUF->shwaddr);325 if(uip_ipaddr_cmp(&BUF->dipaddr, &uip_hostaddr)) { 326 uip_arp_update(&BUF->sipaddr, &BUF->shwaddr); 333 327 } 334 328 break; … … 378 372 379 373 /* First check if destination is a local broadcast. */ 380 if(uip_ipaddr_cmp( IPBUF->destipaddr, broadcast_ipaddr)) {374 if(uip_ipaddr_cmp(&IPBUF->destipaddr, &uip_broadcast_addr)) { 381 375 memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6); 382 } 383 else if(uip_ipaddr_maskcmp(IPBUF->destipaddr, multicast_ipaddr, multicast_mask)) {376 } else if(IPBUF->destipaddr.u8[0] == 224) { 377 /* Multicast. */ 384 378 IPBUF->ethhdr.dest.addr[0] = 0x01; 385 379 IPBUF->ethhdr.dest.addr[1] = 0x00; 386 IPBUF->ethhdr.dest.addr[2] = 0x5 E;387 IPBUF->ethhdr.dest.addr[3] = uip_ipaddr2(IPBUF->destipaddr) & 0x7F;388 IPBUF->ethhdr.dest.addr[4] = uip_ipaddr3(IPBUF->destipaddr);389 IPBUF->ethhdr.dest.addr[5] = uip_ipaddr4(IPBUF->destipaddr);380 IPBUF->ethhdr.dest.addr[2] = 0x5e; 381 IPBUF->ethhdr.dest.addr[3] = IPBUF->destipaddr.u8[1]; 382 IPBUF->ethhdr.dest.addr[4] = IPBUF->destipaddr.u8[2]; 383 IPBUF->ethhdr.dest.addr[5] = IPBUF->destipaddr.u8[3]; 390 384 } else { 391 385 /* Check if the destination address is on the local network. */ 392 if(!uip_ipaddr_maskcmp( IPBUF->destipaddr, uip_hostaddr,uip_netmask)) {386 if(!uip_ipaddr_maskcmp(&IPBUF->destipaddr, &uip_hostaddr, &uip_netmask)) { 393 387 /* Destination address was not on the local network, so we need to 394 388 use the default router's IP address instead of the destination 395 389 address when determining the MAC address. */ 396 uip_ipaddr_copy( ipaddr,uip_draddr);390 uip_ipaddr_copy(&ipaddr, &uip_draddr); 397 391 } else { 398 392 /* Else, we use the destination IP address. */ 399 uip_ipaddr_copy(ipaddr, IPBUF->destipaddr); 400 } 401 393 uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr); 394 } 402 395 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { 403 396 tabptr = &arp_table[i]; 404 if(uip_ipaddr_cmp( ipaddr,tabptr->ipaddr)) {397 if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) { 405 398 break; 406 399 } … … 413 406 memset(BUF->ethhdr.dest.addr, 0xff, 6); 414 407 memset(BUF->dhwaddr.addr, 0x00, 6); 415 memcpy(BUF->ethhdr.src.addr, uip_ ethaddr.addr, 6);416 memcpy(BUF->shwaddr.addr, uip_ ethaddr.addr, 6);417 418 uip_ipaddr_copy( BUF->dipaddr,ipaddr);419 uip_ipaddr_copy( BUF->sipaddr,uip_hostaddr);420 BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */421 BUF->hwtype = HTONS(ARP_HWTYPE_ETH);422 BUF->protocol = HTONS(UIP_ETHTYPE_IP);408 memcpy(BUF->ethhdr.src.addr, uip_lladdr.addr, 6); 409 memcpy(BUF->shwaddr.addr, uip_lladdr.addr, 6); 410 411 uip_ipaddr_copy(&BUF->dipaddr, &ipaddr); 412 uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr); 413 BUF->opcode = UIP_HTONS(ARP_REQUEST); /* ARP request. */ 414 BUF->hwtype = UIP_HTONS(ARP_HWTYPE_ETH); 415 BUF->protocol = UIP_HTONS(UIP_ETHTYPE_IP); 423 416 BUF->hwlen = 6; 424 417 BUF->protolen = 4; 425 BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);418 BUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP); 426 419 427 420 uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN]; … … 434 427 memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6); 435 428 } 436 memcpy(IPBUF->ethhdr.src.addr, uip_ ethaddr.addr, 6);437 438 IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);429 memcpy(IPBUF->ethhdr.src.addr, uip_lladdr.addr, 6); 430 431 IPBUF->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP); 439 432 440 433 uip_len += sizeof(struct uip_eth_hdr); … … 444 437 /** @} */ 445 438 /** @} */ 439 -
uKadecot/trunk/uip/net/ipv4/uip_arp.h
r158 r262 61 61 #endif 62 62 63 extern struct uip_eth_addr uip_ ethaddr;63 extern struct uip_eth_addr uip_lladdr; 64 64 65 65 /** … … 143 143 * \hideinitializer 144 144 */ 145 #define uip_setethaddr(eaddr) do {uip_ ethaddr.addr[0] = eaddr.addr[0]; \146 uip_ ethaddr.addr[1] = eaddr.addr[1];\147 uip_ ethaddr.addr[2] = eaddr.addr[2];\148 uip_ ethaddr.addr[3] = eaddr.addr[3];\149 uip_ ethaddr.addr[4] = eaddr.addr[4];\150 uip_ ethaddr.addr[5] = eaddr.addr[5];} while(0)145 #define uip_setethaddr(eaddr) do {uip_lladdr.addr[0] = eaddr.addr[0]; \ 146 uip_lladdr.addr[1] = eaddr.addr[1];\ 147 uip_lladdr.addr[2] = eaddr.addr[2];\ 148 uip_lladdr.addr[3] = eaddr.addr[3];\ 149 uip_lladdr.addr[4] = eaddr.addr[4];\ 150 uip_lladdr.addr[5] = eaddr.addr[5];} while(0) 151 151 152 152 /** @} */ 153 /** @} */ 153 154 154 155 155 #endif /* __UIP_ARP_H__ */ 156 /** @} */
Note:
See TracChangeset
for help on using the changeset viewer.