1 /*
2 * tc_bpf.h BPF common code
3 *
4 * This program is free software; you can distribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Daniel Borkmann <dborkman@redhat.com>
10 * Jiri Pirko <jiri@resnulli.us>
11 */
12
13 #ifndef _TC_BPF_H_
14 #define _TC_BPF_H_ 1
15
16 #include <linux/netlink.h>
17 #include <linux/bpf.h>
18 #include <linux/magic.h>
19
20 #include "utils.h"
21 #include "bpf_scm.h"
22
23 enum {
24 BPF_NLA_OPS_LEN = 0,
25 BPF_NLA_OPS,
26 BPF_NLA_FD,
27 BPF_NLA_NAME,
28 __BPF_NLA_MAX,
29 };
30
31 #define BPF_NLA_MAX __BPF_NLA_MAX
32
33 #define BPF_ENV_UDS "TC_BPF_UDS"
34 #define BPF_ENV_MNT "TC_BPF_MNT"
35 #define BPF_ENV_NOLOG "TC_BPF_NOLOG"
36
37 #ifndef BPF_FS_MAGIC
38 # define BPF_FS_MAGIC 0xcafe4a11
39 #endif
40
41 #define BPF_DIR_MNT "/sys/fs/bpf"
42
43 #define BPF_DIR_TC "tc"
44 #define BPF_DIR_GLOBALS "globals"
45
46 #ifndef TRACEFS_MAGIC
47 # define TRACEFS_MAGIC 0x74726163
48 #endif
49
50 #define TRACE_DIR_MNT "/sys/kernel/tracing"
51
52 int bpf_trace_pipe(void);
53 const char *bpf_default_section(const enum bpf_prog_type type);
54
55 int bpf_parse_common(int *ptr_argc, char ***ptr_argv, const int *nla_tbl,
56 enum bpf_prog_type type, const char **ptr_object,
57 const char **ptr_uds_name, struct nlmsghdr *n);
58 int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv);
59
60 void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len);
61
62 #ifdef HAVE_ELF
63 int bpf_send_map_fds(const char *path, const char *obj);
64 int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
65 unsigned int entries);
66 #else
bpf_send_map_fds(const char * path,const char * obj)67 static inline int bpf_send_map_fds(const char *path, const char *obj)
68 {
69 return 0;
70 }
71
bpf_recv_map_fds(const char * path,int * fds,struct bpf_map_aux * aux,unsigned int entries)72 static inline int bpf_recv_map_fds(const char *path, int *fds,
73 struct bpf_map_aux *aux,
74 unsigned int entries)
75 {
76 return -1;
77 }
78 #endif /* HAVE_ELF */
79 #endif /* _TC_BPF_H_ */
80