add some infrastructure code for proto handlers
[project/netifd.git] / proto.h
1 #ifndef __NETIFD_PROTO_H
2 #define __NETIFD_PROTO_H
3
4 struct interface_proto_state;
5
6 enum interface_proto_event {
7 IFPEV_UP,
8 IFPEV_DOWN,
9 };
10
11 enum interface_proto_cmd {
12 PROTO_CMD_SETUP,
13 PROTO_CMD_TEARDOWN,
14 };
15
16 enum {
17 PROTO_FLAG_IMMEDIATE = (1 << 0),
18 };
19
20 struct interface_proto_state {
21 struct interface *iface;
22 unsigned int flags;
23
24 /* filled in by the protocol user */
25 void (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
26
27 /* filled in by the protocol handler */
28 int (*handler)(struct interface_proto_state *, enum interface_proto_cmd cmd, bool force);
29 void (*free)(struct interface_proto_state *);
30 };
31
32 struct proto_handler {
33 struct avl_node avl;
34
35 const char *name;
36 struct interface_proto_state * (*attach)(struct proto_handler *h, struct interface *);
37 };
38
39 void add_proto_handler(struct proto_handler *p);
40 void proto_attach_interface(struct interface *iface, struct uci_section *s);
41 int interface_proto_event(struct interface_proto_state *proto,
42 enum interface_proto_cmd cmd, bool force);
43
44 #endif