use calloc_a for interface error allocations
[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
18 #include "netifd.h"
19 #include "device.h"
20 #include "interface.h"
21 #include "interface-ip.h"
22 #include "proto.h"
23 #include "ubus.h"
24 #include "config.h"
25 #include "system.h"
26
27 struct vlist_tree interfaces;
28 static LIST_HEAD(iface_all_users);
29
30 enum {
31 IFACE_ATTR_IFNAME,
32 IFACE_ATTR_PROTO,
33 IFACE_ATTR_AUTO,
34 IFACE_ATTR_DEFAULTROUTE,
35 IFACE_ATTR_PEERDNS,
36 IFACE_ATTR_DNS,
37 IFACE_ATTR_DNS_SEARCH,
38 IFACE_ATTR_METRIC,
39 IFACE_ATTR_INTERFACE,
40 IFACE_ATTR_MAX
41 };
42
43 static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
44 [IFACE_ATTR_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING },
45 [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
46 [IFACE_ATTR_AUTO] = { .name = "auto", .type = BLOBMSG_TYPE_BOOL },
47 [IFACE_ATTR_DEFAULTROUTE] = { .name = "defaultroute", .type = BLOBMSG_TYPE_BOOL },
48 [IFACE_ATTR_PEERDNS] = { .name = "peerdns", .type = BLOBMSG_TYPE_BOOL },
49 [IFACE_ATTR_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 },
50 [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
51 [IFACE_ATTR_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY },
52 [IFACE_ATTR_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
53 };
54
55 static const union config_param_info iface_attr_info[IFACE_ATTR_MAX] = {
56 [IFACE_ATTR_DNS] = { .type = BLOBMSG_TYPE_STRING },
57 };
58
59 const struct config_param_list interface_attr_list = {
60 .n_params = IFACE_ATTR_MAX,
61 .params = iface_attrs,
62 .info = iface_attr_info,
63 };
64
65 static void
66 interface_clear_errors(struct interface *iface)
67 {
68 struct interface_error *error, *tmp;
69
70 list_for_each_entry_safe(error, tmp, &iface->errors, list) {
71 list_del(&error->list);
72 free(error);
73 }
74 }
75
76 void interface_add_error(struct interface *iface, const char *subsystem,
77 const char *code, const char **data, int n_data)
78 {
79 struct interface_error *error;
80 int i, len = 0;
81 int *datalen = NULL;
82 char *dest, *d_subsys, *d_code;
83
84 if (n_data) {
85 len = n_data * sizeof(char *);
86 datalen = alloca(len);
87 for (i = 0; i < n_data; i++) {
88 datalen[i] = strlen(data[i]) + 1;
89 len += datalen[i];
90 }
91 }
92
93 error = calloc_a(sizeof(*error) + sizeof(char *) + len,
94 &d_subsys, subsystem ? strlen(subsystem) + 1 : 0,
95 &d_code, code ? strlen(code) + 1 : 0);
96 if (!error)
97 return;
98
99 list_add_tail(&error->list, &iface->errors);
100
101 dest = (char *) &error->data[n_data + 1];
102 for (i = 0; i < n_data; i++) {
103 error->data[i] = dest;
104 memcpy(dest, data[i], datalen[i]);
105 dest += datalen[i];
106 }
107 error->data[n_data++] = NULL;
108
109 if (subsystem)
110 error->subsystem = strcpy(d_subsys, subsystem);
111
112 if (code)
113 error->code = strcpy(d_code, code);
114 }
115
116 static void
117 interface_data_del(struct interface *iface, struct interface_data *data)
118 {
119 avl_delete(&iface->data, &data->node);
120 free(data);
121 }
122
123 static void
124 interface_data_flush(struct interface *iface)
125 {
126 struct interface_data *d, *tmp;
127
128 avl_for_each_element_safe(&iface->data, d, node, tmp)
129 interface_data_del(iface, d);
130 }
131
132 int
133 interface_add_data(struct interface *iface, const struct blob_attr *data)
134 {
135 struct interface_data *n, *o;
136
137 if (!blobmsg_check_attr(data, true))
138 return UBUS_STATUS_INVALID_ARGUMENT;
139
140 n = calloc(1, sizeof(*n) + blob_pad_len(data));
141 memcpy(n->data, data, blob_pad_len(data));
142 n->node.key = blobmsg_name(data);
143
144 o = avl_find_element(&iface->data, n->node.key, o, node);
145 if (o)
146 interface_data_del(iface, o);
147
148 avl_insert(&iface->data, &n->node);
149 return 0;
150 }
151
152 static void
153 interface_event(struct interface *iface, enum interface_event ev)
154 {
155 struct interface_user *dep, *tmp;
156 struct device *adev = NULL;
157
158 list_for_each_entry_safe(dep, tmp, &iface->users, list)
159 dep->cb(dep, iface, ev);
160
161 list_for_each_entry_safe(dep, tmp, &iface_all_users, list)
162 dep->cb(dep, iface, ev);
163
164 switch (ev) {
165 case IFEV_UP:
166 adev = iface->main_dev.dev;
167 /* fall through */
168 case IFEV_DOWN:
169 alias_notify_device(iface->name, adev);
170 break;
171 default:
172 break;
173 }
174 }
175
176 static void
177 interface_flush_state(struct interface *iface)
178 {
179 if (iface->l3_dev.dev)
180 device_release(&iface->l3_dev);
181 interface_data_flush(iface);
182 }
183
184 static void
185 mark_interface_down(struct interface *iface)
186 {
187 enum interface_state state = iface->state;
188
189 iface->state = IFS_DOWN;
190 if (state == IFS_UP)
191 interface_event(iface, IFEV_DOWN);
192 interface_ip_set_enabled(&iface->config_ip, false);
193 interface_ip_flush(&iface->proto_ip);
194 interface_flush_state(iface);
195 system_flush_routes();
196 }
197
198 void
199 __interface_set_down(struct interface *iface, bool force)
200 {
201 if (iface->state == IFS_DOWN ||
202 iface->state == IFS_TEARDOWN)
203 return;
204
205 if (iface->state == IFS_UP)
206 interface_event(iface, IFEV_DOWN);
207 iface->state = IFS_TEARDOWN;
208 interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, force);
209 if (force)
210 interface_flush_state(iface);
211 }
212
213 static void
214 interface_cb(struct device_user *dep, enum device_event ev)
215 {
216 struct interface *iface;
217 bool new_state;
218
219 iface = container_of(dep, struct interface, main_dev);
220 switch (ev) {
221 case DEV_EVENT_ADD:
222 new_state = true;
223 break;
224 case DEV_EVENT_REMOVE:
225 new_state = false;
226 break;
227 default:
228 return;
229 }
230
231 interface_set_available(iface, new_state);
232 if (!new_state && dep->dev->external)
233 interface_set_main_dev(iface, NULL);
234 }
235
236 void
237 interface_set_available(struct interface *iface, bool new_state)
238 {
239 if (iface->available == new_state)
240 return;
241
242 D(INTERFACE, "Interface '%s', available=%d\n", iface->name, new_state);
243 iface->available = new_state;
244
245 if (new_state) {
246 if (iface->autostart && !config_init)
247 interface_set_up(iface);
248 } else
249 __interface_set_down(iface, true);
250 }
251
252 void
253 interface_add_user(struct interface_user *dep, struct interface *iface)
254 {
255 if (!iface) {
256 list_add(&dep->list, &iface_all_users);
257 return;
258 }
259
260 dep->iface = iface;
261 list_add(&dep->list, &iface->users);
262 if (iface->state == IFS_UP)
263 dep->cb(dep, iface, IFEV_UP);
264 }
265
266 void
267 interface_remove_user(struct interface_user *dep)
268 {
269 list_del_init(&dep->list);
270 dep->iface = NULL;
271 }
272
273 static void
274 interface_alias_cb(struct interface_user *dep, struct interface *iface, enum interface_event ev)
275 {
276 struct interface *alias = container_of(dep, struct interface, parent_iface);
277 struct device *dev = iface->l3_dev.dev;
278
279 switch (ev) {
280 case IFEV_UP:
281 if (!dev)
282 return;
283
284 interface_set_main_dev(alias, dev);
285 interface_set_available(alias, true);
286 break;
287 case IFEV_DOWN:
288 interface_set_available(alias, false);
289 interface_set_main_dev(alias, NULL);
290 break;
291 case IFEV_FREE:
292 interface_remove_user(dep);
293 break;
294 case IFEV_RELOAD:
295 break;
296 }
297 }
298
299 static void
300 interface_claim_device(struct interface *iface)
301 {
302 struct interface *parent;
303 struct device *dev = NULL;
304
305 if (iface->parent_iface.iface)
306 interface_remove_user(&iface->parent_iface);
307
308 if (iface->parent_ifname) {
309 parent = vlist_find(&interfaces, iface->parent_ifname, parent, node);
310 iface->parent_iface.cb = interface_alias_cb;
311 interface_add_user(&iface->parent_iface, parent);
312 } else if (iface->ifname &&
313 !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) {
314 dev = device_get(iface->ifname, true);
315 }
316
317 if (dev)
318 interface_set_main_dev(iface, dev);
319
320 if (iface->proto_handler->flags & PROTO_FLAG_INIT_AVAILABLE)
321 interface_set_available(iface, true);
322 }
323
324
325 static void
326 interface_cleanup(struct interface *iface, bool reload)
327 {
328 struct interface_user *dep, *tmp;
329
330 if (iface->parent_iface.iface)
331 interface_remove_user(&iface->parent_iface);
332
333 list_for_each_entry_safe(dep, tmp, &iface->users, list)
334 interface_remove_user(dep);
335
336 interface_ip_flush(&iface->config_ip);
337 interface_flush_state(iface);
338 interface_clear_errors(iface);
339
340 if (iface->main_dev.dev && !reload)
341 interface_set_main_dev(iface, NULL);
342 interface_set_proto_state(iface, NULL);
343 }
344
345 static void
346 interface_do_free(struct interface *iface)
347 {
348 interface_event(iface, IFEV_FREE);
349 interface_cleanup(iface, false);
350 free(iface->config);
351 netifd_ubus_remove_interface(iface);
352 avl_delete(&interfaces.avl, &iface->node.avl);
353 free(iface);
354 }
355
356 static void
357 interface_do_reload(struct interface *iface)
358 {
359 interface_event(iface, IFEV_RELOAD);
360 interface_cleanup(iface, true);
361 proto_init_interface(iface, iface->config);
362 interface_claim_device(iface);
363 }
364
365 static void
366 interface_handle_config_change(struct interface *iface)
367 {
368 enum interface_config_state state = iface->config_state;
369
370 iface->config_state = IFC_NORMAL;
371 switch(state) {
372 case IFC_NORMAL:
373 break;
374 case IFC_RELOAD:
375 interface_do_reload(iface);
376 break;
377 case IFC_REMOVE:
378 interface_do_free(iface);
379 return;
380 }
381 if (iface->autostart && iface->available)
382 interface_set_up(iface);
383 }
384
385 static void
386 interface_proto_cb(struct interface_proto_state *state, enum interface_proto_event ev)
387 {
388 struct interface *iface = state->iface;
389
390 switch (ev) {
391 case IFPEV_UP:
392 if (iface->state != IFS_SETUP)
393 return;
394
395 interface_ip_set_enabled(&iface->config_ip, true);
396 system_flush_routes();
397 iface->state = IFS_UP;
398 iface->start_time = system_get_rtime();
399 interface_event(iface, IFEV_UP);
400 netifd_log_message(L_NOTICE, "Interface '%s' is now up\n", iface->name);
401 break;
402 case IFPEV_DOWN:
403 if (iface->state == IFS_DOWN)
404 return;
405
406 netifd_log_message(L_NOTICE, "Interface '%s' is now down\n", iface->name);
407 mark_interface_down(iface);
408 if (iface->main_dev.dev)
409 device_release(&iface->main_dev);
410 interface_handle_config_change(iface);
411 break;
412 case IFPEV_LINK_LOST:
413 if (iface->state != IFS_UP)
414 return;
415
416 netifd_log_message(L_NOTICE, "Interface '%s' has lost the connection\n", iface->name);
417 mark_interface_down(iface);
418 iface->state = IFS_SETUP;
419 break;
420 }
421
422 interface_write_resolv_conf();
423 }
424
425 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state)
426 {
427 if (iface->proto) {
428 iface->proto->free(iface->proto);
429 iface->proto = NULL;
430 }
431 iface->state = IFS_DOWN;
432 iface->proto = state;
433 if (!state)
434 return;
435
436 state->proto_event = interface_proto_cb;
437 state->iface = iface;
438 }
439
440 void
441 interface_init(struct interface *iface, const char *name,
442 struct blob_attr *config)
443 {
444 struct blob_attr *tb[IFACE_ATTR_MAX];
445 struct blob_attr *cur;
446 const char *proto_name = NULL;
447
448 strncpy(iface->name, name, sizeof(iface->name) - 1);
449 INIT_LIST_HEAD(&iface->errors);
450 INIT_LIST_HEAD(&iface->users);
451 INIT_LIST_HEAD(&iface->hotplug_list);
452 interface_ip_init(iface);
453 avl_init(&iface->data, avl_strcmp, false, NULL);
454 iface->config_ip.enabled = false;
455
456 iface->main_dev.cb = interface_cb;
457
458 blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
459 blob_data(config), blob_len(config));
460
461 if ((cur = tb[IFACE_ATTR_PROTO]))
462 proto_name = blobmsg_data(cur);
463
464 proto_attach_interface(iface, proto_name);
465
466 iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
467 iface->proto_ip.no_defaultroute =
468 !blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true);
469 iface->proto_ip.no_dns =
470 !blobmsg_get_bool_default(tb[IFACE_ATTR_PEERDNS], true);
471
472 if ((cur = tb[IFACE_ATTR_DNS]))
473 interface_add_dns_server_list(&iface->config_ip, cur);
474
475 if ((cur = tb[IFACE_ATTR_DNS_SEARCH]))
476 interface_add_dns_search_list(&iface->config_ip, cur);
477
478 if ((cur = tb[IFACE_ATTR_METRIC]))
479 iface->metric = blobmsg_get_u32(cur);
480
481 iface->config_autostart = iface->autostart;
482 }
483
484 static bool __interface_add(struct interface *iface, struct blob_attr *config, bool alias)
485 {
486 struct blob_attr *tb[IFACE_ATTR_MAX];
487 struct blob_attr *cur;
488
489 blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
490 blob_data(config), blob_len(config));
491
492 if (alias) {
493 if ((cur = tb[IFACE_ATTR_INTERFACE]))
494 iface->parent_ifname = blobmsg_data(cur);
495
496 if (!iface->parent_ifname)
497 return false;
498 } else {
499 if ((cur = tb[IFACE_ATTR_IFNAME]))
500 iface->ifname = blobmsg_data(cur);
501 }
502
503
504 iface->config = config;
505 vlist_add(&interfaces, &iface->node, iface->name);
506 return true;
507 }
508
509 void
510 interface_add(struct interface *iface, struct blob_attr *config)
511 {
512 __interface_add(iface, config, false);
513 }
514
515 bool
516 interface_add_alias(struct interface *iface, struct blob_attr *config)
517 {
518 if (iface->proto_handler->flags & PROTO_FLAG_NODEV)
519 return false;
520
521 return __interface_add(iface, config, true);
522 }
523
524 void
525 interface_set_l3_dev(struct interface *iface, struct device *dev)
526 {
527 bool enabled = iface->config_ip.enabled;
528 bool claimed = iface->l3_dev.claimed;
529
530 if (iface->l3_dev.dev == dev)
531 return;
532
533 interface_ip_set_enabled(&iface->config_ip, false);
534 interface_ip_flush(&iface->proto_ip);
535 device_add_user(&iface->l3_dev, dev);
536
537 if (dev) {
538 if (claimed)
539 device_claim(&iface->l3_dev);
540 interface_ip_set_enabled(&iface->config_ip, enabled);
541 }
542 }
543
544 void
545 interface_set_main_dev(struct interface *iface, struct device *dev)
546 {
547 bool set_l3 = (iface->main_dev.dev == iface->l3_dev.dev);
548 bool claimed = iface->l3_dev.claimed;
549
550 if (iface->main_dev.dev == dev)
551 return;
552
553 if (set_l3)
554 interface_set_l3_dev(iface, dev);
555
556 device_add_user(&iface->main_dev, dev);
557 if (claimed)
558 device_claim(&iface->l3_dev);
559
560 if (!iface->l3_dev.dev)
561 interface_set_l3_dev(iface, dev);
562 }
563
564 int
565 interface_remove_link(struct interface *iface, struct device *dev)
566 {
567 struct device *mdev = iface->main_dev.dev;
568
569 if (mdev && mdev->hotplug_ops)
570 return mdev->hotplug_ops->del(mdev, dev);
571
572 if (!iface->main_dev.hotplug)
573 return UBUS_STATUS_INVALID_ARGUMENT;
574
575 if (dev != iface->main_dev.dev)
576 return UBUS_STATUS_INVALID_ARGUMENT;
577
578 device_remove_user(&iface->main_dev);
579 return 0;
580 }
581
582 int
583 interface_add_link(struct interface *iface, struct device *dev)
584 {
585 struct device *mdev = iface->main_dev.dev;
586
587 if (mdev == dev)
588 return 0;
589
590 if (iface->main_dev.hotplug)
591 device_remove_user(&iface->main_dev);
592
593 if (mdev) {
594 if (mdev->hotplug_ops)
595 return mdev->hotplug_ops->add(mdev, dev);
596 else
597 return UBUS_STATUS_NOT_SUPPORTED;
598 }
599
600 interface_set_main_dev(iface, dev);
601 iface->main_dev.hotplug = true;
602 return 0;
603 }
604
605 int
606 interface_set_up(struct interface *iface)
607 {
608 int ret;
609
610 iface->autostart = true;
611
612 if (iface->state != IFS_DOWN)
613 return 0;
614
615 interface_clear_errors(iface);
616 if (!iface->available) {
617 interface_add_error(iface, "interface", "NO_DEVICE", NULL, 0);
618 return -1;
619 }
620
621 if (iface->main_dev.dev) {
622 ret = device_claim(&iface->main_dev);
623 if (ret)
624 return ret;
625 }
626
627 iface->state = IFS_SETUP;
628 ret = interface_proto_event(iface->proto, PROTO_CMD_SETUP, false);
629 if (ret) {
630 mark_interface_down(iface);
631 return ret;
632 }
633
634 return 0;
635 }
636
637 int
638 interface_set_down(struct interface *iface)
639 {
640 if (!iface) {
641 vlist_for_each_element(&interfaces, iface, node)
642 __interface_set_down(iface, false);
643 } else {
644 iface->autostart = false;
645 __interface_set_down(iface, false);
646 }
647
648 return 0;
649 }
650
651 void
652 interface_start_pending(void)
653 {
654 struct interface *iface;
655
656 vlist_for_each_element(&interfaces, iface, node) {
657 if (iface->available && iface->autostart)
658 interface_set_up(iface);
659 }
660 }
661
662 static void
663 set_config_state(struct interface *iface, enum interface_config_state s)
664 {
665 iface->config_state = s;
666 if (iface->state == IFS_DOWN)
667 interface_handle_config_change(iface);
668 else
669 __interface_set_down(iface, false);
670 }
671
672 void
673 interface_update_start(struct interface *iface)
674 {
675 interface_ip_update_start(&iface->proto_ip);
676 }
677
678 void
679 interface_update_complete(struct interface *iface)
680 {
681 interface_ip_update_complete(&iface->proto_ip);
682 }
683
684 static void
685 interface_replace_dns(struct interface_ip_settings *new, struct interface_ip_settings *old)
686 {
687 vlist_simple_replace(&new->dns_servers, &old->dns_servers);
688 vlist_simple_replace(&new->dns_search, &old->dns_search);
689 }
690
691 static void
692 interface_change_config(struct interface *if_old, struct interface *if_new)
693 {
694 struct blob_attr *old_config = if_old->config;
695 const char *old_ifname = if_old->ifname;
696 const char *old_parent_ifname = if_old->parent_ifname;
697 const struct proto_handler *proto = if_old->proto_handler;
698
699 interface_clear_errors(if_old);
700 if_old->config = if_new->config;
701 if (!if_old->config_autostart && if_new->config_autostart)
702 if_old->autostart = true;
703
704 if_old->device_config = if_new->device_config;
705 if_old->config_autostart = if_new->config_autostart;
706 if_old->ifname = if_new->ifname;
707 if_old->parent_ifname = if_new->parent_ifname;
708 if_old->proto_handler = if_new->proto_handler;
709
710 #define FIELD_CHANGED_STR(field) \
711 ((!!if_old->field != !!old_ ## field) || \
712 (old_ ## field && \
713 strcmp(old_ ## field, if_old->field) != 0))
714
715 if (FIELD_CHANGED_STR(parent_ifname)) {
716 if (if_old->parent_iface.iface)
717 interface_remove_user(&if_old->parent_iface);
718 goto reload;
719 }
720
721 if (FIELD_CHANGED_STR(ifname) || proto != if_new->proto_handler) {
722 D(INTERFACE, "Reload interface '%s' because of ifname/proto change\n",
723 if_old->name);
724 goto reload;
725 }
726
727 if (!proto->config_params)
728 D(INTERFACE, "No config parameters for interface '%s'\n",
729 if_old->name);
730 else if (!config_check_equal(old_config, if_new->config,
731 proto->config_params)) {
732 D(INTERFACE, "Reload interface '%s because of config changes\n",
733 if_old->name);
734 goto reload;
735 }
736
737 #define UPDATE(field) ({ \
738 bool __changed = (if_old->field != if_new->field); \
739 if_old->field = if_new->field; \
740 __changed; \
741 })
742
743 if (UPDATE(metric) || UPDATE(proto_ip.no_defaultroute)) {
744 interface_ip_set_enabled(&if_old->config_ip, false);
745 interface_ip_set_enabled(&if_old->config_ip, if_new->config_ip.enabled);
746 interface_ip_set_enabled(&if_old->proto_ip, false);
747 interface_ip_set_enabled(&if_old->proto_ip, if_new->proto_ip.enabled);
748 }
749
750 UPDATE(proto_ip.no_dns);
751 interface_replace_dns(&if_old->config_ip, &if_new->config_ip);
752 interface_write_resolv_conf();
753
754 #undef UPDATE
755
756 goto out;
757
758 reload:
759 set_config_state(if_old, IFC_RELOAD);
760 out:
761 if_new->config = NULL;
762 interface_cleanup(if_new, false);
763 free(old_config);
764 free(if_new);
765 }
766
767 static void
768 interface_update(struct vlist_tree *tree, struct vlist_node *node_new,
769 struct vlist_node *node_old)
770 {
771 struct interface *if_old = container_of(node_old, struct interface, node);
772 struct interface *if_new = container_of(node_new, struct interface, node);
773
774 if (node_old && node_new) {
775 D(INTERFACE, "Update interface '%s'\n", if_new->name);
776 interface_change_config(if_old, if_new);
777 } else if (node_old) {
778 D(INTERFACE, "Remove interface '%s'\n", if_old->name);
779 set_config_state(if_old, IFC_REMOVE);
780 } else if (node_new) {
781 D(INTERFACE, "Create interface '%s'\n", if_new->name);
782 proto_init_interface(if_new, if_new->config);
783 interface_claim_device(if_new);
784 netifd_ubus_add_interface(if_new);
785 }
786 }
787
788
789 static void __init
790 interface_init_list(void)
791 {
792 vlist_init(&interfaces, avl_strcmp, interface_update);
793 interfaces.keep_old = true;
794 interfaces.no_delete = true;
795 }