Jiri Pirko | 1d129d1 | 2015-01-19 16:56:29 +0100 | [diff] [blame] | 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 | |
Jiri Pirko | 1d129d1 | 2015-01-19 16:56:29 +0100 | [diff] [blame] | 16 | #include <linux/netlink.h> |
Daniel Borkmann | 11c39b5 | 2015-03-16 19:37:41 +0100 | [diff] [blame] | 17 | #include <linux/bpf.h> |
Daniel Borkmann | 32e93fb | 2015-11-13 00:39:29 +0100 | [diff] [blame^] | 18 | #include <linux/magic.h> |
Daniel Borkmann | 11c39b5 | 2015-03-16 19:37:41 +0100 | [diff] [blame] | 19 | |
| 20 | #include "utils.h" |
Daniel Borkmann | 4bd6244 | 2015-04-16 21:20:06 +0200 | [diff] [blame] | 21 | #include "bpf_scm.h" |
Daniel Borkmann | 11c39b5 | 2015-03-16 19:37:41 +0100 | [diff] [blame] | 22 | |
Daniel Borkmann | 32e93fb | 2015-11-13 00:39:29 +0100 | [diff] [blame^] | 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 | |
Daniel Borkmann | 88eea53 | 2015-06-02 23:35:34 +0200 | [diff] [blame] | 33 | #define BPF_ENV_UDS "TC_BPF_UDS" |
Daniel Borkmann | 32e93fb | 2015-11-13 00:39:29 +0100 | [diff] [blame^] | 34 | #define BPF_ENV_MNT "TC_BPF_MNT" |
| 35 | #define BPF_ENV_NOLOG "TC_BPF_NOLOG" |
Daniel Borkmann | 88eea53 | 2015-06-02 23:35:34 +0200 | [diff] [blame] | 36 | |
Daniel Borkmann | 32e93fb | 2015-11-13 00:39:29 +0100 | [diff] [blame^] | 37 | #ifndef BPF_FS_MAGIC |
| 38 | # define BPF_FS_MAGIC 0xcafe4a11 |
| 39 | #endif |
Jiri Pirko | 1d129d1 | 2015-01-19 16:56:29 +0100 | [diff] [blame] | 40 | |
Daniel Borkmann | 32e93fb | 2015-11-13 00:39:29 +0100 | [diff] [blame^] | 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); |
Daniel Borkmann | 6256f8c | 2015-04-01 17:57:44 +0200 | [diff] [blame] | 53 | const char *bpf_default_section(const enum bpf_prog_type type); |
| 54 | |
Daniel Borkmann | 32e93fb | 2015-11-13 00:39:29 +0100 | [diff] [blame^] | 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); |
Daniel Borkmann | 4bd6244 | 2015-04-16 21:20:06 +0200 | [diff] [blame] | 58 | |
Daniel Borkmann | 32e93fb | 2015-11-13 00:39:29 +0100 | [diff] [blame^] | 59 | void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len); |
| 60 | |
| 61 | #ifdef HAVE_ELF |
Daniel Borkmann | 4bd6244 | 2015-04-16 21:20:06 +0200 | [diff] [blame] | 62 | int bpf_send_map_fds(const char *path, const char *obj); |
| 63 | int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux, |
| 64 | unsigned int entries); |
Daniel Borkmann | 11c39b5 | 2015-03-16 19:37:41 +0100 | [diff] [blame] | 65 | #else |
Daniel Borkmann | 4bd6244 | 2015-04-16 21:20:06 +0200 | [diff] [blame] | 66 | static inline int bpf_send_map_fds(const char *path, const char *obj) |
Daniel Borkmann | 6256f8c | 2015-04-01 17:57:44 +0200 | [diff] [blame] | 67 | { |
| 68 | return 0; |
| 69 | } |
Daniel Borkmann | 4bd6244 | 2015-04-16 21:20:06 +0200 | [diff] [blame] | 70 | |
| 71 | static inline int bpf_recv_map_fds(const char *path, int *fds, |
| 72 | struct bpf_map_aux *aux, |
| 73 | unsigned int entries) |
| 74 | { |
| 75 | return -1; |
| 76 | } |
Daniel Borkmann | 11c39b5 | 2015-03-16 19:37:41 +0100 | [diff] [blame] | 77 | #endif /* HAVE_ELF */ |
| 78 | #endif /* _TC_BPF_H_ */ |