ROHC compression/decompression library
|
IP-agnostic packet. More...
#include "ip.h"
#include "rohc_utils.h"
#include "protocols/ip_numbers.h"
#include <string.h>
#include <assert.h>
Functions | |
static bool | ip_find_next_layer (const struct ip_packet *const ip, struct net_hdr *const nh, struct net_hdr *const nl) |
Find the next header and next layer transported by an IP packet. | |
static bool | ext_get_next_layer (const struct net_hdr *const nh, struct net_hdr *const nl) |
Find the next layer transported by an IP extension. | |
static bool | ext_get_next_header (const unsigned char *const ext, const size_t ext_len, struct net_hdr *const nh) |
Find the next header transported by an IP extension. | |
bool | ip_create (struct ip_packet *const ip, const unsigned char *const packet, const size_t size) |
Create an IP packet from raw data. | |
const unsigned char * | ip_get_raw_data (const struct ip_packet *const ip) |
Get the IP raw data (header + payload) | |
bool | ip_get_inner_packet (const struct ip_packet *const outer, struct ip_packet *const inner) |
Get the inner IP packet (IP in IP) | |
unsigned char * | ip_get_next_header (const struct ip_packet *const ip, uint8_t *const type) |
Get the IP next header. | |
unsigned char * | ip_get_next_layer (const struct ip_packet *const ip) |
Get the next header (but skip IP extensions) | |
unsigned char * | ip_get_next_ext_from_ip (const struct ip_packet *const ip, uint8_t *const type) |
Get the next extension header of IPv6 packets from an IPv6 header. | |
unsigned char * | ip_get_next_ext_from_ext (const unsigned char *const ext, uint8_t *const type) |
Get the next extension header of IPv6 packets from another extension. | |
unsigned short | ip_get_extension_size (const unsigned char *const ext) |
Get the size of an IPv6 extension. | |
unsigned short | ip_get_total_extension_size (const struct ip_packet *const ip) |
Get the size of the extension list. | |
bool | ip_is_fragment (const struct ip_packet *const ip) |
Whether the IP packet is an IP fragment or not. | |
unsigned int | ip_get_totlen (const struct ip_packet *const ip) |
Get the total length of an IP packet. | |
unsigned int | ip_get_hdrlen (const struct ip_packet *const ip) |
Get the length of an IP header. | |
unsigned int | ip_get_plen (const struct ip_packet *const ip) |
Get the length of an IPv4/IPv6 payload. | |
ip_version | ip_get_version (const struct ip_packet *const ip) |
Get the IP version of an IP packet. | |
void | ip_set_version (struct ip_packet *const ip, const ip_version value) |
Set the IP version of an IP packet. | |
uint8_t | ip_get_protocol (const struct ip_packet *const ip) |
Get the protocol transported by an IP packet. | |
void | ip_set_protocol (struct ip_packet *const ip, const uint8_t value) |
Set the protocol transported by an IP packet. | |
unsigned int | ip_get_tos (const struct ip_packet *const ip) |
Get the IPv4 Type Of Service (TOS) or IPv6 Traffic Class (TC) of an IP packet. | |
void | ip_set_tos (struct ip_packet *const ip, const uint8_t value) |
Set the IPv4 Type Of Service (TOS) or IPv6 Traffic Class (TC) of an IP packet. | |
unsigned int | ip_get_ttl (const struct ip_packet *const ip) |
Get the IPv4 Time To Live (TTL) or IPv6 Hop Limit (HL) of an IP packet. | |
void | ip_set_ttl (struct ip_packet *const ip, const uint8_t value) |
Set the IPv4 Time To Live (TTL) or IPv6 Hop Limit (HL) of an IP packet. | |
void | ip_set_saddr (struct ip_packet *const ip, const unsigned char *value) |
Set the Source Address of an IP packet. | |
void | ip_set_daddr (struct ip_packet *const ip, const unsigned char *value) |
Set the Destination Address of an IP packet. | |
struct ipv4_hdr * | ipv4_get_header (const struct ip_packet *const ip) |
Get the IPv4 header. | |
uint16_t | ipv4_get_id (const struct ip_packet *const ip) |
Get the IP-ID of an IPv4 packet. | |
uint16_t | ipv4_get_id_nbo (const struct ip_packet *const ip, const unsigned int nbo) |
Get the IP-ID of an IPv4 packet in Network Byte Order. | |
void | ipv4_set_id (struct ip_packet *const ip, const int value) |
Set the IP-ID of an IPv4 packet. | |
int | ipv4_get_df (const struct ip_packet *const ip) |
Get the Don't Fragment (DF) bit of an IPv4 packet. | |
void | ipv4_set_df (struct ip_packet *const ip, const int value) |
Set the Don't Fragment (DF) bit of an IPv4 packet. | |
uint32_t | ipv4_get_saddr (const struct ip_packet *const ip) |
Get the source address of an IPv4 packet. | |
uint32_t | ipv4_get_daddr (const struct ip_packet *const ip) |
Get the destination address of an IPv4 packet. | |
struct ipv6_hdr * | ipv6_get_header (const struct ip_packet *const ip) |
Get the IPv6 header. | |
uint32_t | ipv6_get_flow_label (const struct ip_packet *const ip) |
Get the flow label of an IPv6 packet. | |
void | ipv6_set_flow_label (struct ip_packet *const ip, const uint32_t value) |
Set the flow label of an IPv6 packet. | |
struct ipv6_addr * | ipv6_get_saddr (const struct ip_packet *const ip) |
Get the source address of an IPv6 packet. | |
struct ipv6_addr * | ipv6_get_daddr (const struct ip_packet *const ip) |
Get the destination address of an IPv6 packet. | |
bool | get_ip_version (const unsigned char *const packet, const size_t size, ip_version *const version) |
IP-agnostic packet.
static bool ext_get_next_header | ( | const unsigned char *const | ext, |
const size_t | ext_len, | ||
struct net_hdr *const | nh | ||
) | [static] |
Find the next header transported by an IP extension.
ext | The extension header | |
ext_len | The maximum length of the extension | |
[out] | nh | The next header transported by the extension header |
static bool ext_get_next_layer | ( | const struct net_hdr *const | nh, |
struct net_hdr *const | nl | ||
) | [static] |
Find the next layer transported by an IP extension.
nh | The first IP extension | |
[out] | nl | The next layer |
bool get_ip_version | ( | const unsigned char *const | packet, |
const size_t | size, | ||
ip_version *const | version | ||
) |
Private functions used by the IP module: (please do not use directly)
Create an IP packet from raw data.
ip | OUT: The IP packet to create |
packet | The IP packet data |
size | The length of the IP packet data |
static bool ip_find_next_layer | ( | const struct ip_packet *const | ip, |
struct net_hdr *const | nh, | ||
struct net_hdr *const | nl | ||
) | [static] |
Find the next header and next layer transported by an IP packet.
ip | The IP packet to analyze | |
[out] | nh | The first IP extension or the transport layer |
[out] | nl | The transport layer |
unsigned short ip_get_extension_size | ( | const unsigned char *const | ext | ) |
Get the size of an IPv6 extension.
ext | The extension |
unsigned int ip_get_hdrlen | ( | const struct ip_packet *const | ip | ) |
Get the length of an IP header.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
bool ip_get_inner_packet | ( | const struct ip_packet *const | outer, |
struct ip_packet *const | inner | ||
) |
Get the inner IP packet (IP in IP)
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
outer | The outer IP packet to analyze |
inner | The inner IP packet to create |
unsigned char* ip_get_next_ext_from_ext | ( | const unsigned char *const | ext, |
uint8_t *const | type | ||
) |
Get the next extension header of IPv6 packets from another extension.
ext | The extension to analyse |
type | OUT: The type of the next header If there is no next header the value must be ignored |
unsigned char* ip_get_next_ext_from_ip | ( | const struct ip_packet *const | ip, |
uint8_t *const | type | ||
) |
Get the next extension header of IPv6 packets from an IPv6 header.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
type | OUT: The type of the next header If there is no next header the value must be ignored |
unsigned char* ip_get_next_header | ( | const struct ip_packet *const | ip, |
uint8_t *const | type | ||
) |
Get the IP next header.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
type | OUT: The type of the next header |
unsigned char* ip_get_next_layer | ( | const struct ip_packet *const | ip | ) |
Get the next header (but skip IP extensions)
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
unsigned int ip_get_plen | ( | const struct ip_packet *const | ip | ) |
Get the length of an IPv4/IPv6 payload.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IPv4/IPv6 packet to analyze |
uint8_t ip_get_protocol | ( | const struct ip_packet *const | ip | ) |
Get the protocol transported by an IP packet.
The protocol returned is the one transported by the last known IP extension header if any is found.
The function handles ip_packet whose ip_packet::version is IP_UNKNOWN. It always returns the special value 0.
ip | The IP packet to analyze |
const unsigned char* ip_get_raw_data | ( | const struct ip_packet *const | ip | ) |
Get the IP raw data (header + payload)
The function handles ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
unsigned int ip_get_tos | ( | const struct ip_packet *const | ip | ) |
Get the IPv4 Type Of Service (TOS) or IPv6 Traffic Class (TC) of an IP packet.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
unsigned short ip_get_total_extension_size | ( | const struct ip_packet *const | ip | ) |
Get the size of the extension list.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The packet to analyse |
unsigned int ip_get_totlen | ( | const struct ip_packet *const | ip | ) |
Get the total length of an IP packet.
The function handles ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
unsigned int ip_get_ttl | ( | const struct ip_packet *const | ip | ) |
Get the IPv4 Time To Live (TTL) or IPv6 Hop Limit (HL) of an IP packet.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
ip_version ip_get_version | ( | const struct ip_packet *const | ip | ) |
Get the IP version of an IP packet.
The function handles ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
bool ip_is_fragment | ( | const struct ip_packet *const | ip | ) |
Whether the IP packet is an IP fragment or not.
The IP packet is a fragment if the MF (More Fragments) bit is set or the Fragment Offset field is non-zero.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to analyze |
void ip_set_daddr | ( | struct ip_packet *const | ip, |
const unsigned char * | value | ||
) |
Set the Destination Address of an IP packet.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to modify |
value | The IP address value |
void ip_set_protocol | ( | struct ip_packet *const | ip, |
const uint8_t | value | ||
) |
Set the protocol transported by an IP packet.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to modify |
value | The protocol value |
void ip_set_saddr | ( | struct ip_packet *const | ip, |
const unsigned char * | value | ||
) |
Set the Source Address of an IP packet.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to modify |
value | The IP address value |
void ip_set_tos | ( | struct ip_packet *const | ip, |
const uint8_t | value | ||
) |
Set the IPv4 Type Of Service (TOS) or IPv6 Traffic Class (TC) of an IP packet.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to modify |
value | The TOS/TC value |
void ip_set_ttl | ( | struct ip_packet *const | ip, |
const uint8_t | value | ||
) |
Set the IPv4 Time To Live (TTL) or IPv6 Hop Limit (HL) of an IP packet.
The function does not handle ip_packet whose ip_packet::version is IP_UNKNOWN.
ip | The IP packet to modify |
value | The TTL/HL value |
void ip_set_version | ( | struct ip_packet *const | ip, |
const ip_version | value | ||
) |
Set the IP version of an IP packet.
ip | The IP packet to modify |
value | The version value |
uint32_t ipv4_get_daddr | ( | const struct ip_packet *const | ip | ) |
Get the destination address of an IPv4 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IPv4 packet to analyze |
int ipv4_get_df | ( | const struct ip_packet *const | ip | ) |
Get the Don't Fragment (DF) bit of an IPv4 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IP packet to analyze |
struct ipv4_hdr* ipv4_get_header | ( | const struct ip_packet *const | ip | ) | [read] |
Get the IPv4 header.
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IP packet to analyze |
uint16_t ipv4_get_id | ( | const struct ip_packet *const | ip | ) |
Get the IP-ID of an IPv4 packet.
The IP-ID value is returned as-is (ie. not automatically converted to the host byte order).
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IP packet to analyze |
uint16_t ipv4_get_id_nbo | ( | const struct ip_packet *const | ip, |
const unsigned int | nbo | ||
) |
Get the IP-ID of an IPv4 packet in Network Byte Order.
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IP packet to analyze |
nbo | The NBO flag (if RND = 1, use NBO = 1) |
uint32_t ipv4_get_saddr | ( | const struct ip_packet *const | ip | ) |
Get the source address of an IPv4 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IPv4 packet to analyze |
void ipv4_set_df | ( | struct ip_packet *const | ip, |
const int | value | ||
) |
Set the Don't Fragment (DF) bit of an IPv4 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IP packet to modify |
value | The value of the DF bit |
void ipv4_set_id | ( | struct ip_packet *const | ip, |
const int | value | ||
) |
Set the IP-ID of an IPv4 packet.
The IP-ID value is set as-is (ie. not automatically converted to the host byte order).
The function does not handle ip_packet whose ip_packet::version is not IPV4.
ip | The IP packet to modify |
value | The IP-ID value |
struct ipv6_addr* ipv6_get_daddr | ( | const struct ip_packet *const | ip | ) | [read] |
Get the destination address of an IPv6 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV6.
ip | The IPv6 packet to analyze |
uint32_t ipv6_get_flow_label | ( | const struct ip_packet *const | ip | ) |
Get the flow label of an IPv6 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV6.
ip | The IPv6 packet to analyze |
struct ipv6_hdr* ipv6_get_header | ( | const struct ip_packet *const | ip | ) | [read] |
Get the IPv6 header.
The function does not handle ip_packet whose ip_packet::version is not IPV6.
ip | The IP packet to analyze |
struct ipv6_addr* ipv6_get_saddr | ( | const struct ip_packet *const | ip | ) | [read] |
Get the source address of an IPv6 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV6.
ip | The IPv6 packet to analyze |
void ipv6_set_flow_label | ( | struct ip_packet *const | ip, |
const uint32_t | value | ||
) |
Set the flow label of an IPv6 packet.
The function does not handle ip_packet whose ip_packet::version is not IPV6.
ip | The IPv6 packet to modify |
value | The flow label value |