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
7d61e62e
Commit
7d61e62e
authored
Jun 16, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #62 from iovisor/bblanco_dev
Compatibility fixes and pyroute2 examples
parents
aa5e456b
051392f9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
examples/simple_tc.py
examples/simple_tc.py
+29
-0
src/python/bpf/__init__.py
src/python/bpf/__init__.py
+3
-2
src/python/setup.py.in
src/python/setup.py.in
+1
-1
No files found.
examples/simple_tc.py
0 → 100755
View file @
7d61e62e
#!/usr/bin/env python
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
from
bpf
import
BPF
from
pyroute2
import
IPRoute
ipr
=
IPRoute
()
text
=
"""
int hello(struct __sk_buff *skb) {
return 1;
}
"""
try
:
b
=
BPF
(
text
=
text
,
debug
=
0
)
fn
=
b
.
load_func
(
"hello"
,
BPF
.
SCHED_CLS
)
ipr
.
link_create
(
ifname
=
"t1a"
,
kind
=
"veth"
,
peer
=
"t1b"
)
idx
=
ipr
.
link_lookup
(
ifname
=
"t1a"
)[
0
]
ipr
.
tc
(
"add"
,
"ingress"
,
idx
,
"ffff:"
)
ipr
.
tc
(
"add-filter"
,
"bpf"
,
idx
,
":1"
,
fd
=
fn
.
fd
,
name
=
fn
.
name
,
parent
=
"ffff:"
,
action
=
"ok"
,
classid
=
1
)
ipr
.
tc
(
"add"
,
"sfq"
,
idx
,
"1:"
)
ipr
.
tc
(
"add-filter"
,
"bpf"
,
idx
,
":1"
,
fd
=
fn
.
fd
,
name
=
fn
.
name
,
parent
=
"1:"
,
action
=
"ok"
,
classid
=
1
)
finally
:
if
"idx"
in
locals
():
ipr
.
link_remove
(
idx
)
src/python/bpf/__init__.py
View file @
7d61e62e
...
...
@@ -15,6 +15,7 @@
import
atexit
import
ctypes
as
ct
import
json
from
past.builtins
import
basestring
import
os
lib
=
ct
.
CDLL
(
"libbpfprog.so"
)
...
...
@@ -190,7 +191,7 @@ class BPF(object):
}
@
staticmethod
def
_decode_table_type
(
desc
):
if
isinstance
(
desc
,
str
):
if
isinstance
(
desc
,
basestring
):
return
BPF
.
str2ctype
[
desc
]
fields
=
[]
for
t
in
desc
[
1
]:
...
...
@@ -198,7 +199,7 @@ class BPF(object):
fields
.
append
((
t
[
0
],
BPF
.
_decode_table_type
(
t
[
1
])))
elif
len
(
t
)
==
3
:
fields
.
append
((
t
[
0
],
BPF
.
_decode_table_type
(
t
[
1
]),
t
[
2
]))
cls
=
type
(
desc
[
0
]
,
(
ct
.
Structure
,),
dict
(
_fields_
=
fields
))
cls
=
type
(
str
(
desc
[
0
])
,
(
ct
.
Structure
,),
dict
(
_fields_
=
fields
))
return
cls
def
get_table
(
self
,
name
,
keytype
=
None
,
leaftype
=
None
):
...
...
src/python/setup.py.in
View file @
7d61e62e
...
...
@@ -10,4 +10,4 @@ setup(name='bpf',
url='http://plumgrid.com',
packages=['bpf'],
platforms=['Linux'],
requires=[
])
install_requires=['future'
])
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