fix unannotated fall-through warnings
[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 fallthrough;
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 break;
323 case IFS_TEARDOWN:
324 default:
325 break;
326 }
327 }
328
329 static int
330 __interface_set_up(struct interface *iface)
331 {
332 int ret;
333
334 netifd_log_message(L_NOTICE, "Interface '%s' is setting up now\n", iface->name);
335
336 iface->state = IFS_SETUP;
337 ret = interface_proto_event(iface->proto, PROTO_CMD_SETUP, false);
338 if (ret)
339 mark_interface_down(iface);
340
341 return ret;
342 }
343
344 static void
345 interface_check_state(struct interface *iface)
346 {
347 bool link_state = iface->link_state || iface->force_link;
348
349 switch (iface->state) {
350 case IFS_UP:
351 case IFS_SETUP:
352 if (!iface->enabled || !link_state) {
353 iface->state = IFS_TEARDOWN;
354 if (iface->dynamic)
355 __set_config_state(iface, IFC_REMOVE);
356
357 interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
358 }
359 break;
360 case IFS_DOWN:
361 if (!iface->available)
362 return;
363
364 if (iface->autostart && iface->enabled && link_state && !config_init)
365 __interface_set_up(iface);
366 break;
367 default:
368 break;
369 }
370 }
371
372 static void
373 interface_set_enabled(struct interface *iface, bool new_state)
374 {
375 if (iface->enabled == new_state)
376 return;
377
378 netifd_log_message(L_NOTICE, "Interface '%s' is %s\n", iface->name, new_state ? "enabled" : "disabled");
379 iface->enabled = new_state;
380 interface_check_state(iface);
381 }
382
383 static void
384 interface_set_link_state(struct interface *iface, bool new_state)
385 {
386 if (iface->link_state == new_state)
387 return;
388
389 netifd_log_message(L_NOTICE, "Interface '%s' has link connectivity %s\n", iface->name, new_state ? "" : "loss");
390 iface->link_state = new_state;
391 interface_check_state(iface);
392
393 if (new_state && iface->force_link && iface->state == IFS_UP && !iface->link_up_event) {
394 interface_event(iface, IFEV_LINK_UP);
395 iface->link_up_event = true;
396 }
397 }
398
399 static void
400 interface_ext_dev_cb(struct device_user *dep, enum device_event ev)
401 {
402 if (ev == DEV_EVENT_REMOVE)
403 device_remove_user(dep);
404 }
405
406 static void
407 interface_main_dev_cb(struct device_user *dep, enum device_event ev)
408 {
409 struct interface *iface;
410
411 iface = container_of(dep, struct interface, main_dev);
412 switch (ev) {
413 case DEV_EVENT_ADD:
414 interface_set_available(iface, true);
415 break;
416 case DEV_EVENT_REMOVE:
417 interface_set_available(iface, false);
418 if (dep->dev && dep->dev->external)
419 interface_set_main_dev(iface, NULL);
420 break;
421 case DEV_EVENT_UP:
422 interface_set_enabled(iface, true);
423 break;
424 case DEV_EVENT_DOWN:
425 interface_set_enabled(iface, false);
426 break;
427 case DEV_EVENT_LINK_UP:
428 interface_set_link_state(iface, true);
429 break;
430 case DEV_EVENT_LINK_DOWN:
431 interface_set_link_state(iface, false);
432 break;
433 case DEV_EVENT_TOPO_CHANGE:
434 interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
435 return;
436 default:
437 break;
438 }
439 }
440
441 static void
442 interface_l3_dev_cb(struct device_user *dep, enum device_event ev)
443 {
444 struct interface *iface;
445
446 iface = container_of(dep, struct interface, l3_dev);
447 if (iface->l3_dev.dev == iface->main_dev.dev)
448 return;
449
450 switch (ev) {
451 case DEV_EVENT_LINK_DOWN:
452 if (iface->proto_handler->flags & PROTO_FLAG_TEARDOWN_ON_L3_LINK_DOWN)
453 interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
454 break;
455 default:
456 break;
457 }
458 }
459
460 void
461 interface_set_available(struct interface *iface, bool new_state)
462 {
463 if (iface->available == new_state)
464 return;
465
466 D(INTERFACE, "Interface '%s', available=%d\n", iface->name, new_state);
467 iface->available = new_state;
468
469 if (new_state) {
470 if (iface->autostart && !config_init)
471 interface_set_up(iface);
472 } else
473 __interface_set_down(iface, true);
474 }
475
476 void
477 interface_add_user(struct interface_user *dep, struct interface *iface)
478 {
479 if (!iface) {
480 list_add(&dep->list, &iface_all_users);
481 return;
482 }
483
484 dep->iface = iface;
485 list_add(&dep->list, &iface->users);
486 if (iface->state == IFS_UP)
487 dep->cb(dep, iface, IFEV_UP);
488 }
489
490 void
491 interface_remove_user(struct interface_user *dep)
492 {
493 list_del_init(&dep->list);
494 dep->iface = NULL;
495 }
496
497 static void
498 interface_add_assignment_classes(struct interface *iface, struct blob_attr *list)
499 {
500 struct blob_attr *cur;
501 int rem;
502
503 blobmsg_for_each_attr(cur, list, rem) {
504 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
505 continue;
506
507 if (!blobmsg_check_attr(cur, false))
508 continue;
509
510 struct interface_assignment_class *c = malloc(sizeof(*c) + blobmsg_data_len(cur));
511 memcpy(c->name, blobmsg_data(cur), blobmsg_data_len(cur));
512 list_add(&c->head, &iface->assignment_classes);
513 }
514 }
515
516 static void
517 interface_clear_assignment_classes(struct interface *iface)
518 {
519 while (!list_empty(&iface->assignment_classes)) {
520 struct interface_assignment_class *c = list_first_entry(&iface->assignment_classes,
521 struct interface_assignment_class, head);
522 list_del(&c->head);
523 free(c);
524 }
525 }
526
527 static void
528 interface_merge_assignment_data(struct interface *old, struct interface *new)
529 {
530 bool changed = (old->assignment_hint != new->assignment_hint ||
531 old->assignment_length != new->assignment_length ||
532 old->assignment_iface_id_selection != new->assignment_iface_id_selection ||
533 old->assignment_weight != new->assignment_weight ||
534 (old->assignment_iface_id_selection == IFID_FIXED &&
535 memcmp(&old->assignment_fixed_iface_id, &new->assignment_fixed_iface_id,
536 sizeof(old->assignment_fixed_iface_id))) ||
537 list_empty(&old->assignment_classes) != list_empty(&new->assignment_classes));
538
539 struct interface_assignment_class *c;
540 list_for_each_entry(c, &new->assignment_classes, head) {
541 /* Compare list entries one-by-one to see if there was a change */
542 if (list_empty(&old->assignment_classes)) /* The new list is longer */
543 changed = true;
544
545 if (changed)
546 break;
547
548 struct interface_assignment_class *c_old = list_first_entry(&old->assignment_classes,
549 struct interface_assignment_class, head);
550
551 if (strcmp(c_old->name, c->name)) /* An entry didn't match */
552 break;
553
554 list_del(&c_old->head);
555 free(c_old);
556 }
557
558 /* The old list was longer than the new one or the last entry didn't match */
559 if (!list_empty(&old->assignment_classes)) {
560 interface_clear_assignment_classes(old);
561 changed = true;
562 }
563
564 list_splice_init(&new->assignment_classes, &old->assignment_classes);
565
566 if (changed) {
567 old->assignment_hint = new->assignment_hint;
568 old->assignment_length = new->assignment_length;
569 old->assignment_iface_id_selection = new->assignment_iface_id_selection;
570 old->assignment_fixed_iface_id = new->assignment_fixed_iface_id;
571 old->assignment_weight = new->assignment_weight;
572 interface_refresh_assignments(true);
573 }
574 }
575
576 static void
577 interface_alias_cb(struct interface_user *dep, struct interface *iface, enum interface_event ev)
578 {
579 struct interface *alias = container_of(dep, struct interface, parent_iface);
580 struct device *dev = iface->l3_dev.dev;
581
582 switch (ev) {
583 case IFEV_UP:
584 if (!dev)
585 return;
586
587 interface_set_main_dev(alias, dev);
588 interface_set_available(alias, true);
589 break;
590 case IFEV_DOWN:
591 case IFEV_UP_FAILED:
592 interface_set_available(alias, false);
593 interface_set_main_dev(alias, NULL);
594 break;
595 case IFEV_FREE:
596 interface_remove_user(dep);
597 break;
598 default:
599 break;
600 }
601 }
602
603 static void
604 interface_set_device_config(struct interface *iface, struct device *dev)
605 {
606 if (!dev || !dev->default_config)
607 return;
608
609 if (!iface->device_config &&
610 (!dev->iface_config || dev->config_iface != iface))
611 return;
612
613 dev->config_iface = iface;
614 dev->iface_config = iface->device_config;
615 device_apply_config(dev, dev->type, iface->config);
616 }
617
618 static void
619 interface_claim_device(struct interface *iface)
620 {
621 struct interface *parent;
622 struct device *dev = NULL;
623
624 if (iface->parent_iface.iface)
625 interface_remove_user(&iface->parent_iface);
626
627 device_lock();
628
629 if (iface->parent_ifname) {
630 parent = vlist_find(&interfaces, iface->parent_ifname, parent, node);
631 iface->parent_iface.cb = interface_alias_cb;
632 interface_add_user(&iface->parent_iface, parent);
633 } else if (iface->ifname &&
634 !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) {
635 dev = device_get(iface->ifname, true);
636 interface_set_device_config(iface, dev);
637 } else {
638 dev = iface->ext_dev.dev;
639 }
640
641 if (dev)
642 interface_set_main_dev(iface, dev);
643
644 device_unlock();
645
646 if (iface->proto_handler->flags & PROTO_FLAG_INIT_AVAILABLE)
647 interface_set_available(iface, true);
648 }
649
650 static void
651 interface_cleanup_state(struct interface *iface)
652 {
653 interface_set_available(iface, false);
654
655 interface_flush_state(iface);
656 interface_clear_errors(iface);
657 interface_set_proto_state(iface, NULL);
658
659 interface_set_main_dev(iface, NULL);
660 interface_set_l3_dev(iface, NULL);
661 }
662
663 static void
664 interface_cleanup(struct interface *iface)
665 {
666 struct interface_user *dep, *tmp;
667
668 uloop_timeout_cancel(&iface->remove_timer);
669 device_remove_user(&iface->ext_dev);
670
671 if (iface->parent_iface.iface)
672 interface_remove_user(&iface->parent_iface);
673
674 list_for_each_entry_safe(dep, tmp, &iface->users, list)
675 interface_remove_user(dep);
676
677 interface_clear_assignment_classes(iface);
678 interface_ip_flush(&iface->config_ip);
679 interface_cleanup_state(iface);
680 }
681
682 static void
683 interface_do_free(struct interface *iface)
684 {
685 interface_event(iface, IFEV_FREE);
686 interface_cleanup(iface);
687 free(iface->config);
688 netifd_ubus_remove_interface(iface);
689 avl_delete(&interfaces.avl, &iface->node.avl);
690 if (iface->jail)
691 free(iface->jail);
692 if (iface->jail_ifname)
693 free(iface->jail_ifname);
694
695 free(iface);
696 }
697
698 static void
699 interface_do_reload(struct interface *iface)
700 {
701 interface_event(iface, IFEV_RELOAD);
702 interface_cleanup_state(iface);
703 proto_init_interface(iface, iface->config);
704 interface_claim_device(iface);
705 }
706
707 static void
708 interface_handle_config_change(struct interface *iface)
709 {
710 enum interface_config_state state = iface->config_state;
711
712 iface->config_state = IFC_NORMAL;
713 switch(state) {
714 case IFC_NORMAL:
715 break;
716 case IFC_RELOAD:
717 interface_do_reload(iface);
718 break;
719 case IFC_REMOVE:
720 interface_do_free(iface);
721 return;
722 }
723 if (iface->autostart)
724 interface_set_up(iface);
725 }
726
727 static void
728 interface_proto_event_cb(struct interface_proto_state *state, enum interface_proto_event ev)
729 {
730 struct interface *iface = state->iface;
731
732 switch (ev) {
733 case IFPEV_UP:
734 if (iface->state != IFS_SETUP) {
735 if (iface->state == IFS_UP && iface->updated)
736 interface_event(iface, IFEV_UPDATE);
737 return;
738 }
739
740 if (!iface->l3_dev.dev)
741 interface_set_l3_dev(iface, iface->main_dev.dev);
742
743 interface_ip_set_enabled(&iface->config_ip, true);
744 interface_ip_set_enabled(&iface->proto_ip, true);
745 system_flush_routes();
746 iface->state = IFS_UP;
747 iface->start_time = system_get_rtime();
748 interface_event(iface, IFEV_UP);
749 netifd_log_message(L_NOTICE, "Interface '%s' is now up\n", iface->name);
750 break;
751 case IFPEV_DOWN:
752 if (iface->state == IFS_DOWN)
753 return;
754
755 netifd_log_message(L_NOTICE, "Interface '%s' is now down\n", iface->name);
756 mark_interface_down(iface);
757 if (iface->main_dev.dev)
758 device_release(&iface->main_dev);
759 if (iface->l3_dev.dev)
760 device_remove_user(&iface->l3_dev);
761 interface_handle_config_change(iface);
762 break;
763 case IFPEV_LINK_LOST:
764 if (iface->state != IFS_UP)
765 return;
766
767 netifd_log_message(L_NOTICE, "Interface '%s' has lost the connection\n", iface->name);
768 mark_interface_down(iface);
769 iface->state = IFS_SETUP;
770 break;
771 default:
772 return;
773 }
774
775 interface_write_resolv_conf(iface->jail);
776 }
777
778 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state)
779 {
780 if (iface->proto) {
781 iface->proto->free(iface->proto);
782 iface->proto = NULL;
783 }
784 iface->state = IFS_DOWN;
785 iface->proto = state;
786 if (!state)
787 return;
788
789 state->proto_event = interface_proto_event_cb;
790 state->iface = iface;
791 }
792
793 struct interface *
794 interface_alloc(const char *name, struct blob_attr *config, bool dynamic)
795 {
796 struct interface *iface;
797 struct blob_attr *tb[IFACE_ATTR_MAX];
798 struct blob_attr *cur;
799 const char *proto_name = NULL;
800 char *iface_name;
801 bool force_link = false;
802
803 iface = calloc_a(sizeof(*iface), &iface_name, strlen(name) + 1);
804 iface->name = strcpy(iface_name, name);
805 INIT_LIST_HEAD(&iface->errors);
806 INIT_LIST_HEAD(&iface->users);
807 INIT_LIST_HEAD(&iface->hotplug_list);
808 INIT_LIST_HEAD(&iface->assignment_classes);
809 interface_ip_init(iface);
810 avl_init(&iface->data, avl_strcmp, false, NULL);
811 iface->config_ip.enabled = false;
812
813 iface->main_dev.cb = interface_main_dev_cb;
814 iface->l3_dev.cb = interface_l3_dev_cb;
815 iface->ext_dev.cb = interface_ext_dev_cb;
816
817 blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
818 blob_data(config), blob_len(config));
819
820 if ((cur = tb[IFACE_ATTR_PROTO]))
821 proto_name = blobmsg_data(cur);
822
823 proto_attach_interface(iface, proto_name);
824 if (iface->proto_handler->flags & PROTO_FLAG_FORCE_LINK_DEFAULT)
825 force_link = true;
826
827 iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
828 iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], force_link);
829 iface->dynamic = dynamic;
830 iface->proto_ip.no_defaultroute =
831 !blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true);
832 iface->proto_ip.no_dns =
833 !blobmsg_get_bool_default(tb[IFACE_ATTR_PEERDNS], true);
834
835 if ((cur = tb[IFACE_ATTR_DNS]))
836 interface_add_dns_server_list(&iface->config_ip, cur);
837
838 if ((cur = tb[IFACE_ATTR_DNS_SEARCH]))
839 interface_add_dns_search_list(&iface->config_ip, cur);
840
841 if ((cur = tb[IFACE_ATTR_DNS_METRIC]))
842 iface->dns_metric = blobmsg_get_u32(cur);
843
844 if ((cur = tb[IFACE_ATTR_METRIC]))
845 iface->metric = blobmsg_get_u32(cur);
846
847 if ((cur = tb[IFACE_ATTR_IP6ASSIGN]))
848 iface->assignment_length = blobmsg_get_u32(cur);
849
850 /* defaults */
851 iface->assignment_iface_id_selection = IFID_FIXED;
852 iface->assignment_fixed_iface_id = in6addr_any;
853 iface->assignment_fixed_iface_id.s6_addr[15] = 1;
854
855 if ((cur = tb[IFACE_ATTR_IP6IFACEID])) {
856 const char *ifaceid = blobmsg_data(cur);
857 if (!strcmp(ifaceid, "random")) {
858 iface->assignment_iface_id_selection = IFID_RANDOM;
859 }
860 else if (!strcmp(ifaceid, "eui64")) {
861 iface->assignment_iface_id_selection = IFID_EUI64;
862 }
863 else {
864 /* we expect an IPv6 address with network id zero here -> fixed iface id
865 if we cannot parse -> revert to iface id 1 */
866 if (inet_pton(AF_INET6,ifaceid,&iface->assignment_fixed_iface_id) != 1 ||
867 iface->assignment_fixed_iface_id.s6_addr32[0] != 0 ||
868 iface->assignment_fixed_iface_id.s6_addr32[1] != 0) {
869 iface->assignment_fixed_iface_id = in6addr_any;
870 iface->assignment_fixed_iface_id.s6_addr[15] = 1;
871 netifd_log_message(L_WARNING, "Failed to parse ip6ifaceid for interface '%s', \
872 falling back to iface id 1.\n", iface->name);
873 }
874 }
875 }
876
877 iface->assignment_hint = -1;
878 if ((cur = tb[IFACE_ATTR_IP6HINT]))
879 iface->assignment_hint = strtol(blobmsg_get_string(cur), NULL, 16) &
880 ~((1 << (64 - iface->assignment_length)) - 1);
881
882 if ((cur = tb[IFACE_ATTR_IP6CLASS]))
883 interface_add_assignment_classes(iface, cur);
884
885 if ((cur = tb[IFACE_ATTR_IP6WEIGHT]))
886 iface->assignment_weight = blobmsg_get_u32(cur);
887
888 if ((cur = tb[IFACE_ATTR_IP4TABLE])) {
889 if (!system_resolve_rt_table(blobmsg_data(cur), &iface->ip4table))
890 DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur));
891 }
892
893 if ((cur = tb[IFACE_ATTR_IP6TABLE])) {
894 if (!system_resolve_rt_table(blobmsg_data(cur), &iface->ip6table))
895 DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur));
896 }
897
898 iface->proto_ip.no_delegation = !blobmsg_get_bool_default(tb[IFACE_ATTR_DELEGATE], true);
899
900 iface->config_autostart = iface->autostart;
901 iface->jail = NULL;
902
903 if ((cur = tb[IFACE_ATTR_JAIL])) {
904 iface->jail = strdup(blobmsg_get_string(cur));
905 iface->autostart = false;
906 }
907
908 iface->jail_ifname = NULL;
909 if ((cur = tb[IFACE_ATTR_JAIL_IFNAME]))
910 iface->jail_ifname = strdup(blobmsg_get_string(cur));
911
912 return iface;
913 }
914
915 static bool __interface_add(struct interface *iface, struct blob_attr *config, bool alias)
916 {
917 struct blob_attr *tb[IFACE_ATTR_MAX];
918 struct blob_attr *cur;
919 char *name = NULL;
920
921 blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
922 blob_data(config), blob_len(config));
923
924 if (alias) {
925 if ((cur = tb[IFACE_ATTR_INTERFACE]))
926 iface->parent_ifname = blobmsg_data(cur);
927
928 if (!iface->parent_ifname)
929 return false;
930 } else {
931 if ((cur = tb[IFACE_ATTR_IFNAME]))
932 iface->ifname = blobmsg_data(cur);
933 }
934
935 if (iface->dynamic) {
936 name = strdup(iface->name);
937
938 if (!name)
939 return false;
940 }
941
942 iface->config = config;
943 vlist_add(&interfaces, &iface->node, iface->name);
944
945 if (name) {
946 iface = vlist_find(&interfaces, name, iface, node);
947 free(name);
948
949 /* Don't delete dynamic interface on reload */
950 if (iface)
951 iface->node.version = -1;
952 }
953
954 return true;
955 }
956
957 bool
958 interface_add(struct interface *iface, struct blob_attr *config)
959 {
960 return __interface_add(iface, config, false);
961 }
962
963 bool
964 interface_add_alias(struct interface *iface, struct blob_attr *config)
965 {
966 if (iface->proto_handler->flags & PROTO_FLAG_NODEV)
967 return false;
968
969 return __interface_add(iface, config, true);
970 }
971
972 void
973 interface_set_l3_dev(struct interface *iface, struct device *dev)
974 {
975 bool enabled = iface->config_ip.enabled;
976 bool claimed = iface->l3_dev.claimed;
977
978 if (iface->l3_dev.dev == dev)
979 return;
980
981 interface_ip_set_enabled(&iface->config_ip, false);
982 interface_ip_set_enabled(&iface->proto_ip, false);
983 interface_ip_flush(&iface->proto_ip);
984 device_add_user(&iface->l3_dev, dev);
985
986 if (dev) {
987 if (claimed) {
988 if (device_claim(&iface->l3_dev) < 0)
989 return;
990 }
991 interface_ip_set_enabled(&iface->config_ip, enabled);
992 interface_ip_set_enabled(&iface->proto_ip, enabled);
993 }
994 }
995
996 static void
997 interface_set_main_dev(struct interface *iface, struct device *dev)
998 {
999 bool claimed = iface->l3_dev.claimed;
1000
1001 if (iface->main_dev.dev == dev)
1002 return;
1003
1004 interface_set_available(iface, false);
1005 device_add_user(&iface->main_dev, dev);
1006 if (!dev) {
1007 interface_set_link_state(iface, false);
1008 return;
1009 }
1010
1011 if (claimed) {
1012 if (device_claim(&iface->l3_dev) < 0)
1013 return;
1014 }
1015
1016 if (!iface->l3_dev.dev)
1017 interface_set_l3_dev(iface, dev);
1018 }
1019
1020 static int
1021 interface_remove_link(struct interface *iface, struct device *dev)
1022 {
1023 struct device *mdev = iface->main_dev.dev;
1024
1025 if (mdev && mdev->hotplug_ops)
1026 return mdev->hotplug_ops->del(mdev, dev);
1027
1028 if (dev == iface->ext_dev.dev)
1029 device_remove_user(&iface->ext_dev);
1030
1031 if (!iface->main_dev.hotplug)
1032 return UBUS_STATUS_INVALID_ARGUMENT;
1033
1034 if (dev != iface->main_dev.dev)
1035 return UBUS_STATUS_INVALID_ARGUMENT;
1036
1037 interface_set_main_dev(iface, NULL);
1038 return 0;
1039 }
1040
1041 static int
1042 interface_add_link(struct interface *iface, struct device *dev,
1043 struct blob_attr *vlan, bool link_ext)
1044 {
1045 struct device *mdev = iface->main_dev.dev;
1046
1047 if (mdev == dev)
1048 return 0;
1049
1050 if (iface->main_dev.hotplug)
1051 device_remove_user(&iface->main_dev);
1052
1053 if (mdev) {
1054 if (mdev->hotplug_ops)
1055 return mdev->hotplug_ops->add(mdev, dev, vlan);
1056 else
1057 return UBUS_STATUS_NOT_SUPPORTED;
1058 }
1059
1060 if (link_ext)
1061 device_add_user(&iface->ext_dev, dev);
1062
1063 interface_set_main_dev(iface, dev);
1064 iface->main_dev.hotplug = true;
1065 return 0;
1066 }
1067
1068 int
1069 interface_handle_link(struct interface *iface, const char *name,
1070 struct blob_attr *vlan, bool add, bool link_ext)
1071 {
1072 struct device *dev;
1073 int ret;
1074
1075 device_lock();
1076
1077 dev = device_get(name, add ? (link_ext ? 2 : 1) : 0);
1078 if (!dev) {
1079 ret = UBUS_STATUS_NOT_FOUND;
1080 goto out;
1081 }
1082
1083 if (add) {
1084 interface_set_device_config(iface, dev);
1085 if (!link_ext)
1086 device_set_present(dev, true);
1087
1088 ret = interface_add_link(iface, dev, vlan, link_ext);
1089 } else {
1090 ret = interface_remove_link(iface, dev);
1091 }
1092
1093 out:
1094 device_unlock();
1095
1096 return ret;
1097 }
1098
1099 void
1100 interface_set_up(struct interface *iface)
1101 {
1102 int ret;
1103 const char *error = NULL;
1104
1105 iface->autostart = true;
1106
1107 if (iface->state != IFS_DOWN)
1108 return;
1109
1110 interface_clear_errors(iface);
1111 if (iface->available) {
1112 if (iface->main_dev.dev) {
1113 ret = device_claim(&iface->main_dev);
1114 if (!ret)
1115 interface_check_state(iface);
1116 else
1117 error = "DEVICE_CLAIM_FAILED";
1118 } else {
1119 ret = __interface_set_up(iface);
1120 if (ret)
1121 error = "SETUP_FAILED";
1122 }
1123 } else
1124 error = "NO_DEVICE";
1125
1126 if (error)
1127 interface_add_error(iface, "interface", error, NULL, 0);
1128 }
1129
1130 void
1131 interface_set_down(struct interface *iface)
1132 {
1133 if (!iface) {
1134 vlist_for_each_element(&interfaces, iface, node)
1135 __interface_set_down(iface, false);
1136 } else {
1137 iface->autostart = false;
1138 __interface_set_down(iface, false);
1139 }
1140 }
1141
1142 int
1143 interface_renew(struct interface *iface)
1144 {
1145 if (iface->state == IFS_TEARDOWN || iface->state == IFS_DOWN)
1146 return -1;
1147
1148 return interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
1149 }
1150
1151 void
1152 interface_start_pending(void)
1153 {
1154 struct interface *iface;
1155
1156 vlist_for_each_element(&interfaces, iface, node) {
1157 if (iface->autostart)
1158 interface_set_up(iface);
1159 }
1160 }
1161
1162 void
1163 interface_start_jail(const char *jail, const pid_t netns_pid)
1164 {
1165 struct interface *iface;
1166 int netns_fd;
1167 int wstatus;
1168 pid_t pr = 0;
1169
1170 netns_fd = system_netns_open(netns_pid);
1171 if (netns_fd < 0)
1172 return;
1173
1174 vlist_for_each_element(&interfaces, iface, node) {
1175 if (!iface->jail || strcmp(iface->jail, jail))
1176 continue;
1177
1178 system_link_netns_move(iface->main_dev.dev, netns_fd, iface->jail_ifname);
1179 }
1180
1181 close(netns_fd);
1182
1183 pr = fork();
1184 if (pr) {
1185 waitpid(pr, &wstatus, WUNTRACED | WCONTINUED);
1186 return;
1187 }
1188
1189 /* child process */
1190 netns_fd = system_netns_open(netns_pid);
1191 if (netns_fd < 0)
1192 return;
1193
1194 system_netns_set(netns_fd);
1195 system_init();
1196 vlist_for_each_element(&interfaces, iface, node) {
1197 if (!iface->jail || strcmp(iface->jail, jail))
1198 continue;
1199
1200 /*
1201 * The interface has already been renamed and is inside target
1202 * namespace, hence overwrite ifname with jail_ifname for
1203 * interface_set_up().
1204 * We are inside a fork which got it's own copy of the interfaces
1205 * list, so we can mess with it :)
1206 */
1207 if (iface->jail_ifname)
1208 iface->ifname = iface->jail_ifname;
1209
1210 interface_do_reload(iface);
1211 interface_set_up(iface);
1212 }
1213
1214 close(netns_fd);
1215 _exit(0);
1216 }
1217
1218 void
1219 interface_stop_jail(const char *jail, const pid_t netns_pid)
1220 {
1221 struct interface *iface;
1222 int netns_fd, root_netns;
1223 int wstatus;
1224 pid_t parent_pid = getpid();
1225 pid_t pr = 0;
1226 const char *orig_ifname;
1227
1228 pr = fork();
1229 if (pr) {
1230 waitpid(pr, &wstatus, WUNTRACED | WCONTINUED);
1231 return;
1232 }
1233
1234 /* child process */
1235 root_netns = system_netns_open(parent_pid);
1236 if (root_netns < 0)
1237 return;
1238
1239 netns_fd = system_netns_open(netns_pid);
1240 if (netns_fd < 0)
1241 return;
1242
1243 system_netns_set(netns_fd);
1244 system_init();
1245 vlist_for_each_element(&interfaces, iface, node) {
1246 if (!iface->jail || strcmp(iface->jail, jail))
1247 continue;
1248
1249 orig_ifname = iface->ifname;
1250 if (iface->jail_ifname)
1251 iface->ifname = iface->jail_ifname;
1252
1253 interface_do_reload(iface);
1254 interface_set_down(iface);
1255 system_link_netns_move(iface->main_dev.dev, root_netns, orig_ifname);
1256 }
1257
1258 close(root_netns);
1259 close(netns_fd);
1260 _exit(0);
1261 }
1262
1263 static void
1264 set_config_state(struct interface *iface, enum interface_config_state s)
1265 {
1266 __set_config_state(iface, s);
1267 if (iface->state == IFS_DOWN)
1268 interface_handle_config_change(iface);
1269 else
1270 __interface_set_down(iface, false);
1271 }
1272
1273 void
1274 interface_update_start(struct interface *iface, const bool keep_old)
1275 {
1276 iface->updated = 0;
1277
1278 if (!keep_old)
1279 interface_ip_update_start(&iface->proto_ip);
1280 }
1281
1282 void
1283 interface_update_complete(struct interface *iface)
1284 {
1285 interface_ip_update_complete(&iface->proto_ip);
1286 }
1287
1288 static void
1289 interface_replace_dns(struct interface_ip_settings *new, struct interface_ip_settings *old)
1290 {
1291 vlist_simple_replace(&new->dns_servers, &old->dns_servers);
1292 vlist_simple_replace(&new->dns_search, &old->dns_search);
1293 }
1294
1295 static bool
1296 interface_device_config_changed(struct interface *if_old, struct interface *if_new)
1297 {
1298 struct blob_attr *ntb[__DEV_ATTR_MAX];
1299 struct blob_attr *otb[__DEV_ATTR_MAX];
1300 struct device *dev = if_old->main_dev.dev;
1301 unsigned long diff = 0;
1302
1303 BUILD_BUG_ON(sizeof(diff) < __DEV_ATTR_MAX / 8);
1304
1305 if (!dev)
1306 return false;
1307
1308 if (if_old->device_config != if_new->device_config)
1309 return true;
1310
1311 if (!if_new->device_config)
1312 return false;
1313
1314 blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, otb,
1315 blob_data(if_old->config), blob_len(if_old->config));
1316
1317 blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, ntb,
1318 blob_data(if_new->config), blob_len(if_new->config));
1319
1320 uci_blob_diff(ntb, otb, &device_attr_list, &diff);
1321 return diff;
1322 }
1323
1324 static void
1325 interface_change_config(struct interface *if_old, struct interface *if_new)
1326 {
1327 struct blob_attr *old_config = if_old->config;
1328 bool reload = false, reload_ip = false, update_prefix_delegation = false;
1329
1330 #define FIELD_CHANGED_STR(field) \
1331 ((!!if_old->field != !!if_new->field) || \
1332 (if_old->field && \
1333 strcmp(if_old->field, if_new->field) != 0))
1334
1335 if (FIELD_CHANGED_STR(parent_ifname)) {
1336 if (if_old->parent_iface.iface)
1337 interface_remove_user(&if_old->parent_iface);
1338 reload = true;
1339 }
1340
1341 if (!reload && interface_device_config_changed(if_old, if_new))
1342 reload = true;
1343
1344 if (FIELD_CHANGED_STR(ifname) ||
1345 if_old->proto_handler != if_new->proto_handler)
1346 reload = true;
1347
1348 if (!if_old->proto_handler->config_params)
1349 D(INTERFACE, "No config parameters for interface '%s'\n",
1350 if_old->name);
1351 else if (!uci_blob_check_equal(if_old->config, if_new->config,
1352 if_old->proto_handler->config_params))
1353 reload = true;
1354
1355 #define UPDATE(field, __var) ({ \
1356 bool __changed = (if_old->field != if_new->field); \
1357 if_old->field = if_new->field; \
1358 __var |= __changed; \
1359 })
1360
1361 if_old->config = if_new->config;
1362 if (if_old->config_autostart != if_new->config_autostart) {
1363 if (if_old->config_autostart)
1364 reload = true;
1365
1366 if_old->autostart = if_new->config_autostart;
1367 }
1368
1369 if_old->device_config = if_new->device_config;
1370 if_old->config_autostart = if_new->config_autostart;
1371 if (if_old->jail)
1372 free(if_old->jail);
1373
1374 if_old->jail = if_new->jail;
1375 if (if_old->jail)
1376 if_old->autostart = false;
1377
1378 if (if_old->jail_ifname)
1379 free(if_old->jail_ifname);
1380
1381 if_old->jail_ifname = if_new->jail_ifname;
1382
1383 if_old->ifname = if_new->ifname;
1384 if_old->parent_ifname = if_new->parent_ifname;
1385 if_old->dynamic = if_new->dynamic;
1386 if_old->proto_handler = if_new->proto_handler;
1387 if_old->force_link = if_new->force_link;
1388 if_old->dns_metric = if_new->dns_metric;
1389
1390 if (if_old->proto_ip.no_delegation != if_new->proto_ip.no_delegation) {
1391 if_old->proto_ip.no_delegation = if_new->proto_ip.no_delegation;
1392 update_prefix_delegation = true;
1393 }
1394
1395 if_old->proto_ip.no_dns = if_new->proto_ip.no_dns;
1396 interface_replace_dns(&if_old->config_ip, &if_new->config_ip);
1397
1398 UPDATE(metric, reload_ip);
1399 UPDATE(proto_ip.no_defaultroute, reload_ip);
1400 UPDATE(ip4table, reload_ip);
1401 UPDATE(ip6table, reload_ip);
1402 interface_merge_assignment_data(if_old, if_new);
1403
1404 #undef UPDATE
1405
1406 if (reload) {
1407 D(INTERFACE, "Reload interface '%s' because of config changes\n",
1408 if_old->name);
1409 interface_clear_errors(if_old);
1410 set_config_state(if_old, IFC_RELOAD);
1411 goto out;
1412 }
1413
1414 if (reload_ip) {
1415 bool config_ip_enabled = if_old->config_ip.enabled;
1416 bool proto_ip_enabled = if_old->proto_ip.enabled;
1417
1418 interface_ip_set_enabled(&if_old->config_ip, false);
1419 interface_ip_set_enabled(&if_old->proto_ip, false);
1420 interface_ip_set_enabled(&if_old->proto_ip, proto_ip_enabled);
1421 interface_ip_set_enabled(&if_old->config_ip, config_ip_enabled);
1422 }
1423
1424 if (update_prefix_delegation)
1425 interface_update_prefix_delegation(&if_old->proto_ip);
1426
1427 interface_write_resolv_conf(if_old->jail);
1428 if (if_old->main_dev.dev)
1429 interface_check_state(if_old);
1430
1431 out:
1432 if_new->config = NULL;
1433 interface_cleanup(if_new);
1434 free(old_config);
1435 free(if_new);
1436 }
1437
1438 static void
1439 interface_update(struct vlist_tree *tree, struct vlist_node *node_new,
1440 struct vlist_node *node_old)
1441 {
1442 struct interface *if_old = container_of(node_old, struct interface, node);
1443 struct interface *if_new = container_of(node_new, struct interface, node);
1444
1445 if (node_old && node_new) {
1446 D(INTERFACE, "Update interface '%s'\n", if_new->name);
1447 interface_change_config(if_old, if_new);
1448 } else if (node_old) {
1449 D(INTERFACE, "Remove interface '%s'\n", if_old->name);
1450 set_config_state(if_old, IFC_REMOVE);
1451 } else if (node_new) {
1452 D(INTERFACE, "Create interface '%s'\n", if_new->name);
1453 interface_event(if_new, IFEV_CREATE);
1454 proto_init_interface(if_new, if_new->config);
1455 interface_claim_device(if_new);
1456 netifd_ubus_add_interface(if_new);
1457 }
1458 }
1459
1460
1461 static void __init
1462 interface_init_list(void)
1463 {
1464 vlist_init(&interfaces, avl_strcmp, interface_update);
1465 interfaces.keep_old = true;
1466 interfaces.no_delete = true;
1467 }