From 0730e77eb4aa9841e90a17f190b9ae7d80565054 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Mon, 16 Jun 2025 17:09:43 +0200 Subject: Initial commit Signed-off-by: Toni Uhlig --- xdp_manip.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 xdp_manip.h (limited to 'xdp_manip.h') diff --git a/xdp_manip.h b/xdp_manip.h new file mode 100644 index 0000000..70eba28 --- /dev/null +++ b/xdp_manip.h @@ -0,0 +1,28 @@ +#ifndef XDP_MANIP_H +#define XDP_MANIP_H 1 + +#include +#include +#include + +static __always_inline void swap_eth_addr(struct ethhdr *const ethhdr) { + unsigned char src_eth[ETH_ALEN]; + + __builtin_memcpy(src_eth, ethhdr->h_source, sizeof(ethhdr->h_source)); + __builtin_memcpy(ethhdr->h_source, ethhdr->h_dest, sizeof(ethhdr->h_source)); + __builtin_memcpy(ethhdr->h_dest, src_eth, sizeof(src_eth)); +} + +static __always_inline void swap_ip4_addr(struct iphdr *const iphdr) { + __be32 src_ip = iphdr->saddr; + iphdr->saddr = iphdr->daddr; + iphdr->daddr = src_ip; +} + +static __always_inline void swap_udp_port(struct udphdr *const udphdr) { + __be16 src_port = udphdr->source; + udphdr->source = udphdr->dest; + udphdr->dest = src_port; +} + +#endif -- cgit v1.2.3