summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-22 13:40:00 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-22 13:40:00 +0200
commit39e8956d056b6b3cb886cdc2ff7eae8b07b53fcc (patch)
tree5d9741121a414a29450357388eb9b70270ce59d3
parent6a0ce89e1110cb49ed1c00bec2d96073b9378cb3 (diff)
Properly hook up igmp with announce
-rw-r--r--announce.c21
-rw-r--r--announce.h2
-rw-r--r--igmp.c17
-rw-r--r--main.c13
-rw-r--r--main.h18
5 files changed, 41 insertions, 30 deletions
diff --git a/announce.c b/announce.c
index 17ab2bb..2510d5d 100644
--- a/announce.c
+++ b/announce.c
@@ -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");
}
diff --git a/announce.h b/announce.h
index c4bd8e3..77a36f2 100644
--- a/announce.h
+++ b/announce.h
@@ -7,7 +7,7 @@ void announce_delete();
void announce_stop();
-void announce_start();
+void announce_start(unsigned duration);
void announce_init();
diff --git a/igmp.c b/igmp.c
index 2fb75a2..a9a8980 100644
--- a/igmp.c
+++ b/igmp.c
@@ -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
diff --git a/main.c b/main.c
index 86681e8..f0cc399 100644
--- a/main.c
+++ b/main.c
@@ -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();
diff --git a/main.h b/main.h
index ac3e0a2..05c5c82 100644
--- a/main.h
+++ b/main.h
@@ -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