blob: 526d0b126b0b23f251f6dac9ac52ff49df0ca2a1 [file] [log] [blame]
Jiri Pirko1d129d12015-01-19 16:56:29 +01001/*
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 Pirko1d129d12015-01-19 16:56:29 +010016#include <linux/netlink.h>
Daniel Borkmann11c39b52015-03-16 19:37:41 +010017#include <linux/bpf.h>
Daniel Borkmann32e93fb2015-11-13 00:39:29 +010018#include <linux/magic.h>
Daniel Borkmann11c39b52015-03-16 19:37:41 +010019
20#include "utils.h"
Daniel Borkmann4bd62442015-04-16 21:20:06 +020021#include "bpf_scm.h"
Daniel Borkmann11c39b52015-03-16 19:37:41 +010022
Daniel Borkmann32e93fb2015-11-13 00:39:29 +010023enum {
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 Borkmann88eea532015-06-02 23:35:34 +020033#define BPF_ENV_UDS "TC_BPF_UDS"
Daniel Borkmann32e93fb2015-11-13 00:39:29 +010034#define BPF_ENV_MNT "TC_BPF_MNT"
35#define BPF_ENV_NOLOG "TC_BPF_NOLOG"
Daniel Borkmann88eea532015-06-02 23:35:34 +020036
Daniel Borkmann32e93fb2015-11-13 00:39:29 +010037#ifndef BPF_FS_MAGIC
38# define BPF_FS_MAGIC 0xcafe4a11
39#endif
Jiri Pirko1d129d12015-01-19 16:56:29 +010040
Daniel Borkmann32e93fb2015-11-13 00:39:29 +010041#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
52int bpf_trace_pipe(void);
Daniel Borkmann6256f8c2015-04-01 17:57:44 +020053const char *bpf_default_section(const enum bpf_prog_type type);
54
Daniel Borkmann32e93fb2015-11-13 00:39:29 +010055int 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 Borkmann91d88ee2015-11-26 15:38:45 +010058int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv);
Daniel Borkmann4bd62442015-04-16 21:20:06 +020059
Daniel Borkmann32e93fb2015-11-13 00:39:29 +010060void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len);
61
62#ifdef HAVE_ELF
Daniel Borkmann4bd62442015-04-16 21:20:06 +020063int bpf_send_map_fds(const char *path, const char *obj);
64int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
65 unsigned int entries);
Daniel Borkmann11c39b52015-03-16 19:37:41 +010066#else
Daniel Borkmann4bd62442015-04-16 21:20:06 +020067static inline int bpf_send_map_fds(const char *path, const char *obj)
Daniel Borkmann6256f8c2015-04-01 17:57:44 +020068{
69 return 0;
70}
Daniel Borkmann4bd62442015-04-16 21:20:06 +020071
72static 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}
Daniel Borkmann11c39b52015-03-16 19:37:41 +010078#endif /* HAVE_ELF */
79#endif /* _TC_BPF_H_ */