From a6126c774f03f2d82245e00bb6dace45f8e6928b Mon Sep 17 00:00:00 2001 From: Timur Celik Date: Tue, 6 Jul 2021 00:15:18 +0200 Subject: [PATCH] modules: Support interface creation at runtime Interfaces might be created at runtime, e.g. USB network adapters or VPN connections. To support these we (a) don't close the module if the interface can't be found at startup and (b) check the interface index for every link event, as it might have changed after recreation. --- modules/network.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/modules/network.c b/modules/network.c index c6b32af..22c1e3f 100644 --- a/modules/network.c +++ b/modules/network.c @@ -230,13 +230,9 @@ handle_link(struct module *mod, uint16_t type, struct private *m = mod->private; - if (m->ifindex == -1) { - /* We don't know our own ifindex yet. Let's see if we can find - * it in the message */ - if (!find_my_ifindex(mod, msg, len)) { - /* Nope, message wasn't for us (IFLA_IFNAME mismatch) */ - return; - } + if (!find_my_ifindex(mod, msg, len)) { + /* Message wasn't for us (IFLA_IFNAME mismatch) */ + return; } assert(m->ifindex >= 0); @@ -314,8 +310,6 @@ handle_address(struct module *mod, uint16_t type, struct private *m = mod->private; - assert(m->ifindex >= 0); - if (msg->ifa_index != m->ifindex) { /* Not for us */ return; @@ -420,8 +414,8 @@ parse_reply(struct module *mod, const struct nlmsghdr *hdr, size_t len) switch (hdr->nlmsg_type) { case NLMSG_DONE: if (m->ifindex == -1) { - LOG_ERR("%s: failed to find interface", m->iface); - return false; + LOG_WARN("%s: failed to find interface", m->iface); + return true; } /* Request initial list of IPv4/6 addresses */