implement uci-to-blobmsg conversion as an abstraction between uci and the rest of...
[project/netifd.git] / proto.h
1 #ifndef __NETIFD_PROTO_H
2 #define __NETIFD_PROTO_H
3
4 struct interface;
5 struct interface_proto_state;
6 struct proto_handler;
7
8 enum interface_proto_event {
9 IFPEV_UP,
10 IFPEV_DOWN,
11 };
12
13 enum interface_proto_cmd {
14 PROTO_CMD_SETUP,
15 PROTO_CMD_TEARDOWN,
16 };
17
18 enum {
19 PROTO_FLAG_IMMEDIATE = (1 << 0),
20 };
21
22 struct interface_proto_state {
23 struct interface *iface;
24 unsigned int flags;
25
26 /* filled in by the protocol user */
27 void (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
28
29 /* filled in by the protocol handler */
30 int (*handler)(struct interface_proto_state *, enum interface_proto_cmd cmd, bool force);
31 void (*free)(struct interface_proto_state *);
32 };
33
34 typedef struct interface_proto_state *
35 (*proto_attach_cb)(struct proto_handler *h, struct interface *,
36 struct uci_section *s);
37
38 struct proto_handler {
39 struct avl_node avl;
40
41 const char *name;
42 proto_attach_cb attach;
43 };
44
45 void add_proto_handler(struct proto_handler *p);
46 struct proto_handler *get_proto_handler(const char *name);
47 void proto_attach_interface(struct interface *iface, struct uci_section *s);
48 int interface_proto_event(struct interface_proto_state *proto,
49 enum interface_proto_cmd cmd, bool force);
50
51 #endif