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