net: checksum: Introduce fine control over checksum type

At present net_checksum_calculate() blindly calculates all types of
checksums (IP, TCP, UDP). Some NICs may have a per type setting in
their BDs to control what checksum should be offloaded. To support
such hardware behavior, introduce a 'csum_flag' parameter to the
net_checksum_calculate() API to allow fine control over what type
checksum is calculated.

Existing users of this API are updated accordingly.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
Bin Meng 2020-12-11 17:35:12 +08:00 committed by Jason Wang
parent d97f11590a
commit f574633529
10 changed files with 55 additions and 33 deletions

View file

@ -57,7 +57,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
return net_checksum_finish(sum);
}
void net_checksum_calculate(uint8_t *data, int length)
void net_checksum_calculate(uint8_t *data, int length, int csum_flag)
{
int mac_hdr_len, ip_len;
struct ip_header *ip;
@ -108,9 +108,11 @@ void net_checksum_calculate(uint8_t *data, int length)
}
/* Calculate IP checksum */
stw_he_p(&ip->ip_sum, 0);
csum = net_raw_checksum((uint8_t *)ip, IP_HDR_GET_LEN(ip));
stw_be_p(&ip->ip_sum, csum);
if (csum_flag & CSUM_IP) {
stw_he_p(&ip->ip_sum, 0);
csum = net_raw_checksum((uint8_t *)ip, IP_HDR_GET_LEN(ip));
stw_be_p(&ip->ip_sum, csum);
}
if (IP4_IS_FRAGMENT(ip)) {
return; /* a fragmented IP packet */
@ -128,6 +130,10 @@ void net_checksum_calculate(uint8_t *data, int length)
switch (ip->ip_p) {
case IP_PROTO_TCP:
{
if (!(csum_flag & CSUM_TCP)) {
return;
}
tcp_header *tcp = (tcp_header *)(ip + 1);
if (ip_len < sizeof(tcp_header)) {
@ -148,6 +154,10 @@ void net_checksum_calculate(uint8_t *data, int length)
}
case IP_PROTO_UDP:
{
if (!(csum_flag & CSUM_UDP)) {
return;
}
udp_header *udp = (udp_header *)(ip + 1);
if (ip_len < sizeof(udp_header)) {