From add9f4a99cc358749b276157d9957c527fef4fe7 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Wed, 29 Jul 2026 18:47:41 +0200 Subject: ipcpd: Flush fd from pff after disconnect The flow descriptors were not immediately removed from the routing tables when they were disconnected, so forwarding paths could still use the fd after the IPCP has deallocated the flow. Refactors the tests and adds some for the del_fd function. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/pff/pft.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/ipcpd/unicast/pff/pft.c') diff --git a/src/ipcpd/unicast/pff/pft.c b/src/ipcpd/unicast/pff/pft.c index d0e562d6..2a295a40 100644 --- a/src/ipcpd/unicast/pff/pft.c +++ b/src/ipcpd/unicast/pff/pft.c @@ -91,6 +91,43 @@ void pft_destroy(struct pft * pft) free(pft); } +void pft_del_fd(struct pft * pft, + int fd) +{ + unsigned int i; + struct list_head * p; + struct list_head * h; + struct pft_entry * entry; + size_t j; + size_t n; + + assert(pft); + + for (i = 0; i < pft->buckets_size; i++) { + list_for_each_safe(p, h, &(pft->buckets[i])) { + entry = list_entry(p, struct pft_entry, next); + + n = 0; + for (j = 0; j < entry->len; j++) { + if (entry->fds[j] != fd) + entry->fds[n++] = entry->fds[j]; + } + + if (n == entry->len) + continue; + + if (n > 0) { + entry->len = n; + continue; + } + + list_del(&entry->next); + free(entry->fds); + free(entry); + } + } +} + void pft_flush(struct pft * pft) { unsigned int i; -- cgit v1.2.3