xref: /linux/tools/testing/selftests/bpf/progs/changes_pkt_data.c (revision 35f301dd4551fa731db4834f915e8351838f6f19)
189ff4089SEduard Zingerman // SPDX-License-Identifier: GPL-2.0
289ff4089SEduard Zingerman 
389ff4089SEduard Zingerman #include <linux/bpf.h>
489ff4089SEduard Zingerman #include <bpf/bpf_helpers.h>
589ff4089SEduard Zingerman 
689ff4089SEduard Zingerman __noinline
changes_pkt_data(struct __sk_buff * sk)7*04789af7SEduard Zingerman long changes_pkt_data(struct __sk_buff *sk)
889ff4089SEduard Zingerman {
9*04789af7SEduard Zingerman 	return bpf_skb_pull_data(sk, 0);
1089ff4089SEduard Zingerman }
1189ff4089SEduard Zingerman 
1289ff4089SEduard Zingerman __noinline __weak
does_not_change_pkt_data(struct __sk_buff * sk)13*04789af7SEduard Zingerman long does_not_change_pkt_data(struct __sk_buff *sk)
1489ff4089SEduard Zingerman {
1589ff4089SEduard Zingerman 	return 0;
1689ff4089SEduard Zingerman }
1789ff4089SEduard Zingerman 
18*04789af7SEduard Zingerman SEC("?tc")
main_with_subprogs(struct __sk_buff * sk)19*04789af7SEduard Zingerman int main_with_subprogs(struct __sk_buff *sk)
2089ff4089SEduard Zingerman {
21*04789af7SEduard Zingerman 	changes_pkt_data(sk);
22*04789af7SEduard Zingerman 	does_not_change_pkt_data(sk);
23*04789af7SEduard Zingerman 	return 0;
24*04789af7SEduard Zingerman }
25*04789af7SEduard Zingerman 
26*04789af7SEduard Zingerman SEC("?tc")
main_changes(struct __sk_buff * sk)27*04789af7SEduard Zingerman int main_changes(struct __sk_buff *sk)
28*04789af7SEduard Zingerman {
29*04789af7SEduard Zingerman 	bpf_skb_pull_data(sk, 0);
30*04789af7SEduard Zingerman 	return 0;
31*04789af7SEduard Zingerman }
32*04789af7SEduard Zingerman 
33*04789af7SEduard Zingerman SEC("?tc")
main_does_not_change(struct __sk_buff * sk)34*04789af7SEduard Zingerman int main_does_not_change(struct __sk_buff *sk)
35*04789af7SEduard Zingerman {
3689ff4089SEduard Zingerman 	return 0;
3789ff4089SEduard Zingerman }
3889ff4089SEduard Zingerman 
3989ff4089SEduard Zingerman char _license[] SEC("license") = "GPL";
40