2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2012 Steven Barth <steven@midlink.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
20 #include <arpa/inet.h>
21 #include <netinet/in.h>
24 #include <netinet/ether.h>
29 #include "interface.h"
30 #include "interface-ip.h"
51 static const struct blobmsg_policy route_attr[__ROUTE_MAX] = {
52 [ROUTE_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
53 [ROUTE_TARGET] = { .name = "target", .type = BLOBMSG_TYPE_STRING },
54 [ROUTE_MASK] = { .name = "netmask", .type = BLOBMSG_TYPE_STRING },
55 [ROUTE_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING },
56 [ROUTE_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 },
57 [ROUTE_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
58 [ROUTE_TABLE] = { .name = "table", .type = BLOBMSG_TYPE_STRING },
59 [ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 },
60 [ROUTE_SOURCE] = { .name = "source", .type = BLOBMSG_TYPE_STRING },
61 [ROUTE_ONLINK] = { .name = "onlink", .type = BLOBMSG_TYPE_BOOL },
62 [ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING },
63 [ROUTE_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING },
66 const struct uci_blob_param_list route_attr_list = {
67 .n_params = __ROUTE_MAX,
80 static const struct blobmsg_policy neighbor_attr[__NEIGHBOR_MAX]={
81 [NEIGHBOR_INTERFACE]= { .name = "interface", .type = BLOBMSG_TYPE_STRING},
82 [NEIGHBOR_ADDRESS]= { .name = "ipaddr", .type = BLOBMSG_TYPE_STRING},
83 [NEIGHBOR_MAC]= { .name = "mac", .type = BLOBMSG_TYPE_STRING},
84 [NEIGHBOR_PROXY]= { .name = "proxy", .type = BLOBMSG_TYPE_BOOL},
85 [NEIGHBOR_ROUTER]= {.name = "router", .type = BLOBMSG_TYPE_BOOL},
88 const struct uci_blob_param_list neighbor_attr_list = {
89 .n_params = __NEIGHBOR_MAX,
90 .params = neighbor_attr,
94 struct list_head prefixes = LIST_HEAD_INIT(prefixes);
95 static struct device_prefix *ula_prefix = NULL;
96 static struct uloop_timeout valid_until_timeout;
100 clear_if_addr(union if_addr *a, int mask)
102 int m_bytes = (mask + 7) / 8;
103 uint8_t m_clear = (1 << (m_bytes * 8 - mask)) - 1;
104 uint8_t *p = (uint8_t *) a;
106 if (m_bytes < sizeof(*a))
107 memset(p + m_bytes, 0, sizeof(*a) - m_bytes);
109 p[m_bytes - 1] &= ~m_clear;
113 match_if_addr(union if_addr *a1, union if_addr *a2, int mask)
115 union if_addr *p1, *p2;
117 p1 = alloca(sizeof(*a1));
118 p2 = alloca(sizeof(*a2));
120 memcpy(p1, a1, sizeof(*a1));
121 clear_if_addr(p1, mask);
122 memcpy(p2, a2, sizeof(*a2));
123 clear_if_addr(p2, mask);
125 return !memcmp(p1, p2, sizeof(*p1));
128 static int set_ip_source_policy(bool add, bool v6, unsigned int priority,
129 const union if_addr *addr, uint8_t mask, unsigned int table,
130 struct interface *in_iface, const char *action, bool src)
132 struct iprule rule = {
133 .flags = IPRULE_PRIORITY,
139 rule.flags |= IPRULE_SRC;
140 rule.src_addr = *addr;
141 rule.src_mask = mask;
143 rule.flags |= IPRULE_DEST;
144 rule.dest_addr = *addr;
145 rule.dest_mask = mask;
150 rule.flags |= IPRULE_LOOKUP;
156 rule.flags |= IPRULE_ACTION;
157 system_resolve_iprule_action(action, &rule.action);
160 if (in_iface && in_iface->l3_dev.dev) {
161 rule.flags |= IPRULE_IN;
162 strcpy(rule.in_dev, in_iface->l3_dev.dev->ifname);
165 rule.flags |= (v6) ? IPRULE_INET6 : IPRULE_INET4;
167 return (add) ? system_add_iprule(&rule) : system_del_iprule(&rule);
170 static int set_ip_lo_policy(bool add, bool v6, struct interface *iface)
172 struct iprule rule = {
173 .flags = IPRULE_IN | IPRULE_LOOKUP | IPRULE_PRIORITY,
174 .priority = IPRULE_PRIORITY_NW + iface->l3_dev.dev->ifindex,
175 .lookup = (v6) ? iface->ip6table : iface->ip4table,
182 rule.flags |= (v6) ? IPRULE_INET6 : IPRULE_INET4;
184 return (add) ? system_add_iprule(&rule) : system_del_iprule(&rule);
188 __find_ip_addr_target(struct interface_ip_settings *ip, union if_addr *a, bool v6)
190 struct device_addr *addr;
192 vlist_for_each_element(&ip->addr, addr, node) {
196 if (v6 != ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6))
199 if (((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) &&
200 addr->point_to_point && a->in.s_addr == addr->point_to_point)
203 /* Handle offlink addresses correctly */
204 unsigned int mask = addr->mask;
205 if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6 &&
206 (addr->flags & DEVADDR_OFFLINK))
209 if (!match_if_addr(&addr->addr, a, mask))
219 __find_ip_route_target(struct interface_ip_settings *ip, union if_addr *a,
220 bool v6, struct device_route **res)
222 struct device_route *route;
224 vlist_for_each_element(&ip->route, route, node) {
228 if (v6 != ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET6))
231 if (!match_if_addr(&route->addr, a, route->mask))
234 if (route->flags & DEVROUTE_TABLE)
237 if (!*res || route->mask > (*res)->mask)
243 interface_ip_find_addr_target(struct interface *iface, union if_addr *a, bool v6)
245 return __find_ip_addr_target(&iface->proto_ip, a, v6) ||
246 __find_ip_addr_target(&iface->config_ip, a, v6);
250 interface_ip_find_route_target(struct interface *iface, union if_addr *a,
251 bool v6, struct device_route **route)
253 __find_ip_route_target(&iface->proto_ip, a, v6, route);
254 __find_ip_route_target(&iface->config_ip, a, v6, route);
258 interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface)
260 struct device_route *route, *r_next = NULL;
261 bool defaultroute_target = false;
262 union if_addr addr_zero;
263 int addrsize = v6 ? sizeof(addr->in6) : sizeof(addr->in);
265 memset(&addr_zero, 0, sizeof(addr_zero));
266 if (memcmp(&addr_zero, addr, addrsize) == 0)
267 defaultroute_target = true;
270 /* look for locally addressable target first */
271 if (interface_ip_find_addr_target(iface, addr, v6))
274 /* do not stop at the first route, let the lookup compare
275 * masks to find the best match */
276 interface_ip_find_route_target(iface, addr, v6, &r_next);
278 vlist_for_each_element(&interfaces, iface, node) {
279 /* look for locally addressable target first */
280 if (interface_ip_find_addr_target(iface, addr, v6))
283 /* do not stop at the first route, let the lookup compare
284 * masks to find the best match */
285 interface_ip_find_route_target(iface, addr, v6, &r_next);
292 iface = r_next->iface;
293 if (defaultroute_target)
296 route = calloc(1, sizeof(*route));
300 route->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
301 route->mask = v6 ? 128 : 32;
302 memcpy(&route->addr, addr, addrsize);
303 memcpy(&route->nexthop, &r_next->nexthop, sizeof(route->nexthop));
304 route->mtu = r_next->mtu;
305 route->metric = r_next->metric;
306 route->table = r_next->table;
307 route->iface = iface;
308 vlist_add(&iface->host_routes, &route->node, route);
314 interface_set_route_info(struct interface *iface, struct device_route *route)
316 bool v6 = ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET6);
321 if (!(route->flags & DEVROUTE_METRIC))
322 route->metric = iface->metric;
324 if (!(route->flags & DEVROUTE_TABLE)) {
325 route->table = (v6) ? iface->ip6table : iface->ip4table;
327 route->flags |= DEVROUTE_SRCTABLE;
332 interface_ip_add_neighbor(struct interface *iface, struct blob_attr *attr, bool v6)
334 struct interface_ip_settings *ip;
335 struct blob_attr *tb[__NEIGHBOR_MAX], *cur;
336 struct device_neighbor *neighbor;
337 int af = v6 ? AF_INET6: AF_INET;
338 struct ether_addr *ea;
340 blobmsg_parse(neighbor_attr, __NEIGHBOR_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));
343 if ((cur = tb[NEIGHBOR_INTERFACE]) == NULL)
346 iface = vlist_find(&interfaces, blobmsg_data(cur), iface, node);
351 ip = &iface->config_ip;
353 ip = &iface->proto_ip;
355 neighbor = calloc(1,sizeof(*neighbor));
359 neighbor->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
361 if ((cur = tb[NEIGHBOR_ADDRESS]) != NULL){
362 if (!inet_pton(af, blobmsg_data(cur), &neighbor->addr))
367 if ((cur = tb[NEIGHBOR_MAC]) != NULL) {
368 neighbor->flags |= DEVNEIGH_MAC;
369 ea = ether_aton(blobmsg_data(cur));
373 memcpy(neighbor->macaddr, ea, 6);
376 if ((cur = tb[NEIGHBOR_PROXY]) != NULL)
377 neighbor->proxy = blobmsg_get_bool(cur);
379 if ((cur = tb[NEIGHBOR_ROUTER]) != NULL)
380 neighbor->router = blobmsg_get_bool(cur);
382 vlist_add(&ip->neighbor, &neighbor->node, neighbor);
390 interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6)
392 struct interface_ip_settings *ip;
393 struct blob_attr *tb[__ROUTE_MAX], *cur;
394 struct device_route *route;
395 int af = v6 ? AF_INET6 : AF_INET;
397 blobmsg_parse(route_attr, __ROUTE_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));
400 if ((cur = tb[ROUTE_INTERFACE]) == NULL)
403 iface = vlist_find(&interfaces, blobmsg_data(cur), iface, node);
407 ip = &iface->config_ip;
409 ip = &iface->proto_ip;
412 route = calloc(1, sizeof(*route));
416 route->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
417 route->mask = v6 ? 128 : 32;
418 if ((cur = tb[ROUTE_MASK]) != NULL) {
419 route->mask = parse_netmask_string(blobmsg_data(cur), v6);
420 if (route->mask > (v6 ? 128 : 32))
424 if ((cur = tb[ROUTE_TARGET]) != NULL) {
425 if (!parse_ip_and_netmask(af, blobmsg_data(cur), &route->addr, &route->mask)) {
426 DPRINTF("Failed to parse route target: %s\n", (char *) blobmsg_data(cur));
431 if ((cur = tb[ROUTE_GATEWAY]) != NULL) {
432 if (!inet_pton(af, blobmsg_data(cur), &route->nexthop)) {
433 DPRINTF("Failed to parse route gateway: %s\n", (char *) blobmsg_data(cur));
438 if ((cur = tb[ROUTE_METRIC]) != NULL) {
439 route->metric = blobmsg_get_u32(cur);
440 route->flags |= DEVROUTE_METRIC;
443 if ((cur = tb[ROUTE_MTU]) != NULL) {
444 route->mtu = blobmsg_get_u32(cur);
445 route->flags |= DEVROUTE_MTU;
448 /* Use source-based routing */
449 if ((cur = tb[ROUTE_SOURCE]) != NULL) {
450 char *saveptr, *source = alloca(blobmsg_data_len(cur));
451 memcpy(source, blobmsg_data(cur), blobmsg_data_len(cur));
453 const char *addr = strtok_r(source, "/", &saveptr);
454 const char *mask = strtok_r(NULL, "/", &saveptr);
456 if (!addr || inet_pton(af, addr, &route->source) < 1) {
457 DPRINTF("Failed to parse route source: %s\n", addr ? addr : "NULL");
461 route->sourcemask = (mask) ? atoi(mask) : ((af == AF_INET6) ? 128 : 32);
464 if ((cur = tb[ROUTE_ONLINK]) != NULL && blobmsg_get_bool(cur))
465 route->flags |= DEVROUTE_ONLINK;
467 if ((cur = tb[ROUTE_TABLE]) != NULL) {
468 if (!system_resolve_rt_table(blobmsg_data(cur), &route->table)) {
469 DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur));
473 /* only set the table flag if not using the main (default) table */
474 if (system_is_default_rt_table(route->table))
478 route->flags |= DEVROUTE_TABLE;
481 if ((cur = tb[ROUTE_VALID]) != NULL) {
482 int64_t valid = blobmsg_get_u32(cur);
483 int64_t valid_until = valid + (int64_t)system_get_rtime();
484 if (valid_until <= LONG_MAX && valid != 0xffffffffLL) /* Catch overflow */
485 route->valid_until = valid_until;
488 if ((cur = tb[ROUTE_TYPE]) != NULL) {
489 if (!system_resolve_rt_type(blobmsg_data(cur), &route->type)) {
490 DPRINTF("Failed to resolve routing type: %s\n", (char *) blobmsg_data(cur));
493 route->flags |= DEVROUTE_TYPE;
496 if ((cur = tb[ROUTE_PROTO]) != NULL) {
497 if (!system_resolve_rt_proto(blobmsg_data(cur), &route->proto)) {
498 DPRINTF("Failed to resolve proto type: %s\n", (char *) blobmsg_data(cur));
501 route->flags |= DEVROUTE_PROTO;
504 interface_set_route_info(iface, route);
505 vlist_add(&ip->route, &route->node, route);
513 addr_cmp(const void *k1, const void *k2, void *ptr)
515 return memcmp(k1, k2, sizeof(struct device_addr) -
516 offsetof(struct device_addr, flags));
520 neighbor_cmp(const void *k1, const void *k2, void *ptr)
522 const struct device_neighbor *n1 = k1, *n2 = k2;
524 return memcmp(&n1->addr, &n2->addr, sizeof(n2->addr));
528 route_cmp(const void *k1, const void *k2, void *ptr)
530 const struct device_route *r1 = k1, *r2 = k2;
532 if (r1->mask != r2->mask)
533 return r2->mask - r1->mask;
535 if (r1->metric != r2->metric)
536 return r1->metric - r2->metric;
538 if (r1->flags != r2->flags)
539 return r2->flags - r1->flags;
541 if (r1->sourcemask != r2->sourcemask)
542 return r1->sourcemask - r2->sourcemask;
544 if (r1->table != r2->table)
545 return r1->table - r2->table;
547 int maskcmp = memcmp(&r1->source, &r2->source, sizeof(r1->source));
551 return memcmp(&r1->addr, &r2->addr, sizeof(r1->addr));
555 prefix_cmp(const void *k1, const void *k2, void *ptr)
557 return memcmp(k1, k2, offsetof(struct device_prefix, pclass) -
558 offsetof(struct device_prefix, addr));
562 interface_handle_subnet_route(struct interface *iface, struct device_addr *addr, bool add)
564 struct device *dev = iface->l3_dev.dev;
565 struct device_route *r = &addr->subnet;
567 if (addr->flags & DEVADDR_OFFLINK)
571 if (!addr->subnet.iface)
574 system_del_route(dev, r);
575 memset(r, 0, sizeof(*r));
580 r->flags = addr->flags;
581 r->mask = addr->mask;
582 memcpy(&r->addr, &addr->addr, sizeof(r->addr));
583 clear_if_addr(&r->addr, r->mask);
585 if (!system_resolve_rt_proto("kernel", &r->proto))
588 r->flags |= DEVROUTE_PROTO;
589 system_del_route(dev, r);
591 r->flags &= ~DEVROUTE_PROTO;
592 interface_set_route_info(iface, r);
594 system_add_route(dev, r);
598 interface_add_addr_rules(struct device_addr *addr, bool enabled)
600 bool v6 = (addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6;
602 set_ip_source_policy(enabled, v6, IPRULE_PRIORITY_ADDR, &addr->addr,
603 (v6) ? 128 : 32, addr->policy_table, NULL, NULL,
605 set_ip_source_policy(enabled, v6, IPRULE_PRIORITY_ADDR_MASK,
606 &addr->addr, addr->mask, addr->policy_table, NULL,
611 interface_update_proto_addr(struct vlist_tree *tree,
612 struct vlist_node *node_new,
613 struct vlist_node *node_old)
615 struct interface_ip_settings *ip;
616 struct interface *iface;
618 struct device_addr *a_new = NULL, *a_old = NULL;
619 bool replace = false;
623 ip = container_of(tree, struct interface_ip_settings, addr);
625 dev = iface->l3_dev.dev;
627 if (!node_new || !node_old)
628 iface->updated |= IUF_ADDRESS;
631 a_new = container_of(node_new, struct device_addr, node);
633 if ((a_new->flags & DEVADDR_FAMILY) == DEVADDR_INET4 &&
636 /* /31 and /32 addressing need 255.255.255.255
637 * as broadcast address. */
638 if (a_new->mask >= 31) {
639 a_new->broadcast = (uint32_t) ~0;
642 uint32_t *a = (uint32_t *) &a_new->addr;
644 mask >>= a_new->mask;
645 a_new->broadcast = *a | htonl(mask);
651 a_old = container_of(node_old, struct device_addr, node);
653 if (a_new && a_old) {
656 if (a_old->flags != a_new->flags || a_old->failed)
659 if (a_old->valid_until != a_new->valid_until ||
660 a_old->preferred_until != a_new->preferred_until)
663 if (((a_new->flags & DEVADDR_FAMILY) == DEVADDR_INET4) &&
664 (a_new->broadcast != a_old->broadcast ||
665 a_new->point_to_point != a_old->point_to_point))
670 if (a_old->enabled && !keep) {
672 * This is needed for source routing to work correctly. If a device
673 * has two connections to a network using the same subnet, adding
674 * only the network-rule will cause packets to be routed through the
675 * first matching network (source IP matches both masks)
677 if (a_old->policy_table)
678 interface_add_addr_rules(a_old, false);
680 if (!(a_old->flags & DEVADDR_EXTERNAL)) {
681 interface_handle_subnet_route(iface, a_old, false);
682 system_del_address(dev, a_old);
690 a_new->enabled = true;
692 if ((a_new->flags & DEVADDR_FAMILY) == DEVADDR_INET6)
695 a_new->policy_table = (v6) ? iface->ip6table : iface->ip4table;
697 if (!keep || replace) {
698 if (!(a_new->flags & DEVADDR_EXTERNAL)) {
699 if (system_add_address(dev, a_new))
700 a_new->failed = true;
702 if (iface->metric || a_new->policy_table)
703 interface_handle_subnet_route(iface, a_new, true);
707 if (a_new->policy_table)
708 interface_add_addr_rules(a_new, true);
715 enable_route(struct interface_ip_settings *ip, struct device_route *route)
717 if (ip->no_defaultroute && !route->mask)
724 interface_update_proto_neighbor(struct vlist_tree *tree,
725 struct vlist_node * node_new,
726 struct vlist_node *node_old)
729 struct device_neighbor *neighbor_old, *neighbor_new;
730 struct interface_ip_settings *ip;
733 ip = container_of(tree, struct interface_ip_settings, neighbor);
734 dev = ip->iface->l3_dev.dev;
736 neighbor_old = container_of(node_old, struct device_neighbor, node);
737 neighbor_new = container_of(node_new, struct device_neighbor, node);
739 if (node_old && node_new) {
740 keep = (!memcmp(neighbor_old->macaddr, neighbor_new->macaddr, sizeof(neighbor_old->macaddr)) &&
741 (neighbor_old->proxy == neighbor_new->proxy) &&
742 (neighbor_old->router == neighbor_new->router));
746 if (!keep && neighbor_old->enabled)
747 system_del_neighbor(dev, neighbor_old);
753 if (!keep && ip->enabled)
754 if (system_add_neighbor(dev, neighbor_new))
755 neighbor_new->failed = true;
757 neighbor_new->enabled = ip->enabled;
762 interface_update_proto_route(struct vlist_tree *tree,
763 struct vlist_node *node_new,
764 struct vlist_node *node_old)
766 struct interface_ip_settings *ip;
767 struct interface *iface;
769 struct device_route *route_old, *route_new;
772 ip = container_of(tree, struct interface_ip_settings, route);
774 dev = iface->l3_dev.dev;
776 if (!node_new || !node_old)
777 iface->updated |= IUF_ROUTE;
779 route_old = container_of(node_old, struct device_route, node);
780 route_new = container_of(node_new, struct device_route, node);
782 if (node_old && node_new)
783 keep = !memcmp(&route_old->nexthop, &route_new->nexthop, sizeof(route_old->nexthop)) &&
784 (route_old->mtu == route_new->mtu) && (route_old->type == route_new->type) &&
785 (route_old->proto == route_new->proto) && !route_old->failed;
788 if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep)
789 system_del_route(dev, route_old);
795 bool _enabled = enable_route(ip, route_new);
797 if (!(route_new->flags & DEVADDR_EXTERNAL) && !keep && _enabled)
798 if (system_add_route(dev, route_new))
799 route_new->failed = true;
801 route_new->iface = iface;
802 route_new->enabled = _enabled;
807 interface_update_host_route(struct vlist_tree *tree,
808 struct vlist_node *node_new,
809 struct vlist_node *node_old)
811 struct interface *iface;
813 struct device_route *route_old, *route_new;
815 iface = container_of(tree, struct interface, host_routes);
816 dev = iface->l3_dev.dev;
818 route_old = container_of(node_old, struct device_route, node);
819 route_new = container_of(node_new, struct device_route, node);
822 system_del_route(dev, route_old);
827 if (system_add_route(dev, route_new))
828 route_new->failed = true;
833 random_ifaceid(struct in6_addr *addr)
835 static bool initialized = false;
840 gettimeofday(&t, NULL);
841 seed = t.tv_sec ^ t.tv_usec ^ getpid();
845 addr->s6_addr32[2] = (uint32_t)mrand48();
846 addr->s6_addr32[3] = (uint32_t)mrand48();
850 eui64_ifaceid(struct interface *iface, struct in6_addr *addr)
852 struct device_settings st;
854 device_merge_settings(iface->l3_dev.dev, &st);
856 if (!(st.flags & DEV_OPT_MACADDR))
859 /* get mac address */
860 uint8_t *ifaceid = addr->s6_addr + 8;
861 memcpy(ifaceid, st.macaddr, 3);
862 memcpy(ifaceid + 5, st.macaddr + 3, 3);
871 generate_ifaceid(struct interface *iface, struct in6_addr *addr)
875 /* generate new iface id */
876 switch (iface->assignment_iface_id_selection) {
879 /* copy host part from assignment_fixed_iface_id */
880 memcpy(addr->s6_addr + 8, iface->assignment_fixed_iface_id.s6_addr + 8, 8);
883 /* randomize last 64 bits */
884 random_ifaceid(addr);
888 ret = eui64_ifaceid(iface, addr);
898 interface_set_prefix_address(struct device_prefix_assignment *assignment,
899 const struct device_prefix *prefix, struct interface *iface, bool add)
901 const struct interface *uplink = prefix->iface;
902 if (!iface->l3_dev.dev)
905 struct device *l3_downlink = iface->l3_dev.dev;
907 struct device_addr addr;
908 struct device_route route;
909 memset(&addr, 0, sizeof(addr));
910 memset(&route, 0, sizeof(route));
912 addr.addr.in6 = assignment->addr;
913 addr.mask = assignment->length;
914 addr.flags = DEVADDR_INET6 | DEVADDR_OFFLINK;
915 addr.preferred_until = prefix->preferred_until;
916 addr.valid_until = prefix->valid_until;
918 route.flags = DEVADDR_INET6;
919 route.mask = addr.mask < 64 ? 64 : addr.mask;
920 route.addr = addr.addr;
922 if (!add && assignment->enabled) {
923 time_t now = system_get_rtime();
925 addr.preferred_until = now;
926 if (!addr.valid_until || addr.valid_until - now > 7200)
927 addr.valid_until = now + 7200;
930 set_ip_source_policy(false, true, IPRULE_PRIORITY_ADDR_MASK, &addr.addr,
931 addr.mask < 64 ? 64 : addr.mask, iface->ip6table, NULL, NULL, false);
934 if (prefix->iface->ip6table)
935 set_ip_source_policy(false, true, IPRULE_PRIORITY_NW, &addr.addr,
936 addr.mask, prefix->iface->ip6table, iface, NULL, true);
938 set_ip_source_policy(false, true, IPRULE_PRIORITY_REJECT, &addr.addr,
939 addr.mask, 0, iface, "unreachable", true);
942 clear_if_addr(&route.addr, route.mask);
943 interface_set_route_info(iface, &route);
945 system_del_route(l3_downlink, &route);
946 system_add_address(l3_downlink, &addr);
948 assignment->addr = in6addr_any;
949 assignment->enabled = false;
950 } else if (add && (iface->state == IFS_UP || iface->state == IFS_SETUP)) {
951 if (IN6_IS_ADDR_UNSPECIFIED(&addr.addr.in6)) {
952 addr.addr.in6 = prefix->addr;
953 addr.addr.in6.s6_addr32[1] |= htonl(assignment->assigned);
954 if (!generate_ifaceid(iface, &addr.addr.in6))
957 assignment->addr = addr.addr.in6;
958 route.addr = addr.addr;
961 if (system_add_address(l3_downlink, &addr))
964 if (!assignment->enabled) {
966 set_ip_source_policy(true, true, IPRULE_PRIORITY_ADDR_MASK, &addr.addr,
967 addr.mask < 64 ? 64 : addr.mask, iface->ip6table, NULL, NULL, false);
970 set_ip_source_policy(true, true, IPRULE_PRIORITY_REJECT, &addr.addr,
971 addr.mask, 0, iface, "unreachable", true);
973 if (prefix->iface->ip6table)
974 set_ip_source_policy(true, true, IPRULE_PRIORITY_NW, &addr.addr,
975 addr.mask, prefix->iface->ip6table, iface, NULL, true);
979 clear_if_addr(&route.addr, route.mask);
980 interface_set_route_info(iface, &route);
982 system_add_route(l3_downlink, &route);
984 if (uplink && uplink->l3_dev.dev && !(l3_downlink->settings.flags & DEV_OPT_MTU6)) {
985 int mtu = system_update_ipv6_mtu(uplink->l3_dev.dev, 0);
986 int mtu_old = system_update_ipv6_mtu(l3_downlink, 0);
988 if (mtu > 0 && mtu_old != mtu) {
989 if (system_update_ipv6_mtu(l3_downlink, mtu) < 0 && mtu < mtu_old)
990 netifd_log_message(L_WARNING, "Failed to set IPv6 mtu to %d "
991 "on interface '%s'\n", mtu, iface->name);
995 assignment->enabled = true;
999 static bool interface_prefix_assign(struct list_head *list,
1000 struct device_prefix_assignment *assign)
1002 int32_t current = 0, asize = (1 << (64 - assign->length)) - 1;
1003 struct device_prefix_assignment *c;
1004 list_for_each_entry(c, list, head) {
1005 if (assign->assigned != -1) {
1006 if (assign->assigned >= current && assign->assigned + asize < c->assigned) {
1007 list_add_tail(&assign->head, &c->head);
1010 } else if (assign->assigned == -1) {
1011 current = (current + asize) & (~asize);
1012 if (current + asize < c->assigned) {
1013 assign->assigned = current;
1014 list_add_tail(&assign->head, &c->head);
1018 current = (c->assigned + (1 << (64 - c->length)));
1024 * Sorting of assignment entries:
1025 * Primary on assignment length: smallest assignment first
1026 * Secondary on assignment weight: highest weight first
1027 * Finally alphabetical order of interface names
1029 static int prefix_assignment_cmp(const void *k1, const void *k2, void *ptr)
1031 const struct device_prefix_assignment *a1 = k1, *a2 = k2;
1033 if (a1->length != a2->length)
1034 return a1->length - a2->length;
1036 if (a1->weight != a2->weight)
1037 return a2->weight - a1->weight;
1039 return strcmp(a1->name, a2->name);
1042 static void interface_update_prefix_assignments(struct device_prefix *prefix, bool setup)
1044 struct device_prefix_assignment *c;
1045 struct interface *iface;
1047 /* Delete all assignments */
1048 while (!list_empty(&prefix->assignments)) {
1049 c = list_first_entry(&prefix->assignments,
1050 struct device_prefix_assignment, head);
1051 if ((iface = vlist_find(&interfaces, c->name, iface, node)))
1052 interface_set_prefix_address(c, prefix, iface, false);
1060 /* End-of-assignment sentinel */
1061 c = malloc(sizeof(*c) + 1);
1065 c->assigned = 1 << (64 - prefix->length);
1068 c->addr = in6addr_any;
1069 list_add(&c->head, &prefix->assignments);
1071 /* Excluded prefix */
1072 if (prefix->excl_length > 0) {
1073 const char name[] = "!excluded";
1074 c = malloc(sizeof(*c) + sizeof(name));
1076 c->assigned = ntohl(prefix->excl_addr.s6_addr32[1]) &
1077 ((1 << (64 - prefix->length)) - 1);
1078 c->length = prefix->excl_length;
1079 c->addr = in6addr_any;
1080 memcpy(c->name, name, sizeof(name));
1081 list_add(&c->head, &prefix->assignments);
1085 bool assigned_any = false;
1087 struct avl_node node;
1089 struct avl_tree assign_later;
1091 avl_init(&assign_later, prefix_assignment_cmp, false, NULL);
1093 vlist_for_each_element(&interfaces, iface, node) {
1094 if (iface->assignment_length < 48 ||
1095 iface->assignment_length > 64)
1098 /* Test whether there is a matching class */
1099 if (!list_empty(&iface->assignment_classes)) {
1102 struct interface_assignment_class *c;
1103 list_for_each_entry(c, &iface->assignment_classes, head) {
1104 if (!strcmp(c->name, prefix->pclass)) {
1114 size_t namelen = strlen(iface->name) + 1;
1115 c = malloc(sizeof(*c) + namelen);
1119 c->length = iface->assignment_length;
1120 c->assigned = iface->assignment_hint;
1121 c->weight = iface->assignment_weight;
1122 c->addr = in6addr_any;
1124 memcpy(c->name, iface->name, namelen);
1126 /* First process all custom assignments, put all others in later-list */
1127 if (c->assigned == -1 || !interface_prefix_assign(&prefix->assignments, c)) {
1128 if (c->assigned != -1) {
1130 netifd_log_message(L_WARNING, "Failed to assign requested subprefix "
1131 "of size %hhu for %s, trying other\n", c->length, c->name);
1134 entry = calloc(1, sizeof(*entry));
1140 entry->node.key = c;
1141 avl_insert(&assign_later, &entry->node);
1144 if (c->assigned != -1)
1145 assigned_any = true;
1148 /* Then try to assign all other + failed custom assignments */
1149 avl_for_each_element_safe(&assign_later, entry, node, n_entry) {
1150 bool assigned = false;
1152 c = (struct device_prefix_assignment *)entry->node.key;
1153 avl_delete(&assign_later, &entry->node);
1156 assigned = interface_prefix_assign(&prefix->assignments, c);
1157 } while (!assigned && ++c->length <= 64);
1160 netifd_log_message(L_WARNING, "Failed to assign subprefix "
1161 "of size %hhu for %s\n", c->length, c->name);
1164 assigned_any = true;
1169 list_for_each_entry(c, &prefix->assignments, head)
1170 if ((iface = vlist_find(&interfaces, c->name, iface, node)))
1171 interface_set_prefix_address(c, prefix, iface, true);
1174 netifd_log_message(L_WARNING, "You have delegated IPv6-prefixes but haven't assigned them "
1175 "to any interface. Did you forget to set option ip6assign on your lan-interfaces?");
1179 void interface_refresh_assignments(bool hint)
1181 static bool refresh = false;
1182 if (!hint && refresh) {
1183 struct device_prefix *p;
1184 list_for_each_entry(p, &prefixes, head)
1185 interface_update_prefix_assignments(p, true);
1190 void interface_update_prefix_delegation(struct interface_ip_settings *ip)
1192 struct device_prefix *prefix;
1194 vlist_for_each_element(&ip->prefix, prefix, node) {
1195 interface_update_prefix_assignments(prefix, !ip->no_delegation);
1197 if (ip->no_delegation) {
1198 if (prefix->head.next)
1199 list_del(&prefix->head);
1201 list_add(&prefix->head, &prefixes);
1206 interface_update_prefix(struct vlist_tree *tree,
1207 struct vlist_node *node_new,
1208 struct vlist_node *node_old)
1210 struct device_prefix *prefix_old, *prefix_new;
1211 prefix_old = container_of(node_old, struct device_prefix, node);
1212 prefix_new = container_of(node_new, struct device_prefix, node);
1214 struct interface_ip_settings *ip = container_of(tree, struct interface_ip_settings, prefix);
1215 if (tree && (!node_new || !node_old))
1216 ip->iface->updated |= IUF_PREFIX;
1218 struct device_route route;
1219 memset(&route, 0, sizeof(route));
1220 route.flags = DEVADDR_INET6;
1221 route.metric = INT32_MAX;
1222 route.mask = (node_new) ? prefix_new->length : prefix_old->length;
1223 route.addr.in6 = (node_new) ? prefix_new->addr : prefix_old->addr;
1226 struct device_prefix_assignment *c;
1227 struct interface *iface;
1229 if (node_old && node_new) {
1230 /* Move assignments and refresh addresses to update valid times */
1231 list_splice(&prefix_old->assignments, &prefix_new->assignments);
1233 list_for_each_entry(c, &prefix_new->assignments, head)
1234 if ((iface = vlist_find(&interfaces, c->name, iface, node)))
1235 interface_set_prefix_address(c, prefix_new, iface, true);
1237 if (prefix_new->preferred_until != prefix_old->preferred_until ||
1238 prefix_new->valid_until != prefix_old->valid_until)
1239 ip->iface->updated |= IUF_PREFIX;
1240 } else if (node_new) {
1241 /* Set null-route to avoid routing loops */
1242 system_add_route(NULL, &route);
1244 if (!prefix_new->iface || !prefix_new->iface->proto_ip.no_delegation)
1245 interface_update_prefix_assignments(prefix_new, true);
1246 } else if (node_old) {
1247 /* Remove null-route */
1248 interface_update_prefix_assignments(prefix_old, false);
1249 system_del_route(NULL, &route);
1253 if (prefix_old->head.next)
1254 list_del(&prefix_old->head);
1258 if (node_new && (!prefix_new->iface || !prefix_new->iface->proto_ip.no_delegation))
1259 list_add(&prefix_new->head, &prefixes);
1263 struct device_prefix*
1264 interface_ip_add_device_prefix(struct interface *iface, struct in6_addr *addr,
1265 uint8_t length, time_t valid_until, time_t preferred_until,
1266 struct in6_addr *excl_addr, uint8_t excl_length, const char *pclass)
1269 pclass = (iface) ? iface->name : "local";
1271 struct device_prefix *prefix = calloc(1, sizeof(*prefix) + strlen(pclass) + 1);
1275 prefix->length = length;
1276 prefix->addr = *addr;
1277 prefix->preferred_until = preferred_until;
1278 prefix->valid_until = valid_until;
1279 prefix->iface = iface;
1280 INIT_LIST_HEAD(&prefix->assignments);
1283 prefix->excl_addr = *excl_addr;
1284 prefix->excl_length = excl_length;
1287 strcpy(prefix->pclass, pclass);
1290 vlist_add(&iface->proto_ip.prefix, &prefix->node, &prefix->addr);
1292 interface_update_prefix(NULL, &prefix->node, NULL);
1298 interface_ip_set_ula_prefix(const char *prefix)
1300 char buf[INET6_ADDRSTRLEN + 4] = {0}, *saveptr;
1302 strncpy(buf, prefix, sizeof(buf) - 1);
1303 char *prefixaddr = strtok_r(buf, "/", &saveptr);
1305 struct in6_addr addr;
1306 if (!prefixaddr || inet_pton(AF_INET6, prefixaddr, &addr) < 1) {
1308 interface_update_prefix(NULL, NULL, &ula_prefix->node);
1315 char *prefixlen = strtok_r(NULL, ",", &saveptr);
1316 if (!prefixlen || (length = atoi(prefixlen)) < 1 || length > 64)
1319 if (!ula_prefix || !IN6_ARE_ADDR_EQUAL(&addr, &ula_prefix->addr) ||
1320 ula_prefix->length != length) {
1322 interface_update_prefix(NULL, NULL, &ula_prefix->node);
1324 ula_prefix = interface_ip_add_device_prefix(NULL, &addr, length,
1325 0, 0, NULL, 0, NULL);
1330 interface_add_dns_server(struct interface_ip_settings *ip, const char *str)
1332 struct dns_server *s;
1334 s = calloc(1, sizeof(*s));
1339 if (inet_pton(s->af, str, &s->addr.in))
1343 if (inet_pton(s->af, str, &s->addr.in))
1350 D(INTERFACE, "Add IPv%c DNS server: %s\n",
1351 s->af == AF_INET6 ? '6' : '4', str);
1352 vlist_simple_add(&ip->dns_servers, &s->node);
1356 interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list)
1358 struct blob_attr *cur;
1361 blobmsg_for_each_attr(cur, list, rem) {
1362 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
1365 if (!blobmsg_check_attr(cur, false))
1368 interface_add_dns_server(ip, blobmsg_data(cur));
1373 interface_add_dns_search_domain(struct interface_ip_settings *ip, const char *str)
1375 struct dns_search_domain *s;
1376 int len = strlen(str);
1378 s = calloc(1, sizeof(*s) + len + 1);
1382 D(INTERFACE, "Add DNS search domain: %s\n", str);
1383 memcpy(s->name, str, len);
1384 vlist_simple_add(&ip->dns_search, &s->node);
1388 interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list)
1390 struct blob_attr *cur;
1393 blobmsg_for_each_attr(cur, list, rem) {
1394 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
1397 if (!blobmsg_check_attr(cur, false))
1400 interface_add_dns_search_domain(ip, blobmsg_data(cur));
1405 write_resolv_conf_entries(FILE *f, struct interface_ip_settings *ip, const char *dev)
1407 struct dns_server *s;
1408 struct dns_search_domain *d;
1410 char buf[INET6_ADDRSTRLEN];
1412 vlist_simple_for_each_element(&ip->dns_servers, s, node) {
1413 str = inet_ntop(s->af, &s->addr, buf, sizeof(buf));
1417 if (s->af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&s->addr.in6))
1418 fprintf(f, "nameserver %s%%%s\n", str, dev);
1420 fprintf(f, "nameserver %s\n", str);
1423 vlist_simple_for_each_element(&ip->dns_search, d, node) {
1424 fprintf(f, "search %s\n", d->name);
1428 /* Sorting of interface resolver entries : */
1429 /* Primary on interface dns_metric : lowest metric first */
1430 /* Secondary on interface metric : lowest metric first */
1431 /* Finally alphabetical order of interface names */
1432 static int resolv_conf_iface_cmp(const void *k1, const void *k2, void *ptr)
1434 const struct interface *iface1 = k1, *iface2 = k2;
1436 if (iface1->dns_metric != iface2->dns_metric)
1437 return iface1->dns_metric - iface2->dns_metric;
1439 if (iface1->metric != iface2->metric)
1440 return iface1->metric - iface2->metric;
1442 return strcmp(iface1->name, iface2->name);
1446 __interface_write_dns_entries(FILE *f)
1448 struct interface *iface;
1450 struct avl_node node;
1452 struct avl_tree resolv_conf_iface_entries;
1454 avl_init(&resolv_conf_iface_entries, resolv_conf_iface_cmp, false, NULL);
1456 vlist_for_each_element(&interfaces, iface, node) {
1457 if (iface->state != IFS_UP)
1460 if (vlist_simple_empty(&iface->proto_ip.dns_search) &&
1461 vlist_simple_empty(&iface->proto_ip.dns_servers) &&
1462 vlist_simple_empty(&iface->config_ip.dns_search) &&
1463 vlist_simple_empty(&iface->config_ip.dns_servers))
1466 entry = calloc(1, sizeof(*entry));
1470 entry->node.key = iface;
1471 avl_insert(&resolv_conf_iface_entries, &entry->node);
1474 avl_for_each_element(&resolv_conf_iface_entries, entry, node) {
1475 iface = (struct interface *)entry->node.key;
1476 struct device *dev = iface->l3_dev.dev;
1478 fprintf(f, "# Interface %s\n", iface->name);
1480 write_resolv_conf_entries(f, &iface->config_ip, dev->ifname);
1482 if (!iface->proto_ip.no_dns)
1483 write_resolv_conf_entries(f, &iface->proto_ip, dev->ifname);
1486 avl_remove_all_elements(&resolv_conf_iface_entries, entry, node, n_entry)
1491 interface_write_resolv_conf(void)
1493 char *path = alloca(strlen(resolv_conf) + 5);
1495 uint32_t crcold, crcnew;
1497 sprintf(path, "%s.tmp", resolv_conf);
1499 f = fopen(path, "w+");
1501 D(INTERFACE, "Failed to open %s for writing\n", path);
1505 __interface_write_dns_entries(f);
1509 crcnew = crc32_file(f);
1512 crcold = crcnew + 1;
1513 f = fopen(resolv_conf, "r");
1515 crcold = crc32_file(f);
1519 if (crcold == crcnew) {
1521 } else if (rename(path, resolv_conf) < 0) {
1522 D(INTERFACE, "Failed to replace %s\n", resolv_conf);
1527 void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled)
1529 struct device_addr *addr;
1530 struct device_route *route;
1531 struct device_neighbor *neighbor;
1533 struct interface *iface;
1535 ip->enabled = enabled;
1537 dev = iface->l3_dev.dev;
1541 vlist_for_each_element(&ip->addr, addr, node) {
1542 bool v6 = ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6) ? true : false;
1544 if (addr->flags & DEVADDR_EXTERNAL)
1547 if (addr->enabled == enabled)
1551 system_add_address(dev, addr);
1553 addr->policy_table = (v6) ? iface->ip6table : iface->ip4table;
1554 if (iface->metric || addr->policy_table)
1555 interface_handle_subnet_route(iface, addr, true);
1557 if (addr->policy_table)
1558 interface_add_addr_rules(addr, true);
1560 interface_handle_subnet_route(iface, addr, false);
1561 system_del_address(dev, addr);
1563 if (addr->policy_table)
1564 interface_add_addr_rules(addr, false);
1566 addr->enabled = enabled;
1569 vlist_for_each_element(&ip->route, route, node) {
1570 bool _enabled = enabled;
1572 if (route->flags & DEVADDR_EXTERNAL)
1575 if (!enable_route(ip, route))
1577 if (route->enabled == _enabled)
1581 interface_set_route_info(ip->iface, route);
1583 if (system_add_route(dev, route))
1584 route->failed = true;
1586 system_del_route(dev, route);
1587 route->enabled = _enabled;
1590 vlist_for_each_element(&ip->neighbor, neighbor, node) {
1591 if (neighbor->enabled == enabled)
1595 if(system_add_neighbor(dev, neighbor))
1596 neighbor->failed = true;
1598 system_del_neighbor(dev, neighbor);
1600 neighbor->enabled = enabled;
1603 struct device_prefix *c;
1604 struct device_prefix_assignment *a;
1605 list_for_each_entry(c, &prefixes, head)
1606 list_for_each_entry(a, &c->assignments, head)
1607 if (!strcmp(a->name, ip->iface->name))
1608 interface_set_prefix_address(a, c, ip->iface, enabled);
1610 if (ip->iface->policy_rules_set != enabled &&
1611 ip->iface->l3_dev.dev) {
1612 set_ip_lo_policy(enabled, true, ip->iface);
1613 set_ip_lo_policy(enabled, false, ip->iface);
1615 set_ip_source_policy(enabled, true, IPRULE_PRIORITY_REJECT + ip->iface->l3_dev.dev->ifindex,
1616 NULL, 0, 0, ip->iface, "failed_policy", true);
1617 ip->iface->policy_rules_set = enabled;
1622 interface_ip_update_start(struct interface_ip_settings *ip)
1624 if (ip != &ip->iface->config_ip) {
1625 vlist_simple_update(&ip->dns_servers);
1626 vlist_simple_update(&ip->dns_search);
1628 vlist_update(&ip->route);
1629 vlist_update(&ip->addr);
1630 vlist_update(&ip->prefix);
1631 vlist_update(&ip->neighbor);
1635 interface_ip_update_complete(struct interface_ip_settings *ip)
1637 vlist_simple_flush(&ip->dns_servers);
1638 vlist_simple_flush(&ip->dns_search);
1639 vlist_flush(&ip->route);
1640 vlist_flush(&ip->addr);
1641 vlist_flush(&ip->prefix);
1642 vlist_flush(&ip->neighbor);
1643 interface_write_resolv_conf();
1647 interface_ip_flush(struct interface_ip_settings *ip)
1649 if (ip == &ip->iface->proto_ip)
1650 vlist_flush_all(&ip->iface->host_routes);
1651 vlist_simple_flush_all(&ip->dns_servers);
1652 vlist_simple_flush_all(&ip->dns_search);
1653 vlist_flush_all(&ip->route);
1654 vlist_flush_all(&ip->addr);
1655 vlist_flush_all(&ip->neighbor);
1656 vlist_flush_all(&ip->prefix);
1660 __interface_ip_init(struct interface_ip_settings *ip, struct interface *iface)
1664 vlist_simple_init(&ip->dns_search, struct dns_search_domain, node);
1665 vlist_simple_init(&ip->dns_servers, struct dns_server, node);
1666 vlist_init(&ip->route, route_cmp, interface_update_proto_route);
1667 vlist_init(&ip->neighbor, neighbor_cmp, interface_update_proto_neighbor);
1668 vlist_init(&ip->addr, addr_cmp, interface_update_proto_addr);
1669 vlist_init(&ip->prefix, prefix_cmp, interface_update_prefix);
1673 interface_ip_init(struct interface *iface)
1675 __interface_ip_init(&iface->proto_ip, iface);
1676 __interface_ip_init(&iface->config_ip, iface);
1677 vlist_init(&iface->host_routes, route_cmp, interface_update_host_route);
1681 interface_ip_valid_until_handler(struct uloop_timeout *t)
1683 time_t now = system_get_rtime();
1684 struct interface *iface;
1685 vlist_for_each_element(&interfaces, iface, node) {
1686 if (iface->state != IFS_UP)
1689 struct device_addr *addr, *addrp;
1690 struct device_route *route, *routep;
1691 struct device_prefix *pref, *prefp;
1693 vlist_for_each_element_safe(&iface->proto_ip.addr, addr, node, addrp)
1694 if (addr->valid_until && addr->valid_until < now)
1695 vlist_delete(&iface->proto_ip.addr, &addr->node);
1697 vlist_for_each_element_safe(&iface->proto_ip.route, route, node, routep)
1698 if (route->valid_until && route->valid_until < now)
1699 vlist_delete(&iface->proto_ip.route, &route->node);
1701 vlist_for_each_element_safe(&iface->proto_ip.prefix, pref, node, prefp)
1702 if (pref->valid_until && pref->valid_until < now)
1703 vlist_delete(&iface->proto_ip.prefix, &pref->node);
1707 uloop_timeout_set(t, 1000);
1711 interface_ip_init_worker(void)
1713 valid_until_timeout.cb = interface_ip_valid_until_handler;
1714 uloop_timeout_set(&valid_until_timeout, 1000);