From d3097762616da57d9c8f5f8181d1685a47431559 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 24 Aug 2021 14:54:02 +0000 Subject: [PATCH] When an interface disappears, e.g. when a usb dongle gets unplugged, we get a RTM_IFANNOUNCE message not a RTM_IFINFO message. Handle this message to not accumulate "unknown" interfaces. OK benno --- sbin/dhcpleased/dhcpleased.c | 5 +++-- sbin/dhcpleased/frontend.c | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sbin/dhcpleased/dhcpleased.c b/sbin/dhcpleased/dhcpleased.c index 5ff5dcc9480..3f9f10714e9 100644 --- a/sbin/dhcpleased/dhcpleased.c +++ b/sbin/dhcpleased/dhcpleased.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpleased.c,v 1.19 2021/08/12 12:41:08 florian Exp $ */ +/* $OpenBSD: dhcpleased.c,v 1.20 2021/08/24 14:54:02 florian Exp $ */ /* * Copyright (c) 2017, 2021 Florian Obser @@ -294,7 +294,8 @@ main(int argc, char *argv[]) AF_INET)) == -1) fatal("route socket"); - rtfilter = ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_PROPOSAL); + rtfilter = ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_PROPOSAL) | + ROUTE_FILTER(RTM_IFANNOUNCE); if (setsockopt(frontend_routesock, AF_ROUTE, ROUTE_MSGFILTER, &rtfilter, sizeof(rtfilter)) == -1) fatal("setsockopt(ROUTE_MSGFILTER)"); diff --git a/sbin/dhcpleased/frontend.c b/sbin/dhcpleased/frontend.c index b3f015bcf07..6d3bf825737 100644 --- a/sbin/dhcpleased/frontend.c +++ b/sbin/dhcpleased/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.20 2021/08/23 18:22:56 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.21 2021/08/24 14:54:02 florian Exp $ */ /* * Copyright (c) 2017, 2021 Florian Obser @@ -768,7 +768,10 @@ route_receive(int fd, short events, void *arg) void handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info) { - struct sockaddr_dl *sdl = NULL; + struct sockaddr_dl *sdl = NULL; + struct if_announcemsghdr *ifan; + uint32_t if_index; + switch (rtm->rtm_type) { case RTM_IFINFO: if (rtm->rtm_addrs & RTA_IFP && rti_info[RTAX_IFP]->sa_family @@ -776,6 +779,15 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info) sdl = (struct sockaddr_dl *)rti_info[RTAX_IFP]; update_iface((struct if_msghdr *)rtm, sdl); break; + case RTM_IFANNOUNCE: + ifan = (struct if_announcemsghdr *)rtm; + if_index = ifan->ifan_index; + if (ifan->ifan_what == IFAN_DEPARTURE) { + frontend_imsg_compose_engine(IMSG_REMOVE_IF, 0, 0, + &if_index, sizeof(if_index)); + remove_iface(if_index); + } + break; case RTM_PROPOSAL: if (rtm->rtm_priority == RTP_PROPOSAL_SOLICIT) { log_debug("RTP_PROPOSAL_SOLICIT"); @@ -784,7 +796,6 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info) } #ifndef SMALL else if (rtm->rtm_flags & RTF_PROTO3) { - uint32_t if_index; char ifnamebuf[IF_NAMESIZE], *if_name; if_index = rtm->rtm_index; -- 2.20.1