djbdnscurve6 53
djbdnscurve6
Loading...
Searching...
No Matches
log.c
Go to the documentation of this file.
1#include "buffer.h"
2#include "uint_t.h"
3#include "error.h"
4#include "byte.h"
5#include "ip.h"
6#include "fmt.h"
7#include "dns.h"
8#include "log.h"
9
10/* work around gcc 2.95.2 bug */
11#define number(x) ( (u64 = (x)), u64_print() )
12static uint64 u64;
13static void u64_print(void)
14{
15 char buf[20];
16 unsigned int pos;
17
18 pos = sizeof(buf);
19 do {
20 if (!pos) break;
21 buf[--pos] = '0' + (u64 % 10);
22 u64 /= 10;
23 } while(u64);
24
25 buffer_put(buffer_2,buf + pos,sizeof(buf) - pos);
26}
27
28static void hex(unsigned char c)
29{
30 buffer_put(buffer_2,"0123456789abcdef" + (c >> 4),1);
31 buffer_put(buffer_2,"0123456789abcdef" + (c & 15),1);
32}
33
34static void string(const char *s)
35{
36 buffer_puts(buffer_2,s);
37}
38
39static void line(void)
40{
41 string("\n");
42 buffer_flush(buffer_2);
43}
44
45static void space(void)
46{
47 string(" ");
48}
49
50static void ip(const char i[16])
51{
52 int j;
53
54 if (ip6_isv4mapped(i))
55 for (j = 12; j < 16; ++j) hex(i[j]);
56 else
57 for (j = 0; j < 16; ++j) hex(i[j]);
58}
59
60static void logid(const char id[2])
61{
62 hex(id[0]);
63 hex(id[1]);
64}
65
66static void logtype(const char type[2])
67{
68 uint16 u;
69
70 uint16_unpack_big(type,&u);
71 number(u);
72}
73
74static void name(const char *q)
75{
76 char ch;
77 int state;
78
79 if (!*q) {
80 string(".");
81 return;
82 }
83 while ((state = *q++)) {
84 while (state) {
85 ch = *q++;
86 --state;
87 if ((ch <= 32) || (ch > 126)) ch = '?';
88 if ((ch >= 'A') && (ch <= 'Z')) ch += 32;
89 buffer_put(buffer_2,&ch,1);
90 }
91 string(".");
92 }
93}
94
95void log_startup(const char listip[16],uint32 scope,const char sendip[16],int size,int opt[MAXOPT])
96{
97 char strnum[FMT_ULONG];
98
99 string("starting dnscache listening on ip ");
100 ip(listip);
101 string("%");
102 strnum[fmt_ulong(strnum,scope)] = 0;
103 string(strnum);
104 string(" sending queries from ip ");
105 ip(sendip);
106 strnum[fmt_ulong(strnum,size)] = 0;
107 string(" udp maxsize = "); string(strnum);
108 string(" { ");
109 if (opt[0]) string("anycast ");
110 if (opt[1]) string("dualstack ");
111 if (opt[2]) string("uz5-txtformat ");
112 if (opt[3]) string("flagedserver ");
113 if (opt[4]) string("opt-rr ");
114 if (opt[4] == 2) string("do ");
115 if (opt[5]) string("forwardonly ");
116 string("}");
117 line();
118}
119
120void log_query(uint64 *qnum,const char client[16],unsigned int port,const char id[2],const char *q,const char qtype[2])
121{
122 string("query "); number(*qnum); space();
123 ip(client); string(":"); hex(port >> 8); hex(port & 255);
124 string(":"); logid(id); space();
125 logtype(qtype); space(); name(q);
126 line();
127}
128
129void log_querydone(uint64 *qnum,unsigned int len)
130{
131 string("sent "); number(*qnum); space();
132 number(len); line();
133}
134
135void log_querydrop(uint64 *qnum)
136{
137 const char *x = errstr(errno);
138
139 string("drop "); number(*qnum); space();
140 string(x);
141 line();
142}
143
144 void log_ignore_referral(const char server[16],const char * control, const char *referral)
145 {
146 string("ignored referral "); ip(server); space();
147 name(control); space(); name(referral);
148 line();
149 }
150
151void log_tcpopen(const char client[16],unsigned int port)
152{
153 string("tcpopen ");
154 ip(client); string(":"); hex(port >> 8); hex(port & 255);
155 line();
156}
157
158void log_tcpclose(const char client[16],unsigned int port)
159{
160 const char *x = errstr(errno);
161 string("tcpclose ");
162 ip(client); string(":"); hex(port >> 8); hex(port & 255); space();
163 string(x);
164 line();
165}
166
167void log_tx(const char *q,const char qtype[2],const char *control,\
168 char servers[QUERY_MAXIPLEN],int flagns,unsigned int gluelessness)
169{
170 int i;
171 int k = 0;
172 char report[QUERY_MAXIPLEN];
173
174 string("tx "); number(gluelessness); space();
175 logtype(qtype); space();
176 name(q); space(); name(control);
177 switch (flagns) {
178 case 0: string(" -"); break; // default
179 case 1: string(" ~"); break; // EDNS0
180 case 2: string(" ?"); break; // EDNS0 + DO
181 case 3: string(" +"); break; // DNSCurve
182 case 4: string(" *"); break; // DNSCurve/txt
183 }
184
186
187 for (i = 0; i < k; i += 16)
188 if (byte_diff(report + i,16,V6localnet)) {
189 space();
190 ip(report + i);
191 }
192 line();
193}
194
195void log_cachedanswer(const char *q,const char type[2])
196{
197 string("cached "); logtype(type); space();
198 name(q);
199 line();
200}
201
202void log_cachedcname(const char *dn,const char *dn2)
203{
204 string("cached cname "); name(dn); space(); name(dn2);
205 line();
206}
207
208void log_cachedns(const char *control,const char *ns)
209{
210 string("cached ns "); name(control); space(); name(ns);
211 line();
212}
213
214void log_cachednxdomain(const char *dn)
215{
216 string("cached nxdomain "); name(dn);
217 line();
218}
219
220void log_nxdomain(const char server[16],const char *q,unsigned int ttl)
221{
222 string("nxdomain "); ip(server); space(); number(ttl); space();
223 name(q);
224 line();
225}
226
227void log_nodata(const char server[16],const char *q,const char qtype[2],unsigned int ttl)
228{
229 string("nodata "); ip(server); space(); number(ttl); space();
230 logtype(qtype); space(); name(q);
231 line();
232}
233
234void log_lame(const char server[16],const char *control,const char *referral)
235{
236 string("lame "); ip(server); space();
237 name(control); space(); name(referral);
238 line();
239}
240
241void log_servflag(const char server[16],int flag)
242{
243 string("servflagged ");
244 if (flag == 1) string("!% ");
245 if (flag == 2) string("!~ ");
246 if (flag == -1) string("!+ ");
247 if (flag == -2) string("!* ");
248 ip(server);
249 line();
250}
251
252void log_servfail(const char *dn)
253{
254 const char *x = errstr(errno);
255
256 string("servfail "); name(dn); space();
257 string(x);
258 line();
259}
260
261void log_rr(const char server[16],const char *q,const char type[2],const char *buf,unsigned int len,unsigned int ttl)
262{
263 int i;
264
265 string("rr "); ip(server); space(); number(ttl); space();
266 logtype(type); space(); name(q); space();
267
268 for (i = 0; i < len; ++i) {
269 hex(buf[i]);
270 if (i > 30) {
271 string("...");
272 break;
273 }
274 }
275 line();
276}
277
278void log_rrns(const char server[16],const char *q,const char *data,unsigned int ttl)
279{
280 string("rr "); ip(server); space(); number(ttl);
281 string(" ns "); name(q); space();
282 name(data); line();
283}
284
285void log_rrcname(const char server[16],const char *q,const char *data,unsigned int ttl)
286{
287 string("rr "); ip(server); space(); number(ttl);
288 string(" cname "); name(q); space();
289 name(data);
290 line();
291}
292
293void log_rrptr(const char server[16],const char *q,const char *data,unsigned int ttl)
294{
295 string("rr "); ip(server); space(); number(ttl);
296 string(" ptr "); name(q); space();
297 name(data);
298 line();
299}
300
301void log_rrmx(const char server[16],const char *q,const char *mx,const char pref[2],unsigned int ttl)
302{
303 uint16 u;
304
305 string("rr "); ip(server); space(); number(ttl);
306 string(" mx "); name(q); space();
307 uint16_unpack_big(pref,&u);
308 number(u); space(); name(mx);
309 line();
310}
311
312void log_rrsoa(const char server[16],const char *q,const char *n1,const char *n2,const char misc[20],unsigned int ttl)
313{
314 uint32 u;
315 int i;
316
317 string("rr "); ip(server); space(); number(ttl);
318 string(" soa "); name(q); space();
319 name(n1); space(); name(n2);
320 for (i = 0; i < 20; i += 4) {
321 uint32_unpack_big(misc + i,&u);
322 space(); number(u);
323 }
324 line();
325}
326
327void log_stats(void)
328{
329 extern uint64 numqueries;
330 extern uint64 cache_motion;
331 extern int uactive;
332 extern int eactive;
333 extern int tactive;
334
335 string("stats ");
336 number(numqueries); space();
337 number(cache_motion); space();
338 number(uactive); space();
339 number(eactive); space();
341 line();
342}
char data[32767]
Definition: axfrdns.c:133
unsigned long port
Definition: axfrdns.c:129
char ip[16]
Definition: axfrdns.c:128
uint16 len
Definition: axfrdns.c:322
char buf[MSGSIZE]
Definition: axfrdns.c:321
#define QUERY_MAXIPLEN
Definition: dns.h:55
#define MAXOPT
Definition: dns.h:53
int dns_uniqip6(const char *in, unsigned int n, char *out)
Definition: dns_sortip.c:55
uint64 numqueries
Definition: dnscache.c:72
int uactive
Definition: dnscache.c:87
int eactive
Definition: dnscache.c:88
int tactive
Definition: dnscache.c:193
char servers[QUERY_MAXIPLEN]
Definition: dnsfilter.c:54
struct line * x
char name[DNS_NAME6_DOMAIN]
Definition: dnsfilter.c:58
char strnum[FMT_ULONG]
Definition: dnsmx.c:24
char type[2]
Definition: dnsq.c:60
void log_rrmx(const char server[16], const char *q, const char *mx, const char pref[2], unsigned int ttl)
Definition: log.c:301
void log_tcpclose(const char client[16], unsigned int port)
Definition: log.c:158
void log_tx(const char *q, const char qtype[2], const char *control, char servers[QUERY_MAXIPLEN], int flagns, unsigned int gluelessness)
Definition: log.c:167
void log_rrcname(const char server[16], const char *q, const char *data, unsigned int ttl)
Definition: log.c:285
void log_query(uint64 *qnum, const char client[16], unsigned int port, const char id[2], const char *q, const char qtype[2])
Definition: log.c:120
void log_servflag(const char server[16], int flag)
Definition: log.c:241
void log_servfail(const char *dn)
Definition: log.c:252
void log_tcpopen(const char client[16], unsigned int port)
Definition: log.c:151
void log_cachedanswer(const char *q, const char type[2])
Definition: log.c:195
void log_nxdomain(const char server[16], const char *q, unsigned int ttl)
Definition: log.c:220
void log_cachednxdomain(const char *dn)
Definition: log.c:214
void log_nodata(const char server[16], const char *q, const char qtype[2], unsigned int ttl)
Definition: log.c:227
void log_rrptr(const char server[16], const char *q, const char *data, unsigned int ttl)
Definition: log.c:293
void log_querydone(uint64 *qnum, unsigned int len)
Definition: log.c:129
void log_ignore_referral(const char server[16], const char *control, const char *referral)
Definition: log.c:144
void log_startup(const char listip[16], uint32 scope, const char sendip[16], int size, int opt[MAXOPT])
Definition: log.c:95
void log_lame(const char server[16], const char *control, const char *referral)
Definition: log.c:234
void log_stats(void)
Definition: log.c:327
void log_cachedcname(const char *dn, const char *dn2)
Definition: log.c:202
void log_rrsoa(const char server[16], const char *q, const char *n1, const char *n2, const char misc[20], unsigned int ttl)
Definition: log.c:312
void log_rrns(const char server[16], const char *q, const char *data, unsigned int ttl)
Definition: log.c:278
void log_querydrop(uint64 *qnum)
Definition: log.c:135
void log_cachedns(const char *control, const char *ns)
Definition: log.c:208
void log_rr(const char server[16], const char *q, const char type[2], const char *buf, unsigned int len, unsigned int ttl)
Definition: log.c:261
#define number(x)
Definition: log.c:11
const char * server
Definition: rbldns.c:17
uint64 cache_motion
Definition: sipcache.c:10
uint64 u64
Definition: siphash.c:24
Definition: dnsfilter.c:29
unsigned long u
Definition: utime.c:10