babeld: add add_filter function
[feed/routing.git] / babeld / src / ubus.h
1 /*
2 IPC integration of babeld with OpenWrt.
3
4 The ubus interface offers following functions:
5 - add_filter '{"ifname":"eth0", "type":0, "metric":5000}'
6 type:
7 0: FILTER_TYPE_INPUT
8 1: FILTER_TYPE_OUTPUT
9 2: FILTER_TYPE_REDISTRIBUTE
10 3: FILTER_TYPE_INSTALL
11 - add_interface '{"ifname":"eth0"}'
12 - get_info
13 - get_neighbours
14 - get_xroutes
15 - get_routes
16
17 All output is divided into IPv4 and IPv6.
18
19 Ubus notifications are sent if we receive updates for
20 - xroutes
21 - routes
22 - neighbours
23
24 The format is:
25 - {route,xroute,neighbour}.add: Object was added
26 - {route,xroute,neighbour}.change: Object was changed
27 - {route,xroute,neighbour}.flush: Object was flushed
28
29 */
30
31 #include <stdbool.h>
32 #include <sys/select.h>
33
34 struct babel_route;
35 struct neighbour;
36 struct xroute;
37
38 // Whether to enable ubus bindings (boolean option).
39 extern int ubus_bindings;
40
41 /**
42 * Initialize ubus interface.
43 *
44 * Connect to the ubus daemon and expose the ubus functions.
45 *
46 * @return if initializing ubus was successful
47 */
48 bool babeld_add_ubus();
49
50 /**
51 * Add ubus socket to given filedescriptor set.
52 *
53 * We need to check repeatedly if the ubus socket has something to read.
54 * The functions allows to add the ubus socket to the normal while(1)-loop of
55 * babeld.
56 *
57 * @param readfs: the filedescriptor set
58 * @param maxfd: the current maximum file descriptor
59 * @return the maximum file descriptor
60 */
61 int babeld_ubus_add_read_sock(fd_set *readfds, int maxfd);
62
63 /**
64 * Check and process ubus socket.
65 *
66 * If the ubus-socket signals that data is available, the ubus_handle_event is
67 * called.
68 */
69 void babeld_ubus_receive(fd_set *readfds);
70
71 /***
72 * Notify the ubus bus that a new xroute is received.
73 *
74 * If a new xroute is received or changed, we will notify subscribers.
75 *
76 * @param xroute: xroute that experienced some change
77 * @param kind: kind that describes if we have a flush, add or change
78 */
79 void ubus_notify_xroute(struct xroute *xroute, int kind);
80
81 /***
82 * Notify the ubus bus that a new route is received.
83 *
84 * If a new route is received or changed, we will notify subscribers.
85 *
86 * @param route: route that experienced some change
87 * @param kind: kind that describes if we have a flush, add or change
88 */
89 void ubus_notify_route(struct babel_route *route, int kind);
90
91 /***
92 * Notify the ubus bus that a new neighbour is received.
93 *
94 * If a new neighbour is received or changed, we will notify subscribers.
95 *
96 * @param neigh: neighbour that experienced some change
97 * @param kind: kind that describes if we have a flush, add or change
98 */
99 void ubus_notify_neighbour(struct neighbour *neigh, int kind);