Skip to content
Snippets Groups Projects
Commit 496c0249 authored by Martin Teichmann's avatar Martin Teichmann
Browse files

quickly document XDP

parent 72145d65
No related branches found
No related tags found
No related merge requests found
"""support for XDP programs"""
from asyncio import DatagramProtocol, Future, get_event_loop from asyncio import DatagramProtocol, Future, get_event_loop
from enum import Enum from enum import Enum
from contextlib import contextmanager from contextlib import contextmanager
...@@ -18,6 +19,8 @@ class XDPExitCode(Enum): ...@@ -18,6 +19,8 @@ class XDPExitCode(Enum):
class XDRFD(DatagramProtocol): class XDRFD(DatagramProtocol):
"""just implement enough of the NETLINK protocol to attach programs"""
def __init__(self, ifindex, fd, future): def __init__(self, ifindex, fd, future):
self.ifindex = ifindex self.ifindex = ifindex
self.fd = fd self.fd = fd
...@@ -70,6 +73,7 @@ class XDRFD(DatagramProtocol): ...@@ -70,6 +73,7 @@ class XDRFD(DatagramProtocol):
class PacketArray: class PacketArray:
"""access a packet like a Python array"""
def __init__(self, ebpf, no, memory): def __init__(self, ebpf, no, memory):
self.ebpf = ebpf self.ebpf = ebpf
self.no = no self.no = no
...@@ -123,12 +127,14 @@ class PacketSize: ...@@ -123,12 +127,14 @@ class PacketSize:
class XDP(EBPF): class XDP(EBPF):
"""the base class for XDP programs"""
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(prog_type=ProgType.XDP, **kwargs) super().__init__(prog_type=ProgType.XDP, **kwargs)
self.packetSize = PacketSize(self) self.packetSize = PacketSize(self)
async def attach(self, network): async def attach(self, network):
"""attach this program to a `network`"""
ifindex = if_nametoindex(network) ifindex = if_nametoindex(network)
fd, _ = self.load(log_level=1) fd, _ = self.load(log_level=1)
future = Future() future = Future()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment