encap-forward: Support conditional IPv6 encapsulation with IPV6=1

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
This commit is contained in:
Toke Høiland-Jørgensen
2020-10-07 13:35:38 +02:00
parent 061bb5026c
commit bc91d4d456
5 changed files with 31 additions and 9 deletions

View File

@@ -4,13 +4,18 @@
#include <xdp/parsing_helpers.h>
#include "encap.h"
#ifdef IPV6
#define OFFSET sizeof(struct ipv6hdr)
#else
#define OFFSET sizeof(struct iphdr)
#endif
SEC("prog") int xdp_encap(struct xdp_md *ctx)
{
volatile struct ethhdr *ehdr, old_ehdr = {};
volatile void *data, *data_end;
size_t offset = OFFSET;
int ret = XDP_ABORTED;
size_t offset = sizeof(struct iphdr);
data = (void *)(long)ctx->data;
data_end = (void *)(long)ctx->data_end;
@@ -33,8 +38,11 @@ SEC("prog") int xdp_encap(struct xdp_md *ctx)
*ehdr = old_ehdr;
ehdr->h_proto = bpf_htons(ETH_P_IP);
// encap_ipv6(data, data_end);
#ifdef IPV6
encap_ipv6(data, data_end);
#else
encap_ipv4(data, data_end);
#endif
ret = XDP_PASS;
out:
return ret;