+ odhcpd_setup_route(addr, 128, iface, NULL, 1024, add);
+}
+
+// compare prefixes
+static int prefixcmp(const void *va, const void *vb)
+{
+ const struct odhcpd_ipaddr *a = va, *b = vb;
+ uint32_t a_pref = ((a->addr.s6_addr[0] & 0xfe) != 0xfc) ? a->preferred : 1;
+ uint32_t b_pref = ((b->addr.s6_addr[0] & 0xfe) != 0xfc) ? b->preferred : 1;
+ return (a_pref < b_pref) ? 1 : (a_pref > b_pref) ? -1 : 0;
+}
+
+// Check address update
+static void check_addr_updates(struct interface *iface)
+{
+ struct odhcpd_ipaddr addr[RELAYD_MAX_ADDRS] = {{IN6ADDR_ANY_INIT, 0, 0, 0, 0}};
+ time_t now = odhcpd_time();
+ ssize_t len = odhcpd_get_interface_addresses(iface->ifindex, addr, ARRAY_SIZE(addr));
+
+ if (len < 0)
+ return;
+
+ qsort(addr, len, sizeof(*addr), prefixcmp);
+
+ for (int i = 0; i < len; ++i) {
+ addr[i].addr.s6_addr32[3] = 0;
+
+ if (addr[i].preferred < UINT32_MAX - now)
+ addr[i].preferred += now;
+
+ if (addr[i].valid < UINT32_MAX - now)
+ addr[i].valid += now;
+ }
+
+ bool change = len != (ssize_t)iface->ia_addr_len;
+ for (ssize_t i = 0; !change && i < len; ++i)
+ if (!IN6_ARE_ADDR_EQUAL(&addr[i].addr, &iface->ia_addr[i].addr) ||
+ (addr[i].preferred > 0) != (iface->ia_addr[i].preferred > 0) ||
+ addr[i].valid < iface->ia_addr[i].valid ||
+ addr[i].preferred < iface->ia_addr[i].preferred)
+ change = true;
+
+ if (change)
+ dhcpv6_ia_preupdate(iface);
+
+ memcpy(iface->ia_addr, addr, len * sizeof(*addr));
+ iface->ia_addr_len = len;
+
+ if (change)
+ dhcpv6_ia_postupdate(iface, now);
+
+ if (change) {
+ syslog(LOG_INFO, "Raising SIGUSR1 due to address change on %s", iface->ifname);
+ raise(SIGUSR1);
+ }
+}
+
+void setup_addr_for_relaying(struct in6_addr *addr, struct interface *iface, bool add)
+{
+ struct interface *c;
+
+ list_for_each_entry(c, &interfaces, head) {
+ if (iface == c || (c->ndp != RELAYD_RELAY && !add))
+ continue;
+
+ odhcpd_setup_proxy_neigh(addr, c, c->ndp == RELAYD_RELAY ? add : false);
+ }
+}
+
+void setup_ping6(struct in6_addr *addr, struct interface *iface)
+{
+ struct interface *c;
+
+ list_for_each_entry(c, &interfaces, head) {
+ if (iface == c || c->ndp != RELAYD_RELAY ||
+ c->external == true)
+ continue;
+
+ ping6(addr, c);
+ }
+}
+
+static struct in6_addr last_solicited;
+
+static void handle_rtnl_event(struct odhcpd_event *e)
+{
+ struct event_socket *ev_sock = container_of(e, struct event_socket, ev);
+
+ nl_recvmsgs_default(ev_sock->sock);