Software /
code /
prosody
Comparison
util/dns.lua @ 12240:ffd66b461f6a
util.dns: Implement SVCB record parser
Based on draft-ietf-dnsop-svcb-https-00
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 04 Oct 2020 21:29:44 +0200 (2020-10-04) |
parent | 12239:578ce0415398 |
child | 12241:dd15f42f6312 |
comparison
equal
deleted
inserted
replaced
12239:578ce0415398 | 12240:ffd66b461f6a |
---|---|
196 match = match; | 196 match = match; |
197 data = s_sub(packet, 4); | 197 data = s_sub(packet, 4); |
198 }, tlsa_mt); | 198 }, tlsa_mt); |
199 end | 199 end |
200 | 200 |
201 local svcb_params = {"alpn"; "no-default-alpn"; "port"; "ipv4hint"; "echconfig"; "ipv6hint"}; | |
202 setmetatable(svcb_params, {__index = function(_, n) return "key" .. tostring(n); end}); | |
203 | |
204 local svcb_mt = { | |
205 __tostring = function (rr) | |
206 local kv = {}; | |
207 for i = 1, #rr.fields do | |
208 t_insert(kv, s_format("%s=%q", svcb_params[rr.fields[i].key], tostring(rr.fields[i].value))); | |
209 end | |
210 return s_format("%d %s %s", rr.prio, rr.name, t_concat(kv, " ")); | |
211 end; | |
212 }; | |
213 local svbc_ip_mt = {__tostring = function(ip) return t_concat(ip, ", "); end} | |
214 | |
215 function parsers.SVCB(packet) | |
216 local prio_h, prio_l = packet:byte(1,2); | |
217 local prio = prio_h*256+prio_l; | |
218 local name, pos = readDnsName(packet, 3); | |
219 local fields = {}; | |
220 while #packet > pos do | |
221 local key_h, key_l = packet:byte(pos+0,pos+1); | |
222 local len_h, len_l = packet:byte(pos+2,pos+3); | |
223 local key = key_h*256+key_l; | |
224 local len = len_h*256+len_l; | |
225 local value = packet:sub(pos+4,pos+4-1+len) | |
226 if key == 1 then | |
227 value = setmetatable(parsers.TXT(value), svbc_ip_mt); | |
228 elseif key == 3 then | |
229 local port_h, port_l = value:byte(1,2); | |
230 local port = port_h*256+port_l; | |
231 value = port; | |
232 elseif key == 4 then | |
233 local ip = {}; | |
234 for i = 1, #value, 4 do | |
235 t_insert(ip, parsers.A(value:sub(i, i+3))); | |
236 end | |
237 value = setmetatable(ip, svbc_ip_mt); | |
238 elseif key == 6 then | |
239 local ip = {}; | |
240 for i = 1, #value, 16 do | |
241 t_insert(ip, parsers.AAAA(value:sub(i, i+15))); | |
242 end | |
243 value = setmetatable(ip, svbc_ip_mt); | |
244 end | |
245 t_insert(fields, { key = key, value = value, len = len }); | |
246 pos = pos+len+4; | |
247 end | |
248 return setmetatable({ | |
249 prio = prio, name = name, fields = fields, | |
250 }, svcb_mt); | |
251 end | |
252 | |
253 parsers.HTTPS = parsers.SVCB; | |
254 | |
201 local params = { | 255 local params = { |
202 TLSA = { | 256 TLSA = { |
203 use = tlsa_usages; | 257 use = tlsa_usages; |
204 select = tlsa_selectors; | 258 select = tlsa_selectors; |
205 match = tlsa_match_types; | 259 match = tlsa_match_types; |