From: florian Date: Sun, 7 Mar 2021 10:31:20 +0000 (+0000) Subject: Fold get_lladdr into update_iface, now the only caller. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8a8bcb8b7f2d92f403f79d9901e5d8bdc1963f4c;p=openbsd Fold get_lladdr into update_iface, now the only caller. This allows us to pass the link state over to engine here instead of in update_addr which is not available in small. This gets us more in line dhcpleased. --- diff --git a/sbin/slaacd/engine.c b/sbin/slaacd/engine.c index 4ed5fa6c350..ad050cca745 100644 --- a/sbin/slaacd/engine.c +++ b/sbin/slaacd/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.65 2021/03/07 10:30:13 florian Exp $ */ +/* $OpenBSD: engine.c,v 1.66 2021/03/07 10:31:20 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -626,7 +626,6 @@ engine_dispatch_main(int fd, short event, void *bula) int shut = 0; #ifndef SMALL struct imsg_addrinfo imsg_addrinfo; - struct imsg_link_state imsg_link_state; struct address_proposal *addr_proposal = NULL; size_t i; #endif /* SMALL */ @@ -745,27 +744,6 @@ engine_dispatch_main(int fd, short event, void *bula) LIST_INSERT_HEAD(&iface->addr_proposals, addr_proposal, entries); - break; - case IMSG_UPDATE_LINK_STATE: - if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_link_state)) - fatalx("%s: IMSG_UPDATE_LINK_STATE wrong " - "length: %lu", __func__, - IMSG_DATA_SIZE(imsg)); - - memcpy(&imsg_link_state, imsg.data, - sizeof(imsg_link_state)); - - iface = get_slaacd_iface_by_id( - imsg_link_state.if_index); - if (iface == NULL) - break; - if (iface->link_state != imsg_link_state.link_state) { - iface->link_state = imsg_link_state.link_state; - if (iface->link_state == LINK_STATE_DOWN) - deprecate_all_proposals(iface); - else - start_probe(iface); - } break; #endif /* SMALL */ default: @@ -1095,6 +1073,7 @@ engine_update_iface(struct imsg_ifinfo *imsg_ifinfo) iface->if_index = imsg_ifinfo->if_index; iface->rdomain = imsg_ifinfo->rdomain; iface->running = imsg_ifinfo->running; + iface->link_state = imsg_ifinfo->link_state; iface->autoconfprivacy = imsg_ifinfo->autoconfprivacy; iface->soii = imsg_ifinfo->soii; memcpy(&iface->hw_address, &imsg_ifinfo->hw_address, @@ -1141,16 +1120,23 @@ engine_update_iface(struct imsg_ifinfo *imsg_ifinfo) iface->running = imsg_ifinfo->running; need_refresh = 1; } + if (imsg_ifinfo->link_state != iface->link_state) { + iface->link_state = imsg_ifinfo->link_state; + need_refresh = 1; + } } if (!need_refresh) return; - if (iface->running) + if (iface->running && LINK_STATE_IS_UP(iface->link_state)) start_probe(iface); else { /* XXX correct state transition */ +#ifndef SMALL + deprecate_all_proposals(iface); +#endif /* SMALL */ iface->state = IF_DOWN; if (evtimer_pending(&iface->timer, NULL)) evtimer_del(&iface->timer); diff --git a/sbin/slaacd/frontend.c b/sbin/slaacd/frontend.c index ab4dba6841d..416a529a65d 100644 --- a/sbin/slaacd/frontend.c +++ b/sbin/slaacd/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.50 2021/03/07 10:30:13 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.51 2021/03/07 10:31:20 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -88,7 +88,6 @@ void icmp6_receive(int, short, void *); int get_flags(char *); int get_xflags(char *); int get_ifrdomain(char *); -void get_lladdr(char *, struct ether_addr *, struct sockaddr_in6 *); struct iface *get_iface_by_id(uint32_t); void remove_iface(uint32_t); struct icmp6_ev *get_icmp6ev_by_rdomain(int); @@ -493,7 +492,10 @@ void update_iface(uint32_t if_index, char* if_name) { struct iface *iface; + struct ifaddrs *ifap, *ifa; struct imsg_ifinfo imsg_ifinfo; + struct sockaddr_dl *sdl; + struct sockaddr_in6 *sin6; int flags, xflags, ifrdomain; if ((flags = get_flags(if_name)) == -1 || (xflags = @@ -532,10 +534,49 @@ update_iface(uint32_t if_index, char* if_name) IFF_RUNNING); imsg_ifinfo.autoconfprivacy = !(xflags & IFXF_INET6_NOPRIVACY); imsg_ifinfo.soii = !(xflags & IFXF_INET6_NOSOII); - get_lladdr(if_name, &imsg_ifinfo.hw_address, &imsg_ifinfo.ll_address); - memcpy(&iface->hw_address, &imsg_ifinfo.hw_address, - sizeof(iface->hw_address)); + if (getifaddrs(&ifap) != 0) + fatal("getifaddrs"); + + for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { + if (strcmp(if_name, ifa->ifa_name) != 0) + continue; + if (ifa->ifa_addr == NULL) + continue; + + switch(ifa->ifa_addr->sa_family) { + case AF_LINK: + imsg_ifinfo.link_state = + ((struct if_data *)ifa->ifa_data)->ifi_link_state; + sdl = (struct sockaddr_dl *)ifa->ifa_addr; + if (sdl->sdl_type != IFT_ETHER || + sdl->sdl_alen != ETHER_ADDR_LEN) + continue; + memcpy(iface->hw_address.ether_addr_octet, + LLADDR(sdl), ETHER_ADDR_LEN); + memcpy(imsg_ifinfo.hw_address.ether_addr_octet, + LLADDR(sdl), ETHER_ADDR_LEN); + case AF_INET6: + sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; +#ifdef __KAME__ + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) && + sin6->sin6_scope_id == 0) { + sin6->sin6_scope_id = ntohs(*(u_int16_t *) + &sin6->sin6_addr.s6_addr[2]); + sin6->sin6_addr.s6_addr[2] = + sin6->sin6_addr.s6_addr[3] = 0; + } +#endif + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) + memcpy(&imsg_ifinfo.ll_address, sin6, + sizeof(imsg_ifinfo.ll_address)); + break; + default: + break; + } + } + + freeifaddrs(ifap); frontend_imsg_compose_main(IMSG_UPDATE_IF, 0, &imsg_ifinfo, sizeof(imsg_ifinfo)); @@ -550,7 +591,6 @@ update_autoconf_addresses(uint32_t if_index, char* if_name) struct ifaddrs *ifap, *ifa; struct in6_addrlifetime *lifetime; struct sockaddr_in6 *sin6; - struct imsg_link_state imsg_link_state; time_t t; int xflags; @@ -563,9 +603,6 @@ update_autoconf_addresses(uint32_t if_index, char* if_name) memset(&imsg_addrinfo, 0, sizeof(imsg_addrinfo)); imsg_addrinfo.if_index = if_index; - memset(&imsg_link_state, 0, sizeof(imsg_link_state)); - imsg_link_state.if_index = if_index; - if (getifaddrs(&ifap) != 0) fatal("getifaddrs"); @@ -575,10 +612,6 @@ update_autoconf_addresses(uint32_t if_index, char* if_name) if (ifa->ifa_addr == NULL) continue; - if (ifa->ifa_addr->sa_family == AF_LINK) - imsg_link_state.link_state = - ((struct if_data *)ifa->ifa_data)->ifi_link_state; - if (ifa->ifa_addr->sa_family != AF_INET6) continue; sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; @@ -645,12 +678,6 @@ update_autoconf_addresses(uint32_t if_index, char* if_name) } freeifaddrs(ifap); - - log_debug("%s: %s link state down? %s", __func__, if_name, - imsg_link_state.link_state == LINK_STATE_DOWN ? "yes" : "no"); - - frontend_imsg_compose_main(IMSG_UPDATE_LINK_STATE, 0, - &imsg_link_state, sizeof(imsg_link_state)); } const char* @@ -917,53 +944,6 @@ get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) } } -void -get_lladdr(char *if_name, struct ether_addr *mac, struct sockaddr_in6 *ll) -{ - struct ifaddrs *ifap, *ifa; - struct sockaddr_dl *sdl; - struct sockaddr_in6 *sin6; - - if (getifaddrs(&ifap) != 0) - fatal("getifaddrs"); - - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if (strcmp(if_name, ifa->ifa_name) != 0) - continue; - if (ifa->ifa_addr == NULL) - continue; - - switch(ifa->ifa_addr->sa_family) { - case AF_LINK: - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - if (sdl->sdl_type != IFT_ETHER || - sdl->sdl_alen != ETHER_ADDR_LEN) - continue; - - memcpy(mac->ether_addr_octet, LLADDR(sdl), - ETHER_ADDR_LEN); - break; - case AF_INET6: - sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; -#ifdef __KAME__ - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) && - sin6->sin6_scope_id == 0) { - sin6->sin6_scope_id = ntohs(*(u_int16_t *) - &sin6->sin6_addr.s6_addr[2]); - sin6->sin6_addr.s6_addr[2] = - sin6->sin6_addr.s6_addr[3] = 0; - } -#endif - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) - memcpy(ll, sin6, sizeof(*ll)); - break; - default: - break; - } - } - freeifaddrs(ifap); -} - void icmp6_receive(int fd, short events, void *arg) { diff --git a/sbin/slaacd/slaacd.c b/sbin/slaacd/slaacd.c index 391680b22da..6aa603e850f 100644 --- a/sbin/slaacd/slaacd.c +++ b/sbin/slaacd/slaacd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slaacd.c,v 1.57 2021/02/27 10:28:12 florian Exp $ */ +/* $OpenBSD: slaacd.c,v 1.58 2021/03/07 10:31:20 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -380,7 +380,6 @@ main_dispatch_frontend(int fd, short event, void *bula) int rdomain; #ifndef SMALL struct imsg_addrinfo imsg_addrinfo; - struct imsg_link_state imsg_link_state; int verbose; #endif /* SMALL */ @@ -431,16 +430,6 @@ main_dispatch_frontend(int fd, short event, void *bula) main_imsg_compose_engine(IMSG_UPDATE_ADDRESS, 0, &imsg_addrinfo, sizeof(imsg_addrinfo)); break; - case IMSG_UPDATE_LINK_STATE: - if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_link_state)) - fatalx("%s: IMSG_UPDATE_LINK_STATE wrong " - "length: %lu", __func__, - IMSG_DATA_SIZE(imsg)); - memcpy(&imsg_link_state, imsg.data, - sizeof(imsg_link_state)); - main_imsg_compose_engine(IMSG_UPDATE_LINK_STATE, 0, - &imsg_link_state, sizeof(imsg_link_state)); - break; #endif /* SMALL */ case IMSG_UPDATE_IF: if (IMSG_DATA_SIZE(imsg) != sizeof(imsg_ifinfo)) diff --git a/sbin/slaacd/slaacd.h b/sbin/slaacd/slaacd.h index 38de182af2b..2f0830f8b59 100644 --- a/sbin/slaacd/slaacd.h +++ b/sbin/slaacd/slaacd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: slaacd.h,v 1.30 2021/03/07 10:30:13 florian Exp $ */ +/* $OpenBSD: slaacd.h,v 1.31 2021/03/07 10:31:20 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser @@ -55,7 +55,6 @@ enum imsg_type { IMSG_CTL_SHOW_INTERFACE_INFO_RDNS_PROPOSAL, IMSG_CTL_END, IMSG_UPDATE_ADDRESS, - IMSG_UPDATE_LINK_STATE, IMSG_PROPOSE_RDNS, IMSG_REPROPOSE_RDNS, #endif /* SMALL */ @@ -176,11 +175,6 @@ struct imsg_addrinfo { uint32_t pltime; }; -struct imsg_link_state { - uint32_t if_index; - int link_state; -}; - struct imsg_propose_rdns { uint32_t if_index; int rdomain; @@ -194,6 +188,7 @@ struct imsg_ifinfo { uint32_t if_index; int rdomain; int running; + int link_state; int autoconfprivacy; int soii; struct ether_addr hw_address;