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
1450e2c4
Commit
1450e2c4
authored
2 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
reduce the proliferation of isinstance
this also improves readabiliy
parent
85e8c698
No related branches found
No related tags found
1 merge request
!15
add a PacketVar to XDP
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ebpfcat/ebpf.py
+7
-7
7 additions, 7 deletions
ebpfcat/ebpf.py
with
7 additions
and
7 deletions
ebpfcat/ebpf.py
+
7
−
7
View file @
1450e2c4
...
...
@@ -372,7 +372,7 @@ class SimpleComparison(Comparison):
def
compare
(
self
,
negative
):
with
self
.
left
.
calculate
(
None
,
None
)
as
(
self
.
dst
,
_
):
with
ExitStack
()
as
exitStack
:
if
not
(
isinstance
(
self
.
right
,
Constant
)
and
self
.
right
.
small
)
:
if
not
self
.
right
.
small_constant
:
self
.
src
,
_
=
exitStack
.
enter_context
(
self
.
right
.
calculate
(
None
,
None
))
self
.
origin
=
len
(
self
.
ebpf
.
opcodes
)
...
...
@@ -385,7 +385,7 @@ class SimpleComparison(Comparison):
if
self
.
opcode
==
Opcode
.
JMP
:
inst
=
Instruction
(
Opcode
.
JMP
,
0
,
0
,
len
(
self
.
ebpf
.
opcodes
)
-
self
.
origin
-
1
,
0
)
elif
isinstance
(
self
.
right
,
Constant
)
and
self
.
right
.
small
:
elif
self
.
right
.
small
_constant
:
inst
=
Instruction
(
self
.
opcode
,
self
.
dst
,
0
,
len
(
self
.
ebpf
.
opcodes
)
-
self
.
origin
-
1
,
...
...
@@ -446,6 +446,7 @@ class Expression:
"""
the base class for all numerical expressions
"""
FIXED_BASE
=
100000
small_constant
=
False
def
_binary
(
self
,
value
,
opcode
):
value
=
ensure_expression
(
self
.
ebpf
,
value
)
...
...
@@ -634,7 +635,7 @@ class Binary(Expression):
with
self
.
left
.
calculate
(
dst
,
long
,
True
)
as
(
dst
,
l_long
):
if
long
is
None
:
long
=
l_long
if
isinstance
(
self
.
right
,
Constant
)
and
self
.
right
.
small
:
if
self
.
right
.
small
_constant
:
self
.
ebpf
.
append
(
self
.
operator
+
Opcode
.
LONG
*
long
,
dst
,
0
,
0
,
int
(
self
.
right
.
value
))
else
:
...
...
@@ -777,7 +778,7 @@ class Constant(Expression):
self
.
signed
=
value
<
0
@property
def
small
(
self
):
def
small
_constant
(
self
):
return
-
0x80000000
<=
self
.
value
<
0x80000000
def
__imul__
(
self
,
value
):
...
...
@@ -788,7 +789,7 @@ class Constant(Expression):
def
calculate
(
self
,
dst
,
long
,
force
=
False
):
value
=
int
(
self
.
value
)
with
self
.
ebpf
.
get_free_register
(
dst
)
as
dst
:
if
self
.
small
:
if
self
.
small
_constant
:
self
.
ebpf
.
append
(
Opcode
.
MOV
+
Opcode
.
LONG
,
dst
,
0
,
0
,
value
)
else
:
self
.
ebpf
.
append
(
Opcode
.
DW
,
dst
,
0
,
0
,
value
&
0xffffffff
)
...
...
@@ -969,8 +970,7 @@ class Memory(Expression):
dst
,
_
=
exitStack
.
enter_context
(
self
.
address
.
calculate
(
None
,
True
))
offset
=
0
if
isinstance
(
value
,
Constant
)
and
value
.
small
\
and
opcode
==
Opcode
.
STX
:
if
value
.
small_constant
and
opcode
==
Opcode
.
STX
:
self
.
ebpf
.
append
(
Opcode
.
ST
+
fmt_to_opcode
(
self
.
fmt
),
dst
,
0
,
offset
,
int
(
value
.
value
))
return
...
...
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