-/* $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 <florian@openbsd.org>
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 */
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:
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,
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);
-/* $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 <florian@openbsd.org>
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);
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 =
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));
struct ifaddrs *ifap, *ifa;
struct in6_addrlifetime *lifetime;
struct sockaddr_in6 *sin6;
- struct imsg_link_state imsg_link_state;
time_t t;
int xflags;
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");
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;
}
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*
}
}
-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)
{
-/* $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 <florian@openbsd.org>
int rdomain;
#ifndef SMALL
struct imsg_addrinfo imsg_addrinfo;
- struct imsg_link_state imsg_link_state;
int verbose;
#endif /* SMALL */
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))