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