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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/skb_pkt_end.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 #ifndef BPF_NO_PRESERVE_ACCESS_INDEX
  3 #define BPF_NO_PRESERVE_ACCESS_INDEX
  4 #endif
  5 #include <vmlinux.h>
  6 #include <bpf/bpf_core_read.h>
  7 #include <bpf/bpf_helpers.h>
  8 
  9 #define INLINE __always_inline
 10 
 11 #define skb_shorter(skb, len) ((void *)(long)(skb)->data + (len) > (void *)(long)skb->data_end)
 12 
 13 #define ETH_IPV4_TCP_SIZE (14 + sizeof(struct iphdr) + sizeof(struct tcphdr))
 14 
 15 static INLINE struct iphdr *get_iphdr(struct __sk_buff *skb)
 16 {
 17         struct iphdr *ip = NULL;
 18         struct ethhdr *eth;
 19 
 20         if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
 21                 goto out;
 22 
 23         eth = (void *)(long)skb->data;
 24         ip = (void *)(eth + 1);
 25 
 26 out:
 27         return ip;
 28 }
 29 
 30 SEC("tc")
 31 int main_prog(struct __sk_buff *skb)
 32 {
 33         struct iphdr *ip = NULL;
 34         struct tcphdr *tcp;
 35         __u8 proto = 0;
 36         int urg_ptr;
 37         u32 offset;
 38 
 39         if (!(ip = get_iphdr(skb)))
 40                 goto out;
 41 
 42         proto = ip->protocol;
 43 
 44         if (proto != IPPROTO_TCP)
 45                 goto out;
 46 
 47         tcp = (void*)(ip + 1);
 48         if (tcp->dest != 0)
 49                 goto out;
 50         if (!tcp)
 51                 goto out;
 52 
 53         urg_ptr = tcp->urg_ptr;
 54 
 55         /* Checksum validation part */
 56         proto++;
 57         offset = sizeof(struct ethhdr) + offsetof(struct iphdr, protocol);
 58         bpf_skb_store_bytes(skb, offset, &proto, sizeof(proto), BPF_F_RECOMPUTE_CSUM);
 59 
 60         return urg_ptr;
 61 out:
 62         return -1;
 63 }
 64 char _license[] SEC("license") = "GPL";
 65 

~ [ 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