Changeset 11012 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jul 30, 2008 7:24:57 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33891
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/checksum/ipv4.cpp
r10998 r11012 85 85 86 86 87 88 87 /** 89 88 * Verifies the header version, header size, packet size, and header checksum … … 97 96 * to be mapped following pIpHdr. 98 97 */ 99 RTDECL(bool) RTNetIPv4IsHdrsValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax) 100 { 98 RTDECL(bool) RTNetIPv4IsHdrValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax) 99 { 100 /* 101 * The header fields. 102 */ 101 103 Assert(cbPktMax >= cbHdrMax); 102 104 if (RT_UNLIKELY(cbHdrMax < RTNETIPV4_MIN_LEN)) … … 113 115 if (RT_UNLIKELY(RT_BE2H_U16(pIpHdr->ip_len) > cbPktMax)) 114 116 return false; 117 118 /* 119 * The header checksum. 120 */ 115 121 uint16_t u16Sum = RTNetIPv4HdrChecksum(pIpHdr); 116 122 if (RT_UNLIKELY(RT_BE2H_U16(pIpHdr->ip_sum) != u16Sum)) … … 380 386 RTDECL(uint16_t) RTNetIPv4UDPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData) 381 387 { 382 uint32_t iSum = RTNetIPv4PseudoChecksum(pIpHdr);383 iSum = RTNetIPv4AddUDPChecksum(pUdpHdr, iSum);388 uint32_t iSum = rtNetIPv4PseudoChecksum(pIpHdr); 389 iSum = rtNetIPv4AddUDPChecksum(pUdpHdr, iSum); 384 390 bool fOdd = false; 385 iSum = RTNetIPv4AddDataChecksum(pvData, RT_BE2H_U16(pUdpHdr->uh_ulen) - sizeof(*pUdpHdr), iSum, &fOdd); 386 iSum = RTNetIPv4FinalizeChecksum(iSum); 387 return iSum; 388 } 389 390 391 iSum = rtNetIPv4AddDataChecksum(pvData, RT_BE2H_U16(pUdpHdr->uh_ulen) - sizeof(*pUdpHdr), iSum, &fOdd); 392 iSum = rtNetIPv4FinalizeChecksum(iSum); 393 return iSum; 394 } 395 396 397 /** 398 * Simple verficiation of an UDP packet size. 399 * 400 * @returns true if valid, false if invalid. 401 * @param pIpHdr Pointer to the IPv4 header, in network endian (big). 402 * This is assumed to be valid and the minimum size being mapped. 403 * @param pUdpHdr Pointer to the UDP header, in network endian (big). 404 * @param cbPktMax The max UDP packet size, UDP header and payload (data). 405 */ 406 DECLINLINE(bool) rtNetIPv4IsUDPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, size_t cbPktMax) 407 { 408 /* 409 * Size validation. 410 */ 411 if (RT_UNLIKELY(cbPktMax < RTNETUDP_MIN_LEN)) 412 return false; 413 size_t cb = RT_BE2H_U16(pUdpHdr->uh_ulen); 414 if (RT_UNLIKELY(cb > cbPktMax)) 415 return false; 416 if (RT_UNLIKELY(cb > RT_BE2H_U16(pIpHdr->ip_len) - pIpHdr->ip_hl * 4)) 417 return false; 418 return true; 419 } 420 421 422 /** 423 * Simple verficiation of an UDP packet size. 424 * 425 * @returns true if valid, false if invalid. 426 * @param pIpHdr Pointer to the IPv4 header, in network endian (big). 427 * This is assumed to be valid and the minimum size being mapped. 428 * @param pUdpHdr Pointer to the UDP header, in network endian (big). 429 * @param cbPktMax The max UDP packet size, UDP header and payload (data). 430 */ 431 RTDECL(bool) RTNetIPv4IsUDPSizeValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, size_t cbPktMax) 432 { 433 return rtNetIPv4IsUDPSizeValid(pIpHdr, pUdpHdr, cbPktMax); 434 } 435 436 437 /** 438 * Simple verficiation of an UDP packet (size + checksum). 439 * 440 * @returns true if valid, false if invalid. 441 * @param pIpHdr Pointer to the IPv4 header, in network endian (big). 442 * This is assumed to be valid and the minimum size being mapped. 443 * @param pUdpHdr Pointer to the UDP header, in network endian (big). 444 * @param pvData Pointer to the data, assuming it's one single segment 445 * and that cbPktMax - sizeof(RTNETUDP) is mapped here. 446 * @param cbPktMax The max UDP packet size, UDP header and payload (data). 447 */ 448 RTDECL(bool) RTNetIPv4IsUDPValid(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData, size_t cbPktMax) 449 { 450 if (RT_UNLIKELY(!rtNetIPv4IsUDPSizeValid(pIpHdr, pUdpHdr, cbPktMax))) 451 return false; 452 uint16_t u16Sum = RTNetIPv4UDPChecksum(pIpHdr, pUdpHdr, pvData); 453 if (RT_UNLIKELY(RT_BE2H_U16(pUdpHdr->uh_sum) != u16Sum)) 454 return false; 455 return true; 456 }
Note:
See TracChangeset
for help on using the changeset viewer.