27 #ifndef ROHC_COMMON_IP_H 28 #define ROHC_COMMON_IP_H 108 static inline uint16_t
swab16(
const uint16_t value)
109 __attribute__((warn_unused_result,
const));
117 static inline uint16_t
swab16(
const uint16_t value)
119 return ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);
123 #if defined(__i386__) || defined(__x86_64__) 127 __attribute__((
nonnull(1), warn_unused_result, pure));
143 uint32_t __ihl = ihl;
146 __asm__ __volatile__(
154 1: adcl 16(%1), %0 \n\ 169 :
"=r" (sum),
"=r" (iph),
"=r" (__ihl)
170 :
"1" (iph),
"2" (__ihl)
173 return (uint16_t) (sum & 0xffff);
179 static inline uint16_t
from32to16(
const uint32_t x)
180 __attribute__((warn_unused_result,
const));
186 y = (x & 0xffff) + (x >> 16);
188 y = (y & 0xffff) + (y >> 16);
192 static inline uint16_t
ip_fast_csum(
const uint8_t *
const iph,
194 __attribute__((
nonnull(1), warn_unused_result, pure));
203 const uint8_t *buff = iph;
204 size_t len = ihl * 4;
213 odd = 1 & (uintptr_t) buff;
216 #ifdef __LITTLE_ENDIAN 219 result += (*buff << 8);
227 if(2 & (uintptr_t) buff)
229 result += *(uint16_t *) buff;
240 uint32_t word = *(uint32_t *) buff;
242 buff +=
sizeof(uint32_t);
245 carry = (word > result);
249 result = (result & 0xffff) + (result >> 16);
253 result += *(uint16_t *) buff;
259 #ifdef __LITTLE_ENDIAN 262 result += (*buff << 8);
268 result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
278 # include <asm/checksum.h> 290 __attribute__((warn_unused_result,
nonnull(1), pure));
292 __attribute__((warn_unused_result,
nonnull(1), pure));
294 __attribute__((warn_unused_result,
nonnull(1), pure));
296 __attribute__((warn_unused_result,
nonnull(1), pure));
307 __attribute__((
nonnull(1, 2)));
309 __attribute__((
nonnull(1, 2)));
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.
Definition: ip.c:114
size_t size
The length (in bytes) of the whole IP data (header + payload)
Definition: ip.h:95
struct ipv4_hdr v4
The IPv4 header.
Definition: ip.h:86
IP version 4 (malformed)
Definition: ip.h:58
not IP
Definition: ip.h:56
union ip_packet::@1 header
The IP header.
const uint8_t * data
The whole IP data (header + payload) if not NULL.
Definition: ip.h:92
static uint16_t swab16(const uint16_t value)
In-place change the byte order in a two-byte value.
Definition: ip.h:117
ip_header_pos_t
Definition: ip.h:39
IP version 6.
Definition: ip.h:54
static ip_version ip_get_version(const struct ip_packet *const ip)
Get the IP version of an IP packet.
Definition: ip.h:321
uint8_t ip_get_protocol(const struct ip_packet *const ip)
Get the protocol transported by an IP packet.
Definition: ip.c:69
static uint16_t ip_fast_csum(const uint8_t *const iph, const size_t ihl)
Definition: ip.h:200
ip_version version
The version of the IP packet.
Definition: ip.h:80
The IPv6 header.
Definition: ipv6.h:82
uint8_t proto
Definition: ip.h:67
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.
Definition: ip.c:149
size_t len
Definition: ip.h:69
The IPv4 header.
Definition: ipv4.h:53
void ip_set_daddr(struct ip_packet *const ip, const uint8_t *value)
Set the Destination Address of an IP packet.
Definition: ip.c:266
void ip_set_saddr(struct ip_packet *const ip, const uint8_t *value)
Set the Source Address of an IP packet.
Definition: ip.c:239
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.
Definition: ip.c:212
struct net_hdr nh
Definition: ip.h:97
IP version 6 (malformed)
Definition: ip.h:60
ip_version
IP version.
Definition: ip.h:49
Defines an IP-agnostic packet that can handle an IPv4 or IPv6 packet.
Definition: ip.h:77
IP version 4.
Definition: ip.h:52
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.
Definition: ip.c:177
void ip_set_protocol(struct ip_packet *const ip, const uint8_t value)
Set the protocol transported by an IP packet.
Definition: ip.c:84
void ip_set_version(struct ip_packet *const ip, const ip_version value)
Set the IP version of an IP packet.
Definition: ip.c:50
uint8_t * data
Definition: ip.h:68
struct ipv6_hdr v6
The IPv6 header.
Definition: ip.h:88
static uint16_t from32to16(const uint32_t x)
Definition: ip.h:182
struct net_hdr nl
Definition: ip.h:98