Expose the netkit host ifname as a public attribute nk_host_ifname
(symmetric with the already-public nk_guest_ifname), rename _attach_bpf
to a public attach_bpf, and add a public detach_bpf helper that
encapsulates the tc-filter teardown bookkeeping. Switch the fixtures
to this public API. No functional change and keeps pylint happy.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>
Link: https://patch.msgid.link/20260614102607.863838-3-daniel@iogearbox.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
cmd(f"ip link del dev {cfg.nk_host_ifname}", fail=False)
cfg.nk_host_ifname = None
cfg.nk_guest_ifname = None
- if getattr(cfg, "_tc_attached", False):
- cmd(
- f"tc filter del dev {cfg.ifname} ingress pref {cfg._bpf_prog_pref}",
- fail=False,
- )
- cfg._tc_attached = False
+ cfg.detach_bpf()
all_links = ip("-d link show", json=True)
old_idxs = {
ns=cfg.netns,
)
- cfg._attach_bpf()
+ cfg.attach_bpf()
def _setup_lease(cfg, rxqueues=2):
self.nk_guest_ifindex = netkit_links[0]['ifindex']
self._setup_ns()
- self._attach_bpf()
+ self.attach_bpf()
if primary_rx_redirect:
self._attach_primary_rx_redirect_bpf()
return bpf_obj
return None
- def _attach_bpf(self):
+ def detach_bpf(self):
+ if self._tc_attached:
+ cmd(f"tc filter del dev {self.ifname} ingress pref "
+ f"{self._bpf_prog_pref}", fail=False)
+ self._tc_attached = False
+
+ def attach_bpf(self):
bpf_obj = self._find_bpf_obj("nk_forward.bpf.o")
if not bpf_obj:
raise KsftSkipEx("BPF prog nk_forward.bpf.o not found")