956ec66bde0e566b000f20e23168df2f89969854
[feed/routing.git] / babeld / patches / 600-add-ubus.patch
1 --- a/babeld.c
2 +++ b/babeld.c
3 @@ -55,6 +55,8 @@ THE SOFTWARE.
4 #include "rule.h"
5 #include "version.h"
6
7 +#include "ubus.h"
8 +
9 struct timeval now;
10
11 unsigned char myid[8];
12 @@ -536,6 +538,9 @@ main(int argc, char **argv)
13 }
14 }
15
16 + if(ubus_bindings)
17 + babeld_add_ubus();
18 +
19 init_signals();
20 rc = resize_receive_buffer(1500);
21 if(rc < 0)
22 @@ -635,6 +640,8 @@ main(int argc, char **argv)
23 FD_SET(local_sockets[i].fd, &readfds);
24 maxfd = MAX(maxfd, local_sockets[i].fd);
25 }
26 + if(ubus_bindings)
27 + maxfd = babeld_ubus_add_read_sock(&readfds, maxfd);
28 rc = select(maxfd + 1, &readfds, NULL, NULL, &tv);
29 if(rc < 0) {
30 if(errno != EINTR) {
31 @@ -703,6 +710,9 @@ main(int argc, char **argv)
32 i++;
33 }
34
35 + if(ubus_bindings)
36 + babeld_ubus_receive(&readfds);
37 +
38 if(reopening) {
39 kernel_dump_time = now.tv_sec;
40 check_neighbours_timeout = now;
41 --- a/Makefile
42 +++ b/Makefile
43 @@ -11,11 +11,11 @@ LDLIBS = -lrt
44
45 SRCS = babeld.c net.c kernel.c util.c interface.c source.c neighbour.c \
46 route.c xroute.c message.c resend.c configuration.c local.c \
47 - disambiguation.c rule.c
48 + disambiguation.c rule.c ubus.c
49
50 OBJS = babeld.o net.o kernel.o util.o interface.o source.o neighbour.o \
51 route.o xroute.o message.o resend.o configuration.o local.o \
52 - disambiguation.o rule.o
53 + disambiguation.o rule.o ubus.o
54
55 babeld: $(OBJS)
56 $(CC) $(CFLAGS) $(LDFLAGS) -o babeld $(OBJS) $(LDLIBS)
57 --- a/generate-version.sh
58 +++ b/generate-version.sh
59 @@ -10,4 +10,4 @@ else
60 version="unknown"
61 fi
62
63 -echo "#define BABELD_VERSION \"$version\""
64 +echo "#define BABELD_VERSION \"$version-ubus-mod\""
65 --- a/configuration.c
66 +++ b/configuration.c
67 @@ -41,6 +41,7 @@ THE SOFTWARE.
68 #include "kernel.h"
69 #include "configuration.h"
70 #include "rule.h"
71 +#include "ubus.h"
72
73 static struct filter *input_filters = NULL;
74 static struct filter *output_filters = NULL;
75 @@ -850,7 +851,8 @@ parse_option(int c, gnc_t gnc, void *clo
76 strcmp(token, "daemonise") == 0 ||
77 strcmp(token, "skip-kernel-setup") == 0 ||
78 strcmp(token, "ipv6-subtrees") == 0 ||
79 - strcmp(token, "reflect-kernel-metric") == 0) {
80 + strcmp(token, "reflect-kernel-metric") == 0 ||
81 + strcmp(token, "ubus-bindings") == 0) {
82 int b;
83 c = getbool(c, &b, gnc, closure);
84 if(c < -1)
85 @@ -868,6 +870,8 @@ parse_option(int c, gnc_t gnc, void *clo
86 has_ipv6_subtrees = b;
87 else if(strcmp(token, "reflect-kernel-metric") == 0)
88 reflect_kernel_metric = b;
89 + else if(strcmp(token, "ubus-bindings") == 0)
90 + ubus_bindings = b;
91 else
92 abort();
93 } else if(strcmp(token, "protocol-group") == 0) {
94 --- a/local.c
95 +++ b/local.c
96 @@ -42,6 +42,8 @@ THE SOFTWARE.
97 #include "local.h"
98 #include "version.h"
99
100 +#include "ubus.h"
101 +
102 int local_server_socket = -1;
103 struct local_socket local_sockets[MAX_LOCAL_SOCKETS];
104 int num_local_sockets = 0;
105 @@ -80,7 +82,7 @@ write_timeout(int fd, const void *buf, i
106 }
107 }
108
109 -static const char *
110 +const char *
111 local_kind(int kind)
112 {
113 switch(kind) {
114 @@ -191,6 +193,8 @@ local_notify_neighbour(struct neighbour
115 if(local_sockets[i].monitor)
116 local_notify_neighbour_1(&local_sockets[i], neigh, kind);
117 }
118 + if(ubus_bindings)
119 + ubus_notify_neighbour(neigh, kind);
120 }
121
122 static void
123 @@ -228,6 +232,8 @@ local_notify_xroute(struct xroute *xrout
124 if(local_sockets[i].monitor)
125 local_notify_xroute_1(&local_sockets[i], xroute, kind);
126 }
127 + if(ubus_bindings)
128 + ubus_notify_xroute(xroute, kind);
129 }
130
131 static void
132 @@ -273,6 +279,8 @@ local_notify_route(struct babel_route *r
133 if(local_sockets[i].monitor)
134 local_notify_route_1(&local_sockets[i], route, kind);
135 }
136 + if(ubus_bindings)
137 + ubus_notify_route(route, kind);
138 }
139
140 static void
141 --- a/local.h
142 +++ b/local.h
143 @@ -55,3 +55,4 @@ int local_read(struct local_socket *s);
144 int local_header(struct local_socket *s);
145 struct local_socket *local_socket_create(int fd);
146 void local_socket_destroy(int i);
147 +const char * local_kind(int kind);