yeyushengfan
yeyushengfan

Reputation: 13

CHECKSUM_NONE and TCP checksum calculation

I modified a packet in tc-ingress ebpf program and then the packet is routed to leave the host machine. More specifically, I add a customized TCP option using bpf_skb_adjust_room/ctx_adjust_hroom to expand the packet.

static inline void __skb_reset_checksum_unnecessary(struct sk_buff *skb)
{
    if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
        skb->ip_summed = CHECKSUM_NONE;
        skb->csum_level = 0;
    }
}

This function above is called inside bpf_skb_adjust_room/ctx_adjust_hroom.

I noticed that even if I set TCP checksum field to 0 (random value), the Linux kernel would update the checksum to a correct value in a later stage.

To provide some more detail: I am using bpf_lxc in Cilium K8S CNI.

Therefore, my questions are:

What's relationship between skb->csum and checksum field of TCP header? Where would Linux kernel modify tcp checksum field? Does ip_summed = CHECKSUM_NONE involved in this process?

Thanks in advance!

Upvotes: 1

Views: 262

Answers (0)

Related Questions