proto: Fix possible buffer overflow due to non null terminated string
[project/netifd.git] / interface-ip.c
1 /*
2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2012 Steven Barth <steven@midlink.org>
5 *
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
9 *
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.
14 */
15 #include <string.h>
16 #include <stdlib.h>
17 #include <stdio.h>
18
19 #include <limits.h>
20 #include <arpa/inet.h>
21 #include <netinet/in.h>
22
23 #include "netifd.h"
24 #include "device.h"
25 #include "interface.h"
26 #include "interface-ip.h"
27 #include "proto.h"
28 #include "ubus.h"
29 #include "system.h"
30
31 enum {
32 ROUTE_INTERFACE,
33 ROUTE_TARGET,
34 ROUTE_MASK,
35 ROUTE_GATEWAY,
36 ROUTE_METRIC,
37 ROUTE_MTU,
38 ROUTE_VALID,
39 ROUTE_TABLE,
40 ROUTE_SOURCE,
41 ROUTE_ONLINK,
42 ROUTE_TYPE,
43 __ROUTE_MAX
44 };
45
46 static const struct blobmsg_policy route_attr[__ROUTE_MAX] = {
47 [ROUTE_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
48 [ROUTE_TARGET] = { .name = "target", .type = BLOBMSG_TYPE_STRING },
49 [ROUTE_MASK] = { .name = "netmask", .type = BLOBMSG_TYPE_STRING },
50 [ROUTE_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING },
51 [ROUTE_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 },
52 [ROUTE_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
53 [ROUTE_TABLE] = { .name = "table", .type = BLOBMSG_TYPE_STRING },
54 [ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 },
55 [ROUTE_SOURCE] = { .name = "source", .type = BLOBMSG_TYPE_STRING },
56 [ROUTE_ONLINK] = { .name = "onlink", .type = BLOBMSG_TYPE_BOOL },
57 [ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING }
58 };
59
60 const struct uci_blob_param_list route_attr_list = {
61 .n_params = __ROUTE_MAX,
62 .params = route_attr,
63 };
64
65
66 struct list_head prefixes = LIST_HEAD_INIT(prefixes);
67 static struct device_prefix *ula_prefix = NULL;
68 static struct uloop_timeout valid_until_timeout;
69
70
71 static void
72 clear_if_addr(union if_addr *a, int mask)
73 {
74 int m_bytes = (mask + 7) / 8;
75 uint8_t m_clear = (1 << (m_bytes * 8 - mask)) - 1;
76 uint8_t *p = (uint8_t *) a;
77
78 if (m_bytes < sizeof(*a))
79 memset(p + m_bytes, 0, sizeof(*a) - m_bytes);
80
81 p[m_bytes - 1] &= ~m_clear;
82 }
83
84 static bool
85 match_if_addr(union if_addr *a1, union if_addr *a2, int mask)
86 {
87 union if_addr *p1, *p2;
88
89 p1 = alloca(sizeof(*a1));
90 p2 = alloca(sizeof(*a2));
91
92 memcpy(p1, a1, sizeof(*a1));
93 clear_if_addr(p1, mask);
94 memcpy(p2, a2, sizeof(*a2));
95 clear_if_addr(p2, mask);
96
97 return !memcmp(p1, p2, sizeof(*p1));
98 }
99
100 static int set_ip_source_policy(bool add, bool v6, unsigned int priority,
101 const union if_addr *addr, uint8_t mask, unsigned int table,
102 struct interface *in_iface, const char *action, bool src)
103 {
104 struct iprule rule = {
105 .flags = IPRULE_PRIORITY,
106 .priority = priority
107 };
108
109 if (addr) {
110 if (src) {
111 rule.flags |= IPRULE_SRC;
112 rule.src_addr = *addr;
113 rule.src_mask = mask;
114 } else {
115 rule.flags |= IPRULE_DEST;
116 rule.dest_addr = *addr;
117 rule.dest_mask = mask;
118 }
119 }
120
121 if (table) {
122 rule.flags |= IPRULE_LOOKUP;
123 rule.lookup = table;
124
125 if (!rule.lookup)
126 return 0;
127 } else if (action) {
128 rule.flags |= IPRULE_ACTION;
129 system_resolve_iprule_action(action, &rule.action);
130 }
131
132 if (in_iface && in_iface->l3_dev.dev) {
133 rule.flags |= IPRULE_IN;
134 strcpy(rule.in_dev, in_iface->l3_dev.dev->ifname);
135 }
136
137 rule.flags |= (v6) ? IPRULE_INET6 : IPRULE_INET4;
138
139 return (add) ? system_add_iprule(&rule) : system_del_iprule(&rule);
140 }
141
142 static int set_ip_lo_policy(bool add, bool v6, struct interface *iface)
143 {
144 struct iprule rule = {
145 .flags = IPRULE_IN | IPRULE_LOOKUP | IPRULE_PRIORITY,
146 .priority = IPRULE_PRIORITY_NW + iface->l3_dev.dev->ifindex,
147 .lookup = (v6) ? iface->ip6table : iface->ip4table,
148 .in_dev = "lo"
149 };
150
151 if (!rule.lookup)
152 return 0;
153
154 rule.flags |= (v6) ? IPRULE_INET6 : IPRULE_INET4;
155
156 return (add) ? system_add_iprule(&rule) : system_del_iprule(&rule);
157 }
158
159 static bool
160 __find_ip_addr_target(struct interface_ip_settings *ip, union if_addr *a, bool v6)
161 {
162 struct device_addr *addr;
163
164 vlist_for_each_element(&ip->addr, addr, node) {
165 if (!addr->enabled)
166 continue;
167
168 if (v6 != ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6))
169 continue;
170
171 // Handle offlink addresses correctly
172 unsigned int mask = addr->mask;
173 if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6 &&
174 (addr->flags & DEVADDR_OFFLINK))
175 mask = 128;
176
177 if (!match_if_addr(&addr->addr, a, mask))
178 continue;
179
180 return true;
181 }
182
183 return false;
184 }
185
186 static void
187 __find_ip_route_target(struct interface_ip_settings *ip, union if_addr *a,
188 bool v6, struct device_route **res)
189 {
190 struct device_route *route;
191
192 vlist_for_each_element(&ip->route, route, node) {
193 if (!route->enabled)
194 continue;
195
196 if (v6 != ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET6))
197 continue;
198
199 if (!match_if_addr(&route->addr, a, route->mask))
200 continue;
201
202 if (route->flags & DEVROUTE_TABLE)
203 continue;
204
205 if (!*res || route->mask < (*res)->mask)
206 *res = route;
207 }
208 }
209
210 static bool
211 interface_ip_find_addr_target(struct interface *iface, union if_addr *a, bool v6)
212 {
213 return __find_ip_addr_target(&iface->proto_ip, a, v6) ||
214 __find_ip_addr_target(&iface->config_ip, a, v6);
215 }
216
217 static void
218 interface_ip_find_route_target(struct interface *iface, union if_addr *a,
219 bool v6, struct device_route **route)
220 {
221 __find_ip_route_target(&iface->proto_ip, a, v6, route);
222 __find_ip_route_target(&iface->config_ip, a, v6, route);
223 }
224
225 struct interface *
226 interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface)
227 {
228 struct device_route *route, *r_next = NULL;
229 bool defaultroute_target = false;
230 int addrsize = v6 ? sizeof(addr->in6) : sizeof(addr->in);
231
232 route = calloc(1, sizeof(*route));
233 if (!route)
234 return NULL;
235
236 route->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
237 route->mask = v6 ? 128 : 32;
238 if (memcmp(&route->addr, addr, addrsize) == 0)
239 defaultroute_target = true;
240 else
241 memcpy(&route->addr, addr, addrsize);
242
243 if (iface) {
244 /* look for locally addressable target first */
245 if (interface_ip_find_addr_target(iface, addr, v6))
246 goto done;
247
248 /* do not stop at the first route, let the lookup compare
249 * masks to find the best match */
250 interface_ip_find_route_target(iface, addr, v6, &r_next);
251 } else {
252 vlist_for_each_element(&interfaces, iface, node) {
253 /* look for locally addressable target first */
254 if (interface_ip_find_addr_target(iface, addr, v6))
255 goto done;
256
257 /* do not stop at the first route, let the lookup compare
258 * masks to find the best match */
259 interface_ip_find_route_target(iface, addr, v6, &r_next);
260 }
261 }
262
263 if (!r_next) {
264 free(route);
265 return NULL;
266 }
267
268 iface = r_next->iface;
269 memcpy(&route->nexthop, &r_next->nexthop, sizeof(route->nexthop));
270 route->mtu = r_next->mtu;
271 route->metric = r_next->metric;
272 route->table = r_next->table;
273
274 done:
275 route->iface = iface;
276 if (defaultroute_target)
277 free(route);
278 else
279 vlist_add(&iface->host_routes, &route->node, route);
280 return iface;
281 }
282
283 static void
284 interface_set_route_info(struct interface *iface, struct device_route *route)
285 {
286 bool v6 = ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET6);
287
288 if (!iface)
289 return;
290
291 if (!(route->flags & DEVROUTE_METRIC))
292 route->metric = iface->metric;
293
294 if (!(route->flags & DEVROUTE_TABLE)) {
295 route->table = (v6) ? iface->ip6table : iface->ip4table;
296 if (route->table)
297 route->flags |= DEVROUTE_SRCTABLE;
298 }
299 }
300
301 void
302 interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6)
303 {
304 struct interface_ip_settings *ip;
305 struct blob_attr *tb[__ROUTE_MAX], *cur;
306 struct device_route *route;
307 int af = v6 ? AF_INET6 : AF_INET;
308
309 blobmsg_parse(route_attr, __ROUTE_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));
310
311 if (!iface) {
312 if ((cur = tb[ROUTE_INTERFACE]) == NULL)
313 return;
314
315 iface = vlist_find(&interfaces, blobmsg_data(cur), iface, node);
316 if (!iface)
317 return;
318
319 ip = &iface->config_ip;
320 } else {
321 ip = &iface->proto_ip;
322 }
323
324 route = calloc(1, sizeof(*route));
325 if (!route)
326 return;
327
328 route->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
329 route->mask = v6 ? 128 : 32;
330 if ((cur = tb[ROUTE_MASK]) != NULL) {
331 route->mask = parse_netmask_string(blobmsg_data(cur), v6);
332 if (route->mask > (v6 ? 128 : 32))
333 goto error;
334 }
335
336 if ((cur = tb[ROUTE_TARGET]) != NULL) {
337 if (!parse_ip_and_netmask(af, blobmsg_data(cur), &route->addr, &route->mask)) {
338 DPRINTF("Failed to parse route target: %s\n", (char *) blobmsg_data(cur));
339 goto error;
340 }
341 }
342
343 if ((cur = tb[ROUTE_GATEWAY]) != NULL) {
344 if (!inet_pton(af, blobmsg_data(cur), &route->nexthop)) {
345 DPRINTF("Failed to parse route gateway: %s\n", (char *) blobmsg_data(cur));
346 goto error;
347 }
348 }
349
350 if ((cur = tb[ROUTE_METRIC]) != NULL) {
351 route->metric = blobmsg_get_u32(cur);
352 route->flags |= DEVROUTE_METRIC;
353 }
354
355 if ((cur = tb[ROUTE_MTU]) != NULL) {
356 route->mtu = blobmsg_get_u32(cur);
357 route->flags |= DEVROUTE_MTU;
358 }
359
360 // Use source-based routing
361 if ((cur = tb[ROUTE_SOURCE]) != NULL) {
362 char *saveptr, *source = alloca(blobmsg_data_len(cur));
363 memcpy(source, blobmsg_data(cur), blobmsg_data_len(cur));
364
365 const char *addr = strtok_r(source, "/", &saveptr);
366 const char *mask = strtok_r(NULL, "/", &saveptr);
367
368 if (!addr || inet_pton(af, addr, &route->source) < 1) {
369 DPRINTF("Failed to parse route source: %s\n", addr);
370 goto error;
371 }
372
373 route->sourcemask = (mask) ? atoi(mask) : ((af == AF_INET6) ? 128 : 32);
374 }
375
376 if ((cur = tb[ROUTE_ONLINK]) != NULL && blobmsg_get_bool(cur))
377 route->flags |= DEVROUTE_ONLINK;
378
379 if ((cur = tb[ROUTE_TABLE]) != NULL) {
380 if (!system_resolve_rt_table(blobmsg_data(cur), &route->table)) {
381 DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur));
382 goto error;
383 }
384
385 /* only set the table flag if not using the main (default) table */
386 if (system_is_default_rt_table(route->table))
387 route->table = 0;
388
389 if (route->table)
390 route->flags |= DEVROUTE_TABLE;
391 }
392
393 if ((cur = tb[ROUTE_VALID]) != NULL) {
394 int64_t valid = blobmsg_get_u32(cur);
395 int64_t valid_until = valid + (int64_t)system_get_rtime();
396 if (valid_until <= LONG_MAX && valid != 0xffffffffLL) // Catch overflow
397 route->valid_until = valid_until;
398 }
399
400 if ((cur = tb[ROUTE_TYPE]) != NULL) {
401 if (!system_resolve_rt_type(blobmsg_data(cur), &route->type)) {
402 DPRINTF("Failed to resolve routing type: %s\n", (char *) blobmsg_data(cur));
403 goto error;
404 }
405 route->flags |= DEVROUTE_TYPE;
406 }
407
408 interface_set_route_info(iface, route);
409 vlist_add(&ip->route, &route->node, route);
410 return;
411
412 error:
413 free(route);
414 }
415
416 static int
417 addr_cmp(const void *k1, const void *k2, void *ptr)
418 {
419 return memcmp(k1, k2, sizeof(struct device_addr) -
420 offsetof(struct device_addr, flags));
421 }
422
423 static int
424 route_cmp(const void *k1, const void *k2, void *ptr)
425 {
426 const struct device_route *r1 = k1, *r2 = k2;
427
428 if (r1->mask != r2->mask)
429 return r2->mask - r1->mask;
430
431 if (r1->metric != r2->metric)
432 return r1->metric - r2->metric;
433
434 if (r1->flags != r2->flags)
435 return r2->flags - r1->flags;
436
437 if (r1->sourcemask != r2->sourcemask)
438 return r1->sourcemask - r2->sourcemask;
439
440 if (r1->table != r2->table)
441 return r1->table - r2->table;
442
443 int maskcmp = memcmp(&r1->source, &r2->source, sizeof(r1->source));
444 if (maskcmp)
445 return maskcmp;
446
447 return memcmp(&r1->addr, &r2->addr, sizeof(r1->addr));
448 }
449
450 static int
451 prefix_cmp(const void *k1, const void *k2, void *ptr)
452 {
453 return memcmp(k1, k2, offsetof(struct device_prefix, pclass) -
454 offsetof(struct device_prefix, addr));
455 }
456
457 static void
458 interface_handle_subnet_route(struct interface *iface, struct device_addr *addr, bool add)
459 {
460 struct device *dev = iface->l3_dev.dev;
461 struct device_route *r = &addr->subnet;
462
463 if (addr->flags & DEVADDR_OFFLINK)
464 return;
465
466 if (!add) {
467 if (!addr->subnet.iface)
468 return;
469
470 system_del_route(dev, r);
471 memset(r, 0, sizeof(*r));
472 return;
473 }
474
475 r->iface = iface;
476 r->flags = addr->flags;
477 r->mask = addr->mask;
478 memcpy(&r->addr, &addr->addr, sizeof(r->addr));
479 clear_if_addr(&r->addr, r->mask);
480
481 r->flags |= DEVADDR_KERNEL;
482 system_del_route(dev, r);
483
484 r->flags &= ~DEVADDR_KERNEL;
485 interface_set_route_info(iface, r);
486
487 system_add_route(dev, r);
488 }
489
490 static void
491 interface_add_addr_rules(struct device_addr *addr, bool enabled)
492 {
493 bool v6 = (addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6;
494
495 set_ip_source_policy(enabled, v6, IPRULE_PRIORITY_ADDR, &addr->addr,
496 (v6) ? 128 : 32, addr->policy_table, NULL, NULL,
497 true);
498 set_ip_source_policy(enabled, v6, IPRULE_PRIORITY_ADDR_MASK,
499 &addr->addr, addr->mask, addr->policy_table, NULL,
500 NULL, false);
501 }
502
503 static void
504 interface_update_proto_addr(struct vlist_tree *tree,
505 struct vlist_node *node_new,
506 struct vlist_node *node_old)
507 {
508 struct interface_ip_settings *ip;
509 struct interface *iface;
510 struct device *dev;
511 struct device_addr *a_new = NULL, *a_old = NULL;
512 bool replace = false;
513 bool keep = false;
514 bool v6 = false;
515
516 ip = container_of(tree, struct interface_ip_settings, addr);
517 iface = ip->iface;
518 dev = iface->l3_dev.dev;
519
520 if (!node_new || !node_old)
521 iface->updated |= IUF_ADDRESS;
522
523 if (node_new) {
524 a_new = container_of(node_new, struct device_addr, node);
525
526 if ((a_new->flags & DEVADDR_FAMILY) == DEVADDR_INET4 &&
527 !a_new->broadcast) {
528
529 /* /31 and /32 addressing need 255.255.255.255
530 * as broadcast address. */
531 if (a_new->mask >= 31) {
532 a_new->broadcast = (uint32_t) ~0;
533 } else {
534 uint32_t mask = ~0;
535 uint32_t *a = (uint32_t *) &a_new->addr;
536
537 mask >>= a_new->mask;
538 a_new->broadcast = *a | htonl(mask);
539 }
540 }
541 }
542
543 if (node_old)
544 a_old = container_of(node_old, struct device_addr, node);
545
546 if (a_new && a_old) {
547 keep = true;
548
549 if (a_old->flags != a_new->flags || a_old->failed)
550 keep = false;
551
552 if (a_old->valid_until != a_new->valid_until ||
553 a_old->preferred_until != a_new->preferred_until)
554 replace = true;
555
556 if ((a_new->flags & DEVADDR_FAMILY) == DEVADDR_INET4 &&
557 a_new->broadcast != a_old->broadcast)
558 keep = false;
559 }
560
561 if (node_old) {
562 if (a_old->enabled && !keep) {
563 //This is needed for source routing to work correctly. If a device
564 //has two connections to a network using the same subnet, adding
565 //only the network-rule will cause packets to be routed through the
566 //first matching network (source IP matches both masks).
567 if (a_old->policy_table)
568 interface_add_addr_rules(a_old, false);
569
570 if (!(a_old->flags & DEVADDR_EXTERNAL)) {
571 interface_handle_subnet_route(iface, a_old, false);
572 system_del_address(dev, a_old);
573 }
574 }
575 free(a_old->pclass);
576 free(a_old);
577 }
578
579 if (node_new) {
580 a_new->enabled = true;
581
582 if ((a_new->flags & DEVADDR_FAMILY) == DEVADDR_INET6)
583 v6 = true;
584
585 a_new->policy_table = (v6) ? iface->ip6table : iface->ip4table;
586
587 if (!keep || replace) {
588 if (!(a_new->flags & DEVADDR_EXTERNAL)) {
589 if (system_add_address(dev, a_new))
590 a_new->failed = true;
591
592 if (iface->metric || a_new->policy_table)
593 interface_handle_subnet_route(iface, a_new, true);
594 }
595
596 if (!keep) {
597 if (a_new->policy_table)
598 interface_add_addr_rules(a_new, true);
599 }
600 }
601 }
602 }
603
604 static bool
605 enable_route(struct interface_ip_settings *ip, struct device_route *route)
606 {
607 if (ip->no_defaultroute && !route->mask)
608 return false;
609
610 return ip->enabled;
611 }
612
613 static void
614 interface_update_proto_route(struct vlist_tree *tree,
615 struct vlist_node *node_new,
616 struct vlist_node *node_old)
617 {
618 struct interface_ip_settings *ip;
619 struct interface *iface;
620 struct device *dev;
621 struct device_route *route_old, *route_new;
622 bool keep = false;
623
624 ip = container_of(tree, struct interface_ip_settings, route);
625 iface = ip->iface;
626 dev = iface->l3_dev.dev;
627
628 if (!node_new || !node_old)
629 iface->updated |= IUF_ROUTE;
630
631 route_old = container_of(node_old, struct device_route, node);
632 route_new = container_of(node_new, struct device_route, node);
633
634 if (node_old && node_new)
635 keep = !memcmp(&route_old->nexthop, &route_new->nexthop, sizeof(route_old->nexthop)) &&
636 (route_old->mtu == route_new->mtu) && (route_old->type == route_new->type) &&
637 !route_old->failed;
638
639 if (node_old) {
640 if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep)
641 system_del_route(dev, route_old);
642
643 free(route_old);
644 }
645
646 if (node_new) {
647 bool _enabled = enable_route(ip, route_new);
648
649 if (!(route_new->flags & DEVADDR_EXTERNAL) && !keep && _enabled)
650 if (system_add_route(dev, route_new))
651 route_new->failed = true;
652
653 route_new->iface = iface;
654 route_new->enabled = _enabled;
655 }
656 }
657
658 static void
659 interface_update_host_route(struct vlist_tree *tree,
660 struct vlist_node *node_new,
661 struct vlist_node *node_old)
662 {
663 struct interface *iface;
664 struct device *dev;
665 struct device_route *route_old, *route_new;
666
667 iface = container_of(tree, struct interface, host_routes);
668 dev = iface->l3_dev.dev;
669
670 route_old = container_of(node_old, struct device_route, node);
671 route_new = container_of(node_new, struct device_route, node);
672
673 if (node_old) {
674 system_del_route(dev, route_old);
675 free(route_old);
676 }
677
678 if (node_new) {
679 if (system_add_route(dev, route_new))
680 route_new->failed = true;
681 }
682 }
683
684 static void
685 random_ifaceid(struct in6_addr *addr)
686 {
687 static bool initialized = false;
688 struct timeval t;
689
690 if (!initialized) {
691 long int seed = 0;
692 gettimeofday(&t, NULL);
693 seed = t.tv_sec ^ t.tv_usec ^ getpid();
694 srand48(seed);
695 initialized = true;
696 }
697 addr->s6_addr32[2] = (uint32_t)mrand48();
698 addr->s6_addr32[3] = (uint32_t)mrand48();
699 }
700
701 static void
702 eui64_ifaceid(struct interface *iface, struct in6_addr *addr)
703 {
704 /* get mac address */
705 uint8_t *macaddr = iface->l3_dev.dev->settings.macaddr;
706 uint8_t *ifaceid = addr->s6_addr + 8;
707 memcpy(ifaceid,macaddr,3);
708 memcpy(ifaceid + 5,macaddr + 3, 3);
709 ifaceid[3] = 0xff;
710 ifaceid[4] = 0xfe;
711 ifaceid[0] ^= 0x02;
712 }
713
714 static void
715 generate_ifaceid(struct interface *iface, struct in6_addr *addr)
716 {
717 /* generate new iface id */
718 switch (iface->assignment_iface_id_selection) {
719 case IFID_FIXED:
720 /* fixed */
721 /* copy host part from assignment_fixed_iface_id */
722 memcpy(addr->s6_addr + 8, iface->assignment_fixed_iface_id.s6_addr + 8, 8);
723 break;
724 case IFID_RANDOM:
725 /* randomize last 64 bits */
726 random_ifaceid(addr);
727 break;
728 case IFID_EUI64:
729 /* eui64 */
730 eui64_ifaceid(iface, addr);
731 break;
732 }
733 }
734
735 static void
736 interface_set_prefix_address(struct device_prefix_assignment *assignment,
737 const struct device_prefix *prefix, struct interface *iface, bool add)
738 {
739 const struct interface *uplink = prefix->iface;
740 if (!iface->l3_dev.dev)
741 return;
742
743 struct device *l3_downlink = iface->l3_dev.dev;
744
745 struct device_addr addr;
746 struct device_route route;
747 memset(&addr, 0, sizeof(addr));
748 memset(&route, 0, sizeof(route));
749
750 if (IN6_IS_ADDR_UNSPECIFIED(&assignment->addr)) {
751 addr.addr.in6 = prefix->addr;
752 addr.addr.in6.s6_addr32[1] |= htonl(assignment->assigned);
753 generate_ifaceid(iface, &addr.addr.in6);
754 assignment->addr = addr.addr.in6;
755 }
756 else
757 addr.addr.in6 = assignment->addr;
758
759 addr.mask = assignment->length;
760 addr.flags = DEVADDR_INET6 | DEVADDR_OFFLINK;
761 addr.preferred_until = prefix->preferred_until;
762 addr.valid_until = prefix->valid_until;
763
764 route.flags = DEVADDR_INET6;
765 route.mask = addr.mask < 64 ? 64 : addr.mask;
766 route.addr = addr.addr;
767 clear_if_addr(&route.addr, route.mask);
768 interface_set_route_info(iface, &route);
769
770 if (!add && assignment->enabled) {
771 time_t now = system_get_rtime();
772 addr.preferred_until = now;
773 if (!addr.valid_until || addr.valid_until - now > 7200)
774 addr.valid_until = now + 7200;
775
776 if (prefix->iface) {
777 if (prefix->iface->ip6table)
778 set_ip_source_policy(false, true, IPRULE_PRIORITY_NW, &addr.addr,
779 addr.mask, prefix->iface->ip6table, iface, NULL, true);
780
781 set_ip_source_policy(false, true, IPRULE_PRIORITY_REJECT, &addr.addr,
782 addr.mask, 0, iface, "unreachable", true);
783 }
784
785 system_del_route(l3_downlink, &route);
786 system_add_address(l3_downlink, &addr);
787
788 assignment->enabled = false;
789 } else if (add && (iface->state == IFS_UP || iface->state == IFS_SETUP) &&
790 !system_add_address(l3_downlink, &addr)) {
791
792 if (prefix->iface && !assignment->enabled) {
793 set_ip_source_policy(true, true, IPRULE_PRIORITY_REJECT, &addr.addr,
794 addr.mask, 0, iface, "unreachable", true);
795
796 if (prefix->iface->ip6table)
797 set_ip_source_policy(true, true, IPRULE_PRIORITY_NW, &addr.addr,
798 addr.mask, prefix->iface->ip6table, iface, NULL, true);
799 }
800
801 route.metric = iface->metric;
802 system_add_route(l3_downlink, &route);
803
804 if (uplink && uplink->l3_dev.dev && !(l3_downlink->settings.flags & DEV_OPT_MTU6)) {
805 int mtu = system_update_ipv6_mtu(uplink->l3_dev.dev, 0);
806 int mtu_old = system_update_ipv6_mtu(l3_downlink, 0);
807
808 if (mtu > 0 && mtu_old > mtu)
809 system_update_ipv6_mtu(l3_downlink, mtu);
810 }
811
812 assignment->enabled = true;
813 }
814 }
815
816 static bool interface_prefix_assign(struct list_head *list,
817 struct device_prefix_assignment *assign)
818 {
819 int32_t current = 0, asize = (1 << (64 - assign->length)) - 1;
820 struct device_prefix_assignment *c;
821 list_for_each_entry(c, list, head) {
822 if (assign->assigned != -1) {
823 if (assign->assigned >= current && assign->assigned + asize < c->assigned) {
824 list_add_tail(&assign->head, &c->head);
825 return true;
826 }
827 } else if (assign->assigned == -1) {
828 current = (current + asize) & (~asize);
829 if (current + asize < c->assigned) {
830 assign->assigned = current;
831 list_add_tail(&assign->head, &c->head);
832 return true;
833 }
834 }
835 current = (c->assigned + (1 << (64 - c->length)));
836 }
837 return false;
838 }
839
840 static void interface_update_prefix_assignments(struct device_prefix *prefix, bool setup)
841 {
842 struct device_prefix_assignment *c;
843 struct interface *iface;
844
845 // Delete all assignments
846 while (!list_empty(&prefix->assignments)) {
847 c = list_first_entry(&prefix->assignments,
848 struct device_prefix_assignment, head);
849 if ((iface = vlist_find(&interfaces, c->name, iface, node)))
850 interface_set_prefix_address(c, prefix, iface, false);
851 list_del(&c->head);
852 free(c);
853 }
854
855 if (!setup)
856 return;
857
858 // End-of-assignment sentinel
859 c = malloc(sizeof(*c) + 1);
860 c->assigned = 1 << (64 - prefix->length);
861 c->length = 64;
862 c->name[0] = 0;
863 c->addr = in6addr_any;
864 list_add(&c->head, &prefix->assignments);
865
866 // Excluded prefix
867 if (prefix->excl_length > 0) {
868 const char name[] = "!excluded";
869 c = malloc(sizeof(*c) + sizeof(name));
870 c->assigned = ntohl(prefix->excl_addr.s6_addr32[1]) &
871 ((1 << (64 - prefix->length)) - 1);
872 c->length = prefix->excl_length;
873 c->addr = in6addr_any;
874 memcpy(c->name, name, sizeof(name));
875 list_add(&c->head, &prefix->assignments);
876 }
877
878 bool assigned_any = false;
879 struct list_head assign_later = LIST_HEAD_INIT(assign_later);
880 vlist_for_each_element(&interfaces, iface, node) {
881 if (iface->assignment_length < 48 ||
882 iface->assignment_length > 64)
883 continue;
884
885 // Test whether there is a matching class
886 if (!list_empty(&iface->assignment_classes)) {
887 bool found = false;
888
889 struct interface_assignment_class *c;
890 list_for_each_entry(c, &iface->assignment_classes, head) {
891 if (!strcmp(c->name, prefix->pclass)) {
892 found = true;
893 break;
894 }
895 }
896
897 if (!found)
898 continue;
899 }
900
901 size_t namelen = strlen(iface->name) + 1;
902 c = malloc(sizeof(*c) + namelen);
903 c->length = iface->assignment_length;
904 c->assigned = iface->assignment_hint;
905 c->addr = in6addr_any;
906 c->enabled = false;
907 memcpy(c->name, iface->name, namelen);
908
909 // First process all custom assignments, put all others in later-list
910 if (c->assigned == -1 || !interface_prefix_assign(&prefix->assignments, c)) {
911 if (c->assigned != -1) {
912 c->assigned = -1;
913 netifd_log_message(L_WARNING, "Failed to assign requested subprefix "
914 "of size %hhu for %s, trying other\n", c->length, c->name);
915 }
916
917 struct list_head *next = &assign_later;
918 struct device_prefix_assignment *n;
919 list_for_each_entry(n, &assign_later, head) {
920 if (n->length < c->length) {
921 next = &n->head;
922 break;
923 }
924 }
925 list_add_tail(&c->head, next);
926 }
927
928 if (c->assigned != -1)
929 assigned_any = true;
930 }
931
932 // Then try to assign all other + failed custom assignments
933 while (!list_empty(&assign_later)) {
934 c = list_first_entry(&assign_later, struct device_prefix_assignment, head);
935 list_del(&c->head);
936
937 bool assigned = false;
938 do {
939 assigned = interface_prefix_assign(&prefix->assignments, c);
940 } while (!assigned && ++c->length <= 64);
941
942 if (!assigned) {
943 netifd_log_message(L_WARNING, "Failed to assign subprefix "
944 "of size %hhu for %s\n", c->length, c->name);
945 free(c);
946 } else {
947 assigned_any = true;
948 }
949 }
950
951 list_for_each_entry(c, &prefix->assignments, head)
952 if ((iface = vlist_find(&interfaces, c->name, iface, node)))
953 interface_set_prefix_address(c, prefix, iface, true);
954
955 if (!assigned_any)
956 netifd_log_message(L_WARNING, "You have delegated IPv6-prefixes but haven't assigned them "
957 "to any interface. Did you forget to set option ip6assign on your lan-interfaces?");
958 }
959
960
961 void interface_refresh_assignments(bool hint)
962 {
963 static bool refresh = false;
964 if (!hint && refresh) {
965 struct device_prefix *p;
966 list_for_each_entry(p, &prefixes, head)
967 interface_update_prefix_assignments(p, true);
968 }
969 refresh = hint;
970 }
971
972
973 static void
974 interface_update_prefix(struct vlist_tree *tree,
975 struct vlist_node *node_new,
976 struct vlist_node *node_old)
977 {
978 struct device_prefix *prefix_old, *prefix_new;
979 prefix_old = container_of(node_old, struct device_prefix, node);
980 prefix_new = container_of(node_new, struct device_prefix, node);
981
982 struct interface_ip_settings *ip = container_of(tree, struct interface_ip_settings, prefix);
983 if (tree && (!node_new || !node_old))
984 ip->iface->updated |= IUF_PREFIX;
985
986 struct device_route route;
987 memset(&route, 0, sizeof(route));
988 route.flags = DEVADDR_INET6;
989 route.metric = INT32_MAX;
990 route.mask = (node_new) ? prefix_new->length : prefix_old->length;
991 route.addr.in6 = (node_new) ? prefix_new->addr : prefix_old->addr;
992
993
994 struct device_prefix_assignment *c;
995 struct interface *iface;
996
997 if (node_old && node_new) {
998 // Move assignments and refresh addresses to update valid times
999 list_splice(&prefix_old->assignments, &prefix_new->assignments);
1000
1001 list_for_each_entry(c, &prefix_new->assignments, head)
1002 if ((iface = vlist_find(&interfaces, c->name, iface, node)))
1003 interface_set_prefix_address(c, prefix_new, iface, true);
1004 } else if (node_new) {
1005 // Set null-route to avoid routing loops
1006 system_add_route(NULL, &route);
1007
1008 if (!prefix_new->iface || !prefix_new->iface->proto_ip.no_delegation)
1009 interface_update_prefix_assignments(prefix_new, true);
1010 } else if (node_old) {
1011 // Remove null-route
1012 interface_update_prefix_assignments(prefix_old, false);
1013 system_del_route(NULL, &route);
1014 }
1015
1016 if (node_old) {
1017 if (prefix_old->head.next)
1018 list_del(&prefix_old->head);
1019 free(prefix_old);
1020 }
1021
1022 if (node_new && (!prefix_new->iface || !prefix_new->iface->proto_ip.no_delegation))
1023 list_add(&prefix_new->head, &prefixes);
1024
1025 }
1026
1027 struct device_prefix*
1028 interface_ip_add_device_prefix(struct interface *iface, struct in6_addr *addr,
1029 uint8_t length, time_t valid_until, time_t preferred_until,
1030 struct in6_addr *excl_addr, uint8_t excl_length, const char *pclass)
1031 {
1032 if (!pclass)
1033 pclass = (iface) ? iface->name : "local";
1034
1035 struct device_prefix *prefix = calloc(1, sizeof(*prefix) + strlen(pclass) + 1);
1036 prefix->length = length;
1037 prefix->addr = *addr;
1038 prefix->preferred_until = preferred_until;
1039 prefix->valid_until = valid_until;
1040 prefix->iface = iface;
1041 INIT_LIST_HEAD(&prefix->assignments);
1042
1043 if (excl_addr) {
1044 prefix->excl_addr = *excl_addr;
1045 prefix->excl_length = excl_length;
1046 }
1047
1048 strcpy(prefix->pclass, pclass);
1049
1050 if (iface)
1051 vlist_add(&iface->proto_ip.prefix, &prefix->node, &prefix->addr);
1052 else
1053 interface_update_prefix(NULL, &prefix->node, NULL);
1054
1055 return prefix;
1056 }
1057
1058 void
1059 interface_ip_set_ula_prefix(const char *prefix)
1060 {
1061 char buf[INET6_ADDRSTRLEN + 4] = {0}, *saveptr;
1062 if (prefix)
1063 strncpy(buf, prefix, sizeof(buf) - 1);
1064 char *prefixaddr = strtok_r(buf, "/", &saveptr);
1065
1066 struct in6_addr addr;
1067 if (!prefixaddr || inet_pton(AF_INET6, prefixaddr, &addr) < 1) {
1068 if (ula_prefix) {
1069 interface_update_prefix(NULL, NULL, &ula_prefix->node);
1070 ula_prefix = NULL;
1071 }
1072 return;
1073 }
1074
1075 int length;
1076 char *prefixlen = strtok_r(NULL, ",", &saveptr);
1077 if (!prefixlen || (length = atoi(prefixlen)) < 1 || length > 64)
1078 return;
1079
1080 if (!ula_prefix || !IN6_ARE_ADDR_EQUAL(&addr, &ula_prefix->addr) ||
1081 ula_prefix->length != length) {
1082 if (ula_prefix)
1083 interface_update_prefix(NULL, NULL, &ula_prefix->node);
1084
1085 ula_prefix = interface_ip_add_device_prefix(NULL, &addr, length,
1086 0, 0, NULL, 0, NULL);
1087 }
1088 }
1089
1090 void
1091 interface_add_dns_server(struct interface_ip_settings *ip, const char *str)
1092 {
1093 struct dns_server *s;
1094
1095 s = calloc(1, sizeof(*s));
1096 if (!s)
1097 return;
1098
1099 s->af = AF_INET;
1100 if (inet_pton(s->af, str, &s->addr.in))
1101 goto add;
1102
1103 s->af = AF_INET6;
1104 if (inet_pton(s->af, str, &s->addr.in))
1105 goto add;
1106
1107 free(s);
1108 return;
1109
1110 add:
1111 D(INTERFACE, "Add IPv%c DNS server: %s\n",
1112 s->af == AF_INET6 ? '6' : '4', str);
1113 vlist_simple_add(&ip->dns_servers, &s->node);
1114 }
1115
1116 void
1117 interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list)
1118 {
1119 struct blob_attr *cur;
1120 int rem;
1121
1122 blobmsg_for_each_attr(cur, list, rem) {
1123 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
1124 continue;
1125
1126 if (!blobmsg_check_attr(cur, NULL))
1127 continue;
1128
1129 interface_add_dns_server(ip, blobmsg_data(cur));
1130 }
1131 }
1132
1133 static void
1134 interface_add_dns_search_domain(struct interface_ip_settings *ip, const char *str)
1135 {
1136 struct dns_search_domain *s;
1137 int len = strlen(str);
1138
1139 s = calloc(1, sizeof(*s) + len + 1);
1140 if (!s)
1141 return;
1142
1143 D(INTERFACE, "Add DNS search domain: %s\n", str);
1144 memcpy(s->name, str, len);
1145 vlist_simple_add(&ip->dns_search, &s->node);
1146 }
1147
1148 void
1149 interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list)
1150 {
1151 struct blob_attr *cur;
1152 int rem;
1153
1154 blobmsg_for_each_attr(cur, list, rem) {
1155 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
1156 continue;
1157
1158 if (!blobmsg_check_attr(cur, NULL))
1159 continue;
1160
1161 interface_add_dns_search_domain(ip, blobmsg_data(cur));
1162 }
1163 }
1164
1165 static void
1166 write_resolv_conf_entries(FILE *f, struct interface_ip_settings *ip, const char *dev)
1167 {
1168 struct dns_server *s;
1169 struct dns_search_domain *d;
1170 const char *str;
1171 char buf[INET6_ADDRSTRLEN];
1172
1173 vlist_simple_for_each_element(&ip->dns_servers, s, node) {
1174 str = inet_ntop(s->af, &s->addr, buf, sizeof(buf));
1175 if (!str)
1176 continue;
1177
1178 if (s->af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&s->addr.in6))
1179 fprintf(f, "nameserver %s%%%s\n", str, dev);
1180 else
1181 fprintf(f, "nameserver %s\n", str);
1182 }
1183
1184 vlist_simple_for_each_element(&ip->dns_search, d, node) {
1185 fprintf(f, "search %s\n", d->name);
1186 }
1187 }
1188
1189 void
1190 interface_write_resolv_conf(void)
1191 {
1192 struct interface *iface;
1193 char *path = alloca(strlen(resolv_conf) + 5);
1194 FILE *f;
1195 uint32_t crcold, crcnew;
1196
1197 sprintf(path, "%s.tmp", resolv_conf);
1198 unlink(path);
1199 f = fopen(path, "w+");
1200 if (!f) {
1201 D(INTERFACE, "Failed to open %s for writing\n", path);
1202 return;
1203 }
1204
1205 vlist_for_each_element(&interfaces, iface, node) {
1206 if (iface->state != IFS_UP)
1207 continue;
1208
1209 if (vlist_simple_empty(&iface->proto_ip.dns_search) &&
1210 vlist_simple_empty(&iface->proto_ip.dns_servers) &&
1211 vlist_simple_empty(&iface->config_ip.dns_search) &&
1212 vlist_simple_empty(&iface->config_ip.dns_servers))
1213 continue;
1214
1215 fprintf(f, "# Interface %s\n", iface->name);
1216 write_resolv_conf_entries(f, &iface->config_ip, iface->ifname);
1217 if (!iface->proto_ip.no_dns)
1218 write_resolv_conf_entries(f, &iface->proto_ip, iface->ifname);
1219 }
1220 fflush(f);
1221 rewind(f);
1222 crcnew = crc32_file(f);
1223 fclose(f);
1224
1225 crcold = crcnew + 1;
1226 f = fopen(resolv_conf, "r");
1227 if (f) {
1228 crcold = crc32_file(f);
1229 fclose(f);
1230 }
1231
1232 if (crcold == crcnew) {
1233 unlink(path);
1234 } else if (rename(path, resolv_conf) < 0) {
1235 D(INTERFACE, "Failed to replace %s\n", resolv_conf);
1236 unlink(path);
1237 }
1238 }
1239
1240 void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled)
1241 {
1242 struct device_addr *addr;
1243 struct device_route *route;
1244 struct device *dev;
1245 struct interface *iface;
1246
1247 ip->enabled = enabled;
1248 iface = ip->iface;
1249 dev = iface->l3_dev.dev;
1250 if (!dev)
1251 return;
1252
1253 vlist_for_each_element(&ip->addr, addr, node) {
1254 bool v6 = ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6) ? true : false;
1255
1256 if (addr->enabled == enabled)
1257 continue;
1258
1259 if (enabled) {
1260 system_add_address(dev, addr);
1261
1262 addr->policy_table = (v6) ? iface->ip6table : iface->ip4table;
1263 if (iface->metric || addr->policy_table)
1264 interface_handle_subnet_route(iface, addr, true);
1265
1266 if (addr->policy_table)
1267 interface_add_addr_rules(addr, true);
1268 } else {
1269 interface_handle_subnet_route(iface, addr, false);
1270 system_del_address(dev, addr);
1271
1272 if (addr->policy_table)
1273 interface_add_addr_rules(addr, false);
1274 }
1275 addr->enabled = enabled;
1276 }
1277
1278 vlist_for_each_element(&ip->route, route, node) {
1279 bool _enabled = enabled;
1280
1281 if (!enable_route(ip, route))
1282 _enabled = false;
1283
1284 if (route->enabled == _enabled)
1285 continue;
1286
1287 if (_enabled) {
1288 interface_set_route_info(ip->iface, route);
1289
1290 if (system_add_route(dev, route))
1291 route->failed = true;
1292 } else
1293 system_del_route(dev, route);
1294 route->enabled = _enabled;
1295 }
1296
1297 struct device_prefix *c;
1298 struct device_prefix_assignment *a;
1299 list_for_each_entry(c, &prefixes, head)
1300 list_for_each_entry(a, &c->assignments, head)
1301 if (!strcmp(a->name, ip->iface->name))
1302 interface_set_prefix_address(a, c, ip->iface, enabled);
1303
1304 if (ip->iface && ip->iface->policy_rules_set != enabled &&
1305 ip->iface->l3_dev.dev) {
1306 set_ip_lo_policy(enabled, true, ip->iface);
1307 set_ip_lo_policy(enabled, false, ip->iface);
1308
1309 set_ip_source_policy(enabled, true, IPRULE_PRIORITY_REJECT + ip->iface->l3_dev.dev->ifindex,
1310 NULL, 0, 0, ip->iface, "failed_policy", true);
1311 ip->iface->policy_rules_set = enabled;
1312 }
1313 }
1314
1315 void
1316 interface_ip_update_start(struct interface_ip_settings *ip)
1317 {
1318 if (ip != &ip->iface->config_ip) {
1319 vlist_simple_update(&ip->dns_servers);
1320 vlist_simple_update(&ip->dns_search);
1321 }
1322 vlist_update(&ip->route);
1323 vlist_update(&ip->addr);
1324 vlist_update(&ip->prefix);
1325 }
1326
1327 void
1328 interface_ip_update_complete(struct interface_ip_settings *ip)
1329 {
1330 vlist_simple_flush(&ip->dns_servers);
1331 vlist_simple_flush(&ip->dns_search);
1332 vlist_flush(&ip->route);
1333 vlist_flush(&ip->addr);
1334 vlist_flush(&ip->prefix);
1335 interface_write_resolv_conf();
1336 }
1337
1338 void
1339 interface_ip_flush(struct interface_ip_settings *ip)
1340 {
1341 if (ip == &ip->iface->proto_ip)
1342 vlist_flush_all(&ip->iface->host_routes);
1343 vlist_simple_flush_all(&ip->dns_servers);
1344 vlist_simple_flush_all(&ip->dns_search);
1345 vlist_flush_all(&ip->route);
1346 vlist_flush_all(&ip->addr);
1347 vlist_flush_all(&ip->prefix);
1348 }
1349
1350 static void
1351 __interface_ip_init(struct interface_ip_settings *ip, struct interface *iface)
1352 {
1353 ip->iface = iface;
1354 ip->enabled = true;
1355 vlist_simple_init(&ip->dns_search, struct dns_search_domain, node);
1356 vlist_simple_init(&ip->dns_servers, struct dns_server, node);
1357 vlist_init(&ip->route, route_cmp, interface_update_proto_route);
1358 vlist_init(&ip->addr, addr_cmp, interface_update_proto_addr);
1359 vlist_init(&ip->prefix, prefix_cmp, interface_update_prefix);
1360 }
1361
1362 void
1363 interface_ip_init(struct interface *iface)
1364 {
1365 __interface_ip_init(&iface->proto_ip, iface);
1366 __interface_ip_init(&iface->config_ip, iface);
1367 vlist_init(&iface->host_routes, route_cmp, interface_update_host_route);
1368 }
1369
1370 static void
1371 interface_ip_valid_until_handler(struct uloop_timeout *t)
1372 {
1373 time_t now = system_get_rtime();
1374 struct interface *iface;
1375 vlist_for_each_element(&interfaces, iface, node) {
1376 if (iface->state != IFS_UP)
1377 continue;
1378
1379 struct device_addr *addr, *addrp;
1380 struct device_route *route, *routep;
1381 struct device_prefix *pref, *prefp;
1382
1383 vlist_for_each_element_safe(&iface->proto_ip.addr, addr, node, addrp)
1384 if (addr->valid_until && addr->valid_until < now)
1385 vlist_delete(&iface->proto_ip.addr, &addr->node);
1386
1387 vlist_for_each_element_safe(&iface->proto_ip.route, route, node, routep)
1388 if (route->valid_until && route->valid_until < now)
1389 vlist_delete(&iface->proto_ip.route, &route->node);
1390
1391 vlist_for_each_element_safe(&iface->proto_ip.prefix, pref, node, prefp)
1392 if (pref->valid_until && pref->valid_until < now)
1393 vlist_delete(&iface->proto_ip.prefix, &pref->node);
1394
1395 }
1396
1397 uloop_timeout_set(t, 1000);
1398 }
1399
1400 static void __init
1401 interface_ip_init_worker(void)
1402 {
1403 valid_until_timeout.cb = interface_ip_valid_until_handler;
1404 uloop_timeout_set(&valid_until_timeout, 1000);
1405 }