~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_tc_link.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 12 char LICENSE[] SEC("license") = "GPL";
 13 
 14 bool seen_tc1;
 15 bool seen_tc2;
 16 bool seen_tc3;
 17 bool seen_tc4;
 18 bool seen_tc5;
 19 bool seen_tc6;
 20 bool seen_tc7;
 21 
 22 bool set_type;
 23 
 24 bool seen_eth;
 25 bool seen_host;
 26 bool seen_mcast;
 27 
 28 SEC("tc/ingress")
 29 int tc1(struct __sk_buff *skb)
 30 {
 31         struct ethhdr eth = {};
 32 
 33         if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
 34                 goto out;
 35         if (bpf_skb_load_bytes(skb, 0, &eth, sizeof(eth)))
 36                 goto out;
 37         seen_eth = eth.h_proto == bpf_htons(ETH_P_IP);
 38         seen_host = skb->pkt_type == PACKET_HOST;
 39         if (seen_host && set_type) {
 40                 eth.h_dest[0] = 4;
 41                 if (bpf_skb_store_bytes(skb, 0, &eth, sizeof(eth), 0))
 42                         goto fail;
 43                 bpf_skb_change_type(skb, PACKET_MULTICAST);
 44         }
 45 out:
 46         seen_tc1 = true;
 47 fail:
 48         return TCX_NEXT;
 49 }
 50 
 51 SEC("tc/egress")
 52 int tc2(struct __sk_buff *skb)
 53 {
 54         seen_tc2 = true;
 55         return TCX_NEXT;
 56 }
 57 
 58 SEC("tc/egress")
 59 int tc3(struct __sk_buff *skb)
 60 {
 61         seen_tc3 = true;
 62         return TCX_NEXT;
 63 }
 64 
 65 SEC("tc/egress")
 66 int tc4(struct __sk_buff *skb)
 67 {
 68         seen_tc4 = true;
 69         return TCX_NEXT;
 70 }
 71 
 72 SEC("tc/egress")
 73 int tc5(struct __sk_buff *skb)
 74 {
 75         seen_tc5 = true;
 76         return TCX_PASS;
 77 }
 78 
 79 SEC("tc/egress")
 80 int tc6(struct __sk_buff *skb)
 81 {
 82         seen_tc6 = true;
 83         return TCX_PASS;
 84 }
 85 
 86 SEC("tc/ingress")
 87 int tc7(struct __sk_buff *skb)
 88 {
 89         struct ethhdr eth = {};
 90 
 91         if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
 92                 goto out;
 93         if (bpf_skb_load_bytes(skb, 0, &eth, sizeof(eth)))
 94                 goto out;
 95         if (eth.h_dest[0] == 4 && set_type) {
 96                 seen_mcast = skb->pkt_type == PACKET_MULTICAST;
 97                 bpf_skb_change_type(skb, PACKET_HOST);
 98         }
 99 out:
100         seen_tc7 = true;
101         return TCX_PASS;
102 }
103 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php