Re: Why verify checksum when CHECKSUM_HW is set in receiving path?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 26, 2003 at 08:53:45AM -0700, Bluesea Yreen wrote:
>
> I think your explanation make sense. I am not sure
> whether the checksum is verified if "skb->ip_summed ==
> CHECKSUM_HW".

It *is* verified by the kernel (verified, *not*
recalculated). Actually what the kernel does is to calculate the
*pseudo-header checksum* on-top of the contents of "skb->csum" (this
is a very cheap operation). If the result is zero ("checksum matches")
then it sets "skb->ip_summed" to CHECKSUM_UNNECESSARY, thus declaring
the packet as valid.

The relevant code in 2.4.20 is:

"net/ipv4/tcp_ipv4.c", function "tcp_v4_rcv()":

    if ((skb->ip_summed != CHECKSUM_UNNECESSARY &&
         tcp_v4_checksum_init(skb) < 0))
            goto bad_packet;

and (same file):

    static int tcp_v4_checksum_init(struct sk_buff *skb)
    {
        if (skb->ip_summed == CHECKSUM_HW) {
            skb->ip_summed = CHECKSUM_UNNECESSARY;
            if (!tcp_v4_check(skb->h.th,skb->len,skb->nh.iph->saddr,
                              skb->nh.iph->daddr,skb->csum))
                    return 0;

            NETDEBUG(if (net_ratelimit())
                printk(KERN_DEBUG "hw tcp v4 csum failed\n"));
            skb->ip_summed = CHECKSUM_NONE;
       	}
     
You may observe also that *if* the verification fails, then
"ip_summed" is set to CHECKSUM_NONE, instead of the packet being
rejected right-there. This will result in re-calculating the checksum
before finally rejecting the packet. Why this happens I don't know!
But for correct packets the transport layer checksum is *not*
recalculated.

> If the cheksum is verified, then I don't
> think it's necessary for the software to calculate the
> checksum again.

As I said above, if the checksum is verified, the software does *not*
recalculate it.

> It seems that setting "skb->ip_summed"
> to "CHECKSUM_UNNECESSARY" is better in this case, even
> the driver could provide IP payload checksumm, right?

I assume that by "IP payload checksum", you mean "IP header
checksum". I believe that the kernel will calculate the IP header
checksum no matter what (*even* if CHECKSUM_UNNECESSARY is set). All
these offloading features apply only to transport-layer (TCP/UDP)
checksums. This is reasonable since calculating the IP header checksum
is very cheap. Therefore by setting CHECKSUM_UNNECESSARY will earn you
nothing (compared to CHECKSUM_HW), except maybe the negligible gain of
not calculating the pseudo-header checksum.

Again, look at the "netdev features" posting for more on this.

/npat

-- 
Mathematics belongs to God.
  -- Donald E. Knuth
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux