ulong lastdial;
};
Forwtarg forwtarg[10];
-int currtarg;
+int forwtcount;
static char *hmsg = "headers";
{
Forwtarg *tp;
- if (currtarg >= nelem(forwtarg)) {
+ if (forwtcount >= nelem(forwtarg)) {
dnslog("too many forwarding targets");
return -1;
}
- tp = forwtarg + currtarg;
- if (parseip(tp->addr, host) < 0) {
+ tp = forwtarg + forwtcount;
+ if(parseip(tp->addr, host) == -1) {
dnslog("can't parse ip %s", host);
return -1;
}
free(tp->host);
tp->host = estrdup(host);
- currtarg++;
+ forwtcount++;
return 0;
}
static void
redistrib(uchar *buf, int len)
{
+ uchar save[Udphdrsize];
Forwtarg *tp;
Udphdr *uh;
- static uchar outpkt[1500];
- assert(len <= sizeof outpkt);
- memmove(outpkt, buf, len);
- uh = (Udphdr *)outpkt;
- for (tp = forwtarg; tp < forwtarg + currtarg; tp++)
+ memmove(save, buf, Udphdrsize);
+
+ uh = (Udphdr *)buf;
+ for (tp = forwtarg; tp < forwtarg + forwtcount; tp++)
if (tp->fd > 0) {
- memmove(outpkt, tp->addr, sizeof tp->addr);
+ memmove(uh->raddr, tp->addr, sizeof tp->addr);
hnputs(uh->rport, 53); /* dns port */
- if (write(tp->fd, outpkt, len) != len) {
+ if (write(tp->fd, buf, len) != len) {
close(tp->fd);
tp->fd = -1;
}
tp->lastdial = time(nil);
tp->fd = udpport(mntpt);
}
+
+ memmove(buf, save, Udphdrsize);
}
/*
if(len <= Udphdrsize)
goto restart;
- redistrib(buf, len);
+ if(forwtcount > 0)
+ redistrib(buf, len);
uh = (Udphdr*)buf;
len -= Udphdrsize;
goto freereq;
}
+ if(reqmsg.qd == nil){
+ dnslog("server: no question RR from %I", buf);
+ goto freereq;
+ }
+
if(debug || (trace && subsume(trace, reqmsg.qd->owner->name)))
dnslog("%d: serve (%I/%d) %d %s %s",
req.id, buf, uh->rport[0]<<8 | uh->rport[1],