2024-08-14 23:51:40 +00:00
|
|
|
#define _GNU_SOURCE
|
2024-08-12 22:59:04 +00:00
|
|
|
#ifndef TYPES_H
|
|
|
|
#define TYPES_H
|
2024-08-14 23:51:40 +00:00
|
|
|
#include <asm/byteorder.h>
|
2024-08-12 22:59:04 +00:00
|
|
|
|
2024-09-01 13:07:47 +00:00
|
|
|
#ifdef KERNEL_SPACE
|
2024-08-12 22:59:04 +00:00
|
|
|
#include <linux/errno.h> // IWYU pragma: export
|
|
|
|
#include <linux/string.h> // IWYU pragma: export
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
typedef __u8 uint8_t;
|
|
|
|
typedef __u16 uint16_t;
|
|
|
|
typedef __u32 uint32_t;
|
|
|
|
typedef __u64 uint64_t;
|
2024-09-01 13:07:47 +00:00
|
|
|
//typedef __i8 int8_t;
|
|
|
|
//typedef __i16 int16_t;
|
|
|
|
//typedef __i32 int32_t;
|
|
|
|
//typedef __i64 int64_t;
|
|
|
|
#else /* USER_SPACE */
|
2024-08-12 22:59:04 +00:00
|
|
|
|
|
|
|
#include <errno.h> // IWYU pragma: export
|
|
|
|
#include <stdint.h> // IWYU pragma: export
|
|
|
|
#include <string.h> // IWYU pragma: export
|
|
|
|
|
2024-09-01 13:07:47 +00:00
|
|
|
#endif /* SPACES */
|
2024-08-12 22:59:04 +00:00
|
|
|
|
2024-08-13 17:48:35 +00:00
|
|
|
// Network specific structures
|
|
|
|
#ifdef KERNEL_SPACE
|
|
|
|
#include <linux/stddef.h> // IWYU pragma: export
|
|
|
|
#include <linux/net.h> // IWYU pragma: export
|
|
|
|
#include <linux/in.h> // IWYU pragma: export
|
|
|
|
#include <linux/ip.h> // IWYU pragma: export
|
2024-09-01 13:07:47 +00:00
|
|
|
#include <linux/ipv6.h> // IWYU pragma: export
|
2024-08-13 17:48:35 +00:00
|
|
|
#include <linux/tcp.h> // IWYU pragma: export
|
2024-09-02 10:41:25 +00:00
|
|
|
#include <linux/version.h>
|
2024-08-13 17:48:35 +00:00
|
|
|
|
2024-09-01 13:07:47 +00:00
|
|
|
#define ip6_hdr ipv6hdr
|
|
|
|
|
2024-08-13 17:48:35 +00:00
|
|
|
/* from <netinet/ip.h> */
|
|
|
|
#define IP_RF 0x8000 /* reserved fragment flag */
|
|
|
|
#define IP_DF 0x4000 /* dont fragment flag */
|
|
|
|
#define IP_MF 0x2000 /* more fragments flag */
|
|
|
|
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
2024-09-01 13:07:47 +00:00
|
|
|
|
|
|
|
#ifdef __LITTLE_ENDIAN
|
|
|
|
#define __BIG_ENDIAN 4321
|
|
|
|
#define __BYTE_ORDER __LITTLE_ENDIAN
|
|
|
|
#elif defined(__BIG_ENDIAN)
|
|
|
|
#define __LITTLE_ENDIAN 1234
|
|
|
|
#define __BYTE_ORDER __BIG_ENDIAN
|
2024-08-13 17:48:35 +00:00
|
|
|
#else
|
2024-09-01 13:07:47 +00:00
|
|
|
#error "Unsupported endian"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ip6_plen payload_len
|
|
|
|
#define ip6_nxt nexthdr
|
|
|
|
#define ip6_hops hop_limit
|
|
|
|
#define ip6_hlim hop_limit
|
|
|
|
#define ip6_src saddr
|
|
|
|
#define ip6_dst daddr
|
|
|
|
|
|
|
|
#else /* USER_SPACE */
|
2024-08-13 17:48:35 +00:00
|
|
|
#include <arpa/inet.h> // IWYU pragma: export
|
|
|
|
#include <netinet/ip.h> // IWYU pragma: export
|
2024-08-27 16:27:27 +00:00
|
|
|
#include <netinet/ip6.h> // IWYU pragma: export
|
2024-08-13 17:48:35 +00:00
|
|
|
#include <netinet/tcp.h> // IWYU pragma: export
|
|
|
|
#include <netinet/udp.h> // IWYU pragma: export
|
|
|
|
#endif
|
|
|
|
|
2024-09-01 13:07:47 +00:00
|
|
|
#ifndef KERNEL_SPACE
|
|
|
|
|
2024-08-14 23:31:48 +00:00
|
|
|
#define max(a,b)__extension__\
|
|
|
|
({ \
|
|
|
|
__typeof__ (a) _a = (a); \
|
|
|
|
__typeof__ (b) _b = (b); \
|
|
|
|
_a > _b ? _a : _b; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define min(a,b)__extension__\
|
|
|
|
({ \
|
|
|
|
__typeof__ (a) _a = (a); \
|
|
|
|
__typeof__ (b) _b = (b); \
|
|
|
|
_a < _b ? _a : _b; \
|
|
|
|
})
|
|
|
|
|
2024-09-01 13:07:47 +00:00
|
|
|
#endif /* not a KERNEL_SPACE */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use NETBUF_ALLOC and NETBUF_FREE as an abstraction of memory allocation.
|
|
|
|
* Do not use it within expressions, consider these defines as separate statements.
|
|
|
|
*
|
|
|
|
* Use NETBUF_CHECK to check that buffer was properly allocated.
|
|
|
|
*/
|
|
|
|
#ifdef KERNEL_SPACE
|
2024-09-01 20:14:22 +00:00
|
|
|
#include <linux/gfp.h>
|
2024-09-01 13:07:47 +00:00
|
|
|
#define NETBUF_ALLOC(buf, buf_len) __u8* buf = kmalloc(buf_len, GFP_ATOMIC);
|
|
|
|
#define NETBUF_CHECK(buf) ((buf) != NULL)
|
|
|
|
#define NETBUF_FREE(buf) kfree(buf);
|
2024-09-14 17:37:19 +00:00
|
|
|
#elif defined(ALLOC_MALLOC)
|
|
|
|
#include <stdlib.h>
|
|
|
|
#define NETBUF_ALLOC(buf, buf_len) __u8* buf = malloc(buf_len);
|
|
|
|
#define NETBUF_CHECK(buf) ((buf) != NULL)
|
|
|
|
#define NETBUF_FREE(buf) free(buf);
|
2024-09-01 13:07:47 +00:00
|
|
|
#else
|
|
|
|
#define NETBUF_ALLOC(buf, buf_len) __u8 buf[buf_len];
|
|
|
|
#define NETBUF_CHECK(buf) (1)
|
|
|
|
#define NETBUF_FREE(buf) ;
|
|
|
|
#endif
|
|
|
|
|
2024-08-12 22:59:04 +00:00
|
|
|
#endif /* TYPES_H */
|