[37aaf89] | 1 | Description: tinydns-data SRV & axfr-get SRV/PTR patches |
---|
| 2 | Here's a combined patch that: |
---|
| 3 | . |
---|
| 4 | a) adds a native SRV type to tinydns-data |
---|
| 5 | . |
---|
| 6 | Sfqdn:ip:x:port:weight:priority:ttl:timestamp |
---|
| 7 | . |
---|
| 8 | Standard rules for ip, x, ttl, and timestamp apply. Port, weight, and |
---|
| 9 | priority all range from 0-65535. Weight and priority are optional; they |
---|
| 10 | default to zero if not provided. |
---|
| 11 | . |
---|
| 12 | Sconsole.zoinks.example.com:1.2.3.4:rack102-con1:2001:69:7:300: |
---|
| 13 | . |
---|
| 14 | b) makes axfr-get decompose SRV and PTR records and write them out in |
---|
| 15 | native format, rather than opaque. Again, this is necessary because if the |
---|
| 16 | DNAME fields in the records reference the same zone as fqdn, they can have |
---|
| 17 | compression pointers that are bogus outside the context of that specific |
---|
| 18 | packet, and which can't be correctly loaded into data.cdb by tinydns-data. |
---|
| 19 | . |
---|
| 20 | --michael |
---|
| 21 | . |
---|
| 22 | Laurent G. Bercot <ska-djbdns@skarnet.org> updated it for |
---|
| 23 | djbdns-1.05. Documentation patch by Alex Efros. |
---|
| 24 | Author: Michael Handler <handler@sub-rosa.com> |
---|
| 25 | Date: Thu, 14 Sep 2000 20:37:50 -0400 |
---|
| 26 | Last-Update: 2020-07-26 |
---|
| 27 | |
---|
| 28 | diff --git a/axfr-get.c b/axfr-get.c |
---|
| 29 | index 75db627..a5d5c0c 100644 |
---|
| 30 | --- a/axfr-get.c |
---|
| 31 | +++ b/axfr-get.c |
---|
| 32 | @@ -209,6 +209,26 @@ unsigned int doit(char *buf,unsigned int len,unsigned int pos) |
---|
| 33 | if (!stralloc_cats(&line,".:")) return 0; |
---|
| 34 | if (!stralloc_catulong0(&line,dist,0)) return 0; |
---|
| 35 | } |
---|
| 36 | + else if (byte_equal(data,2,DNS_T_SRV)) { |
---|
| 37 | + uint16 dist, weight, port; |
---|
| 38 | + if (!stralloc_copys(&line,"S")) return 0; |
---|
| 39 | + if (!dns_domain_todot_cat(&line,d1)) return 0; |
---|
| 40 | + if (!stralloc_cats(&line,"::")) return 0; |
---|
| 41 | + pos = x_copy(buf,len,pos,data,2); |
---|
| 42 | + uint16_unpack_big(data,&dist); |
---|
| 43 | + pos = x_copy(buf,len,pos,data,2); |
---|
| 44 | + uint16_unpack_big(data,&weight); |
---|
| 45 | + pos = x_copy(buf,len,pos,data,2); |
---|
| 46 | + uint16_unpack_big(data,&port); |
---|
| 47 | + x_getname(buf,len,pos,&d1); |
---|
| 48 | + if (!dns_domain_todot_cat(&line,d1)) return 0; |
---|
| 49 | + if (!stralloc_cats(&line,".:")) return 0; |
---|
| 50 | + if (!stralloc_catulong0(&line,dist,0)) return 0; |
---|
| 51 | + if (!stralloc_cats(&line,":")) return 0; |
---|
| 52 | + if (!stralloc_catulong0(&line,weight,0)) return 0; |
---|
| 53 | + if (!stralloc_cats(&line,":")) return 0; |
---|
| 54 | + if (!stralloc_catulong0(&line,port,0)) return 0; |
---|
| 55 | + } |
---|
| 56 | else if (byte_equal(data,2,DNS_T_A) && (dlen == 4)) { |
---|
| 57 | char ipstr[IP4_FMT]; |
---|
| 58 | if (!stralloc_copys(&line,"+")) return 0; |
---|
| 59 | @@ -217,6 +237,14 @@ unsigned int doit(char *buf,unsigned int len,unsigned int pos) |
---|
| 60 | x_copy(buf,len,pos,data,4); |
---|
| 61 | if (!stralloc_catb(&line,ipstr,ip4_fmt(ipstr,data))) return 0; |
---|
| 62 | } |
---|
| 63 | + else if (byte_equal(data,2,DNS_T_PTR)) { |
---|
| 64 | + if (!stralloc_copys(&line,"^")) return 0; |
---|
| 65 | + if (!dns_domain_todot_cat(&line,d1)) return 0; |
---|
| 66 | + if (!stralloc_cats(&line,":")) return 0; |
---|
| 67 | + x_getname(buf,len,pos,&d1); |
---|
| 68 | + if (!dns_domain_todot_cat(&line,d1)) return 0; |
---|
| 69 | + if (!stralloc_cats(&line,".")) return 0; |
---|
| 70 | + } |
---|
| 71 | else { |
---|
| 72 | unsigned char ch; |
---|
| 73 | unsigned char ch2; |
---|
| 74 | diff --git a/dns.h b/dns.h |
---|
| 75 | index 2f899ef..3849f4c 100644 |
---|
| 76 | --- a/dns.h |
---|
| 77 | +++ b/dns.h |
---|
| 78 | @@ -20,6 +20,7 @@ |
---|
| 79 | #define DNS_T_SIG "\0\30" |
---|
| 80 | #define DNS_T_KEY "\0\31" |
---|
| 81 | #define DNS_T_AAAA "\0\34" |
---|
| 82 | +#define DNS_T_SRV "\0\41" |
---|
| 83 | #define DNS_T_AXFR "\0\374" |
---|
| 84 | #define DNS_T_ANY "\0\377" |
---|
| 85 | |
---|
| 86 | diff --git a/tinydns-data.c b/tinydns-data.c |
---|
| 87 | index ba82f84..0137f09 100644 |
---|
| 88 | --- a/tinydns-data.c |
---|
| 89 | +++ b/tinydns-data.c |
---|
| 90 | @@ -196,6 +196,7 @@ int main() |
---|
| 91 | char type[2]; |
---|
| 92 | char soa[20]; |
---|
| 93 | char buf[4]; |
---|
| 94 | + char srv[6]; |
---|
| 95 | |
---|
| 96 | umask(022); |
---|
| 97 | |
---|
| 98 | @@ -369,6 +370,43 @@ int main() |
---|
| 99 | rr_finish(d2); |
---|
| 100 | } |
---|
| 101 | break; |
---|
| 102 | + |
---|
| 103 | + case 'S': |
---|
| 104 | + if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem(); |
---|
| 105 | + if (!stralloc_0(&f[6])) nomem(); |
---|
| 106 | + if (!scan_ulong(f[6].s,&ttl)) ttl = TTL_POSITIVE; |
---|
| 107 | + ttdparse(&f[7],ttd); |
---|
| 108 | + locparse(&f[8],loc); |
---|
| 109 | + |
---|
| 110 | + if (!stralloc_0(&f[1])) nomem(); |
---|
| 111 | + |
---|
| 112 | + if (byte_chr(f[2].s,f[2].len,'.') >= f[2].len) { |
---|
| 113 | + if (!stralloc_cats(&f[2],".srv.")) nomem(); |
---|
| 114 | + if (!stralloc_catb(&f[2],f[0].s,f[0].len)) nomem(); |
---|
| 115 | + } |
---|
| 116 | + if (!dns_domain_fromdot(&d2,f[2].s,f[2].len)) nomem(); |
---|
| 117 | + |
---|
| 118 | + if (!stralloc_0(&f[4])) nomem(); |
---|
| 119 | + if (!scan_ulong(f[4].s,&u)) u = 0; |
---|
| 120 | + uint16_pack_big(srv,u); |
---|
| 121 | + if (!stralloc_0(&f[5])) nomem(); |
---|
| 122 | + if (!scan_ulong(f[5].s,&u)) u = 0; |
---|
| 123 | + uint16_pack_big(srv + 2,u); |
---|
| 124 | + if (!stralloc_0(&f[3])) nomem(); |
---|
| 125 | + if (!scan_ulong(f[3].s,&u)) nomem(); |
---|
| 126 | + uint16_pack_big(srv + 4,u); |
---|
| 127 | + |
---|
| 128 | + rr_start(DNS_T_SRV,ttl,ttd,loc); |
---|
| 129 | + rr_add(srv,6); |
---|
| 130 | + rr_addname(d2); |
---|
| 131 | + rr_finish(d1); |
---|
| 132 | + |
---|
| 133 | + if (ip4_scan(f[1].s,ip)) { |
---|
| 134 | + rr_start(DNS_T_A,ttl,ttd,loc); |
---|
| 135 | + rr_add(ip,4); |
---|
| 136 | + rr_finish(d2); |
---|
| 137 | + } |
---|
| 138 | + break; |
---|
| 139 | |
---|
| 140 | case '^': case 'C': |
---|
| 141 | if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem(); |
---|