add support for interrupting shell protocol setup
[project/netifd.git] / interface-ip.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "netifd.h"
6 #include "device.h"
7 #include "interface.h"
8 #include "interface-ip.h"
9 #include "proto.h"
10 #include "ubus.h"
11 #include "system.h"
12
13 static void
14 interface_update_proto_addr(struct vlist_tree *tree,
15 struct vlist_node *node_new,
16 struct vlist_node *node_old)
17 {
18 struct interface *iface;
19 struct device *dev;
20 struct device_addr *addr;
21
22 iface = container_of(tree, struct interface, proto_addr);
23 dev = iface->l3_iface->dev;
24
25 if (node_old) {
26 addr = container_of(node_old, struct device_addr, node);
27 system_del_address(dev, addr);
28 free(addr);
29 }
30
31 if (node_new) {
32 addr = container_of(node_new, struct device_addr, node);
33 system_add_address(dev, addr);
34 }
35 }
36
37 static void
38 interface_update_proto_route(struct vlist_tree *tree,
39 struct vlist_node *node_new,
40 struct vlist_node *node_old)
41 {
42 struct interface *iface;
43 struct device *dev;
44 struct device_route *route;
45
46 iface = container_of(tree, struct interface, proto_route);
47 dev = iface->l3_iface->dev;
48
49 if (node_old) {
50 route = container_of(node_old, struct device_route, node);
51 system_del_route(dev, route);
52 free(route);
53 }
54
55 if (node_new) {
56 route = container_of(node_new, struct device_route, node);
57 system_add_route(dev, route);
58 }
59 }
60
61 void
62 interface_ip_init(struct interface *iface)
63 {
64 vlist_init(&iface->proto_route, interface_update_proto_route,
65 struct device_route, node, mask, addr);
66 vlist_init(&iface->proto_addr, interface_update_proto_addr,
67 struct device_addr, node, mask, addr);
68 }
69