Commit 7d61e62e authored by 4ast's avatar 4ast

Merge pull request #62 from iovisor/bblanco_dev

Compatibility fixes and pyroute2 examples
parents aa5e456b 051392f9
#!/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)
......@@ -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):
......
......@@ -10,4 +10,4 @@ setup(name='bpf',
url='http://plumgrid.com',
packages=['bpf'],
platforms=['Linux'],
requires=[])
install_requires=['future'])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment