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