retis-org / retis

Tracing packets in the Linux networking stack & friends
https://retis.readthedocs.io/en/stable/
100 stars 14 forks source link

Rework OVS tracking to properly support filtering #133

Closed amorenoz closed 1 year ago

amorenoz commented 1 year ago

Now that filtering has been added and skb-tracking has moved to the core, OVS tracking has to be slightly modified if we want filtering to actually work.

There are currently two problems

We need top propagate the filter through the user-space probes. But there is an added complexity: upcall_recv and flow_op events are correlated to each other based on their order (knowing how upcall batching works in OVS). Therefore, it's not enough to just ignore the event. We actually have to execute the batch-tracking but mark the packet as filtered so we don't send an event on it.

There are two places where we need tracking to happen: when we go from kernel to userspace (i.e: from upcall_enqueue event to upcall_recv event) and when we go from userspace back to kernel (i.e: from op_flow_exec event to execute_action event). For both, this PR adds a tracking map where we store each queue_id (i.e: the packet hash) as key and the timestamp as value. The reason for storing the timestamp is for garbage collection. It should be rare but it can happen that some events are missed and we end up with stale "packets" being tracked. A garbage collector is used to clean it.

Since a garbage collector also lives in skb-tracking.rs and we don't like code-duplication, it's refactored into a common utility struct and used in both places.

Based on #118

amorenoz commented 1 year ago

Rebased on top of master. Main changes:

Please not I've added an opinionated python format. It's quite used (and I really like it, it feels more "modern" than PEP8's) but please give me feedback on it: https://github.com/psf/black

atenart commented 1 year ago

This needs to be rebased to take into account commit 9844df7f0cc6.

amorenoz commented 1 year ago

Rebased on top of main with #165