UDP checksum calculation for IPv6 packet

12k views Asked by At

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.

2

There are 2 answers

3
imran On

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).

0
Amit Kumar On

clear example to understand ipv6 with udp protocol calculation suppose you have data of ipv6 packet as 60000000000C1120FD00C001C0DE0077007700FFFE000005FD00C001C0DE000100000000000000020FDB0328000CED1401020304 IPV6 HEADER 60000000 000C 11 20

IP HEADER PART PSEUDO HEADER(IT IS THAT PART WHICH LINK UDP OR PROTOCOL TO IPVX HEADER SO NAME AS PSEDUO HEADER IT IS OT REAL HEADER BUT MAKE LINK BTWN 2) SRC AND DSTN ADDRESS AND PROTOCOL AND LENTGH TO BE ADD WHICH WE HAVE TO EXTRACT FROM IP HEADER LENTFTH ABOVE IS 0X000C AND PROTOCOL OX11

FD00C001C0DE0077007700FFFE000005

FD00C001C0DE00010000000000000002 UDP HEADER START 0FDB

0328

000C

ED14 CHECKSUM

DATA 0102 0304

ref RFC 2460(https://www.rfc-editor.org/rfc/rfc2460:) IPv6 Pseudo Header ////The source address is the one in the IPv6 header. The destination address is the final destination; if the IPv6 packet does not contain a Routing header, that will be the destination address in the IPv6 header; otherwise, at the originating node, it will be the address in the last element of the Routing header, and, at the receiving node, it will be the destination address in the IPv6 header. The value of the Next Header field is the protocol value for UDP: 17. The UDP length field is the length of the UDP header and data///

note : ipv6 header does not have checksum field so udp or other protocol checksum is must in it to for correct data packet IPv6 Pseudo Header.= (Source IP, Destination IP, Protocol, UDP/TCP Length (header+body)) choose src address an make it in 16 bit FD00:C001:C0DE:0077:0077:00FF:FE00:0005 or short to FD00:C001:C0DE:77:77:FF:FE00:5 same as destination address FD00:C001:C0DE:1::2

Protocol = 0x0011(udp) // it must be include length = 0x000c //

udp header have source port(16bit) = 0x0fdb dstn port 0x0328 length = 0x000c checksum(to be calculate) so consider = 0x0000

data group as(16bit) 0x0102,0x0304... note :if odd number suppose 05 also then take it as 0x0500

checksum here will be = 16 bit sum of pseudo header+udp header +data sum of pseudo header= FD00+C001+C0DE+0077+0077+00FF+FE00+0005+(FD00+C001+C0DE+1+2)+x0011+0x000c

sum of pseudo header= 5fbd0 (16 bit sum can be done here or after each step or in last result will be same) sum of udp header = 0x0fdb+0x0328+0x000c+0x0000+0x000 = 0x130f

sum of data = 0x0102+0x0304 = 0x0406

total of all 5fbd0+0x130f+0x0406 = 0x612e5 make it 16 bit sum by summuning up 5 digits to it = 0X12E5+6 = 0X12EB

TRANSMITTER CHECKSUM WILL BE 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.[7]

SO HERE 1,S COMPLEMENT WILL BE 0X12EB XOR 0XFFFF = 0XED14 (CHEKSUM)