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