Skip to content
Snippets Groups Projects
Commit 1eb3eccb authored by Daniel Salzman's avatar Daniel Salzman
Browse files

xdp: make the filter endian independent

parent 28988ef2
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,9 @@
#include "../../contrib/libbpf/include/uapi/linux/bpf.h"
#include "../../contrib/libbpf/bpf/bpf_helpers.h"
/* Don't fragment flag. */
#define IP_DF 0x4000
/* Assume netdev has no more than 128 queues. */
#define QUEUE_MAX 128
......@@ -47,7 +50,6 @@ struct ipv6_frag_hdr {
unsigned char whatever[7];
} __attribute__((packed));
/* NOTE: this implementation expects little-endian byte ordering! */
SEC("xdp_redirect_udp")
int xdp_redirect_udp_func(struct xdp_md *ctx)
{
......@@ -70,18 +72,19 @@ int xdp_redirect_udp_func(struct xdp_md *ctx)
/* Parse IPv4 or IPv6 header. */
switch (eth->h_proto) {
case 0x0008: /* htons(ETH_P_IP) */
case __constant_htons(ETH_P_IP):
ip4 = data;
if ((void *)ip4 + sizeof(*ip4) > data_end) {
return XDP_PASS;
}
if (ip4->frag_off != 0 && ip4->frag_off != 0x0040) { /* htons(IP_DF) */
if (ip4->frag_off != 0 &&
ip4->frag_off != __constant_htons(IP_DF)) {
fragmented = 1;
}
ip_proto = ip4->protocol;
udp = data + ip4->ihl * 4;
break;
case 0xDD86: /* htons(ETH_P_IPV6) */
case __constant_htons(ETH_P_IPV6):
ip6 = data;
if ((void *)ip6 + sizeof(*ip6) > data_end) {
return XDP_PASS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment