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