1 Index: dnsmasq-2.77/src/dnsmasq.c
2 ===================================================================
3 --- dnsmasq-2.77.orig/src/dnsmasq.c
4 +++ dnsmasq-2.77/src/dnsmasq.c
6 /* Declare static char *compiler_opts in config.h */
7 #define DNSMASQ_COMPILE_OPTS
13 struct daemon *daemon;
14 @@ -32,6 +34,62 @@ static void fatal_event(struct event_des
15 static int read_event(int fd, struct event_desc *evp, char **msg);
16 static void poll_resolv(int force, int do_reload, time_t now);
18 +static struct ubus_context *ubus;
19 +static struct blob_buf b;
21 +static struct ubus_object_type ubus_object_type = {
25 +static struct ubus_object ubus_object = {
27 + .type = &ubus_object_type,
30 +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name)
32 + if (!ubus || !ubus_object.has_subscribers)
35 + blob_buf_init(&b, 0);
37 + blobmsg_add_string(&b, "mac", mac);
39 + blobmsg_add_string(&b, "ip", ip);
41 + blobmsg_add_string(&b, "name", name);
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 +969,7 @@ int main (int argc, char **argv)
81 + set_ubus_listeners();
83 if (daemon->dhcp || daemon->relay4)
85 @@ -1041,6 +1100,8 @@ int main (int argc, char **argv)
86 check_dbus_listeners();
89 + check_ubus_listeners();
91 check_dns_listeners(now);
94 Index: dnsmasq-2.77/Makefile
95 ===================================================================
96 --- dnsmasq-2.77.orig/Makefile
97 +++ dnsmasq-2.77/Makefile
98 @@ -85,7 +85,7 @@ all : $(BUILDDIR)
99 @cd $(BUILDDIR) && $(MAKE) \
101 build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
102 - build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \
103 + build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) -lubox -lubus" \
104 -f $(top)/Makefile dnsmasq
107 Index: dnsmasq-2.77/src/dnsmasq.h
108 ===================================================================
109 --- dnsmasq-2.77.orig/src/dnsmasq.h
110 +++ dnsmasq-2.77/src/dnsmasq.h
111 @@ -1389,6 +1389,8 @@ void emit_dbus_signal(int action, struct
115 +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name);
119 void ipset_init(void);
120 Index: dnsmasq-2.77/src/rfc2131.c
121 ===================================================================
122 --- dnsmasq-2.77.orig/src/rfc2131.c
123 +++ dnsmasq-2.77/src/rfc2131.c
124 @@ -1621,6 +1621,10 @@ static void log_packet(char *type, void
126 string ? string : "",
128 + if (!strcmp(type, "DHCPACK"))
129 + ubus_event_bcast("dhcp.ack", addr ? inet_ntoa(a) : NULL, daemon->namebuff, string ? string : NULL);
130 + else if (!strcmp(type, "DHCPRELEASE"))
131 + ubus_event_bcast("dhcp.release", addr ? inet_ntoa(a) : NULL, daemon->namebuff, string ? string : NULL);
134 static void log_options(unsigned char *start, u32 xid)