mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user