diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2025-06-16 17:09:43 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2025-06-18 15:16:30 +0200 |
commit | 0730e77eb4aa9841e90a17f190b9ae7d80565054 (patch) | |
tree | b214414fb23070fcfcbfc880f78eb7b4cef987c8 /xdp_manip.h |
Initial commitmain
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'xdp_manip.h')
-rw-r--r-- | xdp_manip.h | 28 |
1 files changed, 28 insertions, 0 deletions
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 <linux/if_ether.h> +#include <linux/ip.h> +#include <linux/udp.h> + +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 |