restructure the proto state, add a callback for notifications by the protocol handler...
[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 enum interface_proto_event {
16 PROTO_UP,
17 PROTO_DOWN,
18 };
19
20 struct interface_proto_state {
21 struct interface *iface;
22 const struct interface_proto *proto;
23
24 /* filled in by the protocol user */
25 int (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
26
27 /* filled in by the protocol handler */
28 int (*event)(struct interface_proto_state *, enum interface_event ev);
29 void (*free)(struct interface_proto_state *);
30 };
31
32 struct interface_error {
33 struct list_head list;
34
35 const char *subsystem;
36 const char *code;
37 const char *data[];
38 };
39
40 /*
41 * interface configuration
42 */
43 struct interface {
44 struct list_head list;
45
46 char name[IFNAMSIZ];
47
48 bool up;
49 bool active;
50 bool autostart;
51
52 /* main interface that the interface is bound to */
53 struct device_user main_dev;
54
55 /* interface that layer 3 communication will go through */
56 struct device_user *l3_iface;
57
58 /* primary protocol state */
59 struct interface_proto_state *state;
60
61 /* errors/warnings while trying to bring up the interface */
62 struct list_head errors;
63
64 struct ubus_object ubus;
65 };
66
67 struct interface *get_interface(const char *name);
68 struct interface *alloc_interface(const char *name);
69 void free_interface(struct interface *iface);
70
71 int set_interface_up(struct interface *iface);
72 int set_interface_down(struct interface *iface);
73
74 int interface_add_link(struct interface *iface, struct device *llif);
75 void interface_remove_link(struct interface *iface, struct device *llif);
76
77 void interface_add_error(struct interface *iface, const char *subsystem,
78 const char *code, const char **data, int n_data);
79
80 int interface_attach_bridge(struct interface *iface, struct uci_section *s);
81
82 #endif