| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <linux/bpf.h> |
| 8 |
|
| 9 |
#include <bpf/bpf_endian.h> |
| 10 |
#include <bpf/bpf_helpers.h> |
| 11 |
|
| 12 |
#include <xdp/xdp_helpers.h> |
| 13 |
|
| 14 |
#include "net_def.h" |
| 15 |
#include "xdp_metadata.c" |
| 16 |
|
| 17 |
struct { |
| 18 |
__uint(type, BPF_MAP_TYPE_XSKMAP); |
| 19 |
__uint(key_size, sizeof(int)); |
| 20 |
__uint(value_size, sizeof(int)); |
| 21 |
__uint(max_entries, 128); |
| 22 |
} xsks_map SEC(".maps"); |
| 23 |
|
| 24 |
struct { |
| 25 |
__uint(priority, 20); |
| 26 |
__uint(XDP_PASS, 1); |
| 27 |
} XDP_RUN_CONFIG(xdp_sock_prog); |
| 28 |
|
| 29 |
SEC("xdp_sock") |
| 30 |
int xdp_sock_prog(struct xdp_md *ctx) |
| 31 |
{ |
| 32 |
void *data_end = (void *)(long)ctx->data_end; |
| 33 |
void *data = (void *)(long)ctx->data; |
| 34 |
struct vlan_ethernet_header *veth; |
| 35 |
int idx = ctx->rx_queue_index; |
| 36 |
void *p = data; |
| 37 |
|
| 38 |
veth = p; |
| 39 |
if ((void *)(veth + 1) > data_end) |
| 40 |
return XDP_PASS; |
| 41 |
|
| 42 |
|
| 43 |
if (veth->vlan_proto != bpf_htons(ETH_P_8021Q)) |
| 44 |
return XDP_PASS; |
| 45 |
|
| 46 |
|
| 47 |
if (veth->vlan_encapsulated_proto != bpf_htons(ETH_P_OPCUA_PUBSUB)) |
| 48 |
return XDP_PASS; |
| 49 |
|
| 50 |
|
| 51 |
if ((bpf_ntohs(veth->vlantci) & VLAN_ID_MASK) != 100) |
| 52 |
return XDP_PASS; |
| 53 |
|
| 54 |
|
| 55 |
if (bpf_map_lookup_elem(&xsks_map, &idx)) { |
| 56 |
populate_rx_timestamp(ctx); |
| 57 |
return bpf_redirect_map(&xsks_map, idx, 0); |
| 58 |
} |
| 59 |
|
| 60 |
return XDP_PASS; |
| 61 |
} |
| 62 |
|
| 63 |
char _license[] SEC("license") = "Dual BSD/GPL"; |