Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/* Copyright (c) 2023 Isovalent */
  3#include <stdbool.h>
  4
  5#include <linux/bpf.h>
  6#include <linux/if_ether.h>
  7#include <linux/stddef.h>
  8#include <linux/if_packet.h>
  9#include <bpf/bpf_endian.h>
 10#include <bpf/bpf_helpers.h>
 11
 12char LICENSE[] SEC("license") = "GPL";
 13
 14bool seen_tc1;
 15bool seen_tc2;
 16bool seen_tc3;
 17bool seen_tc4;
 18bool seen_tc5;
 19bool seen_tc6;
 20bool seen_tc7;
 21bool seen_tc8;
 22
 23bool set_type;
 24
 25bool seen_eth;
 26bool seen_host;
 27bool seen_mcast;
 28
 29int mark, prio;
 30
 31SEC("tc/ingress")
 32int tc1(struct __sk_buff *skb)
 33{
 34	struct ethhdr eth = {};
 35
 36	if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
 37		goto out;
 38	if (bpf_skb_load_bytes(skb, 0, &eth, sizeof(eth)))
 39		goto out;
 40	seen_eth = eth.h_proto == bpf_htons(ETH_P_IP);
 41	seen_host = skb->pkt_type == PACKET_HOST;
 42	if (seen_host && set_type) {
 43		eth.h_dest[0] = 4;
 44		if (bpf_skb_store_bytes(skb, 0, &eth, sizeof(eth), 0))
 45			goto fail;
 46		bpf_skb_change_type(skb, PACKET_MULTICAST);
 47	}
 48out:
 49	seen_tc1 = true;
 50fail:
 51	return TCX_NEXT;
 52}
 53
 54SEC("tc/egress")
 55int tc2(struct __sk_buff *skb)
 56{
 57	seen_tc2 = true;
 58	return TCX_NEXT;
 59}
 60
 61SEC("tc/egress")
 62int tc3(struct __sk_buff *skb)
 63{
 64	seen_tc3 = true;
 65	return TCX_NEXT;
 66}
 67
 68SEC("tc/egress")
 69int tc4(struct __sk_buff *skb)
 70{
 71	seen_tc4 = true;
 72	return TCX_NEXT;
 73}
 74
 75SEC("tc/egress")
 76int tc5(struct __sk_buff *skb)
 77{
 78	seen_tc5 = true;
 79	return TCX_PASS;
 80}
 81
 82SEC("tc/egress")
 83int tc6(struct __sk_buff *skb)
 84{
 85	seen_tc6 = true;
 86	return TCX_PASS;
 87}
 88
 89SEC("tc/ingress")
 90int tc7(struct __sk_buff *skb)
 91{
 92	struct ethhdr eth = {};
 93
 94	if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
 95		goto out;
 96	if (bpf_skb_load_bytes(skb, 0, &eth, sizeof(eth)))
 97		goto out;
 98	if (eth.h_dest[0] == 4 && set_type) {
 99		seen_mcast = skb->pkt_type == PACKET_MULTICAST;
100		bpf_skb_change_type(skb, PACKET_HOST);
101	}
102out:
103	seen_tc7 = true;
104	return TCX_PASS;
105}
106
107SEC("tc/egress")
108int tc8(struct __sk_buff *skb)
109{
110	seen_tc8 = true;
111	mark = skb->mark;
112	prio = skb->priority;
113	return TCX_PASS;
114}
v6.9.4
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2023 Isovalent */
 3#include <stdbool.h>
 4
 5#include <linux/bpf.h>
 6#include <linux/if_ether.h>
 7
 
 8#include <bpf/bpf_endian.h>
 9#include <bpf/bpf_helpers.h>
10
11char LICENSE[] SEC("license") = "GPL";
12
13bool seen_tc1;
14bool seen_tc2;
15bool seen_tc3;
16bool seen_tc4;
17bool seen_tc5;
18bool seen_tc6;
 
 
 
 
 
19bool seen_eth;
 
 
 
 
20
21SEC("tc/ingress")
22int tc1(struct __sk_buff *skb)
23{
24	struct ethhdr eth = {};
25
26	if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
27		goto out;
28	if (bpf_skb_load_bytes(skb, 0, &eth, sizeof(eth)))
29		goto out;
30	seen_eth = eth.h_proto == bpf_htons(ETH_P_IP);
 
 
 
 
 
 
 
31out:
32	seen_tc1 = true;
 
33	return TCX_NEXT;
34}
35
36SEC("tc/egress")
37int tc2(struct __sk_buff *skb)
38{
39	seen_tc2 = true;
40	return TCX_NEXT;
41}
42
43SEC("tc/egress")
44int tc3(struct __sk_buff *skb)
45{
46	seen_tc3 = true;
47	return TCX_NEXT;
48}
49
50SEC("tc/egress")
51int tc4(struct __sk_buff *skb)
52{
53	seen_tc4 = true;
54	return TCX_NEXT;
55}
56
57SEC("tc/egress")
58int tc5(struct __sk_buff *skb)
59{
60	seen_tc5 = true;
61	return TCX_PASS;
62}
63
64SEC("tc/egress")
65int tc6(struct __sk_buff *skb)
66{
67	seen_tc6 = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68	return TCX_PASS;
69}