11#define number(x) ( (u64 = (x)), u64_print() )
13static void u64_print(
void)
21 buf[--pos] =
'0' + (
u64 % 10);
25 buffer_put(buffer_2,
buf + pos,
sizeof(
buf) - pos);
28static void hex(
unsigned char c)
30 buffer_put(buffer_2,
"0123456789abcdef" + (c >> 4),1);
31 buffer_put(buffer_2,
"0123456789abcdef" + (c & 15),1);
34static void string(
const char *s)
36 buffer_puts(buffer_2,s);
42 buffer_flush(buffer_2);
45static void space(
void)
50static void ip(
const char i[16])
54 if (ip6_isv4mapped(i))
55 for (j = 12; j < 16; ++j) hex(i[j]);
57 for (j = 0; j < 16; ++j) hex(i[j]);
60static void logid(
const char id[2])
66static void logtype(
const char type[2])
70 uint16_unpack_big(
type,&u);
74static void name(
const char *q)
83 while ((state = *q++)) {
87 if ((ch <= 32) || (ch > 126)) ch =
'?';
88 if ((ch >=
'A') && (ch <=
'Z')) ch += 32;
89 buffer_put(buffer_2,&ch,1);
95void log_startup(
const char listip[16],uint32 scope,
const char sendip[16],
int size,
int opt[
MAXOPT])
99 string(
"starting dnscache listening on ip ");
104 string(
" sending queries from ip ");
107 string(
" udp maxsize = "); string(
strnum);
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 ");
120void log_query(uint64 *qnum,
const char client[16],
unsigned int port,
const char id[2],
const char *q,
const char qtype[2])
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);
131 string(
"sent ");
number(*qnum); space();
137 const char *
x = errstr(errno);
139 string(
"drop ");
number(*qnum); space();
146 string(
"ignored referral ");
ip(
server); space();
147 name(control); space();
name(referral);
154 ip(client); string(
":"); hex(
port >> 8); hex(
port & 255);
160 const char *
x = errstr(errno);
162 ip(client); string(
":"); hex(
port >> 8); hex(
port & 255); space();
167void log_tx(
const char *q,
const char qtype[2],
const char *control,\
174 string(
"tx ");
number(gluelessness); space();
175 logtype(qtype); space();
178 case 0: string(
" -");
break;
179 case 1: string(
" ~");
break;
180 case 2: string(
" ?");
break;
181 case 3: string(
" +");
break;
182 case 4: string(
" *");
break;
187 for (i = 0; i < k; i += 16)
188 if (byte_diff(report + i,16,V6localnet)) {
197 string(
"cached "); logtype(
type); space();
204 string(
"cached cname ");
name(dn); space();
name(dn2);
210 string(
"cached ns ");
name(control); space();
name(ns);
216 string(
"cached nxdomain ");
name(dn);
227void log_nodata(
const char server[16],
const char *q,
const char qtype[2],
unsigned int ttl)
230 logtype(qtype); space();
name(q);
234void log_lame(
const char server[16],
const char *control,
const char *referral)
236 string(
"lame ");
ip(
server); space();
237 name(control); space();
name(referral);
243 string(
"servflagged ");
244 if (flag == 1) string(
"!% ");
245 if (flag == 2) string(
"!~ ");
246 if (flag == -1) string(
"!+ ");
247 if (flag == -2) string(
"!* ");
254 const char *
x = errstr(errno);
256 string(
"servfail ");
name(dn); space();
261void log_rr(
const char server[16],
const char *q,
const char type[2],
const char *
buf,
unsigned int len,
unsigned int ttl)
266 logtype(
type); space();
name(q); space();
268 for (i = 0; i <
len; ++i) {
278void log_rrns(
const char server[16],
const char *q,
const char *
data,
unsigned int ttl)
281 string(
" ns ");
name(q); space();
285void log_rrcname(
const char server[16],
const char *q,
const char *
data,
unsigned int ttl)
288 string(
" cname ");
name(q); space();
293void log_rrptr(
const char server[16],
const char *q,
const char *
data,
unsigned int ttl)
296 string(
" ptr ");
name(q); space();
301void log_rrmx(
const char server[16],
const char *q,
const char *mx,
const char pref[2],
unsigned int ttl)
306 string(
" mx ");
name(q); space();
307 uint16_unpack_big(pref,&
u);
312void log_rrsoa(
const char server[16],
const char *q,
const char *n1,
const char *n2,
const char misc[20],
unsigned int ttl)
318 string(
" soa ");
name(q); space();
320 for (i = 0; i < 20; i += 4) {
321 uint32_unpack_big(misc + i,&
u);
int dns_uniqip6(const char *in, unsigned int n, char *out)
char servers[QUERY_MAXIPLEN]
char name[DNS_NAME6_DOMAIN]
void log_rrmx(const char server[16], const char *q, const char *mx, const char pref[2], unsigned int ttl)
void log_tcpclose(const char client[16], unsigned int port)
void log_tx(const char *q, const char qtype[2], const char *control, char servers[QUERY_MAXIPLEN], int flagns, unsigned int gluelessness)
void log_rrcname(const char server[16], const char *q, const char *data, unsigned int ttl)
void log_query(uint64 *qnum, const char client[16], unsigned int port, const char id[2], const char *q, const char qtype[2])
void log_servflag(const char server[16], int flag)
void log_servfail(const char *dn)
void log_tcpopen(const char client[16], unsigned int port)
void log_cachedanswer(const char *q, const char type[2])
void log_nxdomain(const char server[16], const char *q, unsigned int ttl)
void log_cachednxdomain(const char *dn)
void log_nodata(const char server[16], const char *q, const char qtype[2], unsigned int ttl)
void log_rrptr(const char server[16], const char *q, const char *data, unsigned int ttl)
void log_querydone(uint64 *qnum, unsigned int len)
void log_ignore_referral(const char server[16], const char *control, const char *referral)
void log_startup(const char listip[16], uint32 scope, const char sendip[16], int size, int opt[MAXOPT])
void log_lame(const char server[16], const char *control, const char *referral)
void log_cachedcname(const char *dn, const char *dn2)
void log_rrsoa(const char server[16], const char *q, const char *n1, const char *n2, const char misc[20], unsigned int ttl)
void log_rrns(const char server[16], const char *q, const char *data, unsigned int ttl)
void log_querydrop(uint64 *qnum)
void log_cachedns(const char *control, const char *ns)
void log_rr(const char server[16], const char *q, const char type[2], const char *buf, unsigned int len, unsigned int ttl)