IP stack headers

Overview

Definition of the auxiliary data structures and functions to operate the IP stack headers and checksums

Copyright (C) 2004-2022 OKTET Labs Ltd. More…

// structs

struct te_ipstack_pseudo_header_ip;
struct te_ipstack_pseudo_header_ip6;
struct vlanhdr;

// global functions

te_errno te_ipstack_calc_l4_cksum(const struct sockaddr* ip_dst_addr, const struct sockaddr* ip_src_addr, const uint8_t next_hdr, const uint8_t* datagram, const size_t datagram_len, uint16_t* cksum_out);
te_errno te_ipstack_prepare_raw_tcpv4_packet(uint8_t* raw_packet, ssize_t* total_size, bool remove_vlan_hdr, struct sockaddr_ll* sadr_ll);
te_errno te_ipstack_mirror_udp_packet(uint8_t* pkt, size_t len);

Detailed Documentation

Definition of the auxiliary data structures and functions to operate the IP stack headers and checksums

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Global Functions

te_errno te_ipstack_calc_l4_cksum(const struct sockaddr* ip_dst_addr, const struct sockaddr* ip_src_addr, const uint8_t next_hdr, const uint8_t* datagram, const size_t datagram_len, uint16_t* cksum_out)

Auxiliary function to calculate checksums for L4 datagrams (UDP, TCP) using a so-called pseudo-header in accordance with principles of checksum calculation defined by RFC 793 (in case of underlying IPv4 network) and RFC 2460 (i.e., it takes into account pseudo-header composition peculiarities brought by IPv6) but without taking into account any possible IPv6 routing headers (i.e., it uses IPv6 DST address from the main header)

Parameters:

ip_dst_addr

Destination IPv4/6 address

ip_src_addr

Source IPv4/6 address

next_hdr

L4 protocol ID (i.e., IPPROTO_UDP)

datagram

Buffer containing L4 header and L4 payload

datagram_len

Buffer length

cksum_out

Location for the resulting checksum

Returns:

Status code

te_errno te_ipstack_prepare_raw_tcpv4_packet(uint8_t* raw_packet, ssize_t* total_size, bool remove_vlan_hdr, struct sockaddr_ll* sadr_ll)

Function to prepare raw TCPv4 packet for sending via raw socket. This includes checking headers, filling checksums and removing of the VLAN header to avoid duplication during sending via raw socket. In addition, it prepares the address for sending based on given headers.

Parameters:

raw_packet

Pointer to buffer with headers and payload

total_size

Total size of raw packet

remove_vlan_hdr

Remove all VLAN headers if true

sadr_ll

Link local address to filling. May be NULL.

Returns:

Status code

te_errno te_ipstack_mirror_udp_packet(uint8_t* pkt, size_t len)

Reverse addresses and ports of a RAW Ethernet/IP[4,6]/UDP packet, so that it can be echoed back.

Parameters:

pkt

UDP packet.

len

Packet length.

Returns:

Status code.