Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UDP checksum calculation for IPv6 packet

Tags:

checksum

ipv6

udp

I am trying to understand the UDP checksum calculation method for IPv6.

I have this packet:

IPv6 Header is -- 60 00 00 00 00 0c 11 fd 21 00 00 00 00 00 00 01 ab cd 00 00 00 00 00 01 fd 00 00 00 00 00 00 00 00 00 00 00 00 00 01 60
UDP Header is -- 26 92 26 92 00 0c 7e d5
Data is -- 12 34 56 78

As per the checksum calculation, the checksum is 7ed5. Can anyone explain how the checksum ended up with that value? I want to calculate it manually to understand the method.

like image 419
baila Avatar asked Oct 25 '25 20:10

baila


1 Answers

In case this question hasn't been answered yet, and for the benefit of others.

Your IPv6 Packet UDP Packet (in Hex format)

60 00 00 00 . 00 34 11 01 . 21 00 00 00 - `....4..!...
00 00 00 01 . AB CD 00 00 . 00 00 00 01 - ............
FD 00 00 00 . 00 00 00 00 . 00 00 00 00 - ............
00 00 01 60 . 26 92 26 92 . 00 0C 7E D5 - ...`&.&...~.
12 34 56 78                             - .4Vx

Steps for calculating the checksum (0x7ED5) in the UDP header. All numbers are represented in hexadecimal format.

Step 1) Calculate 16-bit sum of pseudo header. The pseudo header contains Source IP, Destination IP, Protocol, UDP/TCP Length (header+body)

Source IP: 21 00 00 00 . 00 00 00 01 . AB CD 00 00 . 00 00 00 01
Dest   IP: FD 00 00 00 . 00 00 00 00 . 00 00 00 00 . 00 00 01 60
Protocol : 00 11  (UDP)
Proto Len: 00 0C  (UDP Header + Body)

The sum of your pseudo header is:

SUM_PHDR = 0x2100 + 0x0000 + ... + 0x0011 + 0x000C
         = 0x1CB4C

Step 2) Calculate 16-bit sum of UDP Header + Data (excluding checksum)

UDP Hdr  : 26 92 26 92 . 00 0C 00 00
UDP Body : 12 34 56 78

The sum of your UDP section is:

SUM_BODY = 0x2692 + 0x2692 + ... + 0x5678
         = B5DC

Step 3) Calculate Total

SUM_TOTAL = SUM_PHDR + SUM_BODY
          = 0x1CB4C + 0xB5DC
SUM_TOTAL = 0x28128  (or 0x00028128)

Step 4) Calculate 16-bit Sum from total (since it is > 0xFFFF)

SUM_16BIT = 0x0002 + 0x8218
          = 0x821A

Step 5) Calculate one's compliment of the 16-bit Sum

CHECKSUM  = 0x821A Xor 0xFFFF
          = 0x7ED5

Your checksum is 0x7ED5

The procedure is the same as with IPv4. The difference is just the length of the Source and Destination IP in the pseudo header (in step 1).

like image 62
imran Avatar answered Oct 29 '25 09:10

imran