rework route handling, move parser code to interface-ip.c, add extra options and...
[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
46         struct vlist_tree addr;
47         struct vlist_tree route;
48
49         struct list_head dns_servers;
50         struct list_head dns_search;
51 };
52
53 /*
54  * interface configuration
55  */
56 struct interface {
57         struct vlist_node node;
58         struct list_head hotplug_list;
59         enum interface_event hotplug_ev;
60
61         char name[IFNAMSIZ];
62         const char *ifname;
63
64         bool available;
65         bool autostart;
66         bool config_autostart;
67
68         time_t start_time;
69         enum interface_state state;
70         enum interface_config_state config_state;
71
72         struct list_head users;
73
74         /* main interface that the interface is bound to */
75         struct device_user main_dev;
76
77         /* interface that layer 3 communication will go through */
78         struct device_user *l3_dev;
79
80         struct blob_attr *config;
81
82         /* primary protocol state */
83         const struct proto_handler *proto_handler;
84         struct interface_proto_state *proto;
85
86         struct interface_ip_settings proto_ip;
87         struct interface_ip_settings config_ip;
88
89         /* errors/warnings while trying to bring up the interface */
90         struct list_head errors;
91
92         struct uloop_timeout remove_timer;
93         struct ubus_object ubus;
94 };
95
96 extern struct vlist_tree interfaces;
97 extern const struct config_param_list interface_attr_list;
98
99 void interface_init(struct interface *iface, const char *name,
100                     struct blob_attr *config);
101
102 void interface_add(struct interface *iface, struct blob_attr *config);
103
104 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
105
106 void interface_set_available(struct interface *iface, bool new_state);
107 int interface_set_up(struct interface *iface);
108 int interface_set_down(struct interface *iface);
109 void __interface_set_down(struct interface *iface, bool force);
110
111
112 void interface_add_user(struct interface_user *dep, struct interface *iface);
113 void interface_remove_user(struct interface_user *dep);
114
115 int interface_add_link(struct interface *iface, struct device *llif);
116 void interface_remove_link(struct interface *iface, struct device *llif);
117
118 void interface_add_error(struct interface *iface, const char *subsystem,
119                          const char *code, const char **data, int n_data);
120
121 void interface_update_start(struct interface *iface);
122 void interface_update_complete(struct interface *iface);
123
124 void interface_queue_event(struct interface *iface, enum interface_event ev);
125 void interface_dequeue_event(struct interface *iface);
126
127 void interface_start_pending(void);
128
129 #endif