8 /* get a notification from another system of a changed zone */
10 dnnotify(DNSmsg *reqp, DNSmsg *repp, Request *)
15 /* move one question from reqp to repp */
16 memset(repp, 0, sizeof(*repp));
22 repp->flags = Fresp | Onotify | Fauth;
25 if(zonerefreshprogram == nil)
28 /* make sure its the right type */
29 if(repp->qd->type != Tsoa)
32 dnslog("notification for %s", repp->qd->owner->name);
34 /* is it something we care about? */
35 a = inmyarea(repp->qd->owner->name);
39 dnslog("serial old %lud new %lud", a->soarr->soa->serial,
40 repp->qd->soa->serial);
42 /* do nothing if it didn't change */
43 if(a->soarr->soa->serial != repp->qd->soa->serial)
47 /* notify a slave that an area has changed. */
49 send_notify(char *slave, RR *soa, Request *req)
51 int i, len, n, reqno, status, fd;
53 uchar ibuf[Maxudp+Udphdrsize], obuf[Maxudp+Udphdrsize];
55 Udphdr *up = (Udphdr*)obuf;
58 /* create the request */
60 n = mkreq(soa->owner, Cin, obuf, Fauth | Onotify, reqno);
63 if(strcmp(ipattr(slave), "ip") == 0) {
64 if (parseip(up->raddr, slave) == -1)
65 dnslog("bad address %s to notify", slave);
67 rp = dnresolve(slave, Cin, Ta, req, nil, 0, 1, 1, &status);
69 rp = dnresolve(slave, Cin, Taaaa, req, nil, 0, 1, 1, &status);
72 parseip(up->raddr, rp->ip->name);
73 rrfreelist(rp); /* was rrfree */
80 /* send 3 times or until we get anything back */
82 for(i = 0; i < 3; i++, freeanswers(&repmsg)){
83 dnslog("sending %d byte notify to %s/%I.%d about %s", n, slave,
84 up->raddr, nhgets(up->rport), soa->owner->name);
85 memset(&repmsg, 0, sizeof repmsg);
86 if(write(fd, obuf, n) != n)
89 len = read(fd, ibuf, sizeof ibuf);
93 err = convM2DNS(&ibuf[Udphdrsize], len, &repmsg, nil);
98 if(repmsg.id == reqno && (repmsg.flags & Omask) == Onotify)
102 freeanswers(&repmsg);
106 /* send notifies for any updated areas */
108 notify_areas(Area *a, Request *req)
112 for(; a != nil; a = a->next){
116 /* send notifies to all slaves */
117 for(s = a->soarr->soa->slaves; s != nil; s = s->next)
118 send_notify(s->name, a->soarr, req);
124 * process to notify other servers of changes
125 * (also reads in new databases)
132 switch(rfork(RFPROC|RFNOTEG|RFMEM|RFNOWAIT)){
141 procsetname("notify slaves");
142 memset(&req, 0, sizeof req);
143 req.isslave = 1; /* don't fork off subprocesses */
146 getactivity(&req, 0);
147 notify_areas(owned, &req);