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
5270dcd5
Commit
5270dcd5
authored
Jun 11, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #50 from iovisor/bblanco_dev
Remove the BPF_EXPORT macro, use rewriter instead
parents
2e657fe8
0283f825
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
13 additions
and
25 deletions
+13
-25
examples/hello_world.py
examples/hello_world.py
+0
-1
examples/vlan_learning.c
examples/vlan_learning.c
+0
-2
src/cc/b_frontend_action.cc
src/cc/b_frontend_action.cc
+6
-0
src/cc/export/helpers.h
src/cc/export/helpers.h
+7
-8
tests/cc/test_brb.c
tests/cc/test_brb.c
+0
-3
tests/cc/test_brb2.c
tests/cc/test_brb2.c
+0
-1
tests/cc/test_call1.c
tests/cc/test_call1.c
+0
-4
tests/cc/test_stat1.c
tests/cc/test_stat1.c
+0
-1
tests/cc/test_trace2.c
tests/cc/test_trace2.c
+0
-1
tests/cc/test_trace2.py
tests/cc/test_trace2.py
+0
-1
tests/cc/test_trace3.c
tests/cc/test_trace3.c
+0
-2
tests/cc/test_xlate1.c
tests/cc/test_xlate1.c
+0
-1
No files found.
examples/hello_world.py
View file @
5270dcd5
...
...
@@ -9,7 +9,6 @@ from bpf import BPF
from
subprocess
import
call
prog
=
"""
BPF_EXPORT(hello)
int hello(void *ctx) {
char fmt[] = "Hello, World!
\
\
n";
bpf_trace_printk(fmt, sizeof(fmt));
...
...
examples/vlan_learning.c
View file @
5270dcd5
...
...
@@ -15,7 +15,6 @@ BPF_TABLE("hash", u64, struct ifindex_leaf_t, egress, 4096);
// redirect based on mac -> out_ifindex (config-driven)
BPF_TABLE
(
"hash"
,
u64
,
struct
ifindex_leaf_t
,
ingress
,
4096
);
BPF_EXPORT
(
handle_phys2virt
)
int
handle_phys2virt
(
struct
__sk_buff
*
skb
)
{
BEGIN
(
ethernet
);
PROTO
(
ethernet
)
{
...
...
@@ -37,7 +36,6 @@ EOP:
return
1
;
}
BPF_EXPORT
(
handle_virt2phys
)
int
handle_virt2phys
(
struct
__sk_buff
*
skb
)
{
BEGIN
(
ethernet
);
PROTO
(
ethernet
)
{
...
...
src/cc/b_frontend_action.cc
View file @
5270dcd5
...
...
@@ -39,6 +39,12 @@ BTypeVisitor::BTypeVisitor(ASTContext &C, Rewriter &rewriter, map<string, BPFTab
}
bool
BTypeVisitor
::
VisitFunctionDecl
(
FunctionDecl
*
D
)
{
// put each non-static non-inline function decl in its own section, to be
// extracted by the MemoryManager
if
(
D
->
isExternallyVisible
()
&&
D
->
hasBody
())
{
string
attr
=
string
(
"__attribute__((section(
\"
."
)
+
D
->
getName
().
str
()
+
"
\"
)))"
;
rewriter_
.
InsertText
(
D
->
getLocStart
(),
attr
);
}
return
true
;
}
...
...
src/cc/export/helpers.h
View file @
5270dcd5
...
...
@@ -42,8 +42,6 @@ __attribute__((section("maps/" _table_type))) \
struct _name##_table_t _name
// packet parsing state machine helpers
#define STATE_MACHINE(name) \
BPF_EXPORT(name) int _##name(struct __sk_buff *skb)
#define BEGIN(next) \
u64 _parse_cursor = 0; \
goto next
...
...
@@ -54,10 +52,6 @@ name: ; \
struct name##_t *name __attribute__((deprecated("packet"))) = (void *)_parse_cursor; \
_parse_cursor += sizeof(*name);
// export this function to llvm by putting it into a specially named section
//#define BPF_EXPORT(_ret, _name, ...) SEC("." #_name) _ret _name(__VA_ARGS__)
#define BPF_EXPORT(_name) __attribute__((section("." #_name)))
char
_license
[
4
]
SEC
(
"license"
)
=
"GPL"
;
unsigned
_version
SEC
(
"version"
)
=
LINUX_VERSION_CODE
;
...
...
@@ -163,7 +157,7 @@ static inline void bpf_store_dword(void *skb, u64 off, u64 val) {
struct
bpf_context
;
//
static inline __attribute__((always_inline))
static
inline
__attribute__
((
always_inline
))
SEC
(
"helpers"
)
u64
bpf_dext_pkt
(
void
*
pkt
,
u64
off
,
u64
bofs
,
u64
bsz
)
{
if
(
bofs
==
0
&&
bsz
==
8
)
{
...
...
@@ -186,7 +180,7 @@ u64 bpf_dext_pkt(void *pkt, u64 off, u64 bofs, u64 bsz) {
return
0
;
}
//
static inline __attribute__((always_inline))
static
inline
__attribute__
((
always_inline
))
SEC
(
"helpers"
)
void
bpf_dins_pkt
(
void
*
pkt
,
u64
off
,
u64
bofs
,
u64
bsz
,
u64
val
)
{
// The load_xxx function does a bswap before returning the short/word/dword,
...
...
@@ -229,21 +223,25 @@ void bpf_dins_pkt(void *pkt, u64 off, u64 bofs, u64 bsz, u64 val) {
}
}
static
inline
__attribute__
((
always_inline
))
SEC
(
"helpers"
)
void
*
bpf_map_lookup_elem_
(
uintptr_t
map
,
void
*
key
)
{
return
bpf_map_lookup_elem
((
void
*
)
map
,
key
);
}
static
inline
__attribute__
((
always_inline
))
SEC
(
"helpers"
)
int
bpf_map_update_elem_
(
uintptr_t
map
,
void
*
key
,
void
*
value
,
u64
flags
)
{
return
bpf_map_update_elem
((
void
*
)
map
,
key
,
value
,
flags
);
}
static
inline
__attribute__
((
always_inline
))
SEC
(
"helpers"
)
int
bpf_map_delete_elem_
(
uintptr_t
map
,
void
*
key
)
{
return
bpf_map_delete_elem
((
void
*
)
map
,
key
);
}
static
inline
__attribute__
((
always_inline
))
SEC
(
"helpers"
)
int
bpf_l3_csum_replace_
(
void
*
ctx
,
u64
off
,
u64
from
,
u64
to
,
u64
flags
)
{
switch
(
flags
&
0xf
)
{
...
...
@@ -259,6 +257,7 @@ int bpf_l3_csum_replace_(void *ctx, u64 off, u64 from, u64 to, u64 flags) {
return
bpf_l3_csum_replace
(
ctx
,
off
,
from
,
to
,
flags
);
}
static
inline
__attribute__
((
always_inline
))
SEC
(
"helpers"
)
int
bpf_l4_csum_replace_
(
void
*
ctx
,
u64
off
,
u64
from
,
u64
to
,
u64
flags
)
{
switch
(
flags
&
0xf
)
{
...
...
tests/cc/test_brb.c
View file @
5270dcd5
...
...
@@ -54,7 +54,6 @@ BPF_TABLE("array", u32, u32, br2_rtr, 1);
// <mac, ifindex>
BPF_TABLE
(
"hash"
,
eth_addr_t
,
u32
,
br2_mac_ifindex
,
1
);
BPF_EXPORT
(
pem
)
int
pem
(
struct
__sk_buff
*
skb
)
{
bpf_metadata_t
meta
=
{};
u32
ifindex
;
...
...
@@ -217,12 +216,10 @@ EOP:
return
0
;
}
BPF_EXPORT
(
br1
)
int
br1
(
struct
__sk_buff
*
skb
)
{
return
br_common
(
skb
,
1
);
}
BPF_EXPORT
(
br2
)
int
br2
(
struct
__sk_buff
*
skb
)
{
return
br_common
(
skb
,
2
);
}
tests/cc/test_brb2.c
View file @
5270dcd5
...
...
@@ -8,7 +8,6 @@ BPF_TABLE("hash", u32, u32, pem_dest, 256);
// <0, tx_pkts>
BPF_TABLE
(
"array"
,
u32
,
u32
,
pem_stats
,
1
);
BPF_EXPORT
(
pem
)
int
pem
(
struct
__sk_buff
*
skb
)
{
u32
ifindex_in
,
*
ifindex_p
;
...
...
tests/cc/test_call1.c
View file @
5270dcd5
...
...
@@ -11,7 +11,6 @@ enum states {
S_IP
};
BPF_EXPORT
(
parse_ether
)
int
parse_ether
(
struct
__sk_buff
*
skb
)
{
size_t
cur
=
0
;
size_t
next
=
cur
+
14
;
...
...
@@ -28,7 +27,6 @@ int parse_ether(struct __sk_buff *skb) {
return
1
;
}
BPF_EXPORT
(
parse_arp
)
int
parse_arp
(
struct
__sk_buff
*
skb
)
{
size_t
cur
=
14
;
// TODO: get from ctx
size_t
next
=
cur
+
28
;
...
...
@@ -41,7 +39,6 @@ int parse_arp(struct __sk_buff *skb) {
return
1
;
}
BPF_EXPORT
(
parse_ip
)
int
parse_ip
(
struct
__sk_buff
*
skb
)
{
size_t
cur
=
14
;
// TODO: get from ctx
size_t
next
=
cur
+
20
;
...
...
@@ -54,7 +51,6 @@ int parse_ip(struct __sk_buff *skb) {
return
1
;
}
BPF_EXPORT
(
eop
)
int
eop
(
struct
__sk_buff
*
skb
)
{
int
key
=
S_EOP
;
u64
*
leaf
=
stats
.
lookup
(
&
key
);
...
...
tests/cc/test_stat1.c
View file @
5270dcd5
...
...
@@ -14,7 +14,6 @@ struct IPLeaf {
BPF_TABLE
(
"hash"
,
struct
IPKey
,
struct
IPLeaf
,
stats
,
256
);
BPF_EXPORT
(
on_packet
)
int
on_packet
(
struct
__sk_buff
*
skb
)
{
BEGIN
(
ethernet
);
...
...
tests/cc/test_trace2.c
View file @
5270dcd5
...
...
@@ -5,7 +5,6 @@ struct Ptr { u64 ptr; };
struct
Counters
{
u64
stat1
;
};
BPF_TABLE
(
"hash"
,
struct
Ptr
,
struct
Counters
,
stats
,
1024
);
BPF_EXPORT
(
count_sched
)
int
count_sched
(
struct
pt_regs
*
ctx
)
{
struct
Ptr
key
=
{.
ptr
=
ctx
->
bx
};
struct
Counters
zleaf
=
{
0
};
...
...
tests/cc/test_trace2.py
View file @
5270dcd5
...
...
@@ -14,7 +14,6 @@ struct Ptr { u64 ptr; };
struct Counters { u64 stat1; };
BPF_TABLE("hash", struct Ptr, struct Counters, stats, 1024);
BPF_EXPORT(count_sched)
int count_sched(struct pt_regs *ctx) {
struct Ptr key = {.ptr=ctx->bx};
stats.data[(u64)&key].stat1++;
...
...
tests/cc/test_trace3.c
View file @
5270dcd5
...
...
@@ -27,7 +27,6 @@ static u32 log2l(u64 v) {
return
log2
(
v
);
}
BPF_EXPORT
(
probe_blk_start_request
)
int
probe_blk_start_request
(
struct
pt_regs
*
ctx
)
{
struct
Request
rq
=
{.
rq
=
ctx
->
di
};
struct
Time
tm
=
{.
start
=
bpf_ktime_get_ns
()};
...
...
@@ -35,7 +34,6 @@ int probe_blk_start_request(struct pt_regs *ctx) {
return
0
;
}
BPF_EXPORT
(
probe_blk_update_request
)
int
probe_blk_update_request
(
struct
pt_regs
*
ctx
)
{
struct
Request
rq
=
{.
rq
=
ctx
->
di
};
struct
Time
*
tm
=
requests
.
lookup
(
&
rq
);
...
...
tests/cc/test_xlate1.c
View file @
5270dcd5
...
...
@@ -13,7 +13,6 @@ struct IPLeaf {
};
BPF_TABLE
(
"hash"
,
struct
IPKey
,
struct
IPLeaf
,
xlate
,
1024
);
BPF_EXPORT
(
on_packet
)
int
on_packet
(
struct
__sk_buff
*
skb
)
{
u32
orig_dip
=
0
;
...
...
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