c53c091c32325c13e61a70caa628e15699e5871a
[project/netifd.git] / interface.c
1 /*
2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 #include <string.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <sys/types.h>
18 #include <sys/wait.h>
19
20 #include "netifd.h"
21 #include "device.h"
22 #include "interface.h"
23 #include "interface-ip.h"
24 #include "proto.h"
25 #include "ubus.h"
26 #include "config.h"
27 #include "system.h"
28
29 struct vlist_tree interfaces;
30 static LIST_HEAD(iface_all_users);
31
32 enum {
33 IFACE_ATTR_IFNAME,
34 IFACE_ATTR_PROTO,
35 IFACE_ATTR_AUTO,
36 IFACE_ATTR_JAIL,
37 IFACE_ATTR_JAIL_IFNAME,
38 IFACE_ATTR_DEFAULTROUTE,
39 IFACE_ATTR_PEERDNS,
40 IFACE_ATTR_DNS,
41 IFACE_ATTR_DNS_SEARCH,
42 IFACE_ATTR_DNS_METRIC,
43 IFACE_ATTR_METRIC,
44 IFACE_ATTR_INTERFACE,
45 IFACE_ATTR_IP6ASSIGN,
46 IFACE_ATTR_IP6HINT,
47 IFACE_ATTR_IP4TABLE,
48 IFACE_ATTR_IP6TABLE,
49 IFACE_ATTR_IP6CLASS,
50 IFACE_ATTR_DELEGATE,
51 IFACE_ATTR_IP6IFACEID,
52 IFACE_ATTR_FORCE_LINK,
53 IFACE_ATTR_IP6WEIGHT,
54 IFACE_ATTR_MAX
55 };
56
57 static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
58 [IFACE_ATTR_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING },
59 [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
60 [IFACE_ATTR_AUTO] = { .name = "auto", .type = BLOBMSG_TYPE_BOOL },
61 [IFACE_ATTR_JAIL] = { .name = "jail", .type = BLOBMSG_TYPE_STRING },
62 [IFACE_ATTR_JAIL_IFNAME] = { .name = "jail_ifname", .type = BLOBMSG_TYPE_STRING },
63 [IFACE_ATTR_DEFAULTROUTE] = { .name = "defaultroute", .type = BLOBMSG_TYPE_BOOL },
64 [IFACE_ATTR_PEERDNS] = { .name = "peerdns", .type = BLOBMSG_TYPE_BOOL },
65 [IFACE_ATTR_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 },
66 [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
67 [IFACE_ATTR_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY },
68 [IFACE_ATTR_DNS_METRIC] = { .name = "dns_metric", .type = BLOBMSG_TYPE_INT32 },
69 [IFACE_ATTR_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
70 [IFACE_ATTR_IP6ASSIGN] = { .name = "ip6assign", .type = BLOBMSG_TYPE_INT32 },
71 [IFACE_ATTR_IP6HINT] = { .name = "ip6hint", .type = BLOBMSG_TYPE_STRING },
72 [IFACE_ATTR_IP4TABLE] = { .name = "ip4table", .type = BLOBMSG_TYPE_STRING },
73 [IFACE_ATTR_IP6TABLE] = { .name = "ip6table", .type = BLOBMSG_TYPE_STRING },
74 [IFACE_ATTR_IP6CLASS] = { .name = "ip6class", .type = BLOBMSG_TYPE_ARRAY },
75 [IFACE_ATTR_DELEGATE] = { .name = "delegate", .type = BLOBMSG_TYPE_BOOL },
76 [IFACE_ATTR_IP6IFACEID] = { .name = "ip6ifaceid", .type = BLOBMSG_TYPE_STRING },
77 [IFACE_ATTR_FORCE_LINK] = { .name = "force_link", .type = BLOBMSG_TYPE_BOOL },
78 [IFACE_ATTR_IP6WEIGHT] = { .name = "ip6weight", .type = BLOBMSG_TYPE_INT32 },
79 };
80
81 const struct uci_blob_param_list interface_attr_list = {
82 .n_params = IFACE_ATTR_MAX,
83 .params = iface_attrs,
84 };
85
86 static void
87 interface_set_main_dev(struct interface *iface, struct device *dev);
88 static void
89 interface_event(struct interface *iface, enum interface_event ev);
90
91 static void
92 interface_error_flush(struct interface *iface)
93 {
94 struct interface_error *error, *tmp;
95
96 list_for_each_entry_safe(error, tmp, &iface->errors, list) {
97 list_del(&error->list);
98 free(error);
99 }
100 }
101
102 static void
103 interface_clear_errors(struct interface *iface)
104 {
105 /* don't flush the errors in case the configured protocol handler matches the
106 running protocol handler and is having the last error capability */
107 if (!(iface->proto &&
108 (iface->proto->handler->flags & PROTO_FLAG_LASTERROR) &&
109 (iface->proto->handler->name == iface->proto_handler->name)))
110 interface_error_flush(iface);
111 }
112
113 void interface_add_error(struct interface *iface, const char *subsystem,
114 const char *code, const char **data, int n_data)
115 {
116 struct interface_error *error;
117 int i, len = 0;
118 int *datalen = NULL;
119 char *dest, *d_subsys, *d_code;
120
121 /* if the configured protocol handler has the last error support capability,
122 errors should only be added if the running protocol handler matches the
123 configured one */
124 if (iface->proto &&
125 (iface->proto->handler->flags & PROTO_FLAG_LASTERROR) &&
126 (iface->proto->handler->name != iface->proto_handler->name))
127 return;
128
129 if (n_data) {
130 len = n_data * sizeof(char *);
131 datalen = alloca(len);
132 for (i = 0; i < n_data; i++) {
133 datalen[i] = strlen(data[i]) + 1;
134 len += datalen[i];
135 }
136 }
137
138 error = calloc_a(sizeof(*error) + sizeof(char *) + len,
139 &d_subsys, subsystem ? strlen(subsystem) + 1 : 0,
140 &d_code, code ? strlen(code) + 1 : 0);
141 if (!error)
142 return;
143
144 /* Only keep the last flagged error, prevent this list grows unlimitted in case the
145 protocol can't be established (e.g auth failure) */
146 if (iface->proto_handler->flags & PROTO_FLAG_LASTERROR)
147 interface_error_flush(iface);
148
149 list_add_tail(&error->list, &iface->errors);
150
151 dest = (char *) &error->data[n_data + 1];
152 for (i = 0; i < n_data; i++) {
153 error->data[i] = dest;
154 memcpy(dest, data[i], datalen[i]);
155 dest += datalen[i];
156 }
157 error->data[n_data] = NULL;
158
159 if (subsystem)
160 error->subsystem = strcpy(d_subsys, subsystem);
161
162 if (code)
163 error->code = strcpy(d_code, code);
164 }
165
166 static void
167 interface_data_del(struct interface *iface, struct interface_data *data)
168 {
169 avl_delete(&iface->data, &data->node);
170 free(data);
171 }
172
173 static void
174 interface_data_flush(struct interface *iface)
175 {
176 struct interface_data *d, *tmp;
177
178 avl_for_each_element_safe(&iface->data, d, node, tmp)
179 interface_data_del(iface, d);
180 }
181
182 int
183 interface_add_data(struct interface *iface, const struct blob_attr *data)
184 {
185 struct interface_data *n, *o;
186
187 if (!blobmsg_check_attr(data, true))
188 return UBUS_STATUS_INVALID_ARGUMENT;
189
190 const char *name = blobmsg_name(data);
191 unsigned len = blob_pad_len(data);
192
193 o = avl_find_element(&iface->data, name, o, node);
194 if (o) {
195 if (blob_pad_len(o->data) == len && !memcmp(o->data, data, len))
196 return 0;
197
198 interface_data_del(iface, o);
199 }
200
201 n = calloc(1, sizeof(*n) + len);
202 if (!n)
203 return UBUS_STATUS_UNKNOWN_ERROR;
204
205 memcpy(n->data, data, len);
206 n->node.key = blobmsg_name(n->data);
207 avl_insert(&iface->data, &n->node);
208
209 iface->updated |= IUF_DATA;
210 return 0;
211 }
212
213 int interface_parse_data(struct interface *iface, const struct blob_attr *attr)
214 {
215 struct blob_attr *cur;
216 int rem, ret;
217
218 iface->updated = 0;
219
220 blob_for_each_attr(cur, attr, rem) {
221 ret = interface_add_data(iface, cur);
222 if (ret)
223 return ret;
224 }
225
226 if (iface->updated && iface->state == IFS_UP)
227 interface_event(iface, IFEV_UPDATE);
228
229 return 0;
230 }
231
232 static void
233 interface_event(struct interface *iface, enum interface_event ev)
234 {
235 struct interface_user *dep, *tmp;
236 struct device *adev = NULL;
237
238 list_for_each_entry_safe(dep, tmp, &iface->users, list)
239 dep->cb(dep, iface, ev);
240
241 list_for_each_entry_safe(dep, tmp, &iface_all_users, list)
242 dep->cb(dep, iface, ev);
243
244 switch (ev) {
245 case IFEV_UP:
246 interface_error_flush(iface);
247 adev = iface->l3_dev.dev;
248 /* fall through */
249 case IFEV_DOWN:
250 case IFEV_UP_FAILED:
251 alias_notify_device(iface->name, adev);
252 break;
253 default:
254 break;
255 }
256 }
257
258 static void
259 interface_flush_state(struct interface *iface)
260 {
261 if (iface->l3_dev.dev)
262 device_release(&iface->l3_dev);
263 interface_data_flush(iface);
264 }
265
266 static void
267 mark_interface_down(struct interface *iface)
268 {
269 enum interface_state state = iface->state;
270
271 if (state == IFS_DOWN)
272 return;
273
274 iface->link_up_event = false;
275 iface->state = IFS_DOWN;
276 switch (state) {
277 case IFS_UP:
278 case IFS_TEARDOWN:
279 interface_event(iface, IFEV_DOWN);
280 break;
281 case IFS_SETUP:
282 interface_event(iface, IFEV_UP_FAILED);
283 break;
284 default:
285 break;
286 }
287 interface_ip_set_enabled(&iface->config_ip, false);
288 interface_ip_set_enabled(&iface->proto_ip, false);
289 interface_ip_flush(&iface->proto_ip);
290 interface_flush_state(iface);
291 system_flush_routes();
292 }
293
294 static inline void
295 __set_config_state(struct interface *iface, enum interface_config_state s)
296 {
297 iface->config_state = s;
298 }
299
300 static void
301 __interface_set_down(struct interface *iface, bool force)
302 {
303 enum interface_state state = iface->state;
304 switch (state) {
305 case IFS_UP:
306 case IFS_SETUP:
307 iface->state = IFS_TEARDOWN;
308 if (iface->dynamic)
309 __set_config_state(iface, IFC_REMOVE);
310
311 if (state == IFS_UP)
312 interface_event(iface, IFEV_DOWN);
313
314 interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, force);
315 if (force)
316 interface_flush_state(iface);
317 break;
318
319 case IFS_DOWN:
320 if (iface->main_dev.dev)
321 device_release(&iface->main_dev);
322 case IFS_TEARDOWN:
323 default:
324 break;
325 }
326 }
327
328 static int
329 __interface_set_up(struct interface *iface)
330 {
331 int ret;
332
333 netifd_log_message(L_NOTICE, "Interface '%s' is setting up now\n", iface->name);
334
335 iface->state = IFS_SETUP;
336 ret = interface_proto_event(iface->proto, PROTO_CMD_SETUP, false);
337 if (ret)
338 mark_interface_down(iface);
339
340 return ret;
341 }
342
343 static void
344 interface_check_state(struct interface *iface)
345 {
346 bool link_state = iface->link_state || iface->force_link;
347
348 switch (iface->state) {
349 case IFS_UP:
350 case IFS_SETUP:
351 if (!iface->enabled || !link_state) {
352 iface->state = IFS_TEARDOWN;
353 if (iface->dynamic)
354 __set_config_state(iface, IFC_REMOVE);
355
356 interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
357 }
358 break;
359 case IFS_DOWN:
360 if (!iface->available)
361 return;
362
363 if (iface->autostart && iface->enabled && link_state && !config_init)
364 __interface_set_up(iface);
365 break;
366 default:
367 break;
368 }
369 }
370
371 static void
372 interface_set_enabled(struct interface *iface, bool new_state)
373 {
374 if (iface->enabled == new_state)
375 return;
376
377 netifd_log_message(L_NOTICE, "Interface '%s' is %s\n", iface->name, new_state ? "enabled" : "disabled");
378 iface->enabled = new_state;
379 interface_check_state(iface);
380 }
381
382 static void
383 interface_set_link_state(struct interface *iface, bool new_state)
384 {
385 if (iface->link_state == new_state)
386 return;
387
388 netifd_log_message(L_NOTICE, "Interface '%s' has link connectivity %s\n", iface->name, new_state ? "" : "loss");
389 iface->link_state = new_state;
390 interface_check_state(iface);
391
392 if (new_state && iface->force_link && iface->state == IFS_UP && !iface->link_up_event) {
393 interface_event(iface, IFEV_LINK_UP);
394 iface->link_up_event = true;
395 }
396 }
397
398 static void
399 interface_ext_dev_cb(struct device_user *dep, enum device_event ev)
400 {
401 if (ev == DEV_EVENT_REMOVE)
402 device_remove_user(dep);
403 }
404
405 static void
406 interface_main_dev_cb(struct device_user *dep, enum device_event ev)
407 {
408 struct interface *iface;
409
410 iface = container_of(dep, struct interface, main_dev);
411 switch (ev) {
412 case DEV_EVENT_ADD:
413 interface_set_available(iface, true);
414 break;
415 case DEV_EVENT_REMOVE:
416 interface_set_available(iface, false);
417 if (dep->dev && dep->dev->external)
418 interface_set_main_dev(iface, NULL);
419 break;
420 case DEV_EVENT_UP:
421 interface_set_enabled(iface, true);
422 break;
423 case DEV_EVENT_DOWN:
424 interface_set_enabled(iface, false);
425 break;
426 case DEV_EVENT_LINK_UP:
427 interface_set_link_state(iface, true);
428 break;
429 case DEV_EVENT_LINK_DOWN:
430 interface_set_link_state(iface, false);
431 break;
432 case DEV_EVENT_TOPO_CHANGE:
433 interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
434 return;
435 default:
436 break;
437 }
438 }
439
440 static void
441 interface_l3_dev_cb(struct device_user *dep, enum device_event ev)
442 {
443 struct interface *iface;
444
445 iface = container_of(dep, struct interface, l3_dev);
446 if (iface->l3_dev.dev == iface->main_dev.dev)
447 return;
448
449 switch (ev) {
450 case DEV_EVENT_LINK_DOWN:
451 if (iface->proto_handler->flags & PROTO_FLAG_TEARDOWN_ON_L3_LINK_DOWN)
452 interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
453 break;
454 default:
455 break;
456 }
457 }
458
459 void
460 interface_set_available(struct interface *iface, bool new_state)
461 {
462 if (iface->available == new_state)
463 return;
464
465 D(INTERFACE, "Interface '%s', available=%d\n", iface->name, new_state);
466 iface->available = new_state;
467
468 if (new_state) {
469 if (iface->autostart && !config_init)
470 interface_set_up(iface);
471 } else
472 __interface_set_down(iface, true);
473 }
474
475 void
476 interface_add_user(struct interface_user *dep, struct interface *iface)
477 {
478 if (!iface) {
479 list_add(&dep->list, &iface_all_users);
480 return;
481 }
482
483 dep->iface = iface;
484 list_add(&dep->list, &iface->users);
485 if (iface->state == IFS_UP)
486 dep->cb(dep, iface, IFEV_UP);
487 }
488
489 void
490 interface_remove_user(struct interface_user *dep)
491 {
492 list_del_init(&dep->list);
493 dep->iface = NULL;
494 }
495
496 static void
497 interface_add_assignment_classes(struct interface *iface, struct blob_attr *list)
498 {
499 struct blob_attr *cur;
500 int rem;
501
502 blobmsg_for_each_attr(cur, list, rem) {
503 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
504 continue;
505
506 if (!blobmsg_check_attr(cur, false))
507 continue;
508
509 struct interface_assignment_class *c = malloc(sizeof(*c) + blobmsg_data_len(cur));
510 memcpy(c->name, blobmsg_data(cur), blobmsg_data_len(cur));
511 list_add(&c->head, &iface->assignment_classes);
512 }
513 }
514
515 static void
516 interface_clear_assignment_classes(struct interface *iface)
517 {
518 while (!list_empty(&iface->assignment_classes)) {
519 struct interface_assignment_class *c = list_first_entry(&iface->assignment_classes,
520 struct interface_assignment_class, head);
521 list_del(&c->head);
522 free(c);
523 }
524 }
525
526 static void
527 interface_merge_assignment_data(struct interface *old, struct interface *new)
528 {
529 bool changed = (old->assignment_hint != new->assignment_hint ||
530 old->assignment_length != new->assignment_length ||
531 old->assignment_iface_id_selection != new->assignment_iface_id_selection ||
532 old->assignment_weight != new->assignment_weight ||
533 (old->assignment_iface_id_selection == IFID_FIXED &&
534 memcmp(&old->assignment_fixed_iface_id, &new->assignment_fixed_iface_id,
535 sizeof(old->assignment_fixed_iface_id))) ||
536 list_empty(&old->assignment_classes) != list_empty(&new->assignment_classes));
537
538 struct interface_assignment_class *c;
539 list_for_each_entry(c, &new->assignment_classes, head) {
540 /* Compare list entries one-by-one to see if there was a change */
541 if (list_empty(&old->assignment_classes)) /* The new list is longer */
542 changed = true;
543
544 if (changed)
545 break;
546
547 struct interface_assignment_class *c_old = list_first_entry(&old->assignment_classes,
548 struct interface_assignment_class, head);
549
550 if (strcmp(c_old->name, c->name)) /* An entry didn't match */
551 break;
552
553 list_del(&c_old->head);
554 free(c_old);
555 }
556
557 /* The old list was longer than the new one or the last entry didn't match */
558 if (!list_empty(&old->assignment_classes)) {
559 interface_clear_assignment_classes(old);
560 changed = true;
561 }
562
563 list_splice_init(&new->assignment_classes, &old->assignment_classes);
564
565 if (changed) {
566 old->assignment_hint = new->assignment_hint;
567 old->assignment_length = new->assignment_length;
568 old->assignment_iface_id_selection = new->assignment_iface_id_selection;
569 old->assignment_fixed_iface_id = new->assignment_fixed_iface_id;
570 old->assignment_weight = new->assignment_weight;
571 interface_refresh_assignments(true);
572 }
573 }
574
575 static void
576 interface_alias_cb(struct interface_user *dep, struct interface *iface, enum interface_event ev)
577 {
578 struct interface *alias = container_of(dep, struct interface, parent_iface);
579 struct device *dev = iface->l3_dev.dev;
580
581 switch (ev) {
582 case IFEV_UP:
583 if (!dev)
584 return;
585
586 interface_set_main_dev(alias, dev);
587 interface_set_available(alias, true);
588 break;
589 case IFEV_DOWN:
590 case IFEV_UP_FAILED:
591 interface_set_available(alias, false);
592 interface_set_main_dev(alias, NULL);
593 break;
594 case IFEV_FREE:
595 interface_remove_user(dep);
596 break;
597 default:
598 break;
599 }
600 }
601
602 static void
603 interface_set_device_config(struct interface *iface, struct device *dev)
604 {
605 if (!dev || !dev->default_config)
606 return;
607
608 if (!iface->device_config &&
609 (!dev->iface_config || dev->config_iface != iface))
610 return;
611
612 dev->config_iface = iface;
613 dev->iface_config = iface->device_config;
614 device_apply_config(dev, dev->type, iface->config);
615 }
616
617 static void
618 interface_claim_device(struct interface *iface)
619 {
620 struct interface *parent;
621 struct device *dev = NULL;
622
623 if (iface->parent_iface.iface)
624 interface_remove_user(&iface->parent_iface);
625
626 device_lock();
627
628 if (iface->parent_ifname) {
629 parent = vlist_find(&interfaces, iface->parent_ifname, parent, node);
630 iface->parent_iface.cb = interface_alias_cb;
631 interface_add_user(&iface->parent_iface, parent);
632 } else if (iface->ifname &&
633 !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) {
634 dev = device_get(iface->ifname, true);
635 interface_set_device_config(iface, dev);
636 } else {
637 dev = iface->ext_dev.dev;
638 }
639
640 if (dev)
641 interface_set_main_dev(iface, dev);
642
643 device_unlock();
644
645 if (iface->proto_handler->flags & PROTO_FLAG_INIT_AVAILABLE)
646 interface_set_available(iface, true);
647 }
648
649 static void
650 interface_cleanup_state(struct interface *iface)
651 {
652 interface_set_available(iface, false);
653
654 interface_flush_state(iface);
655 interface_clear_errors(iface);
656 interface_set_proto_state(iface, NULL);
657
658 interface_set_main_dev(iface, NULL);
659 interface_set_l3_dev(iface, NULL);
660 }
661
662 static void
663 interface_cleanup(struct interface *iface)
664 {
665 struct interface_user *dep, *tmp;
666
667 uloop_timeout_cancel(&iface->remove_timer);
668 device_remove_user(&iface->ext_dev);
669
670 if (iface->parent_iface.iface)
671 interface_remove_user(&iface->parent_iface);
672
673 list_for_each_entry_safe(dep, tmp, &iface->users, list)
674 interface_remove_user(dep);
675
676 interface_clear_assignment_classes(iface);
677 interface_ip_flush(&iface->config_ip);
678 interface_cleanup_state(iface);
679 }
680
681 static void
682 interface_do_free(struct interface *iface)
683 {
684 interface_event(iface, IFEV_FREE);
685 interface_cleanup(iface);
686 free(iface->config);
687 netifd_ubus_remove_interface(iface);
688 avl_delete(&interfaces.avl, &iface->node.avl);
689 if (iface->jail)
690 free(iface->jail);
691 if (iface->jail_ifname)
692 free(iface->jail_ifname);
693
694 free(iface);
695 }
696
697 static void
698 interface_do_reload(struct interface *iface)
699 {
700 interface_event(iface, IFEV_RELOAD);
701 interface_cleanup_state(iface);
702 proto_init_interface(iface, iface->config);
703 interface_claim_device(iface);
704 }
705
706 static void
707 interface_handle_config_change(struct interface *iface)
708 {
709 enum interface_config_state state = iface->config_state;
710
711 iface->config_state = IFC_NORMAL;
712 switch(state) {
713 case IFC_NORMAL:
714 break;
715 case IFC_RELOAD:
716 interface_do_reload(iface);
717 break;
718 case IFC_REMOVE:
719 interface_do_free(iface);
720 return;
721 }
722 if (iface->autostart)
723 interface_set_up(iface);
724 }
725
726 static void
727 interface_proto_event_cb(struct interface_proto_state *state, enum interface_proto_event ev)
728 {
729 struct interface *iface = state->iface;
730
731 switch (ev) {
732 case IFPEV_UP:
733 if (iface->state != IFS_SETUP) {
734 if (iface->state == IFS_UP && iface->updated)
735 interface_event(iface, IFEV_UPDATE);
736 return;
737 }
738
739 if (!iface->l3_dev.dev)
740 interface_set_l3_dev(iface, iface->main_dev.dev);
741
742 interface_ip_set_enabled(&iface->config_ip, true);
743 interface_ip_set_enabled(&iface->proto_ip, true);
744 system_flush_routes();
745 iface->state = IFS_UP;
746 iface->start_time = system_get_rtime();
747 interface_event(iface, IFEV_UP);
748 netifd_log_message(L_NOTICE, "Interface '%s' is now up\n", iface->name);
749 break;
750 case IFPEV_DOWN:
751 if (iface->state == IFS_DOWN)
752 return;
753
754 netifd_log_message(L_NOTICE, "Interface '%s' is now down\n", iface->name);
755 mark_interface_down(iface);
756 if (iface->main_dev.dev)
757 device_release(&iface->main_dev);
758 if (iface->l3_dev.dev)
759 device_remove_user(&iface->l3_dev);
760 interface_handle_config_change(iface);
761 break;
762 case IFPEV_LINK_LOST:
763 if (iface->state != IFS_UP)
764 return;
765
766 netifd_log_message(L_NOTICE, "Interface '%s' has lost the connection\n", iface->name);
767 mark_interface_down(iface);
768 iface->state = IFS_SETUP;
769 break;
770 default:
771 return;
772 }
773
774 interface_write_resolv_conf(iface->jail);
775 }
776
777 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state)
778 {
779 if (iface->proto) {
780 iface->proto->free(iface->proto);
781 iface->proto = NULL;
782 }
783 iface->state = IFS_DOWN;
784 iface->proto = state;
785 if (!state)
786 return;
787
788 state->proto_event = interface_proto_event_cb;
789 state->iface = iface;
790 }
791
792 struct interface *
793 interface_alloc(const char *name, struct blob_attr *config, bool dynamic)
794 {
795 struct interface *iface;
796 struct blob_attr *tb[IFACE_ATTR_MAX];
797 struct blob_attr *cur;
798 const char *proto_name = NULL;
799 char *iface_name;
800 bool force_link = false;
801
802 iface = calloc_a(sizeof(*iface), &iface_name, strlen(name) + 1);
803 iface->name = strcpy(iface_name, name);
804 INIT_LIST_HEAD(&iface->errors);
805 INIT_LIST_HEAD(&iface->users);
806 INIT_LIST_HEAD(&iface->hotplug_list);
807 INIT_LIST_HEAD(&iface->assignment_classes);
808 interface_ip_init(iface);
809 avl_init(&iface->data, avl_strcmp, false, NULL);
810 iface->config_ip.enabled = false;
811
812 iface->main_dev.cb = interface_main_dev_cb;
813 iface->l3_dev.cb = interface_l3_dev_cb;
814 iface->ext_dev.cb = interface_ext_dev_cb;
815
816 blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
817 blob_data(config), blob_len(config));
818
819 if ((cur = tb[IFACE_ATTR_PROTO]))
820 proto_name = blobmsg_data(cur);
821
822 proto_attach_interface(iface, proto_name);
823 if (iface->proto_handler->flags & PROTO_FLAG_FORCE_LINK_DEFAULT)
824 force_link = true;
825
826 iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
827 iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], force_link);
828 iface->dynamic = dynamic;
829 iface->proto_ip.no_defaultroute =
830 !blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true);
831 iface->proto_ip.no_dns =
832 !blobmsg_get_bool_default(tb[IFACE_ATTR_PEERDNS], true);
833
834 if ((cur = tb[IFACE_ATTR_DNS]))
835 interface_add_dns_server_list(&iface->config_ip, cur);
836
837 if ((cur = tb[IFACE_ATTR_DNS_SEARCH]))
838 interface_add_dns_search_list(&iface->config_ip, cur);
839
840 if ((cur = tb[IFACE_ATTR_DNS_METRIC]))
841 iface->dns_metric = blobmsg_get_u32(cur);
842
843 if ((cur = tb[IFACE_ATTR_METRIC]))
844 iface->metric = blobmsg_get_u32(cur);
845
846 if ((cur = tb[IFACE_ATTR_IP6ASSIGN]))
847 iface->assignment_length = blobmsg_get_u32(cur);
848
849 /* defaults */
850 iface->assignment_iface_id_selection = IFID_FIXED;
851 iface->assignment_fixed_iface_id = in6addr_any;
852 iface->assignment_fixed_iface_id.s6_addr[15] = 1;
853
854 if ((cur = tb[IFACE_ATTR_IP6IFACEID])) {
855 const char *ifaceid = blobmsg_data(cur);
856 if (!strcmp(ifaceid, "random")) {
857 iface->assignment_iface_id_selection = IFID_RANDOM;
858 }
859 else if (!strcmp(ifaceid, "eui64")) {
860 iface->assignment_iface_id_selection = IFID_EUI64;
861 }
862 else {
863 /* we expect an IPv6 address with network id zero here -> fixed iface id
864 if we cannot parse -> revert to iface id 1 */
865 if (inet_pton(AF_INET6,ifaceid,&iface->assignment_fixed_iface_id) != 1 ||
866 iface->assignment_fixed_iface_id.s6_addr32[0] != 0 ||
867 iface->assignment_fixed_iface_id.s6_addr32[1] != 0) {
868 iface->assignment_fixed_iface_id = in6addr_any;
869 iface->assignment_fixed_iface_id.s6_addr[15] = 1;
870 netifd_log_message(L_WARNING, "Failed to parse ip6ifaceid for interface '%s', \
871 falling back to iface id 1.\n", iface->name);
872 }
873 }
874 }
875
876 iface->assignment_hint = -1;
877 if ((cur = tb[IFACE_ATTR_IP6HINT]))
878 iface->assignment_hint = strtol(blobmsg_get_string(cur), NULL, 16) &
879 ~((1 << (64 - iface->assignment_length)) - 1);
880
881 if ((cur = tb[IFACE_ATTR_IP6CLASS]))
882 interface_add_assignment_classes(iface, cur);
883
884 if ((cur = tb[IFACE_ATTR_IP6WEIGHT]))
885 iface->assignment_weight = blobmsg_get_u32(cur);
886
887 if ((cur = tb[IFACE_ATTR_IP4TABLE])) {
888 if (!system_resolve_rt_table(blobmsg_data(cur), &iface->ip4table))
889 DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur));
890 }
891
892 if ((cur = tb[IFACE_ATTR_IP6TABLE])) {
893 if (!system_resolve_rt_table(blobmsg_data(cur), &iface->ip6table))
894 DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur));
895 }
896
897 iface->proto_ip.no_delegation = !blobmsg_get_bool_default(tb[IFACE_ATTR_DELEGATE], true);
898
899 iface->config_autostart = iface->autostart;
900 iface->jail = NULL;
901
902 if ((cur = tb[IFACE_ATTR_JAIL])) {
903 iface->jail = strdup(blobmsg_get_string(cur));
904 iface->autostart = false;
905 }
906
907 iface->jail_ifname = NULL;
908 if ((cur = tb[IFACE_ATTR_JAIL_IFNAME]))
909 iface->jail_ifname = strdup(blobmsg_get_string(cur));
910
911 return iface;
912 }
913
914 static bool __interface_add(struct interface *iface, struct blob_attr *config, bool alias)
915 {
916 struct blob_attr *tb[IFACE_ATTR_MAX];
917 struct blob_attr *cur;
918 char *name = NULL;
919
920 blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
921 blob_data(config), blob_len(config));
922
923 if (alias) {
924 if ((cur = tb[IFACE_ATTR_INTERFACE]))
925 iface->parent_ifname = blobmsg_data(cur);
926
927 if (!iface->parent_ifname)
928 return false;
929 } else {
930 if ((cur = tb[IFACE_ATTR_IFNAME]))
931 iface->ifname = blobmsg_data(cur);
932 }
933
934 if (iface->dynamic) {
935 name = strdup(iface->name);
936
937 if (!name)
938 return false;
939 }
940
941 iface->config = config;
942 vlist_add(&interfaces, &iface->node, iface->name);
943
944 if (name) {
945 iface = vlist_find(&interfaces, name, iface, node);
946 free(name);
947
948 /* Don't delete dynamic interface on reload */
949 if (iface)
950 iface->node.version = -1;
951 }
952
953 return true;
954 }
955
956 bool
957 interface_add(struct interface *iface, struct blob_attr *config)
958 {
959 return __interface_add(iface, config, false);
960 }
961
962 bool
963 interface_add_alias(struct interface *iface, struct blob_attr *config)
964 {
965 if (iface->proto_handler->flags & PROTO_FLAG_NODEV)
966 return false;
967
968 return __interface_add(iface, config, true);
969 }
970
971 void
972 interface_set_l3_dev(struct interface *iface, struct device *dev)
973 {
974 bool enabled = iface->config_ip.enabled;
975 bool claimed = iface->l3_dev.claimed;
976
977 if (iface->l3_dev.dev == dev)
978 return;
979
980 interface_ip_set_enabled(&iface->config_ip, false);
981 interface_ip_set_enabled(&iface->proto_ip, false);
982 interface_ip_flush(&iface->proto_ip);
983 device_add_user(&iface->l3_dev, dev);
984
985 if (dev) {
986 if (claimed) {
987 if (device_claim(&iface->l3_dev) < 0)
988 return;
989 }
990 interface_ip_set_enabled(&iface->config_ip, enabled);
991 interface_ip_set_enabled(&iface->proto_ip, enabled);
992 }
993 }
994
995 static void
996 interface_set_main_dev(struct interface *iface, struct device *dev)
997 {
998 bool claimed = iface->l3_dev.claimed;
999
1000 if (iface->main_dev.dev == dev)
1001 return;
1002
1003 interface_set_available(iface, false);
1004 device_add_user(&iface->main_dev, dev);
1005 if (!dev) {
1006 interface_set_link_state(iface, false);
1007 return;
1008 }
1009
1010 if (claimed) {
1011 if (device_claim(&iface->l3_dev) < 0)
1012 return;
1013 }
1014
1015 if (!iface->l3_dev.dev)
1016 interface_set_l3_dev(iface, dev);
1017 }
1018
1019 static int
1020 interface_remove_link(struct interface *iface, struct device *dev)
1021 {
1022 struct device *mdev = iface->main_dev.dev;
1023
1024 if (mdev && mdev->hotplug_ops)
1025 return mdev->hotplug_ops->del(mdev, dev);
1026
1027 if (dev == iface->ext_dev.dev)
1028 device_remove_user(&iface->ext_dev);
1029
1030 if (!iface->main_dev.hotplug)
1031 return UBUS_STATUS_INVALID_ARGUMENT;
1032
1033 if (dev != iface->main_dev.dev)
1034 return UBUS_STATUS_INVALID_ARGUMENT;
1035
1036 interface_set_main_dev(iface, NULL);
1037 return 0;
1038 }
1039
1040 static int
1041 interface_add_link(struct interface *iface, struct device *dev,
1042 struct blob_attr *vlan, bool link_ext)
1043 {
1044 struct device *mdev = iface->main_dev.dev;
1045
1046 if (mdev == dev)
1047 return 0;
1048
1049 if (iface->main_dev.hotplug)
1050 device_remove_user(&iface->main_dev);
1051
1052 if (mdev) {
1053 if (mdev->hotplug_ops)
1054 return mdev->hotplug_ops->add(mdev, dev, vlan);
1055 else
1056 return UBUS_STATUS_NOT_SUPPORTED;
1057 }
1058
1059 if (link_ext)
1060 device_add_user(&iface->ext_dev, dev);
1061
1062 interface_set_main_dev(iface, dev);
1063 iface->main_dev.hotplug = true;
1064 return 0;
1065 }
1066
1067 int
1068 interface_handle_link(struct interface *iface, const char *name,
1069 struct blob_attr *vlan, bool add, bool link_ext)
1070 {
1071 struct device *dev;
1072 int ret;
1073
1074 device_lock();
1075
1076 dev = device_get(name, add ? (link_ext ? 2 : 1) : 0);
1077 if (!dev) {
1078 ret = UBUS_STATUS_NOT_FOUND;
1079 goto out;
1080 }
1081
1082 if (add) {
1083 interface_set_device_config(iface, dev);
1084 device_set_present(dev, true);
1085
1086 ret = interface_add_link(iface, dev, vlan, link_ext);
1087 } else {
1088 ret = interface_remove_link(iface, dev);
1089 }
1090
1091 out:
1092 device_unlock();
1093
1094 return ret;
1095 }
1096
1097 void
1098 interface_set_up(struct interface *iface)
1099 {
1100 int ret;
1101 const char *error = NULL;
1102
1103 iface->autostart = true;
1104
1105 if (iface->state != IFS_DOWN)
1106 return;
1107
1108 interface_clear_errors(iface);
1109 if (iface->available) {
1110 if (iface->main_dev.dev) {
1111 ret = device_claim(&iface->main_dev);
1112 if (!ret)
1113 interface_check_state(iface);
1114 else
1115 error = "DEVICE_CLAIM_FAILED";
1116 } else {
1117 ret = __interface_set_up(iface);
1118 if (ret)
1119 error = "SETUP_FAILED";
1120 }
1121 } else
1122 error = "NO_DEVICE";
1123
1124 if (error)
1125 interface_add_error(iface, "interface", error, NULL, 0);
1126 }
1127
1128 void
1129 interface_set_down(struct interface *iface)
1130 {
1131 if (!iface) {
1132 vlist_for_each_element(&interfaces, iface, node)
1133 __interface_set_down(iface, false);
1134 } else {
1135 iface->autostart = false;
1136 __interface_set_down(iface, false);
1137 }
1138 }
1139
1140 int
1141 interface_renew(struct interface *iface)
1142 {
1143 if (iface->state == IFS_TEARDOWN || iface->state == IFS_DOWN)
1144 return -1;
1145
1146 return interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
1147 }
1148
1149 void
1150 interface_start_pending(void)
1151 {
1152 struct interface *iface;
1153
1154 vlist_for_each_element(&interfaces, iface, node) {
1155 if (iface->autostart)
1156 interface_set_up(iface);
1157 }
1158 }
1159
1160 void
1161 interface_start_jail(const char *jail, const pid_t netns_pid)
1162 {
1163 struct interface *iface;
1164 int netns_fd;
1165 int wstatus;
1166 pid_t pr = 0;
1167
1168 netns_fd = system_netns_open(netns_pid);
1169 if (netns_fd < 0)
1170 return;
1171
1172 vlist_for_each_element(&interfaces, iface, node) {
1173 if (!iface->jail || strcmp(iface->jail, jail))
1174 continue;
1175
1176 system_link_netns_move(iface->main_dev.dev, netns_fd, iface->jail_ifname);
1177 }
1178
1179 close(netns_fd);
1180
1181 pr = fork();
1182 if (pr) {
1183 waitpid(pr, &wstatus, WUNTRACED | WCONTINUED);
1184 return;
1185 }
1186
1187 /* child process */
1188 netns_fd = system_netns_open(netns_pid);
1189 if (netns_fd < 0)
1190 return;
1191
1192 system_netns_set(netns_fd);
1193 system_init();
1194 vlist_for_each_element(&interfaces, iface, node) {
1195 if (!iface->jail || strcmp(iface->jail, jail))
1196 continue;
1197
1198 /*
1199 * The interface has already been renamed and is inside target
1200 * namespace, hence overwrite ifname with jail_ifname for
1201 * interface_set_up().
1202 * We are inside a fork which got it's own copy of the interfaces
1203 * list, so we can mess with it :)
1204 */
1205 if (iface->jail_ifname)
1206 iface->ifname = iface->jail_ifname;
1207
1208 interface_do_reload(iface);
1209 interface_set_up(iface);
1210 }
1211
1212 close(netns_fd);
1213 _exit(0);
1214 }
1215
1216 void
1217 interface_stop_jail(const char *jail, const pid_t netns_pid)
1218 {
1219 struct interface *iface;
1220 int netns_fd, root_netns;
1221 int wstatus;
1222 pid_t parent_pid = getpid();
1223 pid_t pr = 0;
1224 const char *orig_ifname;
1225
1226 pr = fork();
1227 if (pr) {
1228 waitpid(pr, &wstatus, WUNTRACED | WCONTINUED);
1229 return;
1230 }
1231
1232 /* child process */
1233 root_netns = system_netns_open(parent_pid);
1234 if (root_netns < 0)
1235 return;
1236
1237 netns_fd = system_netns_open(netns_pid);
1238 if (netns_fd < 0)
1239 return;
1240
1241 system_netns_set(netns_fd);
1242 system_init();
1243 vlist_for_each_element(&interfaces, iface, node) {
1244 if (!iface->jail || strcmp(iface->jail, jail))
1245 continue;
1246
1247 orig_ifname = iface->ifname;
1248 if (iface->jail_ifname)
1249 iface->ifname = iface->jail_ifname;
1250
1251 interface_do_reload(iface);
1252 interface_set_down(iface);
1253 system_link_netns_move(iface->main_dev.dev, root_netns, orig_ifname);
1254 }
1255
1256 close(root_netns);
1257 close(netns_fd);
1258 _exit(0);
1259 }
1260
1261 static void
1262 set_config_state(struct interface *iface, enum interface_config_state s)
1263 {
1264 __set_config_state(iface, s);
1265 if (iface->state == IFS_DOWN)
1266 interface_handle_config_change(iface);
1267 else
1268 __interface_set_down(iface, false);
1269 }
1270
1271 void
1272 interface_update_start(struct interface *iface, const bool keep_old)
1273 {
1274 iface->updated = 0;
1275
1276 if (!keep_old)
1277 interface_ip_update_start(&iface->proto_ip);
1278 }
1279
1280 void
1281 interface_update_complete(struct interface *iface)
1282 {
1283 interface_ip_update_complete(&iface->proto_ip);
1284 }
1285
1286 static void
1287 interface_replace_dns(struct interface_ip_settings *new, struct interface_ip_settings *old)
1288 {
1289 vlist_simple_replace(&new->dns_servers, &old->dns_servers);
1290 vlist_simple_replace(&new->dns_search, &old->dns_search);
1291 }
1292
1293 static bool
1294 interface_device_config_changed(struct interface *if_old, struct interface *if_new)
1295 {
1296 struct blob_attr *ntb[__DEV_ATTR_MAX];
1297 struct blob_attr *otb[__DEV_ATTR_MAX];
1298 struct device *dev = if_old->main_dev.dev;
1299 unsigned long diff = 0;
1300
1301 BUILD_BUG_ON(sizeof(diff) < __DEV_ATTR_MAX / 8);
1302
1303 if (!dev)
1304 return false;
1305
1306 if (if_old->device_config != if_new->device_config)
1307 return true;
1308
1309 if (!if_new->device_config)
1310 return false;
1311
1312 blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, otb,
1313 blob_data(if_old->config), blob_len(if_old->config));
1314
1315 blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, ntb,
1316 blob_data(if_new->config), blob_len(if_new->config));
1317
1318 uci_blob_diff(ntb, otb, &device_attr_list, &diff);
1319 return diff;
1320 }
1321
1322 static void
1323 interface_change_config(struct interface *if_old, struct interface *if_new)
1324 {
1325 struct blob_attr *old_config = if_old->config;
1326 bool reload = false, reload_ip = false, update_prefix_delegation = false;
1327
1328 #define FIELD_CHANGED_STR(field) \
1329 ((!!if_old->field != !!if_new->field) || \
1330 (if_old->field && \
1331 strcmp(if_old->field, if_new->field) != 0))
1332
1333 if (FIELD_CHANGED_STR(parent_ifname)) {
1334 if (if_old->parent_iface.iface)
1335 interface_remove_user(&if_old->parent_iface);
1336 reload = true;
1337 }
1338
1339 if (!reload && interface_device_config_changed(if_old, if_new))
1340 reload = true;
1341
1342 if (FIELD_CHANGED_STR(ifname) ||
1343 if_old->proto_handler != if_new->proto_handler)
1344 reload = true;
1345
1346 if (!if_old->proto_handler->config_params)
1347 D(INTERFACE, "No config parameters for interface '%s'\n",
1348 if_old->name);
1349 else if (!uci_blob_check_equal(if_old->config, if_new->config,
1350 if_old->proto_handler->config_params))
1351 reload = true;
1352
1353 #define UPDATE(field, __var) ({ \
1354 bool __changed = (if_old->field != if_new->field); \
1355 if_old->field = if_new->field; \
1356 __var |= __changed; \
1357 })
1358
1359 if_old->config = if_new->config;
1360 if (if_old->config_autostart != if_new->config_autostart) {
1361 if (if_old->config_autostart)
1362 reload = true;
1363
1364 if_old->autostart = if_new->config_autostart;
1365 }
1366
1367 if_old->device_config = if_new->device_config;
1368 if_old->config_autostart = if_new->config_autostart;
1369 if (if_old->jail)
1370 free(if_old->jail);
1371
1372 if_old->jail = if_new->jail;
1373 if (if_old->jail)
1374 if_old->autostart = false;
1375
1376 if (if_old->jail_ifname)
1377 free(if_old->jail_ifname);
1378
1379 if_old->jail_ifname = if_new->jail_ifname;
1380
1381 if_old->ifname = if_new->ifname;
1382 if_old->parent_ifname = if_new->parent_ifname;
1383 if_old->dynamic = if_new->dynamic;
1384 if_old->proto_handler = if_new->proto_handler;
1385 if_old->force_link = if_new->force_link;
1386 if_old->dns_metric = if_new->dns_metric;
1387
1388 if (if_old->proto_ip.no_delegation != if_new->proto_ip.no_delegation) {
1389 if_old->proto_ip.no_delegation = if_new->proto_ip.no_delegation;
1390 update_prefix_delegation = true;
1391 }
1392
1393 if_old->proto_ip.no_dns = if_new->proto_ip.no_dns;
1394 interface_replace_dns(&if_old->config_ip, &if_new->config_ip);
1395
1396 UPDATE(metric, reload_ip);
1397 UPDATE(proto_ip.no_defaultroute, reload_ip);
1398 UPDATE(ip4table, reload_ip);
1399 UPDATE(ip6table, reload_ip);
1400 interface_merge_assignment_data(if_old, if_new);
1401
1402 #undef UPDATE
1403
1404 if (reload) {
1405 D(INTERFACE, "Reload interface '%s' because of config changes\n",
1406 if_old->name);
1407 interface_clear_errors(if_old);
1408 set_config_state(if_old, IFC_RELOAD);
1409 goto out;
1410 }
1411
1412 if (reload_ip) {
1413 bool config_ip_enabled = if_old->config_ip.enabled;
1414 bool proto_ip_enabled = if_old->proto_ip.enabled;
1415
1416 interface_ip_set_enabled(&if_old->config_ip, false);
1417 interface_ip_set_enabled(&if_old->proto_ip, false);
1418 interface_ip_set_enabled(&if_old->proto_ip, proto_ip_enabled);
1419 interface_ip_set_enabled(&if_old->config_ip, config_ip_enabled);
1420 }
1421
1422 if (update_prefix_delegation)
1423 interface_update_prefix_delegation(&if_old->proto_ip);
1424
1425 interface_write_resolv_conf(if_old->jail);
1426 if (if_old->main_dev.dev)
1427 interface_check_state(if_old);
1428
1429 out:
1430 if_new->config = NULL;
1431 interface_cleanup(if_new);
1432 free(old_config);
1433 free(if_new);
1434 }
1435
1436 static void
1437 interface_update(struct vlist_tree *tree, struct vlist_node *node_new,
1438 struct vlist_node *node_old)
1439 {
1440 struct interface *if_old = container_of(node_old, struct interface, node);
1441 struct interface *if_new = container_of(node_new, struct interface, node);
1442
1443 if (node_old && node_new) {
1444 D(INTERFACE, "Update interface '%s'\n", if_new->name);
1445 interface_change_config(if_old, if_new);
1446 } else if (node_old) {
1447 D(INTERFACE, "Remove interface '%s'\n", if_old->name);
1448 set_config_state(if_old, IFC_REMOVE);
1449 } else if (node_new) {
1450 D(INTERFACE, "Create interface '%s'\n", if_new->name);
1451 interface_event(if_new, IFEV_CREATE);
1452 proto_init_interface(if_new, if_new->config);
1453 interface_claim_device(if_new);
1454 netifd_ubus_add_interface(if_new);
1455 }
1456 }
1457
1458
1459 static void __init
1460 interface_init_list(void)
1461 {
1462 vlist_init(&interfaces, avl_strcmp, interface_update);
1463 interfaces.keep_old = true;
1464 interfaces.no_delete = true;
1465 }