IPv6 header

IPv6 header types and helper functions.

void ipv6_hdr_set_version(ipv6_hdr_t * hdr)

Sets the version field of hdr to 6.

Parameters

hdr:Pointer to an IPv6 header.

uint8_t ipv6_hdr_get_version(const ipv6_hdr_t * hdr)

Gets the value of the version field of hdr.

Parameters

hdr:Pointer to an IPv6 header.

Return values

  • Value of the version field of hdr.
bool ipv6_hdr_is(const ipv6_hdr_t * hdr)

Checks if the version field is set to 6.

Parameters

hdr:Pointer to an IPv6 header.

Return values

  • true, if version field is 6
  • false, otherwise
void ipv6_hdr_set_tc(ipv6_hdr_t * hdr, uint8_t tc)

Sets the traffic class field of hdr.

Parameters

hdr:Pointer to an IPv6 header.
tc:The new value for the traffic class field.

void ipv6_hdr_set_tc_ecn(ipv6_hdr_t * hdr, uint8_t ecn)

Sets the value of the Explicit Congestion Notification (ECN) part of the traffic class field of hdr.

The field is needed e.g. in context of 6LoWPAN header compression

Parameters

hdr:Pointer to an IPv6 header.
ecn:The new value for the 2-bit ECN part of the traffic class field.

void ipv6_hdr_set_tc_dscp(ipv6_hdr_t * hdr, uint8_t dscp)

Sets the value of the Differentiated Service Codepoint (DSCP) part of the traffic class field of hdr.

The field is needed e.g. in context of 6LoWPAN header compression

Parameters

hdr:Pointer to an IPv6 header.
dscp:The new value for the 6-bit DSCP part of the traffic class field.

uint8_t ipv6_hdr_get_tc(const ipv6_hdr_t * hdr)

Gets the value of the traffic class field of hdr.

Parameters

hdr:Pointer to an IPv6 header.

Return values

  • Value of the traffic class field of hdr.
uint8_t ipv6_hdr_get_tc_ecn(const ipv6_hdr_t * hdr)

Gets the value of the Explicit Congestion Notification (ECN) part of the traffic class field of hdr.

The field is needed e.g. in context of 6LoWPAN header compression

Parameters

hdr:Pointer to an IPv6 header.

Return values

  • Value of the ECN part of the traffic class field of hdr.
uint8_t ipv6_hdr_get_tc_dscp(const ipv6_hdr_t * hdr)

Gets the value of the Differentiated Service Codepoint (DSCP) part of the traffic class field of hdr.

The field is needed e.g. in context of 6LoWPAN header compression

Parameters

hdr:Pointer to an IPv6 header.

Return values

  • Value of the DSCP part of the traffic class field of hdr.
void ipv6_hdr_set_fl(ipv6_hdr_t * hdr, uint32_t fl)

Sets the flow label field of hdr.

Parameters

hdr:Pointer to an IPv6 header.
fl:The new value for the flow label field in host byte order.

uint32_t ipv6_hdr_get_fl(const ipv6_hdr_t * hdr)

Gets the value of the flow label field of hdr.

Parameters

hdr:Pointer to an IPv6 header.

Return values

  • Value of the flow label field of hdr.
uint16_t ipv6_hdr_inet_csum(uint16_t sum, ipv6_hdr_t * hdr, uint8_t prot_num, uint16_t len)

Calculates the Internet Checksum for the IPv6 Pseudo Header.

Parameters

sum:Preinialized value of the sum.
prot_num:The Protocol Numbers you want to calculate the checksum for. Can not be inferred from ipv6/hdr.h::ipv6_hdr_t::nh, since it can be an IPv6 exentension header.
hdr:An IPv6 header to derive the Pseudo Header from.
len:The upper-layer packet length for the pseudo header. Can not be inferred from ipv6/hdr.h::ipv6_hdr_t::len, since there can be extension headers between the IPv6 header and the payload.

Return values

  • The non-normalized Internet Checksum of the given IPv6 pseudo header.
void ipv6_hdr_print(ipv6_hdr_t * hdr)

Outputs an IPv6 header to stdout.

Parameters

hdr:An IPv6 header.

struct ipv6_hdr_t

Data type to represent an IPv6 packet header.

The structure of the header is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
                     1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class |           Flow Label                  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Payload Length        |  Next Header  |   Hop Limit   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                         Source Address                        +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                      Destination Address                      +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

byteorder.h::network_uint32_t v_tc_fl

Version, traffic class, and flow label.

The version are the 4 most significant bits, the traffic class the 8 next bit, and the remainding 20 bits are the flow label (see above).

This module provides helper functions to set, get, and check these fields accordingly:

byteorder.h::network_uint16_t len

payload length of this packet.

uint8_t nh

type of next header in this packet.

uint8_t hl

hop limit for this packet.

ipv6_addr_t src

source address of this packet.

ipv6_addr_t dst

destination address of this packet.