xdp-project / xdp-tutorial

XDP tutorial
2.33k stars 562 forks source link

complete udp checksum in xdp_patch_ports_func #394

Closed bigclouds closed 4 months ago

bigclouds commented 4 months ago

complete udp checksum so as for udp server to receive packets.

bigclouds commented 4 months ago

@tohojo Hi, length parameter of bpf_csum_diff must be a multiple of 4. this patch is a hint to tell all things people have to do to make it work and verify. But It is easier to verify udp(nc -l -u) than tcp,because reply packets are not handled, for tcp nothing can be seen.

tohojo commented 4 months ago

ylg @.***> writes:

@tohojo Hi, length parameter of bpf_csum_diff must be a multiple of 4, so in this case it does not matter much.

No, my point was that you don't need to use bpf_csum_diff() at all, you can just directly update the checksum value (see RFC1071).

Something like:

udphdr->check += bpf_htons(1); if (!udphdr->check) udphdr->check += bpf_htons(1); / overflow, add carry /

this patch is a hint to tell all things people have to do to make it work and verify. But It is easier to verify udp(nc -l -u) than tcp,because reply packets are not handled.

Right, so the end-to-end connection is not going to work anyway for TCP, you mean? Doesn't mean we can't still add the checksum update, it's literally the same code :)

-Toke

bigclouds commented 4 months ago

ylg @.**> writes: @tohojo Hi, length parameter of bpf_csum_diff must be a multiple of 4, so in this case it does not matter much. No, my point was that you don't need to use bpf_csum_diff() at all, you can just directly update the checksum value (see RFC1071). Something like: udphdr->check += bpf_htons(1); if (!udphdr->check) udphdr->check += bpf_htons(1); / overflow, add carry */ clever code. I keep old codes as commits because bpf_csum_diff is normally used.

this patch is a hint to tell all things people have to do to make it work and verify. But It is easier to verify udp(nc -l -u) than tcp,because reply packets are not handled. Right, so the end-to-end connection is not going to work anyway for TCP, you mean? Doesn't mean we can't still add the checksum update, it's literally the same code :) -Toke Right. Done.

bigclouds commented 4 months ago

ylg @.**> writes: @tohojo Hi, length parameter of bpf_csum_diff must be a multiple of 4, so in this case it does not matter much. No, my point was that you don't need to use bpf_csum_diff() at all, you can just directly update the checksum value (see RFC1071). Something like: udphdr->check += bpf_htons(1); if (!udphdr->check) udphdr->check += bpf_htons(1); / overflow, add carry */ clever code. I keep old codes as commits because bpf_csum_diff is normally used.

this patch is a hint to tell all things people have to do to make it work and verify. But It is easier to verify udp(nc -l -u) than tcp,because reply packets are not handled. Right, so the end-to-end connection is not going to work anyway for TCP, you mean? Doesn't mean we can't still add the checksum update, it's literally the same code :) -Toke Right. Done.