1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
#include "buffer.h"
#include "uint32.h"
#include "uint16.h"
#include "error.h"
#include "byte.h"
#include "log.h"
/* work around gcc 2.95.2 bug */
#define number(x) ( (u64 = (x)), u64_print() )
static uint64 u64;
static void u64_print(void)
{
char buf[20];
unsigned int pos;
pos = sizeof buf;
do {
if (!pos) break;
buf[--pos] = '0' + (u64 % 10);
u64 /= 10;
} while(u64);
buffer_put(buffer_2,buf + pos,sizeof buf - pos);
}
static void hex(unsigned char c)
{
buffer_put(buffer_2,"0123456789abcdef" + (c >> 4),1);
buffer_put(buffer_2,"0123456789abcdef" + (c & 15),1);
}
static void string(const char *s)
{
buffer_puts(buffer_2,s);
}
static void line(void)
{
string("\n");
buffer_flush(buffer_2);
}
static void space(void)
{
string(" ");
}
static void ip(const char i[4])
{
hex(i[0]);
hex(i[1]);
hex(i[2]);
hex(i[3]);
}
static void logid(const char id[2])
{
hex(id[0]);
hex(id[1]);
}
static void logtype(const char type[2])
{
uint16 u;
uint16_unpack_big(type,&u);
number(u);
}
static void name(const char *q)
{
char ch;
int state;
if (!*q) {
string(".");
return;
}
while (state = *q++) {
while (state) {
ch = *q++;
--state;
if ((ch <= 32) || (ch > 126)) ch = '?';
if ((ch >= 'A') && (ch <= 'Z')) ch += 32;
buffer_put(buffer_2,&ch,1);
}
string(".");
}
}
void log_startup(void)
{
string("starting");
line();
}
void log_query(uint64 *qnum,const char client[4],unsigned int port,const char id[2],const char *q,const char qtype[2])
{
string("query "); number(*qnum); space();
ip(client); string(":"); hex(port >> 8); hex(port & 255);
string(":"); logid(id); space();
logtype(qtype); space(); name(q);
line();
}
void log_querydone(uint64 *qnum,unsigned int len)
{
string("sent "); number(*qnum); space();
number(len);
line();
}
void log_querydrop(uint64 *qnum)
{
const char *x = error_str(errno);
string("drop "); number(*qnum); space();
string(x);
line();
}
void log_tcpopen(const char client[4],unsigned int port)
{
string("tcpopen ");
ip(client); string(":"); hex(port >> 8); hex(port & 255);
line();
}
void log_tcpclose(const char client[4],unsigned int port)
{
const char *x = error_str(errno);
string("tcpclose ");
ip(client); string(":"); hex(port >> 8); hex(port & 255); space();
string(x);
line();
}
void log_tx(const char *q,const char qtype[2],const char *control,const char servers[64],unsigned int gluelessness)
{
int i;
string("tx "); number(gluelessness); space();
logtype(qtype); space(); name(q); space();
name(control);
for (i = 0;i < 64;i += 4)
if (byte_diff(servers + i,4,"\0\0\0\0")) {
space();
ip(servers + i);
}
line();
}
void log_cachedanswer(const char *q,const char type[2])
{
string("cached "); logtype(type); space();
name(q);
line();
}
void log_cachedcname(const char *dn,const char *dn2)
{
string("cached cname "); name(dn); space(); name(dn2);
line();
}
void log_cachedns(const char *control,const char *ns)
{
string("cached ns "); name(control); space(); name(ns);
line();
}
void log_cachednxdomain(const char *dn)
{
string("cached nxdomain "); name(dn);
line();
}
void log_nxdomain(const char server[4],const char *q,unsigned int ttl)
{
string("nxdomain "); ip(server); space(); number(ttl); space();
name(q);
line();
}
void log_nodata(const char server[4],const char *q,const char qtype[2],unsigned int ttl)
{
string("nodata "); ip(server); space(); number(ttl); space();
logtype(qtype); space(); name(q);
line();
}
void log_lame(const char server[4],const char *control,const char *referral)
{
string("lame "); ip(server); space();
name(control); space(); name(referral);
line();
}
void log_servfail(const char *dn)
{
const char *x = error_str(errno);
string("servfail "); name(dn); space();
string(x);
line();
}
void log_rr(const char server[4],const char *q,const char type[2],const char *buf,unsigned int len,unsigned int ttl)
{
int i;
string("rr "); ip(server); space(); number(ttl); space();
logtype(type); space(); name(q); space();
for (i = 0;i < len;++i) {
hex(buf[i]);
if (i > 30) {
string("...");
break;
}
}
line();
}
void log_rrns(const char server[4],const char *q,const char *data,unsigned int ttl)
{
string("rr "); ip(server); space(); number(ttl);
string(" ns "); name(q); space();
name(data);
line();
}
void log_rrcname(const char server[4],const char *q,const char *data,unsigned int ttl)
{
string("rr "); ip(server); space(); number(ttl);
string(" cname "); name(q); space();
name(data);
line();
}
void log_rrptr(const char server[4],const char *q,const char *data,unsigned int ttl)
{
string("rr "); ip(server); space(); number(ttl);
string(" ptr "); name(q); space();
name(data);
line();
}
void log_rrmx(const char server[4],const char *q,const char *mx,const char pref[2],unsigned int ttl)
{
uint16 u;
string("rr "); ip(server); space(); number(ttl);
string(" mx "); name(q); space();
uint16_unpack_big(pref,&u);
number(u); space(); name(mx);
line();
}
void log_rrsoa(const char server[4],const char *q,const char *n1,const char *n2,const char misc[20],unsigned int ttl)
{
uint32 u;
int i;
string("rr "); ip(server); space(); number(ttl);
string(" soa "); name(q); space();
name(n1); space(); name(n2);
for (i = 0;i < 20;i += 4) {
uint32_unpack_big(misc + i,&u);
space(); number(u);
}
line();
}
void log_stats(void)
{
extern uint64 numqueries;
extern uint64 cache_motion;
extern int uactive;
extern int tactive;
string("stats ");
number(numqueries); space();
number(cache_motion); space();
number(uactive); space();
number(tactive);
line();
}
|