11 static volatile pid_t pid = 0;
12 @@ -32,6 +34,64 @@ static void fatal_event(struct event_des
13 static int read_event(int fd, struct event_desc *evp, char **msg);
14 static void poll_resolv(int force, int do_reload, time_t now);
16 +static struct ubus_context *ubus;
17 +static struct blob_buf b;
19 +static struct ubus_object_type ubus_object_type = {
23 +static struct ubus_object ubus_object = {
25 + .type = &ubus_object_type,
28 +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface)
30 + if (!ubus || !ubus_object.has_subscribers)
33 + blob_buf_init(&b, 0);
35 + blobmsg_add_string(&b, "mac", mac);
37 + blobmsg_add_string(&b, "ip", ip);
39 + blobmsg_add_string(&b, "name", name);
41 + blobmsg_add_string(&b, "interface", interface);
42 + ubus_notify(ubus, &ubus_object, type, b.head, -1);
45 +static void set_ubus_listeners(void)
50 + poll_listen(ubus->sock.fd, POLLIN);
51 + poll_listen(ubus->sock.fd, POLLERR);
52 + poll_listen(ubus->sock.fd, POLLHUP);
55 +static void check_ubus_listeners()
58 + ubus = ubus_connect(NULL);
60 + ubus_add_object(ubus, &ubus_object);
65 + if (poll_check(ubus->sock.fd, POLLIN))
66 + ubus_handle_event(ubus);
68 + if (poll_check(ubus->sock.fd, POLLHUP)) {
74 int main (int argc, char **argv)
76 int bind_fallback = 0;
77 @@ -911,6 +971,7 @@ int main (int argc, char **argv)
81 + set_ubus_listeners();
83 if (daemon->dhcp || daemon->relay4)
85 @@ -1041,6 +1102,8 @@ int main (int argc, char **argv)
86 check_dbus_listeners();
89 + check_ubus_listeners();
91 check_dns_listeners(now);
96 @@ -85,7 +85,7 @@ all : $(BUILDDIR)
97 @cd $(BUILDDIR) && $(MAKE) \
99 build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
100 - build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \
101 + build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) -lubox -lubus" \
102 -f $(top)/Makefile dnsmasq
107 @@ -1397,6 +1397,8 @@ void emit_dbus_signal(int action, struct
111 +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface);
115 void ipset_init(void);
118 @@ -1621,6 +1621,10 @@ static void log_packet(char *type, void
120 string ? string : "",
122 + if (!strcmp(type, "DHCPACK"))
123 + ubus_event_bcast("dhcp.ack", daemon->namebuff, addr ? inet_ntoa(a) : NULL, string ? string : NULL, interface);
124 + else if (!strcmp(type, "DHCPRELEASE"))
125 + ubus_event_bcast("dhcp.release", daemon->namebuff, addr ? inet_ntoa(a) : NULL, string ? string : NULL, interface);
128 static void log_options(unsigned char *start, u32 xid)