From caf4d571e6d86285a3690cfcc8de9c5f394320a8 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Sat, 21 Jul 2018 21:45:03 +0100 Subject: [PATCH] Add OpenWRT ubus patch Originally written by John Crispin --- Makefile | 5 +++-- bld/Android.mk | 2 +- src/config.h | 3 +++ src/dnsmasq.c | 14 +++++++++++--- src/dnsmasq.h | 7 +++++++ src/rfc2131.c | 7 +++++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 3817cb0..583e33a 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,7 @@ top?=$(CURDIR) dbus_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1` dbus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1` +ubus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_UBUS $(PKG_CONFIG) --copy -lubox -lubus` idn_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn` idn_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn` idn2_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LIBIDN2 $(PKG_CONFIG) --cflags libidn2` @@ -76,7 +77,7 @@ objs = cache.o rfc1035.o util.o option.o forward.o network.o \ helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o \ dhcp-common.o outpacket.o radv.o slaac.o auth.o ipset.o \ domain.o dnssec.o blockdata.o tables.o loop.o inotify.o \ - poll.o rrfilter.o edns0.o arp.o crypto.o dump.o + poll.o rrfilter.o edns0.o arp.o crypto.o dump.o ubus.o hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \ dns-protocol.h radv-protocol.h ip6addr.h @@ -85,7 +86,7 @@ all : $(BUILDDIR) @cd $(BUILDDIR) && $(MAKE) \ top="$(top)" \ build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \ - build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \ + build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs)" \ -f $(top)/Makefile dnsmasq mostly_clean : diff --git a/bld/Android.mk b/bld/Android.mk index 55e102e..080a615 100644 --- a/bld/Android.mk +++ b/bld/Android.mk @@ -11,7 +11,7 @@ LOCAL_SRC_FILES := bpf.c cache.c dbus.c dhcp.c dnsmasq.c \ radv.c slaac.c auth.c ipset.c domain.c \ dnssec.c dnssec-openssl.c blockdata.c tables.c \ loop.c inotify.c poll.c rrfilter.c edns0.c arp.c \ - crypto.c dump.c + crypto.c dump.c ubus.c LOCAL_MODULE := dnsmasq diff --git a/src/config.h b/src/config.h index 33ff36a..762c49b 100644 --- a/src/config.h +++ b/src/config.h @@ -94,6 +94,9 @@ HAVE_DBUS support some methods to allow (re)configuration of the upstream DNS servers via DBus. +HAVE_UBUS + define this if you want to link against libubus + HAVE_IDN define this if you want international domain name 2003 support. diff --git a/src/dnsmasq.c b/src/dnsmasq.c index 480c5f9..c70b90e 100644 --- a/src/dnsmasq.c +++ b/src/dnsmasq.c @@ -947,8 +947,12 @@ int main (int argc, char **argv) #ifdef HAVE_DBUS set_dbus_listeners(); -#endif - +#endif + +#ifdef HAVE_UBUS + set_ubus_listeners(); +#endif + #ifdef HAVE_DHCP if (daemon->dhcp || daemon->relay4) { @@ -1078,7 +1082,11 @@ int main (int argc, char **argv) } check_dbus_listeners(); #endif - + +#ifdef HAVE_UBUS + check_ubus_listeners(); +#endif + check_dns_listeners(now); #ifdef HAVE_TFTP diff --git a/src/dnsmasq.h b/src/dnsmasq.h index a7c3ea8..989a881 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -1445,6 +1445,13 @@ void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname); # endif #endif +/* ubus.c */ +#ifdef HAVE_UBUS +void set_ubus_listeners(void); +void check_ubus_listeners(void); +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface); +#endif + /* ipset.c */ #ifdef HAVE_IPSET void ipset_init(void); diff --git a/src/rfc2131.c b/src/rfc2131.c index 5416f3e..8c418da 100644 --- a/src/rfc2131.c +++ b/src/rfc2131.c @@ -1636,6 +1636,13 @@ static void log_packet(char *type, void *addr, unsigned char *ext_mac, daemon->namebuff, string ? string : "", err ? err : ""); + +#ifdef HAVE_UBUS + if (!strcmp(type, "DHCPACK")) + ubus_event_bcast("dhcp.ack", daemon->namebuff, addr ? inet_ntoa(a) : NULL, string ? string : NULL, interface); + else if (!strcmp(type, "DHCPRELEASE")) + ubus_event_bcast("dhcp.release", daemon->namebuff, addr ? inet_ntoa(a) : NULL, string ? string : NULL, interface); +#endif } static void log_options(unsigned char *start, u32 xid)