add a new event for interface reload
[project/netifd.git] / interface.h
1 #ifndef __NETIFD_INTERFACE_H
2 #define __NETIFD_INTERFACE_H
3
4 #include "device.h"
5 #include "config.h"
6
7 struct interface;
8 struct interface_proto_state;
9
10 enum interface_event {
11 IFEV_DOWN,
12 IFEV_UP,
13 IFEV_FREE,
14 IFEV_RELOAD,
15 };
16
17 enum interface_state {
18 IFS_SETUP,
19 IFS_UP,
20 IFS_TEARDOWN,
21 IFS_DOWN,
22 };
23
24 enum interface_config_state {
25 IFC_NORMAL,
26 IFC_RELOAD,
27 IFC_REMOVE
28 };
29
30 struct interface_error {
31 struct list_head list;
32
33 const char *subsystem;
34 const char *code;
35 const char *data[];
36 };
37
38 struct interface_user {
39 struct list_head list;
40 struct interface *iface;
41 void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
42 };
43
44 struct interface_ip_settings {
45 struct interface *iface;
46 bool enabled;
47 bool no_defaultroute;
48
49 struct vlist_tree addr;
50 struct vlist_tree route;
51
52 struct vlist_simple_tree dns_servers;
53 struct vlist_simple_tree dns_search;
54 };
55
56 struct interface_data {
57 struct avl_node node;
58 struct blob_attr data[];
59 };
60
61 /*
62 * interface configuration
63 */
64 struct interface {
65 struct vlist_node node;
66 struct list_head hotplug_list;
67 enum interface_event hotplug_ev;
68
69 char name[IFNAMSIZ];
70 const char *ifname;
71
72 bool available;
73 bool autostart;
74 bool config_autostart;
75
76 time_t start_time;
77 enum interface_state state;
78 enum interface_config_state config_state;
79
80 struct list_head users;
81
82 /* main interface that the interface is bound to */
83 struct device_user main_dev;
84
85 /* interface that layer 3 communication will go through */
86 struct device_user l3_dev;
87
88 struct blob_attr *config;
89
90 /* primary protocol state */
91 const struct proto_handler *proto_handler;
92 struct interface_proto_state *proto;
93
94 struct interface_ip_settings proto_ip;
95 struct interface_ip_settings config_ip;
96 struct vlist_tree host_routes;
97
98 int metric;
99
100 /* errors/warnings while trying to bring up the interface */
101 struct list_head errors;
102
103 /* extra data provided by protocol handlers or modules */
104 struct avl_tree data;
105
106 struct uloop_timeout remove_timer;
107 struct ubus_object ubus;
108 };
109
110 extern struct vlist_tree interfaces;
111 extern const struct config_param_list interface_attr_list;
112
113 void interface_init(struct interface *iface, const char *name,
114 struct blob_attr *config);
115
116 void interface_add(struct interface *iface, struct blob_attr *config);
117
118 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
119
120 void interface_set_available(struct interface *iface, bool new_state);
121 int interface_set_up(struct interface *iface);
122 int interface_set_down(struct interface *iface);
123 void __interface_set_down(struct interface *iface, bool force);
124
125 void interface_set_main_dev(struct interface *iface, struct device *dev);
126 void interface_set_l3_dev(struct interface *iface, struct device *dev);
127
128 void interface_add_user(struct interface_user *dep, struct interface *iface);
129 void interface_remove_user(struct interface_user *dep);
130
131 int interface_add_link(struct interface *iface, struct device *dev);
132 int interface_remove_link(struct interface *iface, struct device *dev);
133
134 void interface_add_error(struct interface *iface, const char *subsystem,
135 const char *code, const char **data, int n_data);
136
137 int interface_add_data(struct interface *iface, const struct blob_attr *data);
138
139 void interface_update_start(struct interface *iface);
140 void interface_update_complete(struct interface *iface);
141
142 void interface_queue_event(struct interface *iface, enum interface_event ev);
143 void interface_dequeue_event(struct interface *iface);
144
145 void interface_start_pending(void);
146
147 #endif