]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/testing/selftests/bpf/test_pkt_md_access.c
cpufreq: intel_pstate: report correct CPU frequencies during trace
[mirror_ubuntu-artful-kernel.git] / tools / testing / selftests / bpf / test_pkt_md_access.c
1 /* Copyright (c) 2017 Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7 #include <stddef.h>
8 #include <string.h>
9 #include <linux/bpf.h>
10 #include <linux/pkt_cls.h>
11 #include "bpf_helpers.h"
12
13 int _version SEC("version") = 1;
14
15 #define TEST_FIELD(TYPE, FIELD, MASK) \
16 { \
17 TYPE tmp = *(volatile TYPE *)&skb->FIELD; \
18 if (tmp != ((*(volatile __u32 *)&skb->FIELD) & MASK)) \
19 return TC_ACT_SHOT; \
20 }
21
22 SEC("test1")
23 int process(struct __sk_buff *skb)
24 {
25 TEST_FIELD(__u8, len, 0xFF);
26 TEST_FIELD(__u16, len, 0xFFFF);
27 TEST_FIELD(__u32, len, 0xFFFFFFFF);
28 TEST_FIELD(__u16, protocol, 0xFFFF);
29 TEST_FIELD(__u32, protocol, 0xFFFFFFFF);
30 TEST_FIELD(__u8, hash, 0xFF);
31 TEST_FIELD(__u16, hash, 0xFFFF);
32 TEST_FIELD(__u32, hash, 0xFFFFFFFF);
33
34 return TC_ACT_OK;
35 }