From c932786d4831ccff19aa7e406a5f4fb49b712590 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 24 Aug 2021 14:56:06 +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. While here fix a bug where we would remove an interface only in the engine process but not in the frontend when an interfaces gets unplugged while we process a RTM_IFINFO message for it. OK benno --- sbin/slaacd/frontend.c | 13 ++++++++++++- sbin/slaacd/slaacd.c | 5 +++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sbin/slaacd/frontend.c b/sbin/slaacd/frontend.c index d3cb23a2925..72d7929c5df 100644 --- a/sbin/slaacd/frontend.c +++ b/sbin/slaacd/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.57 2021/07/12 15:09:19 beck Exp $ */ +/* $OpenBSD: frontend.c,v 1.58 2021/08/24 14:56:06 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -778,6 +778,7 @@ void handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info) { struct if_msghdr *ifm; + struct if_announcemsghdr *ifan; struct imsg_del_addr del_addr; struct imsg_del_route del_route; struct imsg_dup_addr dup_addr; @@ -798,6 +799,7 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info) if_index = ifm->ifm_index; frontend_imsg_compose_engine(IMSG_REMOVE_IF, 0, 0, &if_index, sizeof(if_index)); + remove_iface(if_index); } else { xflags = get_xflags(if_name); if (xflags == -1 || !(xflags & (IFXF_AUTOCONF6 | @@ -817,6 +819,15 @@ handle_route_message(struct rt_msghdr *rtm, struct sockaddr **rti_info) } } 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_NEWADDR: ifm = (struct if_msghdr *)rtm; if_name = if_indextoname(ifm->ifm_index, ifnamebuf); diff --git a/sbin/slaacd/slaacd.c b/sbin/slaacd/slaacd.c index 0b31934c211..e167f58411c 100644 --- a/sbin/slaacd/slaacd.c +++ b/sbin/slaacd/slaacd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slaacd.c,v 1.63 2021/07/27 08:15:11 florian Exp $ */ +/* $OpenBSD: slaacd.c,v 1.64 2021/08/24 14:56:06 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -255,7 +255,8 @@ main(int argc, char *argv[]) rtfilter = ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_NEWADDR) | ROUTE_FILTER(RTM_DELADDR) | ROUTE_FILTER(RTM_DELETE) | - ROUTE_FILTER(RTM_CHGADDRATTR) | ROUTE_FILTER(RTM_PROPOSAL); + ROUTE_FILTER(RTM_CHGADDRATTR) | ROUTE_FILTER(RTM_PROPOSAL) | + ROUTE_FILTER(RTM_IFANNOUNCE); if (setsockopt(frontend_routesock, AF_ROUTE, ROUTE_MSGFILTER, &rtfilter, sizeof(rtfilter)) == -1) fatal("setsockopt(ROUTE_MSGFILTER)"); -- 2.20.1