Page MenuHomeFreeBSD

ure: improve receive checksum offloading
AcceptedPublic

Authored by tuexen on Sun, Feb 8, 9:22 PM.

Details

Summary

Let the receive checksum offload for TCP/IPv6 and UDP/IPv6 be controlled by ifconfig rxcsum6 and not by ifconfig rxcsum.
While there, make the code more compact and improve stlye.9 conformity.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

tuexen requested review of this revision.Sun, Feb 8, 9:22 PM
tuexen edited the summary of this revision. (Show Details)
sys/dev/usb/net/if_ure.c
2142

This condition:

(csum & URE_RXPKT_IPV4_CS) != 0

is checked in line 2148 again. Seems better to check this only once.

2148โ€“2151

For a consistent style:

if ((csum & URE_RXPKT_IPV4_CS) != 0) {
2150

Should a __predict_true be used for this condition?

Address two comments provided by Timo.

tuexen added inline comments.
sys/dev/usb/net/if_ure.c
2142

This condition:

(csum & URE_RXPKT_IPV4_CS) != 0

is checked in line 2148 again. Seems better to check this only once.

That is true. But I am checking the same condition in two different contexts:

  1. The first is checking whether the corresponding receive checksum offload is enabled for IPv4 and IPv6.
  1. The second is checking if the IPv4 check was made and set the flags for the IPv4 header checksum offloading.

I would prefer to not mix these two things.

2148โ€“2151

Makes sense, done.

2150

Make sense. Done.

timo.voelker_fh-muenster.de added inline comments.
sys/dev/usb/net/if_ure.c
2142

I would have done it like this:

if ((csum & URE_RXPKT_IPV6_CS) != 0 &&
    (capenb & IFCAP_RXCSUM_IPV6) == 0)
	return;

if ((csum & URE_RXPKT_IPV4_CS) != 0) {
	if ((capenb & IFCAP_RXCSUM) == 0)
		return;
	m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
	if (__predict_true((misc & URE_RXPKT_IP_F) == 0))
		m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
}

If it looks too much mixed up to you, leave it as it is.

This revision is now accepted and ready to land.Tue, Feb 10, 7:53 AM
tuexen added inline comments.
sys/dev/usb/net/if_ure.c
2142

I see. My mental model of the code is:

  1. Ensure receive checksum offload is enabled.
  2. Perform offload for IPv4 header checksum, if applicable.
  3. Perform offload for TCP und UDP checksum, if applicable.

Your proposal mixes 1. and 2.