Debian Codegraph @

src/xdp_kern_avtp_vid400.c

raw symbols SCIP
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /*
3 * Copyright (C) 2022 Linutronix GmbH
4 * Author Kurt Kanzenbach <[email protected]>
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 /* Check for VLAN frames */
43 if (veth->vlan_proto != bpf_htons(ETH_P_8021Q))
44 return XDP_PASS;
45
46 /* Check for AVTP EtherType */
47 if (veth->vlan_encapsulated_proto != bpf_htons(ETH_P_AVTP))
48 return XDP_PASS;
49
50 /* Check for VID 400 */
51 if ((bpf_ntohs(veth->vlantci) & VLAN_ID_MASK) != 400)
52 return XDP_PASS;
53
54 /* If socket bound to rx_queue then redirect to user space */
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";