When an interface disappears, e.g. when a usb dongle gets unplugged,
authorflorian <florian@openbsd.org>
Tue, 24 Aug 2021 14:54:02 +0000 (14:54 +0000)
committerflorian <florian@openbsd.org>
Tue, 24 Aug 2021 14:54:02 +0000 (14:54 +0000)
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
sbin/dhcpleased/frontend.c

index 5ff5dcc..3f9f107 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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)");
index b3f015b..6d3bf82 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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;