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