8 /* work around gcc 2.95.2 bug */
9 #define number(x) ( (u64 = (x)), u64_print() )
11 static void u64_print(void)
19 buf
[--pos
] = '0' + (u64
% 10);
23 buffer_put(buffer_2
,buf
+ pos
,sizeof buf
- pos
);
26 static void hex(unsigned char c
)
28 buffer_put(buffer_2
,"0123456789abcdef" + (c
>> 4),1);
29 buffer_put(buffer_2
,"0123456789abcdef" + (c
& 15),1);
32 static void string(const char *s
)
34 buffer_puts(buffer_2
,s
);
37 static void line(void)
40 buffer_flush(buffer_2
);
43 static void space(void)
48 static void ip(const char i
[4])
56 static void logid(const char id
[2])
62 static void logtype(const char type
[2])
66 uint16_unpack_big(type
,&u
);
70 static void name(const char *q
)
79 while (state
= *q
++) {
83 if ((ch
<= 32) || (ch
> 126)) ch
= '?';
84 if ((ch
>= 'A') && (ch
<= 'Z')) ch
+= 32;
85 buffer_put(buffer_2
,&ch
,1);
91 void log_startup(void)
97 void log_query(uint64
*qnum
,const char client
[4],unsigned int port
,const char id
[2],const char *q
,const char qtype
[2])
99 string("query "); number(*qnum
); space();
100 ip(client
); string(":"); hex(port
>> 8); hex(port
& 255);
101 string(":"); logid(id
); space();
102 logtype(qtype
); space(); name(q
);
106 void log_querydone(uint64
*qnum
,unsigned int len
)
108 string("sent "); number(*qnum
); space();
113 void log_querydrop(uint64
*qnum
)
115 const char *x
= error_str(errno
);
117 string("drop "); number(*qnum
); space();
122 void log_tcpopen(const char client
[4],unsigned int port
)
125 ip(client
); string(":"); hex(port
>> 8); hex(port
& 255);
129 void log_tcpclose(const char client
[4],unsigned int port
)
131 const char *x
= error_str(errno
);
133 ip(client
); string(":"); hex(port
>> 8); hex(port
& 255); space();
138 void log_tx(const char *q
,const char qtype
[2],const char *control
,const char servers
[64],unsigned int gluelessness
)
142 string("tx "); number(gluelessness
); space();
143 logtype(qtype
); space(); name(q
); space();
145 for (i
= 0;i
< 64;i
+= 4)
146 if (byte_diff(servers
+ i
,4,"\0\0\0\0")) {
153 void log_cachedanswer(const char *q
,const char type
[2])
155 string("cached "); logtype(type
); space();
160 void log_cachedcname(const char *dn
,const char *dn2
)
162 string("cached cname "); name(dn
); space(); name(dn2
);
166 void log_cachedns(const char *control
,const char *ns
)
168 string("cached ns "); name(control
); space(); name(ns
);
172 void log_cachednxdomain(const char *dn
)
174 string("cached nxdomain "); name(dn
);
178 void log_nxdomain(const char server
[4],const char *q
,unsigned int ttl
)
180 string("nxdomain "); ip(server
); space(); number(ttl
); space();
185 void log_nodata(const char server
[4],const char *q
,const char qtype
[2],unsigned int ttl
)
187 string("nodata "); ip(server
); space(); number(ttl
); space();
188 logtype(qtype
); space(); name(q
);
192 void log_lame(const char server
[4],const char *control
,const char *referral
)
194 string("lame "); ip(server
); space();
195 name(control
); space(); name(referral
);
199 void log_servfail(const char *dn
)
201 const char *x
= error_str(errno
);
203 string("servfail "); name(dn
); space();
208 void log_rr(const char server
[4],const char *q
,const char type
[2],const char *buf
,unsigned int len
,unsigned int ttl
)
212 string("rr "); ip(server
); space(); number(ttl
); space();
213 logtype(type
); space(); name(q
); space();
215 for (i
= 0;i
< len
;++i
) {
225 void log_rrns(const char server
[4],const char *q
,const char *data
,unsigned int ttl
)
227 string("rr "); ip(server
); space(); number(ttl
);
228 string(" ns "); name(q
); space();
233 void log_rrcname(const char server
[4],const char *q
,const char *data
,unsigned int ttl
)
235 string("rr "); ip(server
); space(); number(ttl
);
236 string(" cname "); name(q
); space();
241 void log_rrptr(const char server
[4],const char *q
,const char *data
,unsigned int ttl
)
243 string("rr "); ip(server
); space(); number(ttl
);
244 string(" ptr "); name(q
); space();
249 void log_rrmx(const char server
[4],const char *q
,const char *mx
,const char pref
[2],unsigned int ttl
)
253 string("rr "); ip(server
); space(); number(ttl
);
254 string(" mx "); name(q
); space();
255 uint16_unpack_big(pref
,&u
);
256 number(u
); space(); name(mx
);
260 void log_rrsoa(const char server
[4],const char *q
,const char *n1
,const char *n2
,const char misc
[20],unsigned int ttl
)
265 string("rr "); ip(server
); space(); number(ttl
);
266 string(" soa "); name(q
); space();
267 name(n1
); space(); name(n2
);
268 for (i
= 0;i
< 20;i
+= 4) {
269 uint32_unpack_big(misc
+ i
,&u
);
277 extern uint64 numqueries
;
278 extern uint64 cache_motion
;
283 number(numqueries
); space();
284 number(cache_motion
); space();
285 number(uactive
); space();