optioncodes.js (1464B)
1 'use strict' 2 3 exports.toString = function (type) { 4 switch (type) { 5 // list at 6 // https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11 7 case 1: return 'LLQ' 8 case 2: return 'UL' 9 case 3: return 'NSID' 10 case 5: return 'DAU' 11 case 6: return 'DHU' 12 case 7: return 'N3U' 13 case 8: return 'CLIENT_SUBNET' 14 case 9: return 'EXPIRE' 15 case 10: return 'COOKIE' 16 case 11: return 'TCP_KEEPALIVE' 17 case 12: return 'PADDING' 18 case 13: return 'CHAIN' 19 case 14: return 'KEY_TAG' 20 case 15: return 'EDNS_ERROR' 21 case 26946: return 'DEVICEID' 22 } 23 if (type < 0) { 24 return null 25 } 26 return `OPTION_${type}` 27 } 28 29 exports.toCode = function (name) { 30 if (typeof name === 'number') { 31 return name 32 } 33 if (!name) { 34 return -1 35 } 36 switch (name.toUpperCase()) { 37 case 'OPTION_0': return 0 38 case 'LLQ': return 1 39 case 'UL': return 2 40 case 'NSID': return 3 41 case 'OPTION_4': return 4 42 case 'DAU': return 5 43 case 'DHU': return 6 44 case 'N3U': return 7 45 case 'CLIENT_SUBNET': return 8 46 case 'EXPIRE': return 9 47 case 'COOKIE': return 10 48 case 'TCP_KEEPALIVE': return 11 49 case 'PADDING': return 12 50 case 'CHAIN': return 13 51 case 'KEY_TAG': return 14 52 case 'EDNS_ERROR': return 15 53 case 'DEVICEID': return 26946 54 case 'OPTION_65535': return 65535 55 } 56 const m = name.match(/_(\d+)$/) 57 if (m) { 58 return parseInt(m[1], 10) 59 } 60 return -1 61 }