mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 13:47:56 +00:00
internet checksum: no default arg value
Prevent public reflection of the only internally used 'init_sum' argument in 'uint16_t internet_checksum(...)' that, in addition, added a default value to the function interface. Ref #4555
This commit is contained in:
parent
07d4a7c11f
commit
6b3ed6c75b
@ -42,16 +42,16 @@ namespace Net {
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
Genode::uint16_t internet_checksum(Packed_uint16 const *addr,
|
||||
Genode::size_t size,
|
||||
Genode::addr_t init_sum = 0);
|
||||
Genode::uint16_t internet_checksum(Packed_uint16 const *data_ptr,
|
||||
Genode::size_t data_sz);
|
||||
|
||||
Genode::uint16_t internet_checksum_pseudo_ip(Packed_uint16 const *addr,
|
||||
Genode::size_t size,
|
||||
Genode::uint16_t size_be,
|
||||
Ipv4_packet::Protocol ip_prot,
|
||||
Ipv4_address &ip_src,
|
||||
Ipv4_address &ip_dst);
|
||||
Genode::uint16_t
|
||||
internet_checksum_pseudo_ip(Packed_uint16 const *data_ptr,
|
||||
Genode::size_t data_sz,
|
||||
Genode::uint16_t ip_data_sz_be,
|
||||
Ipv4_packet::Protocol ip_prot,
|
||||
Ipv4_address &ip_src,
|
||||
Ipv4_address &ip_dst);
|
||||
}
|
||||
|
||||
#endif /* _NET__INTERNET_CHECKSUM_H_ */
|
||||
|
@ -17,6 +17,11 @@
|
||||
using namespace Net;
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
/**************************
|
||||
** Unit-local utilities **
|
||||
**************************/
|
||||
|
||||
struct Packed_uint8
|
||||
{
|
||||
Genode::uint8_t value;
|
||||
@ -24,21 +29,19 @@ struct Packed_uint8
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
uint16_t Net::internet_checksum(Packed_uint16 const *addr,
|
||||
size_t size,
|
||||
addr_t init_sum)
|
||||
static uint16_t checksum_of_raw_data(Packed_uint16 const *data_ptr,
|
||||
size_t data_sz,
|
||||
addr_t sum)
|
||||
{
|
||||
/* add up bytes in pairs */
|
||||
addr_t sum = init_sum;
|
||||
for (; size > 1; size -= sizeof(Packed_uint16)) {
|
||||
sum += addr->value;
|
||||
addr++;
|
||||
for (; data_sz > 1; data_sz -= sizeof(Packed_uint16)) {
|
||||
sum += data_ptr->value;
|
||||
data_ptr++;
|
||||
}
|
||||
|
||||
/* add left-over byte, if any */
|
||||
if (size > 0)
|
||||
sum += ((Packed_uint8 const *)addr)->value;
|
||||
|
||||
if (data_sz > 0) {
|
||||
sum += ((Packed_uint8 const *)data_ptr)->value;
|
||||
}
|
||||
/* fold sum to 16-bit value */
|
||||
while (addr_t const sum_rsh = sum >> 16)
|
||||
sum = (sum & 0xffff) + sum_rsh;
|
||||
@ -48,8 +51,19 @@ uint16_t Net::internet_checksum(Packed_uint16 const *addr,
|
||||
}
|
||||
|
||||
|
||||
uint16_t Net::internet_checksum_pseudo_ip(Packed_uint16 const *ip_data,
|
||||
size_t ip_data_sz,
|
||||
/***********************
|
||||
** Internet_checksum **
|
||||
***********************/
|
||||
|
||||
uint16_t Net::internet_checksum(Packed_uint16 const *data_ptr,
|
||||
size_t data_sz)
|
||||
{
|
||||
return checksum_of_raw_data(data_ptr, data_sz, 0);
|
||||
}
|
||||
|
||||
|
||||
uint16_t Net::internet_checksum_pseudo_ip(Packed_uint16 const *data_ptr,
|
||||
size_t data_sz,
|
||||
uint16_t ip_data_sz_be,
|
||||
Ipv4_packet::Protocol ip_prot,
|
||||
Ipv4_address &ip_src,
|
||||
@ -67,6 +81,6 @@ uint16_t Net::internet_checksum_pseudo_ip(Packed_uint16 const *ip_data,
|
||||
for (size_t i = 0; i < Ipv4_packet::ADDR_LEN; i += 2)
|
||||
sum += *(uint16_t*)&ip_src.addr[i] + *(uint16_t*)&ip_dst.addr[i];
|
||||
|
||||
/* add up IP data bytes */
|
||||
return internet_checksum(ip_data, ip_data_sz, sum);
|
||||
/* add up data bytes */
|
||||
return checksum_of_raw_data(data_ptr, data_sz, sum);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user