djbdnscurve6 50
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)
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 line();
109}
110
111void log_query(uint64 *qnum,const char client[16],unsigned int port,const char id[2],const char *q,const char qtype[2],const char *p)
112{
113 string(p); string(".query "); number(*qnum); space();
114 ip(client); string(":"); hex(port >> 8); hex(port & 255);
115 string(":"); logid(id); space();
116 logtype(qtype); space(); name(q);
117 line();
118}
119
120void log_querydone(uint64 *qnum,unsigned int len,const char *p)
121{
122 string(p); string(".sent "); number(*qnum); space();
123 number(len); line();
124}
125
126void log_querydrop(uint64 *qnum,const char *p)
127{
128 const char *x = errstr(errno);
129
130 string(p); string(".drop "); number(*qnum); space();
131 string(x);
132 line();
133}
134
135 void log_ignore_referral(const char server[16],const char * control, const char *referral)
136 {
137 string("ignored referral "); ip(server); space();
138 name(control); space(); name(referral);
139 line();
140 }
141
142void log_tcpopen(const char client[16],unsigned int port)
143{
144 string("tcpopen ");
145 ip(client); string(":"); hex(port >> 8); hex(port & 255);
146 line();
147}
148
149void log_tcpclose(const char client[16],unsigned int port)
150{
151 const char *x = errstr(errno);
152 string("tcpclose ");
153 ip(client); string(":"); hex(port >> 8); hex(port & 255); space();
154 string(x);
155 line();
156}
157
158void log_tx(const char *q,const char qtype[2],const char *control,const char servers[QUERY_MAXIPLEN],int flagkey,unsigned int gluelessness)
159{
160 int i;
161
162 string("tx "); number(gluelessness); space();
163 logtype(qtype); space();
164 name(q); space(); name(control);
165 switch (flagkey) {
166 case -1: string(" !"); break;
167 case 0: string(" -"); break;
168 case 1: string(" +"); break;
169 case 2: string(" *"); break;
170 }
171
172 for (i = 0; i < QUERY_MAXIPLEN; i += 16)
173 if (byte_diff(servers + i,16,V6localnet)) {
174 space();
175 ip(servers + i);
176 }
177 line();
178}
179
180void log_cachedanswer(const char *q,const char type[2])
181{
182 string("cached "); logtype(type); space();
183 name(q);
184 line();
185}
186
187void log_cachedcname(const char *dn,const char *dn2)
188{
189 string("cached cname "); name(dn); space(); name(dn2);
190 line();
191}
192
193void log_cachedns(const char *control,const char *ns)
194{
195 string("cached ns "); name(control); space(); name(ns);
196 line();
197}
198
199void log_cachednxdomain(const char *dn)
200{
201 string("cached nxdomain "); name(dn);
202 line();
203}
204
205void log_nxdomain(const char server[16],const char *q,unsigned int ttl)
206{
207 string("nxdomain "); ip(server); space(); number(ttl); space();
208 name(q);
209 line();
210}
211
212void log_nodata(const char server[16],const char *q,const char qtype[2],unsigned int ttl)
213{
214 string("nodata "); ip(server); space(); number(ttl); space();
215 logtype(qtype); space(); name(q);
216 line();
217}
218
219void log_lame(const char server[16],const char *control,const char *referral)
220{
221 string("lame "); ip(server); space();
222 name(control); space(); name(referral);
223 line();
224}
225
226void log_servflag(const char server[16],int flag)
227{
228 string("servflagged ");
229 if (flag == 1) string("% ");
230 if (flag == -1) string("- ");
231 if (flag == -2) string("! ");
232 ip(server);
233 line();
234}
235
236void log_servfail(const char *dn)
237{
238 const char *x = errstr(errno);
239
240 string("servfail "); name(dn); space();
241 string(x);
242 line();
243}
244
245void log_rr(const char server[16],const char *q,const char type[2],const char *buf,unsigned int len,unsigned int ttl)
246{
247 int i;
248
249 string("rr "); ip(server); space(); number(ttl); space();
250 logtype(type); space(); name(q); space();
251
252 for (i = 0; i < len; ++i) {
253 hex(buf[i]);
254 if (i > 30) {
255 string("...");
256 break;
257 }
258 }
259 line();
260}
261
262void log_rrns(const char server[16],const char *q,const char *data,unsigned int ttl)
263{
264 string("rr "); ip(server); space(); number(ttl);
265 string(" ns "); name(q); space();
266 name(data); line();
267}
268
269void log_rrcname(const char server[16],const char *q,const char *data,unsigned int ttl)
270{
271 string("rr "); ip(server); space(); number(ttl);
272 string(" cname "); name(q); space();
273 name(data);
274 line();
275}
276
277void log_rrptr(const char server[16],const char *q,const char *data,unsigned int ttl)
278{
279 string("rr "); ip(server); space(); number(ttl);
280 string(" ptr "); name(q); space();
281 name(data);
282 line();
283}
284
285void log_rrmx(const char server[16],const char *q,const char *mx,const char pref[2],unsigned int ttl)
286{
287 uint16 u;
288
289 string("rr "); ip(server); space(); number(ttl);
290 string(" mx "); name(q); space();
291 uint16_unpack_big(pref,&u);
292 number(u); space(); name(mx);
293 line();
294}
295
296void log_rrsoa(const char server[16],const char *q,const char *n1,const char *n2,const char misc[20],unsigned int ttl)
297{
298 uint32 u;
299 int i;
300
301 string("rr "); ip(server); space(); number(ttl);
302 string(" soa "); name(q); space();
303 name(n1); space(); name(n2);
304 for (i = 0; i < 20; i += 4) {
305 uint32_unpack_big(misc + i,&u);
306 space(); number(u);
307 }
308 line();
309}
310
311void log_stats(void)
312{
313 extern uint64 numqueries;
314 extern uint64 cache_motion;
315 extern int uactive;
316 extern int eactive;
317 extern int tactive;
318
319 string("stats ");
320 number(numqueries); space();
321 number(cache_motion); space();
322 number(uactive); space();
323 number(eactive); space();
325 line();
326}
char data[32767]
Definition: axfrdns.c:130
unsigned long port
Definition: axfrdns.c:126
char ip[16]
Definition: axfrdns.c:125
uint16 len
Definition: axfrdns.c:319
char buf[MSGSIZE]
Definition: axfrdns.c:318
#define QUERY_MAXIPLEN
Definition: dns.h:47
uint64 numqueries
Definition: dnscache.c:68
char * p
Definition: dnscache.c:37
int uactive
Definition: dnscache.c:83
int eactive
Definition: dnscache.c:84
int tactive
Definition: dnscache.c:187
char servers[QUERY_MAXIPLEN]
Definition: dnsfilter.c:48
struct line * x
char name[DNS_NAME6_DOMAIN]
Definition: dnsfilter.c:52
char strnum[FMT_ULONG]
Definition: dnsmx.c:22
char type[2]
Definition: dnsq.c:56
void log_rrmx(const char server[16], const char *q, const char *mx, const char pref[2], unsigned int ttl)
Definition: log.c:285
void log_tcpclose(const char client[16], unsigned int port)
Definition: log.c:149
void log_rrcname(const char server[16], const char *q, const char *data, unsigned int ttl)
Definition: log.c:269
void log_servflag(const char server[16], int flag)
Definition: log.c:226
void log_servfail(const char *dn)
Definition: log.c:236
void log_tcpopen(const char client[16], unsigned int port)
Definition: log.c:142
void log_cachedanswer(const char *q, const char type[2])
Definition: log.c:180
void log_nxdomain(const char server[16], const char *q, unsigned int ttl)
Definition: log.c:205
void log_cachednxdomain(const char *dn)
Definition: log.c:199
void log_nodata(const char server[16], const char *q, const char qtype[2], unsigned int ttl)
Definition: log.c:212
void log_rrptr(const char server[16], const char *q, const char *data, unsigned int ttl)
Definition: log.c:277
void log_ignore_referral(const char server[16], const char *control, const char *referral)
Definition: log.c:135
void log_querydone(uint64 *qnum, unsigned int len, const char *p)
Definition: log.c:120
void log_tx(const char *q, const char qtype[2], const char *control, const char servers[QUERY_MAXIPLEN], int flagkey, unsigned int gluelessness)
Definition: log.c:158
void log_startup(const char listip[16], uint32 scope, const char sendip[16], int size)
Definition: log.c:95
void log_lame(const char server[16], const char *control, const char *referral)
Definition: log.c:219
void log_query(uint64 *qnum, const char client[16], unsigned int port, const char id[2], const char *q, const char qtype[2], const char *p)
Definition: log.c:111
void log_stats(void)
Definition: log.c:311
void log_cachedcname(const char *dn, const char *dn2)
Definition: log.c:187
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:296
void log_rrns(const char server[16], const char *q, const char *data, unsigned int ttl)
Definition: log.c:262
void log_cachedns(const char *control, const char *ns)
Definition: log.c:193
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:245
void log_querydrop(uint64 *qnum, const char *p)
Definition: log.c:126
#define number(x)
Definition: log.c:11
uint64 cache_motion
Definition: sipcache.c:10
uint64 u64
Definition: siphash.c:24
Definition: dnsfilter.c:23
unsigned long u
Definition: utime.c:10