Commit Graph

11 Commits

Author SHA1 Message Date
ac03d27590 pkt-loop-filter: Provide file mode for open() call
This is needed when opening with O_CREAT.

Reported-by: Simon Sundberg <Simon.Sundberg@kau.se>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-11-16 15:29:57 +01:00
846acc75e7 pkt-loop-filter: Keep running in background instead of foreground
When pinning of the bpf_link fails, we keep running to keep the PID alive.
However, staying in the foreground causes problems with scripts that
expects the setup to finish running; so fork into the background instead
and write a PID file so we can kill the running instance on unload.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-07-11 12:21:40 +02:00
c833c5ad32 pkt-loop-filter: Unload after interruption in keep running fallback mode
When running in the fallback mode where we keep running in the foreground
to keep the kprobe alive, we should unload the cls_bpf programs after being
interrupted instead of just exiting.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-07-08 14:49:31 +02:00
53a9bbe4c4 pkt-loop-filter: Add fallback if we can't pin bpf_link for kprobe
Support for bpf_link-based attaching of kprobes was added to kernel 5.15
with commit: b89fbfbb854c ("bpf: Implement minimal BPF perf link"). Prior
to this, it is not possible to pin kprobe attachments in bpffs, which
causes the pkt-loop-filter to fail. Add a fallback where we just keep
running in the foreground to keep the probe alive if bpf_link pinning
fails.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-07-08 14:46:53 +02:00
c1e1aaf019 pkt-loop-filter: Operate directly on bond devices
Instead of having to pass the component interfaces to the userspace
program, we can just pass the bond ifname, and have the loader detect which
bond component interfaces are in the bond, and automatically load the BPF
program on each one. Reusing the active bond detection code from the
previous commit also allows us to automatically detect the right initial
active interface, and keep this up-to-date by hooking into the bonding code
that changes it when an iface goes down, instead of naively rotating
between active interfaces.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-06-29 16:58:34 +02:00
6f47602582 pkt-loop-filter: Add optional debugging of dropped packets
Add a debug mode to pkt-loop-filter that outputs debug messages for every
dropped packet (with the reason it was dropped). Also add a small script to
read the kernel trace pipe, after making sure tracing is active (otherwise
there will be no output in the pipe).

The source MAC address+VLAN is squeezed into a single u64 when printing as
a quick workaround to the lack of MAC address printing in BPF printk.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-06-29 16:58:34 +02:00
96a5c2ebbf pkt-loop-filter: Set map size from userspace instead of in BPF definition
With this we can add a command line parameter to dynamically size the map
later.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-06-14 17:43:39 +02:00
60ed7a8e8b pkt-loop-filter: Filter multicast traffic
This adds filtering of multicast traffic to the set of interfaces. The
filtering works by marking one of the interfaces as "primary" (which is
just the first interface name that is supplied on the command line) and
filtering everything with an all-ones destination MAC address if it's
coming in on any interface that's not the primary one.

To handle interfaces going down, we actually supply all the ifindexes to
the BPF program, and also install a tracing hook that listens to ifdown
events and switches the logic to the next ifindex in the sequence if the
primary one goes down. This is a bit rudimentary but should at least
provide basic filtering.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-06-14 17:43:35 +02:00
50f3609658 pkt-loop-filter: Switch to using BPF skeletons
This makes it easier to populate the global variables we'll need for
handling multicast, and also means we don't have to worry about keeping the
BPF object file around (since it'll be statically linked).

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-06-14 17:43:35 +02:00
c57a5bc169 pkt-loop-filter: Attach a tracing program to catch ifdown events
This is needed to be able to react to interfaces going down so we can
allow multicast on a secondary interface if the primary goes down. We don't
actually react to the event yet, just print it; handling this will be added
in a subsequent commit.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-06-14 17:43:31 +02:00
070715cf1c Add pkt-loop-filter example
Add an example to filter looping packets on (for instance) a bond
interface, by recording the egress MAC+VLAN and dropping any packets that
come in on other (related) interfaces with the same MAC+VLAN.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-05-20 14:53:14 +02:00