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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
karaboDevices
ebpfCAT
Commits
3d7457aa
Commit
3d7457aa
authored
2 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
new way to define Else statements
parent
7b4f931b
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
+15
-1
15 additions, 1 deletion
ebpfcat/ebpf.py
ebpfcat/ebpf_test.py
+25
-0
25 additions, 0 deletions
ebpfcat/ebpf_test.py
with
40 additions
and
1 deletion
ebpfcat/ebpf.py
+
15
−
1
View file @
3d7457aa
...
...
@@ -273,6 +273,20 @@ def comparison(uposop, unegop, sposop, snegop):
return
ret
class
Elser
:
def
__init__
(
self
,
comp
):
self
.
comp
=
comp
def
__enter__
(
self
):
return
self
.
comp
.
Else
()
def
__exit__
(
self
,
exc_type
,
exc
,
tb
):
self
.
comp
.
__exit__
(
exc_type
,
exc
,
tb
)
def
Else
(
self
):
return
self
.
comp
.
Else
()
class
Comparison
(
ABC
):
"""
Base class for all logical operations
"""
...
...
@@ -283,7 +297,7 @@ class Comparison(ABC):
def
__enter__
(
self
):
if
self
.
else_origin
is
None
:
self
.
compare
(
True
)
return
self
return
Elser
(
self
)
def
__exit__
(
self
,
exc_type
,
exc
,
tb
):
if
self
.
else_origin
is
None
:
...
...
This diff is collapsed.
Click to expand it.
ebpfcat/ebpf_test.py
+
25
−
0
View file @
3d7457aa
...
...
@@ -391,6 +391,31 @@ class Tests(TestCase):
Instruction
(
opcode
=
O
.
JMP
,
dst
=
0
,
src
=
0
,
off
=
1
,
imm
=
0
),
Instruction
(
opcode
=
O
.
MOV
+
O
.
LONG
,
dst
=
7
,
src
=
0
,
off
=
0
,
imm
=
8
)])
def
test_with_new
(
self
):
e
=
EBPF
()
e
.
owners
=
set
(
range
(
11
))
with
e
.
r2
>
3
as
Else
:
e
.
r2
=
5
with
Else
:
e
.
r6
=
7
with
e
.
r2
:
e
.
r3
=
2
with
e
.
r4
>
3
as
Else
:
e
.
r5
=
7
with
Else
:
e
.
r7
=
8
self
.
assertEqual
(
e
.
opcodes
,
[
Instruction
(
opcode
=
0xb5
,
dst
=
2
,
src
=
0
,
off
=
2
,
imm
=
3
),
Instruction
(
opcode
=
0xb7
,
dst
=
2
,
src
=
0
,
off
=
0
,
imm
=
5
),
Instruction
(
opcode
=
0x5
,
dst
=
0
,
src
=
0
,
off
=
1
,
imm
=
0
),
Instruction
(
opcode
=
O
.
MOV
+
O
.
LONG
,
dst
=
6
,
src
=
0
,
off
=
0
,
imm
=
7
),
Instruction
(
opcode
=
O
.
JEQ
,
dst
=
2
,
src
=
0
,
off
=
1
,
imm
=
0
),
Instruction
(
opcode
=
O
.
MOV
+
O
.
LONG
,
dst
=
3
,
src
=
0
,
off
=
0
,
imm
=
2
),
Instruction
(
opcode
=
O
.
JLE
,
dst
=
4
,
src
=
0
,
off
=
2
,
imm
=
3
),
Instruction
(
opcode
=
O
.
MOV
+
O
.
LONG
,
dst
=
5
,
src
=
0
,
off
=
0
,
imm
=
7
),
Instruction
(
opcode
=
O
.
JMP
,
dst
=
0
,
src
=
0
,
off
=
1
,
imm
=
0
),
Instruction
(
opcode
=
O
.
MOV
+
O
.
LONG
,
dst
=
7
,
src
=
0
,
off
=
0
,
imm
=
8
)])
def
test_with_inversion
(
self
):
e
=
EBPF
()
with
e
.
r1
&
1
as
cond
:
...
...
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