From 2759ba6349cf3e03ea509616f8ef6da6d613dacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 28 Aug 2022 20:19:22 +0200 Subject: [PATCH] module/network: generate nl80211 sequence number from /dev/urandom --- modules/network.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/network.c b/modules/network.c index 9ec5993..e196e14 100644 --- a/modules/network.c +++ b/modules/network.c @@ -11,6 +11,9 @@ #include #include +#include +#include + #include #include #include @@ -51,6 +54,7 @@ struct private { int genl_sock; int rt_sock; + int urandom_fd; struct { uint16_t family_id; @@ -90,6 +94,9 @@ destroy(struct module *mod) m->label->destroy(m->label); + if (m->urandom_fd >= 0) + close(m->urandom_fd); + tll_free(m->addrs); free(m->ssid); free(m->iface); @@ -411,7 +418,12 @@ send_nl80211_get_interface(struct private *m) LOG_DBG("%s: sending nl80211 get-interface request", m->iface); - uint32_t seq = time(NULL); + uint32_t seq; + if (read(m->urandom_fd, &seq, sizeof(seq)) != sizeof(seq)) { + LOG_ERRNO("failed to read from /dev/urandom"); + return false; + } + if (send_nl80211_request(m, NL80211_CMD_GET_INTERFACE, NLM_F_REQUEST, seq)) { m->nl80211.get_interface_seq_nr = seq; return true; @@ -1285,6 +1297,12 @@ run(struct module *mod) static struct module * network_new(const char *iface, struct particle *label, int poll_interval) { + int urandom_fd = open("/dev/urandom", O_RDONLY); + if (urandom_fd < 0) { + LOG_ERRNO("failed to open /dev/urandom"); + return NULL; + } + struct private *priv = calloc(1, sizeof(*priv)); priv->iface = strdup(iface); priv->label = label; @@ -1292,6 +1310,7 @@ network_new(const char *iface, struct particle *label, int poll_interval) priv->genl_sock = -1; priv->rt_sock = -1; + priv->urandom_fd = urandom_fd; priv->nl80211.family_id = -1; priv->get_addresses = true; priv->ifindex = -1;