From 9657b6ed05cc67273f6bab1751ae98ca4e89f114 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 27 Sep 2021 05:24:30 +0200 Subject: conf, tcp: Periodic detection of bound ports for pasta port forwarding Detecting bound ports at start-up time isn't terribly useful: do this periodically instead, if configured. This is only implemented for TCP at the moment, UDP is somewhat more complicated: leave a TODO there. Signed-off-by: Stefano Brivio --- util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 285c0b6..3cf3a82 100644 --- a/util.c +++ b/util.c @@ -266,8 +266,9 @@ int bitmap_isset(uint8_t *map, int bit) * procfs_scan_listen() - Set bits for listening TCP or UDP sockets from procfs * @name: Corresponding name of file under /proc/net/ * @map: Bitmap where numbers of ports in listening state will be set + * @exclude: Bitmap of ports to exclude from setting (and clear) */ -void procfs_scan_listen(char *name, uint8_t *map) +void procfs_scan_listen(char *name, uint8_t *map, uint8_t *exclude) { char line[200], path[PATH_MAX]; unsigned long port; @@ -288,7 +289,10 @@ void procfs_scan_listen(char *name, uint8_t *map) (strstr(name, "udp") && state != 0x07)) continue; - bitmap_set(map, port); + if (bitmap_isset(exclude, port)) + bitmap_clear(map, port); + else + bitmap_set(map, port); } fclose(fp); -- cgit v1.2.3