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
27a9cae5
Commit
27a9cae5
authored
Mar 06, 2017
by
Brenden Blanco
Committed by
GitHub
Mar 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1006 from pchaigno/fix-bpf_dins_pkt-rewrite
Fix bpf_dins_pkt rewrite in BinaryOperator
parents
bbba2d4e
47b74fe0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
+22
-4
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+3
-4
tests/python/test_clang.py
tests/python/test_clang.py
+19
-0
No files found.
src/cc/frontends/clang/b_frontend_action.cc
View file @
27a9cae5
...
...
@@ -521,7 +521,6 @@ bool BTypeVisitor::VisitBinaryOperator(BinaryOperator *E) {
if
(
!
E
->
isAssignmentOp
())
return
true
;
Expr
*
LHS
=
E
->
getLHS
()
->
IgnoreImplicit
();
Expr
*
RHS
=
E
->
getRHS
()
->
IgnoreImplicit
();
if
(
MemberExpr
*
Memb
=
dyn_cast
<
MemberExpr
>
(
LHS
))
{
if
(
DeclRefExpr
*
Base
=
dyn_cast
<
DeclRefExpr
>
(
Memb
->
getBase
()
->
IgnoreImplicit
()))
{
if
(
DeprecatedAttr
*
A
=
Base
->
getDecl
()
->
getAttr
<
DeprecatedAttr
>
())
{
...
...
@@ -534,10 +533,10 @@ bool BTypeVisitor::VisitBinaryOperator(BinaryOperator *E) {
uint64_t
ofs
=
C
.
getFieldOffset
(
F
);
uint64_t
sz
=
F
->
isBitField
()
?
F
->
getBitWidthValue
(
C
)
:
C
.
getTypeSize
(
F
->
getType
());
string
base
=
rewriter_
.
getRewrittenText
(
expansionRange
(
Base
->
getSourceRange
()));
string
rhs
=
rewriter_
.
getRewrittenText
(
expansionRange
(
RHS
->
getSourceRange
()));
string
text
=
"bpf_dins_pkt("
+
fn_args_
[
0
]
->
getName
().
str
()
+
", (u64)"
+
base
+
"+"
+
to_string
(
ofs
>>
3
)
+
", "
+
to_string
(
ofs
&
0x7
)
+
", "
+
to_string
(
sz
)
+
", "
+
rhs
+
")"
;
rewriter_
.
ReplaceText
(
expansionRange
(
E
->
getSourceRange
()),
text
);
+
", "
+
to_string
(
ofs
&
0x7
)
+
", "
+
to_string
(
sz
)
+
","
;
rewriter_
.
ReplaceText
(
expansionRange
(
SourceRange
(
E
->
getLocStart
(),
E
->
getOperatorLoc
())),
text
);
rewriter_
.
InsertTextAfterToken
(
E
->
getLocEnd
(),
")"
);
}
}
}
...
...
tests/python/test_clang.py
View file @
27a9cae5
...
...
@@ -392,5 +392,24 @@ int process(struct xdp_md *ctx) {
t
=
b
[
"act"
]
self
.
assertEquals
(
len
(
t
),
32
);
def
test_bpf_dins_pkt_rewrite
(
self
):
text
=
"""
#include <bcc/proto.h>
int dns_test(struct __sk_buff *skb) {
u8 *cursor = 0;
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
if(ethernet->type == ETH_P_IP) {
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
ip->src = ip->dst;
return 0;
}
return -1;
}
"""
b
=
BPF
(
text
=
text
)
if
__name__
==
"__main__"
:
main
()
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