OpenWrt – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
4 | office | 1 | --- a/src/dnsmasq.c |
2 | +++ b/src/dnsmasq.c |
||
3 | @@ -19,6 +19,8 @@ |
||
4 | |||
5 | #include "dnsmasq.h" |
||
6 | |||
7 | +#include <libubus.h> |
||
8 | + |
||
9 | struct daemon *daemon; |
||
10 | |||
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); |
||
15 | |||
16 | +static struct ubus_context *ubus; |
||
17 | +static struct blob_buf b; |
||
18 | + |
||
19 | +static struct ubus_object_type ubus_object_type = { |
||
20 | + .name = "dnsmasq", |
||
21 | +}; |
||
22 | + |
||
23 | +static struct ubus_object ubus_object = { |
||
24 | + .name = "dnsmasq", |
||
25 | + .type = &ubus_object_type, |
||
26 | +}; |
||
27 | + |
||
28 | +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface) |
||
29 | +{ |
||
30 | + if (!ubus || !ubus_object.has_subscribers) |
||
31 | + return; |
||
32 | + |
||
33 | + blob_buf_init(&b, 0); |
||
34 | + if (mac) |
||
35 | + blobmsg_add_string(&b, "mac", mac); |
||
36 | + if (ip) |
||
37 | + blobmsg_add_string(&b, "ip", ip); |
||
38 | + if (name) |
||
39 | + blobmsg_add_string(&b, "name", name); |
||
40 | + if (interface) |
||
41 | + blobmsg_add_string(&b, "interface", interface); |
||
42 | + ubus_notify(ubus, &ubus_object, type, b.head, -1); |
||
43 | +} |
||
44 | + |
||
45 | +static void set_ubus_listeners(void) |
||
46 | +{ |
||
47 | + if (!ubus) |
||
48 | + return; |
||
49 | + |
||
50 | + poll_listen(ubus->sock.fd, POLLIN); |
||
51 | + poll_listen(ubus->sock.fd, POLLERR); |
||
52 | + poll_listen(ubus->sock.fd, POLLHUP); |
||
53 | +} |
||
54 | + |
||
55 | +static void check_ubus_listeners() |
||
56 | +{ |
||
57 | + if (!ubus) { |
||
58 | + ubus = ubus_connect(NULL); |
||
59 | + if (ubus) |
||
60 | + ubus_add_object(ubus, &ubus_object); |
||
61 | + else |
||
62 | + return; |
||
63 | + } |
||
64 | + |
||
65 | + if (poll_check(ubus->sock.fd, POLLIN)) |
||
66 | + ubus_handle_event(ubus); |
||
67 | + |
||
68 | + if (poll_check(ubus->sock.fd, POLLHUP)) { |
||
69 | + ubus_free(ubus); |
||
70 | + ubus = NULL; |
||
71 | + } |
||
72 | +} |
||
73 | + |
||
74 | int main (int argc, char **argv) |
||
75 | { |
||
76 | int bind_fallback = 0; |
||
77 | @@ -949,6 +1009,7 @@ int main (int argc, char **argv) |
||
78 | set_dbus_listeners(); |
||
79 | #endif |
||
80 | |||
81 | + set_ubus_listeners(); |
||
82 | #ifdef HAVE_DHCP |
||
83 | if (daemon->dhcp || daemon->relay4) |
||
84 | { |
||
85 | @@ -1079,6 +1140,8 @@ int main (int argc, char **argv) |
||
86 | check_dbus_listeners(); |
||
87 | #endif |
||
88 | |||
89 | + check_ubus_listeners(); |
||
90 | + |
||
91 | check_dns_listeners(now); |
||
92 | |||
93 | #ifdef HAVE_TFTP |
||
94 | --- a/Makefile |
||
95 | +++ b/Makefile |
||
96 | @@ -85,7 +85,7 @@ all : $(BUILDDIR) |
||
97 | @cd $(BUILDDIR) && $(MAKE) \ |
||
98 | top="$(top)" \ |
||
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 |
||
103 | |||
104 | mostly_clean : |
||
105 | --- a/src/dnsmasq.h |
||
106 | +++ b/src/dnsmasq.h |
||
107 | @@ -1445,6 +1445,8 @@ void emit_dbus_signal(int action, struct |
||
108 | # endif |
||
109 | #endif |
||
110 | |||
111 | +void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface); |
||
112 | + |
||
113 | /* ipset.c */ |
||
114 | #ifdef HAVE_IPSET |
||
115 | void ipset_init(void); |
||
116 | --- a/src/rfc2131.c |
||
117 | +++ b/src/rfc2131.c |
||
118 | @@ -1636,6 +1636,10 @@ static void log_packet(char *type, void |
||
119 | daemon->namebuff, |
||
120 | string ? string : "", |
||
121 | err ? err : ""); |
||
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); |
||
126 | } |
||
127 | |||
128 | static void log_options(unsigned char *start, u32 xid) |