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
c9dcf813
Commit
c9dcf813
authored
2 years ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
remove old Else version
parent
865515e2
No related branches found
No related tags found
2 merge requests
!9
support Leybold turbo pump
,
!8
Draft: move the index field to the end of packet
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ebpfcat/ebpf.py
+2
-5
2 additions, 5 deletions
ebpfcat/ebpf.py
ebpfcat/ebpf_test.py
+13
-38
13 additions, 38 deletions
ebpfcat/ebpf_test.py
ebpfcat/ebpfcat.py
+4
-4
4 additions, 4 deletions
ebpfcat/ebpfcat.py
ebpfcat/xdp.py
+6
-9
6 additions, 9 deletions
ebpfcat/xdp.py
with
25 additions
and
56 deletions
ebpfcat/ebpf.py
+
2
−
5
View file @
c9dcf813
...
@@ -283,9 +283,6 @@ class Elser:
...
@@ -283,9 +283,6 @@ class Elser:
def
__exit__
(
self
,
exc_type
,
exc
,
tb
):
def
__exit__
(
self
,
exc_type
,
exc
,
tb
):
self
.
comp
.
__exit__
(
exc_type
,
exc
,
tb
)
self
.
comp
.
__exit__
(
exc_type
,
exc
,
tb
)
def
Else
(
self
):
return
self
.
comp
.
Else
()
class
Comparison
(
ABC
):
class
Comparison
(
ABC
):
"""
Base class for all logical operations
"""
"""
Base class for all logical operations
"""
...
@@ -865,9 +862,9 @@ class MemoryDesc:
...
@@ -865,9 +862,9 @@ class MemoryDesc:
value
=
before
&
~
(
1
<<
fmt
[
0
])
value
=
before
&
~
(
1
<<
fmt
[
0
])
except
AssembleError
:
except
AssembleError
:
with
ebpf
.
wtmp
:
with
ebpf
.
wtmp
:
with
value
as
cond
:
with
value
as
Else
:
ebpf
.
wtmp
=
before
|
(
1
<<
fmt
[
0
])
ebpf
.
wtmp
=
before
|
(
1
<<
fmt
[
0
])
with
cond
.
Else
()
:
with
Else
:
ebpf
.
wtmp
=
before
&
~
(
1
<<
fmt
[
0
])
ebpf
.
wtmp
=
before
&
~
(
1
<<
fmt
[
0
])
else
:
else
:
mask
=
((
1
<<
fmt
[
1
])
-
1
)
<<
fmt
[
0
]
mask
=
((
1
<<
fmt
[
1
])
-
1
)
<<
fmt
[
0
]
...
...
This diff is collapsed.
Click to expand it.
ebpfcat/ebpf_test.py
+
13
−
38
View file @
c9dcf813
...
@@ -367,31 +367,6 @@ class Tests(TestCase):
...
@@ -367,31 +367,6 @@ class Tests(TestCase):
Instruction
(
opcode
=
0xb7
,
dst
=
0
,
src
=
0
,
off
=
0
,
imm
=
1
)])
Instruction
(
opcode
=
0xb7
,
dst
=
0
,
src
=
0
,
off
=
0
,
imm
=
1
)])
def
test_with
(
self
):
def
test_with
(
self
):
e
=
EBPF
()
e
.
owners
=
set
(
range
(
11
))
with
e
.
r2
>
3
as
cond
:
e
.
r2
=
5
with
cond
.
Else
():
e
.
r6
=
7
with
e
.
r2
:
e
.
r3
=
2
with
e
.
r4
>
3
as
cond
:
e
.
r5
=
7
with
cond
.
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_new
(
self
):
e
=
EBPF
()
e
=
EBPF
()
e
.
owners
=
set
(
range
(
11
))
e
.
owners
=
set
(
range
(
11
))
with
e
.
r2
>
3
as
Else
:
with
e
.
r2
>
3
as
Else
:
...
@@ -420,10 +395,10 @@ class Tests(TestCase):
...
@@ -420,10 +395,10 @@ class Tests(TestCase):
e
=
EBPF
()
e
=
EBPF
()
with
e
.
r1
&
1
as
cond
:
with
e
.
r1
&
1
as
cond
:
e
.
r0
=
2
e
.
r0
=
2
with
e
.
r1
&
7
as
cond
:
with
e
.
r1
&
7
as
Else
:
e
.
r0
=
2
e
.
r0
=
2
e
.
r1
=
4
e
.
r1
=
4
with
cond
.
Else
()
:
with
Else
:
e
.
r0
=
3
e
.
r0
=
3
self
.
assertEqual
(
e
.
opcodes
,
[
self
.
assertEqual
(
e
.
opcodes
,
[
Instruction
(
opcode
=
69
,
dst
=
1
,
src
=
0
,
off
=
1
,
imm
=
1
),
Instruction
(
opcode
=
69
,
dst
=
1
,
src
=
0
,
off
=
1
,
imm
=
1
),
...
@@ -438,11 +413,11 @@ class Tests(TestCase):
...
@@ -438,11 +413,11 @@ class Tests(TestCase):
def
test_with_and
(
self
):
def
test_with_and
(
self
):
e
=
EBPF
()
e
=
EBPF
()
e
.
owners
=
set
(
range
(
11
))
e
.
owners
=
set
(
range
(
11
))
with
(
e
.
r2
>
3
)
&
(
e
.
r3
>
2
)
as
cond
:
with
(
e
.
r2
>
3
)
&
(
e
.
r3
>
2
)
as
Else
:
e
.
r1
=
5
e
.
r1
=
5
with
(
e
.
r2
>
2
)
&
(
e
.
r1
<
2
)
as
cond
:
with
(
e
.
r2
>
2
)
&
(
e
.
r1
<
2
)
as
Else
:
e
.
r2
=
5
e
.
r2
=
5
with
cond
.
Else
()
:
with
Else
:
e
.
r3
=
7
e
.
r3
=
7
self
.
assertEqual
(
e
.
opcodes
,
[
self
.
assertEqual
(
e
.
opcodes
,
[
Instruction
(
opcode
=
O
.
JLE
,
dst
=
2
,
src
=
0
,
off
=
2
,
imm
=
3
),
Instruction
(
opcode
=
O
.
JLE
,
dst
=
2
,
src
=
0
,
off
=
2
,
imm
=
3
),
...
@@ -457,12 +432,12 @@ class Tests(TestCase):
...
@@ -457,12 +432,12 @@ class Tests(TestCase):
def
test_with_or
(
self
):
def
test_with_or
(
self
):
e
=
EBPF
()
e
=
EBPF
()
e
.
owners
=
set
(
range
(
11
))
e
.
owners
=
set
(
range
(
11
))
with
(
e
.
r2
>
3
)
|
(
e
.
r3
>
2
)
as
cond
:
with
(
e
.
r2
>
3
)
|
(
e
.
r3
>
2
)
as
Else
:
e
.
r1
=
5
e
.
r1
=
5
with
(
e
.
r2
>
2
)
|
(
e
.
r1
>
2
)
as
cond
:
with
(
e
.
r2
>
2
)
|
(
e
.
r1
>
2
)
as
Else
:
e
.
r2
=
5
e
.
r2
=
5
e
.
r5
=
4
e
.
r5
=
4
with
cond
.
Else
()
:
with
Else
:
e
.
r3
=
7
e
.
r3
=
7
e
.
r4
=
3
e
.
r4
=
3
self
.
maxDiff
=
None
self
.
maxDiff
=
None
...
@@ -481,9 +456,9 @@ class Tests(TestCase):
...
@@ -481,9 +456,9 @@ class Tests(TestCase):
def
test_comp_binary
(
self
):
def
test_comp_binary
(
self
):
e
=
EBPF
()
e
=
EBPF
()
e
.
owners
=
{
1
,
2
,
3
,
5
}
e
.
owners
=
{
1
,
2
,
3
,
5
}
with
e
.
r1
+
e
.
r3
>
3
as
cond
:
with
e
.
r1
+
e
.
r3
>
3
as
Else
:
e
.
r0
=
5
e
.
r0
=
5
with
cond
.
Else
()
:
with
Else
:
e
.
r0
=
7
e
.
r0
=
7
tgt
=
e
.
jumpIf
(
e
.
r0
<
e
.
r2
+
e
.
r5
)
tgt
=
e
.
jumpIf
(
e
.
r0
<
e
.
r2
+
e
.
r5
)
...
@@ -638,10 +613,10 @@ class Tests(TestCase):
...
@@ -638,10 +613,10 @@ class Tests(TestCase):
def
test_with_data
(
self
):
def
test_with_data
(
self
):
e
=
EBPF
()
e
=
EBPF
()
with
e
.
r1
>
0
as
cond
:
with
e
.
r1
>
0
as
Else
:
e
.
r2
=
3
e
.
r2
=
3
e
.
r3
=
5
e
.
r3
=
5
with
cond
.
Else
()
:
with
Else
:
with
self
.
assertRaises
(
AssembleError
):
with
self
.
assertRaises
(
AssembleError
):
e
.
r0
=
e
.
r2
e
.
r0
=
e
.
r2
e
.
r3
=
5
e
.
r3
=
5
...
@@ -751,7 +726,7 @@ class Tests(TestCase):
...
@@ -751,7 +726,7 @@ class Tests(TestCase):
e
=
XDP
(
license
=
"
GPL
"
)
e
=
XDP
(
license
=
"
GPL
"
)
with
e
.
packetSize
>
100
as
p
:
with
e
.
packetSize
>
100
as
p
:
e
.
r3
=
p
.
pH
[
22
]
e
.
r3
=
p
.
pH
[
22
]
with
p
.
Else
()
:
with
p
.
Else
:
e
.
r3
=
77
e
.
r3
=
77
self
.
assertEqual
(
e
.
opcodes
,
[
self
.
assertEqual
(
e
.
opcodes
,
[
Instruction
(
opcode
=
O
.
LD
+
O
.
W
,
dst
=
9
,
src
=
1
,
off
=
0
,
imm
=
0
),
Instruction
(
opcode
=
O
.
LD
+
O
.
W
,
dst
=
9
,
src
=
1
,
off
=
0
,
imm
=
0
),
...
...
This diff is collapsed.
Click to expand it.
ebpfcat/ebpfcat.py
+
4
−
4
View file @
c9dcf813
...
@@ -275,16 +275,16 @@ class EtherXDP(XDP):
...
@@ -275,16 +275,16 @@ class EtherXDP(XDP):
self
.
r
[
dst
]
+=
4
*
self
.
r3
self
.
r
[
dst
]
+=
4
*
self
.
r3
self
.
r4
=
self
.
mB
[
self
.
r
[
dst
]]
self
.
r4
=
self
.
mB
[
self
.
r
[
dst
]]
# we lost a packet
# we lost a packet
with
p
.
pB
[
IDX0
]
==
self
.
r4
as
cond
:
with
p
.
pB
[
IDX0
]
==
self
.
r4
as
Else
:
self
.
mI
[
self
.
r
[
dst
]]
+=
1
+
(
self
.
r4
&
1
)
self
.
mI
[
self
.
r
[
dst
]]
+=
1
+
(
self
.
r4
&
1
)
# normal case: two packets on the wire
# normal case: two packets on the wire
with
cond
.
Else
()
,
((
p
.
pB
[
IDX0
]
+
1
&
0xff
)
==
self
.
r4
)
\
with
Else
,
((
p
.
pB
[
IDX0
]
+
1
&
0xff
)
==
self
.
r4
)
\
|
(
p
.
pB
[
IDX0
]
==
0
)
as
c2
:
|
(
p
.
pB
[
IDX0
]
==
0
)
as
Else
:
self
.
mI
[
self
.
r
[
dst
]]
+=
1
self
.
mI
[
self
.
r
[
dst
]]
+=
1
with
self
.
r4
&
1
:
# last one was active
with
self
.
r4
&
1
:
# last one was active
p
.
pB
[
IDX0
]
=
self
.
mB
[
self
.
r
[
dst
]]
p
.
pB
[
IDX0
]
=
self
.
mB
[
self
.
r
[
dst
]]
self
.
exit
(
XDPExitCode
.
TX
)
self
.
exit
(
XDPExitCode
.
TX
)
with
c2
.
Else
()
:
with
Else
:
self
.
exit
(
XDPExitCode
.
PASS
)
self
.
exit
(
XDPExitCode
.
PASS
)
p
.
pB
[
IDX0
]
=
self
.
mB
[
self
.
r
[
dst
]]
p
.
pB
[
IDX0
]
=
self
.
mB
[
self
.
r
[
dst
]]
self
.
r2
=
self
.
get_fd
(
self
.
programs
)
self
.
r2
=
self
.
get_fd
(
self
.
programs
)
...
...
This diff is collapsed.
Click to expand it.
ebpfcat/xdp.py
+
6
−
9
View file @
c9dcf813
...
@@ -104,9 +104,9 @@ class PacketArray:
...
@@ -104,9 +104,9 @@ class PacketArray:
class
Packet
:
class
Packet
:
def
__init__
(
self
,
ebpf
,
comp
,
no
):
def
__init__
(
self
,
ebpf
,
Else
,
no
):
self
.
ebpf
=
ebpf
self
.
ebpf
=
ebpf
self
.
comp
=
comp
self
.
Else
=
Else
self
.
no
=
no
self
.
no
=
no
self
.
pB
=
PacketArray
(
self
.
ebpf
,
self
.
no
,
self
.
ebpf
.
mB
)
self
.
pB
=
PacketArray
(
self
.
ebpf
,
self
.
no
,
self
.
ebpf
.
mB
)
...
@@ -114,9 +114,6 @@ class Packet:
...
@@ -114,9 +114,6 @@ class Packet:
self
.
pI
=
PacketArray
(
self
.
ebpf
,
self
.
no
,
self
.
ebpf
.
mI
)
self
.
pI
=
PacketArray
(
self
.
ebpf
,
self
.
no
,
self
.
ebpf
.
mI
)
self
.
pQ
=
PacketArray
(
self
.
ebpf
,
self
.
no
,
self
.
ebpf
.
mQ
)
self
.
pQ
=
PacketArray
(
self
.
ebpf
,
self
.
no
,
self
.
ebpf
.
mQ
)
def
Else
(
self
):
return
self
.
comp
.
Else
()
class
PacketSize
:
class
PacketSize
:
def
__init__
(
self
,
ebpf
):
def
__init__
(
self
,
ebpf
):
...
@@ -126,15 +123,15 @@ class PacketSize:
...
@@ -126,15 +123,15 @@ class PacketSize:
def
__lt__
(
self
,
value
):
def
__lt__
(
self
,
value
):
e
=
self
.
ebpf
e
=
self
.
ebpf
e
.
r9
=
e
.
mA
[
e
.
r1
]
e
.
r9
=
e
.
mA
[
e
.
r1
]
with
e
.
mA
[
e
.
r1
+
4
]
<
e
.
mA
[
e
.
r1
]
+
value
as
comp
:
with
e
.
mA
[
e
.
r1
+
4
]
<
e
.
mA
[
e
.
r1
]
+
value
as
Else
:
yield
Packet
(
e
,
comp
,
9
)
yield
Packet
(
e
,
Else
,
9
)
@contextmanager
@contextmanager
def
__gt__
(
self
,
value
):
def
__gt__
(
self
,
value
):
e
=
self
.
ebpf
e
=
self
.
ebpf
e
.
r9
=
e
.
mA
[
e
.
r1
]
e
.
r9
=
e
.
mA
[
e
.
r1
]
with
e
.
mA
[
e
.
r1
+
4
]
>
e
.
mA
[
e
.
r1
]
+
value
as
comp
:
with
e
.
mA
[
e
.
r1
+
4
]
>
e
.
mA
[
e
.
r1
]
+
value
as
Else
:
yield
Packet
(
e
,
comp
,
9
)
yield
Packet
(
e
,
Else
,
9
)
def
__le__
(
self
,
value
):
def
__le__
(
self
,
value
):
return
self
<
value
+
1
return
self
<
value
+
1
...
...
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