87a7cb3a195b92a45eecbc92b69813a4c3d57931
[project/netifd.git] / interface.h
1 #ifndef __NETIFD_INTERFACE_H
2 #define __NETIFD_INTERFACE_H
3
4 struct interface;
5 struct interface_proto_state;
6
7 enum interface_event {
8         IFEV_UP,
9         IFEV_DOWN,
10 };
11
12 enum interface_state {
13         IFS_SETUP,
14         IFS_UP,
15         IFS_TEARDOWN,
16         IFS_DOWN,
17 };
18
19 struct interface_error {
20         struct list_head list;
21
22         const char *subsystem;
23         const char *code;
24         const char *data[];
25 };
26
27 /*
28  * interface configuration
29  */
30 struct interface {
31         struct list_head list;
32
33         char name[IFNAMSIZ];
34
35         bool active;
36         bool autostart;
37
38         enum interface_state state;
39
40         /* main interface that the interface is bound to */
41         struct device_user main_dev;
42
43         /* interface that layer 3 communication will go through */
44         struct device_user *l3_iface;
45
46         /* primary protocol state */
47         struct interface_proto_state *proto;
48
49         /* errors/warnings while trying to bring up the interface */
50         struct list_head errors;
51
52         struct ubus_object ubus;
53 };
54
55 struct interface *get_interface(const char *name);
56 struct interface *alloc_interface(const char *name);
57 void free_interface(struct interface *iface);
58
59 int set_interface_up(struct interface *iface);
60 int set_interface_down(struct interface *iface);
61
62 int interface_add_link(struct interface *iface, struct device *llif);
63 void interface_remove_link(struct interface *iface, struct device *llif);
64
65 void interface_add_error(struct interface *iface, const char *subsystem,
66                          const char *code, const char **data, int n_data);
67
68 int interface_attach_bridge(struct interface *iface, struct uci_section *s);
69
70 #endif