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