DPDK usage discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: "Gábor LENCSE" <lencse@hit.bme.hu>
Cc: "users@dpdk.org" <users@dpdk.org>
Subject: Re: How to calculate ICMPv6 checksum?
Date: Tue, 12 Aug 2025 16:57:06 -0700	[thread overview]
Message-ID: <20250812165706.52ac3b50@hermes.local> (raw)
In-Reply-To: <aa22c96e-ccaa-413a-9784-bb9e8ee7ee8e@hit.bme.hu>

On Fri, 8 Aug 2025 20:56:33 +0200
Gábor LENCSE <lencse@hit.bme.hu> wrote:

> Dear Stephen,
> 
> Thank you very much for your answer. It helps me a lot, but I have 
> further questions. Please see my comments inline.
> > The pseudo-header part is different.  
> If I understand it correctly, then it means that I need to write the 
> ICMPv6 checksum function myself. To that end, I reviewed the source code 
> of the "rte_ipv6_udptcp_cksum()" function so that I can learn from it. 
> However, I did not find where it differs from the one that I need. I 
> took the below source code from here: 
> https://doc.dpdk.org/api/rte__ip6_8h_source.html#l00610 
> rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void 
> *l4_hdr) { uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr); 
> cksum = ~cksum; /* * Per RFC 768: If the computed checksum is zero for 
> UDP, * it is transmitted as all ones * (the equivalent in one's 
> complement arithmetic). */ if (cksum == 0 && ipv6_hdr->proto == 
> IPPROTO_UDP) cksum = 0xffff; return cksum; } It is the highest level. It 
> calls an internal function and at the end it considers the protocol 
> number (with other words, the next header field of the IPv6 header) when 
> it handles UDP specific things, thus I think that this time it does not 
> cause any problem in the case of ICMPv6.
> 
> This is the source code of the internal function:
> 
> static inline uint16_t
> __rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void 
> *l4_hdr)
> {
>      uint32_t cksum;
>      uint32_t l4_len;
> 
>      l4_len = rte_be_to_cpu_16(ipv6_hdr->payload_len);
> 
>      cksum = rte_raw_cksum(l4_hdr, l4_len);
>      cksum += rte_ipv6_phdr_cksum(ipv6_hdr, 0);
> 
>      cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
> 
>      return (uint16_t)cksum;
> }

Yes this is similar but in UDP/TCP case the UDP/TCP header is included in
the checksum. l4_hdr points to the UDP/TCP header. l4_len is the payload
length that is TCP/UDP header and the associated data.

The pseudo header is done by rte_ipv6_phdr_cksum().

For ICMPv6 you would need to point l4_hdr at ICMP header.
Even though ICMP is not really an L4 protocol.

https://en.wikipedia.org/wiki/ICMPv6#Checksum




      reply	other threads:[~2025-08-12 23:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-07 15:32 Gábor LENCSE
2025-08-07 17:57 ` Stephen Hemminger
2025-08-08 18:56   ` Gábor LENCSE
2025-08-12 23:57     ` Stephen Hemminger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250812165706.52ac3b50@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=lencse@hit.bme.hu \
    --cc=users@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).