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;
// ((Udphdr*)buf)->raddr, ((Udphdr*)buf)->laddr);
getactivity(&req, 0);
req.aborttime = timems() + Maxreqtm;
-// req.from = smprint("%I", ((Udphdr*)buf)->raddr);
req.from = smprint("%I", buf);
rcode = 0;
stats.qrecvdudp++;
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],
ctl = announce(datafile, dir);
if(ctl < 0){
if(!whined++)
- warning("can't announce on dns udp port");
+ warning("can't announce on %s", datafile);
return -1;
}
- snprint(datafile, sizeof(datafile), "%s/data", dir);
/* turn on header style interface */
- if(write(ctl, hmsg, strlen(hmsg)) != strlen(hmsg))
- abort(); /* hmsg */
+ if(write(ctl, hmsg, strlen(hmsg)) != strlen(hmsg)){
+ close(ctl);
+ if(!whined++)
+ warning("can't enable headers on %s", datafile);
+ return -1;
+ }
+
+ snprint(datafile, sizeof(datafile), "%s/data", dir);
data = open(datafile, ORDWR);
if(data < 0){
close(ctl);
if(!whined++)
- warning("can't announce on dns udp port");
+ warning("can't open %s to announce on dns udp port",
+ datafile);
return -1;
}