Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
31571b4f
Commit
31571b4f
authored
Mar 31, 2016
by
Brenden Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #472 from iovisor/ast_dev
get rid of version checks
parents
63a88006
f09b5b8a
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
414 additions
and
18 deletions
+414
-18
src/cc/compat/linux/bpf.h
src/cc/compat/linux/bpf.h
+21
-0
src/cc/compat/linux/virtual_bpf.h
src/cc/compat/linux/virtual_bpf.h
+384
-0
src/cc/export/helpers.h
src/cc/export/helpers.h
+0
-10
src/cc/exported_files.cc
src/cc/exported_files.cc
+4
-0
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+3
-6
src/cc/frontends/clang/loader.cc
src/cc/frontends/clang/loader.cc
+2
-2
No files found.
src/cc/compat/linux/bpf.h
View file @
31571b4f
...
...
@@ -101,12 +101,15 @@ enum bpf_prog_type {
#define BPF_NOEXIST 1
/* create new element if it didn't exist */
#define BPF_EXIST 2
/* update existing element */
#define BPF_F_NO_PREALLOC (1U << 0)
union
bpf_attr
{
struct
{
/* anonymous struct used by BPF_MAP_CREATE command */
__u32
map_type
;
/* one of enum bpf_map_type */
__u32
key_size
;
/* size of key in bytes */
__u32
value_size
;
/* size of value in bytes */
__u32
max_entries
;
/* max number of entries in a map */
__u32
map_flags
;
/* prealloc or not */
};
struct
{
/* anonymous struct used by BPF_MAP_*_ELEM commands */
...
...
@@ -298,6 +301,17 @@ enum bpf_func_id {
* Return: csum result
*/
BPF_FUNC_csum_diff
,
/**
* bpf_skb_[gs]et_tunnel_opt(skb, opt, size)
* retrieve or populate tunnel options metadata
* @skb: pointer to skb
* @opt: pointer to raw tunnel option data
* @size: size of @opt
* Return: 0 on success for set, option size for get
*/
BPF_FUNC_skb_get_tunnel_opt
,
BPF_FUNC_skb_set_tunnel_opt
,
__BPF_FUNC_MAX_ID
,
};
...
...
@@ -305,6 +319,7 @@ enum bpf_func_id {
/* BPF_FUNC_skb_store_bytes flags. */
#define BPF_F_RECOMPUTE_CSUM (1ULL << 0)
#define BPF_F_INVALIDATE_HASH (1ULL << 1)
/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
* First 4 bits are for passing the header field size.
...
...
@@ -327,6 +342,10 @@ enum bpf_func_id {
#define BPF_F_FAST_STACK_CMP (1ULL << 9)
#define BPF_F_REUSE_STACKID (1ULL << 10)
/* BPF_FUNC_skb_set_tunnel_key flags. */
#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
#define BPF_F_DONT_FRAGMENT (1ULL << 2)
/* user accessible mirror of in-kernel sk_buff.
* new fields can only be added to the end of this structure
*/
...
...
@@ -356,6 +375,8 @@ struct bpf_tunnel_key {
};
__u8
tunnel_tos
;
__u8
tunnel_ttl
;
__u16
tunnel_ext
;
__u32
tunnel_label
;
};
#endif
/* _UAPI__LINUX_BPF_H__ */
src/cc/compat/linux/virtual_bpf.h
0 → 100644
View file @
31571b4f
This diff is collapsed.
Click to expand it.
src/cc/export/helpers.h
View file @
31571b4f
...
...
@@ -142,7 +142,6 @@ static u32 (*bpf_get_prandom_u32)(void) =
static int (*bpf_trace_printk_)(const char *fmt, u64 fmt_size, ...) =
(void *) BPF_FUNC_trace_printk;
int bpf_trace_printk(const char *fmt, ...) asm("
llvm
.
bpf
.
extra
");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
static void bpf_tail_call_(u64 map_fd, void *ctx, int index) {
((void (*)(void *, u64, int))BPF_FUNC_tail_call)(ctx, map_fd, index);
}
...
...
@@ -156,8 +155,6 @@ static u64 (*bpf_get_current_uid_gid)(void) =
(void *) BPF_FUNC_get_current_uid_gid;
static int (*bpf_get_current_comm)(void *buf, int buf_size) =
(void *) BPF_FUNC_get_current_comm;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
static u64 (*bpf_get_cgroup_classid)(void *ctx) =
(void *) BPF_FUNC_get_cgroup_classid;
static u64 (*bpf_skb_vlan_push)(void *ctx, u16 proto, u16 vlan_tci) =
...
...
@@ -170,20 +167,14 @@ static int (*bpf_skb_set_tunnel_key)(void *ctx, void *from, u32 size, u64 flags)
(void *) BPF_FUNC_skb_set_tunnel_key;
static int (*bpf_perf_event_read)(void *map, u32 index) =
(void *) BPF_FUNC_perf_event_read;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0)
static int (*bpf_redirect)(int ifindex, u32 flags) =
(void *) BPF_FUNC_redirect;
static u32 (*bpf_get_route_realm)(void *ctx) =
(void *) BPF_FUNC_get_route_realm;
static int (*bpf_perf_event_output)(void *ctx, void *map, u32 index, void *data, u32 size) =
(void *) BPF_FUNC_perf_event_output;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0)
static int (*bpf_skb_load_bytes)(void *ctx, int offset, void *to, u32 len) =
(void *) BPF_FUNC_skb_load_bytes;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
static int (*bpf_get_stackid_)(void *ctx, void *map, u64 flags) =
(void *) BPF_FUNC_get_stackid;
static inline __attribute__((always_inline))
...
...
@@ -192,7 +183,6 @@ int bpf_get_stackid(uintptr_t map, void *ctx, u64 flags) {
}
static int (*bpf_csum_diff)(void *from, u64 from_size, void *to, u64 to_size, u64 seed) =
(void *) BPF_FUNC_csum_diff;
#endif
/* llvm builtin functions that eBPF C program may use to
* emit BPF_LD_ABS and BPF_LD_IND instructions
...
...
src/cc/exported_files.cc
View file @
31571b4f
...
...
@@ -25,6 +25,10 @@ namespace ebpf {
// see http://www.stroustrup.com/C++11FAQ.html#raw-strings
map
<
string
,
const
char
*>
ExportedFiles
::
headers_
=
{
{
"/virtual/include/bcc/bpf.h"
,
#include "compat/linux/virtual_bpf.h"
},
{
"/virtual/include/bcc/proto.h"
,
#include "export/proto.h"
...
...
src/cc/frontends/clang/b_frontend_action.cc
View file @
31571b4f
...
...
@@ -585,17 +585,14 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
diag_
.
Report
(
Decl
->
getLocStart
(),
diag_id
)
<<
table
.
leaf_desc
;
}
}
else
if
(
A
->
getName
()
==
"maps/prog"
)
{
if
(
KERNEL_VERSION
(
major
,
minor
,
0
)
>=
KERNEL_VERSION
(
4
,
2
,
0
))
map_type
=
BPF_MAP_TYPE_PROG_ARRAY
;
}
else
if
(
A
->
getName
()
==
"maps/perf_output"
)
{
if
(
KERNEL_VERSION
(
major
,
minor
,
0
)
>=
KERNEL_VERSION
(
4
,
3
,
0
))
map_type
=
BPF_MAP_TYPE_PERF_EVENT_ARRAY
;
int
numcpu
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
if
(
numcpu
<=
0
)
numcpu
=
1
;
table
.
max_entries
=
numcpu
;
}
else
if
(
A
->
getName
()
==
"maps/perf_array"
)
{
if
(
KERNEL_VERSION
(
major
,
minor
,
0
)
>=
KERNEL_VERSION
(
4
,
3
,
0
))
map_type
=
BPF_MAP_TYPE_PERF_EVENT_ARRAY
;
}
else
if
(
A
->
getName
()
==
"maps/stacktrace"
)
{
map_type
=
BPF_MAP_TYPE_STACK_TRACE
;
...
...
src/cc/frontends/clang/loader.cc
View file @
31571b4f
...
...
@@ -77,8 +77,6 @@ int ClangLoader::parse(unique_ptr<llvm::Module> *mod, unique_ptr<vector<TableDes
using
namespace
clang
;
string
main_path
=
"/virtual/main.c"
;
string
proto_path
=
"/virtual/include/bcc/proto.h"
;
string
helpers_path
=
"/virtual/include/bcc/helpers.h"
;
unique_ptr
<
llvm
::
MemoryBuffer
>
main_buf
;
struct
utsname
un
;
uname
(
&
un
);
...
...
@@ -110,6 +108,8 @@ int ClangLoader::parse(unique_ptr<llvm::Module> *mod, unique_ptr<vector<TableDes
if
(
kbuild_helper
.
get_flags
(
un
.
machine
,
&
kflags
))
return
-
1
;
kflags
.
push_back
(
"-include"
);
kflags
.
push_back
(
"/virtual/include/bcc/bpf.h"
);
kflags
.
push_back
(
"-include"
);
kflags
.
push_back
(
"/virtual/include/bcc/helpers.h"
);
kflags
.
push_back
(
"-isystem"
);
kflags
.
push_back
(
"/virtual/include"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment