6 #include "../../ndb/dns.h"
8 /* names of RR types - /sys/src/cmd/ndb/dn.c:/rrtname */
33 [Tnsapptr] "nsap-ptr",
55 [Tipseckey] "ipseckey",
78 if(t >= 0 && t < nelem(rrtname) && rrtname[t])
80 snprint(buf, sizeof buf, "type%d", t);
85 fmtrr(Msg *m, RR **rrp, int quest)
95 m->p = seprint(m->p, m->e, "%s name=%s ttl=%lud",
97 rr->owner->name, rr->ttl);
103 m->p = seprint(m->p, m->e, " cpu=%s os=%s",
104 rr->cpu->name, rr->os->name);
111 m->p = seprint(m->p, m->e, " host=%s", rr->host->name);
115 m->p = seprint(m->p, m->e, " mb=%s", rr->mb->name);
118 m->p = seprint(m->p, m->e, " rmb=%s", rr->rmb->name);
119 m->p = seprint(m->p, m->e, " mb=%s", rr->mb->name);
122 m->p = seprint(m->p, m->e, " pref=%lud", rr->pref);
123 m->p = seprint(m->p, m->e, " host=%s", rr->host->name);
127 m->p = seprint(m->p, m->e, " ip=%s", rr->ip->name);
130 m->p = seprint(m->p, m->e, " ptr=%s", rr->ptr->name);
133 m->p = seprint(m->p, m->e, " host=%s", rr->host->name);
134 m->p = seprint(m->p, m->e, " rmb=%s", rr->rmb->name);
135 m->p = seprint(m->p, m->e, " soa.serial=%lud", rr->soa->serial);
136 m->p = seprint(m->p, m->e, " soa.refresh=%lud", rr->soa->refresh);
137 m->p = seprint(m->p, m->e, " soa.retry=%lud", rr->soa->retry);
138 m->p = seprint(m->p, m->e, " soa.expire=%lud", rr->soa->expire);
139 m->p = seprint(m->p, m->e, " soa.minttl=%lud", rr->soa->minttl);
142 for(t=rr->txt; t; t=t->next)
143 m->p = seprint(m->p, m->e, " txt=%q", t->p);
146 m->p = seprint(m->p, m->e, " null=%.*H",
147 rr->null->dlen, rr->null->data);
150 m->p = seprint(m->p, m->e, " rmb=%s", rr->rmb->name);
151 m->p = seprint(m->p, m->e, " rp=%s", rr->rp->name);
154 m->p = seprint(m->p, m->e, " flags=%d proto=%d alg=%d data=%.*H",
155 rr->key->flags, rr->key->proto, rr->key->alg,
156 rr->key->dlen, rr->key->data);
159 m->p = seprint(m->p, m->e,
160 " type=%d alg=%d labels=%d ttl=%lud exp=%lud incep=%lud tag=%d signer=%s data=%.*H",
161 rr->sig->type, rr->sig->alg, rr->sig->labels,
162 rr->sig->ttl, rr->sig->exp, rr->sig->incep, rr->sig->tag,
163 rr->sig->signer->name, rr->sig->dlen, rr->sig->data);
166 m->p = seprint(m->p, m->e, " type=%d tag=%d alg=%d data=%.*H",
167 rr->cert->type, rr->cert->tag, rr->cert->alg,
168 rr->cert->dlen, rr->cert->data);
174 void freealldn(void);
175 static Proto dnsqd, dnsan, dnsns, dnsar;
177 static void donext(Msg*);
185 if((e = convM2DNS(m->ps, m->pe-m->ps, &dm, nil)) != nil){
186 m->p = seprint(m->p, m->e, "error: %s", e);
189 m->p = seprint(m->p, m->e, "id=%d flags=%#ux", dm.id, dm.flags);
207 memset(&dm, 0, sizeof dm);
312 sysfatal("out of memory");
321 sysfatal("out of memory");
328 dnlookup(char *name, int class, int)
332 dn = emalloc(sizeof *dn);
333 dn->name = estrdup(name);
353 int debug; /* for ndb/dns.h */
357 dnslog(char *fmt, ...) /* don't log */
362 /*************************************************
363 * Everything below here is copied from /sys/src/cmd/ndb/dn.c
364 * without modification and can be recopied to update.
368 * convert an integer RR type to it's ascii name
371 rrname(int type, char *buf, int len)
376 if(type >= 0 && type <= Tall)
379 snprint(buf, len, "%d", type);
386 * free a list of resource records and any related structs
393 for(; rp; rp = next){
400 freeserverlist(Server *s)
404 for(; s != nil; s = next){
411 * allocate a resource record of a given type
418 rp = emalloc(sizeof(*rp));
420 rp->pc = getcallerpc(&type);
422 setmalloctag(rp, rp->pc);
425 rp->soa = emalloc(sizeof(*rp->soa));
426 rp->soa->slaves = nil;
427 setmalloctag(rp->soa, rp->pc);
430 rp->srv = emalloc(sizeof(*rp->srv));
431 setmalloctag(rp->srv, rp->pc);
435 rp->key = emalloc(sizeof(*rp->key));
436 setmalloctag(rp->key, rp->pc);
439 rp->caa = emalloc(sizeof(*rp->caa));
440 setmalloctag(rp->caa, rp->pc);
443 rp->cert = emalloc(sizeof(*rp->cert));
444 setmalloctag(rp->cert, rp->pc);
447 rp->sig = emalloc(sizeof(*rp->sig));
448 setmalloctag(rp->sig, rp->pc);
451 rp->null = emalloc(sizeof(*rp->null));
452 setmalloctag(rp->null, rp->pc);
462 * free a resource record and any related structs
471 assert(rp->magic = RRmagic);
476 assert(dp->magic == DNmagic);
477 for(nrp = dp->rr; nrp; nrp = nrp->next)
478 assert(nrp != rp); /* "rrfree of live rr" */
483 freeserverlist(rp->soa->slaves);
484 memset(rp->soa, 0, sizeof *rp->soa); /* cause trouble */
488 memset(rp->srv, 0, sizeof *rp->srv); /* cause trouble */
494 memset(rp->key, 0, sizeof *rp->key); /* cause trouble */
498 free(rp->cert->data);
499 memset(rp->cert, 0, sizeof *rp->cert); /* cause trouble */
504 memset(rp->sig, 0, sizeof *rp->sig); /* cause trouble */
508 free(rp->null->data);
509 memset(rp->null, 0, sizeof *rp->null); /* cause trouble */
514 memset(rp->caa, 0, sizeof *rp->caa); /* cause trouble */
520 memset(t, 0, sizeof *t); /* cause trouble */
526 rp->magic = ~rp->magic;
527 memset(rp, 0, sizeof *rp); /* cause trouble */