11 static volatile pid_t pid = 0;
12 @@ -32,6 +34,62 @@ 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)
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);
40 + ubus_notify(ubus, &ubus_object, type, b.head, -1);
43 +static void set_ubus_listeners(void)
48 + poll_listen(ubus->sock.fd, POLLIN);
49 + poll_listen(ubus->sock.fd, POLLERR);
50 + poll_listen(ubus->sock.fd, POLLHUP);
53 +static void check_ubus_listeners()
56 + ubus = ubus_connect(NULL);
58 + ubus_add_object(ubus, &ubus_object);
63 + if (poll_check(ubus->sock.fd, POLLIN))
64 + ubus_handle_event(ubus);
66 + if (poll_check(ubus->sock.fd, POLLHUP)) {
72 int main (int argc, char **argv)
74 int bind_fallback = 0;
75 @@ -911,6 +969,7 @@ int main (int argc, char **argv)
79 + set_ubus_listeners();
81 if (daemon->dhcp || daemon->relay4)
83 @@ -1041,6 +1100,8 @@ int main (int argc, char **argv)
84 check_dbus_listeners();
87 + check_ubus_listeners();
89 check_dns_listeners(now);
94 @@ -85,7 +85,7 @@ all : $(BUILDDIR)
95 @cd $(BUILDDIR) && $(MAKE) \
97 build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
98 - build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \
99 + build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) -lubox -lubus" \
100 -f $(top)/Makefile dnsmasq
105 @@ -1397,6 +1397,8 @@ void emit_dbus_signal(int action, struct
109 +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name);
113 void ipset_init(void);
116 @@ -1621,6 +1621,10 @@ static void log_packet(char *type, void
118 string ? string : "",
120 + if (!strcmp(type, "DHCPACK"))
121 + ubus_event_bcast("dhcp.ack", daemon->namebuff, addr ? inet_ntoa(a) : NULL, string ? string : NULL);
122 + else if (!strcmp(type, "DHCPRELEASE"))
123 + ubus_event_bcast("dhcp.release", daemon->namebuff, addr ? inet_ntoa(a) : NULL, string ? string : NULL);
126 static void log_options(unsigned char *start, u32 xid)