diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-22 13:40:00 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-22 13:40:00 +0200 |
commit | 39e8956d056b6b3cb886cdc2ff7eae8b07b53fcc (patch) | |
tree | 5d9741121a414a29450357388eb9b70270ce59d3 | |
parent | 6a0ce89e1110cb49ed1c00bec2d96073b9378cb3 (diff) |
Properly hook up igmp with announce
-rw-r--r-- | announce.c | 21 | ||||
-rw-r--r-- | announce.h | 2 | ||||
-rw-r--r-- | igmp.c | 17 | ||||
-rw-r--r-- | main.c | 13 | ||||
-rw-r--r-- | main.h | 18 |
5 files changed, 41 insertions, 30 deletions
@@ -5,6 +5,7 @@ #include <arpa/inet.h> #include <string.h> #include <unistd.h> +#include <time.h> #include "main.h" #include "uring.h" @@ -15,6 +16,7 @@ struct announce { uint64_t value; struct uring_task task; int mcast_fd; + time_t until; }; static void @@ -31,9 +33,15 @@ announce_cb(struct uring_task *task, int res) return; } - debug(DBG_ANN, "timerfd value %" PRIu64, announce->value); - list_for_each_entry(server, &cfg->servers, list) - server_announce(server, announce->mcast_fd); + if (announce->until != 0 && time(NULL) > announce->until) { + debug(DBG_ANN, "stopping announcements"); + announce_stop(); + } else { + debug(DBG_ANN, "announcing servers"); + list_for_each_entry(server, &cfg->servers, list) + server_announce(server, announce->mcast_fd); + } + uring_read(&announce->task, &announce->value, sizeof(announce->value), announce_cb); } @@ -88,7 +96,7 @@ announce_stop() } void -announce_start() +announce_start(unsigned duration) { struct itimerspec tspec = { .it_interval = { @@ -103,6 +111,11 @@ announce_start() assert_return(cfg->announce); + if (duration > 0) + cfg->announce->until = time(NULL) + duration; + else + cfg->announce->until = 0; + if (timerfd_settime(cfg->announce->task.fd, 0, &tspec, NULL) != 0) error("timerfd_settime: %m"); } @@ -7,7 +7,7 @@ void announce_delete(); void announce_stop(); -void announce_start(); +void announce_start(unsigned duration); void announce_init(); @@ -12,12 +12,10 @@ #include <errno.h> #include <sys/ioctl.h> -/* FIXME: Remove later */ -#include <time.h> - #include "main.h" #include "uring.h" #include "igmp.h" +#include "announce.h" struct igmp { struct uring_task task; @@ -173,13 +171,12 @@ csum_valid(const char *buf, size_t len) static void igmp_match() { - /* Sent with approx 120-130 sec intervals */ - time_t t = time(NULL); - struct tm *tm = localtime(&t); - char s[64]; - strftime(s, sizeof(s), "%c", tm); - debug(DBG_IGMP, "multicast request discovered at: %s", s); - //start announce + debug(DBG_IGMP, "multicast request discovered"); + /* + * IGMP messages are sent with approx 120-130 sec intervals, + * so set time to 5 minutes to allow some slack. + */ + announce_start(5 * 60); } static void @@ -501,11 +501,11 @@ cfg_apply() CAPNG_DROP_SUPP_GRP | CAPNG_CLEAR_BOUNDING)) die("capng_change_id failed"); } else { - if (capng_apply(CAPNG_SELECT_BOTH)) { - capng_clear(CAPNG_SELECT_BOTH); - if (capng_apply(CAPNG_SELECT_BOTH)) - die("capng_apply failed"); - } + /* + * This can fail if any of the caps are lacking, but it'll + * be re-checked later. + */ + capng_apply(CAPNG_SELECT_BOTH); setgroups(0, NULL); } @@ -596,7 +596,8 @@ main(int argc, char **argv) announce_init(); - announce_start(); + if (!cfg->igmp) + announce_start(0); idle_init(); @@ -20,15 +20,15 @@ enum debug_lvl { DBG_REF = (0x1 << 5), DBG_MALLOC = (0x1 << 6), DBG_ANN = (0x1 << 7), - DBG_SIG = (0x1 << 7), - DBG_UR = (0x1 << 8), - DBG_SRV = (0x1 << 9), - DBG_PROXY = (0x1 << 10), - DBG_RCON = (0x1 << 11), - DBG_IDLE = (0x1 << 12), - DBG_IGMP = (0x1 << 13), - DBG_SYSD = (0x1 << 14), - DBG_DNS = (0x1 << 15), + DBG_SIG = (0x1 << 8), + DBG_UR = (0x1 << 9), + DBG_SRV = (0x1 << 10), + DBG_PROXY = (0x1 << 11), + DBG_RCON = (0x1 << 12), + DBG_IDLE = (0x1 << 13), + DBG_IGMP = (0x1 << 14), + DBG_SYSD = (0x1 << 15), + DBG_DNS = (0x1 << 16), }; static inline bool |