Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ebpfCAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Teichmann
ebpfCAT
Commits
7b4f931b
Commit
7b4f931b
authored
2 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
add an absolute value function
parent
08c86558
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ebpfcat/ebpf.py
+20
-0
20 additions, 0 deletions
ebpfcat/ebpf.py
ebpfcat/ebpf_test.py
+8
-0
8 additions, 0 deletions
ebpfcat/ebpf_test.py
with
28 additions
and
0 deletions
ebpfcat/ebpf.py
+
20
−
0
View file @
7b4f931b
...
...
@@ -460,6 +460,9 @@ class Expression:
def
__neg__
(
self
):
return
Negate
(
self
.
ebpf
,
self
)
def
__abs__
(
self
):
return
Absolute
(
self
.
ebpf
,
self
)
def
__bool__
(
self
):
raise
AssembleError
(
"
Expression only has a value at execution time
"
)
...
...
@@ -615,6 +618,23 @@ class Negate(Expression):
return
self
.
arg
.
contains
(
no
)
class
Absolute
(
Expression
):
def
__init__
(
self
,
ebpf
,
arg
):
self
.
ebpf
=
ebpf
self
.
arg
=
arg
@contextmanager
def
calculate
(
self
,
dst
,
long
,
signed
,
force
=
False
):
with
self
.
arg
.
calculate
(
dst
,
long
,
True
,
force
)
as
\
(
dst
,
long
,
signed
):
with
self
.
ebpf
.
r
[
dst
]
<
0
:
self
.
ebpf
.
r
[
dst
]
=
-
self
.
ebpf
.
r
[
dst
]
yield
dst
,
long
,
True
def
contains
(
self
,
no
):
return
self
.
arg
.
contains
(
no
)
class
Sum
(
Binary
):
"""
represent the sum of one register and a constant value
...
...
This diff is collapsed.
Click to expand it.
ebpfcat/ebpf_test.py
+
8
−
0
View file @
7b4f931b
...
...
@@ -583,6 +583,14 @@ class Tests(TestCase):
Instruction
(
opcode
=
O
.
LONG
+
O
.
REG
+
O
.
MOV
,
dst
=
7
,
src
=
1
,
off
=
0
,
imm
=
0
),
Instruction
(
opcode
=
O
.
LONG
+
O
.
NEG
,
dst
=
7
,
src
=
0
,
off
=
0
,
imm
=
0
)])
def
test_absolute
(
self
):
e
=
EBPF
()
e
.
r7
=
abs
(
e
.
r1
)
self
.
assertEqual
(
e
.
opcodes
,
[
Instruction
(
opcode
=
O
.
LONG
+
O
.
REG
+
O
.
MOV
,
dst
=
7
,
src
=
1
,
off
=
0
,
imm
=
0
),
Instruction
(
opcode
=
O
.
JGE
,
dst
=
7
,
src
=
0
,
off
=
1
,
imm
=
0
),
Instruction
(
opcode
=
O
.
LONG
+
O
.
NEG
,
dst
=
7
,
src
=
0
,
off
=
0
,
imm
=
0
)])
def
test_jump_data
(
self
):
e
=
EBPF
()
t1
=
e
.
jumpIf
(
e
.
r1
>
0
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment