| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <linux/bpf.h> |
| 8 |
#include <linux/types.h> |
| 9 |
|
| 10 |
#include <bpf/bpf_endian.h> |
| 11 |
#include <bpf/bpf_helpers.h> |
| 12 |
|
| 13 |
#include <xdp/xdp_helpers.h> |
| 14 |
|
| 15 |
#include "net_def.h" |
| 16 |
#include "xdp_metadata.c" |
| 17 |
|
| 18 |
struct { |
| 19 |
__uint(type, BPF_MAP_TYPE_XSKMAP); |
| 20 |
__uint(key_size, sizeof(int)); |
| 21 |
__uint(value_size, sizeof(int)); |
| 22 |
__uint(max_entries, 128); |
| 23 |
} xsks_map SEC(".maps"); |
| 24 |
|
| 25 |
struct { |
| 26 |
__uint(priority, 10); |
| 27 |
__uint(XDP_PASS, 1); |
| 28 |
} XDP_RUN_CONFIG(xdp_sock_prog); |
| 29 |
|
| 30 |
SEC("xdp_sock") |
| 31 |
int xdp_sock_prog(struct xdp_md *ctx) |
| 32 |
{ |
| 33 |
void *data_end = (void *)(long)ctx->data_end; |
| 34 |
void *data = (void *)(long)ctx->data; |
| 35 |
struct vlan_ethernet_header *veth; |
| 36 |
int idx = ctx->rx_queue_index; |
| 37 |
struct profinet_rt_header *rt; |
| 38 |
__be16 frame_id; |
| 39 |
void *p = data; |
| 40 |
|
| 41 |
veth = p; |
| 42 |
if ((void *)(veth + 1) > data_end) |
| 43 |
return XDP_PASS; |
| 44 |
p += sizeof(*veth); |
| 45 |
|
| 46 |
|
| 47 |
if (veth->vlan_proto != bpf_htons(ETH_P_8021Q)) |
| 48 |
return XDP_PASS; |
| 49 |
|
| 50 |
|
| 51 |
if (veth->vlan_encapsulated_proto != bpf_htons(ETH_P_PROFINET_RT)) |
| 52 |
return XDP_PASS; |
| 53 |
|
| 54 |
|
| 55 |
if ((bpf_ntohs(veth->vlantci) & VLAN_ID_MASK) != 200) |
| 56 |
return XDP_PASS; |
| 57 |
|
| 58 |
|
| 59 |
rt = p; |
| 60 |
if ((void *)(rt + 1) > data_end) |
| 61 |
return XDP_PASS; |
| 62 |
p += sizeof(*rt); |
| 63 |
|
| 64 |
frame_id = bpf_htons(rt->frame_id); |
| 65 |
switch (frame_id) { |
| 66 |
case TSN_HIGH_FRAMEID: |
| 67 |
case TSN_HIGH_SEC_FRAMEID: |
| 68 |
case TSN_LOW_FRAMEID: |
| 69 |
case TSN_LOW_SEC_FRAMEID: |
| 70 |
case RTC_FRAMEID: |
| 71 |
case RTC_SEC_FRAMEID: |
| 72 |
case RTA_FRAMEID: |
| 73 |
case RTA_SEC_FRAMEID: |
| 74 |
goto redirect; |
| 75 |
default: |
| 76 |
return XDP_PASS; |
| 77 |
} |
| 78 |
|
| 79 |
redirect: |
| 80 |
|
| 81 |
if (bpf_map_lookup_elem(&xsks_map, &idx)) { |
| 82 |
populate_rx_timestamp(ctx); |
| 83 |
return bpf_redirect_map(&xsks_map, idx, 0); |
| 84 |
} |
| 85 |
|
| 86 |
return XDP_PASS; |
| 87 |
} |
| 88 |
|
| 89 |
char _license[] SEC("license") = "Dual BSD/GPL"; |