"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "svcb.go" between
dns-1.1.47.tar.gz and dns-1.1.48.tar.gz

About: GO DNS implements a DNS library in Go.

svcb.go  (dns-1.1.47):svcb.go  (dns-1.1.48)
skipping to change at line 16 skipping to change at line 16
"errors" "errors"
"net" "net"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
) )
// SVCBKey is the type of the keys used in the SVCB RR. // SVCBKey is the type of the keys used in the SVCB RR.
type SVCBKey uint16 type SVCBKey uint16
// Keys defined in draft-ietf-dnsop-svcb-https-01 Section 12.3.2. // Keys defined in draft-ietf-dnsop-svcb-https-08 Section 14.3.2.
const ( const (
SVCB_MANDATORY SVCBKey = 0 SVCB_MANDATORY SVCBKey = iota
SVCB_ALPN SVCBKey = 1 SVCB_ALPN
SVCB_NO_DEFAULT_ALPN SVCBKey = 2 SVCB_NO_DEFAULT_ALPN
SVCB_PORT SVCBKey = 3 SVCB_PORT
SVCB_IPV4HINT SVCBKey = 4 SVCB_IPV4HINT
SVCB_ECHCONFIG SVCBKey = 5 SVCB_ECHCONFIG
SVCB_IPV6HINT SVCBKey = 6 SVCB_IPV6HINT
svcb_RESERVED SVCBKey = 65535
svcb_RESERVED SVCBKey = 65535
) )
var svcbKeyToStringMap = map[SVCBKey]string{ var svcbKeyToStringMap = map[SVCBKey]string{
SVCB_MANDATORY: "mandatory", SVCB_MANDATORY: "mandatory",
SVCB_ALPN: "alpn", SVCB_ALPN: "alpn",
SVCB_NO_DEFAULT_ALPN: "no-default-alpn", SVCB_NO_DEFAULT_ALPN: "no-default-alpn",
SVCB_PORT: "port", SVCB_PORT: "port",
SVCB_IPV4HINT: "ipv4hint", SVCB_IPV4HINT: "ipv4hint",
SVCB_ECHCONFIG: "echconfig", SVCB_ECHCONFIG: "ech",
SVCB_IPV6HINT: "ipv6hint", SVCB_IPV6HINT: "ipv6hint",
} }
var svcbStringToKeyMap = reverseSVCBKeyMap(svcbKeyToStringMap) var svcbStringToKeyMap = reverseSVCBKeyMap(svcbKeyToStringMap)
func reverseSVCBKeyMap(m map[SVCBKey]string) map[string]SVCBKey { func reverseSVCBKeyMap(m map[SVCBKey]string) map[string]SVCBKey {
n := make(map[string]SVCBKey, len(m)) n := make(map[string]SVCBKey, len(m))
for u, s := range m { for u, s := range m {
n[s] = u n[s] = u
} }
skipping to change at line 170 skipping to change at line 171
xs = append(xs, kv) xs = append(xs, kv)
case zQuote: case zQuote:
return &ParseError{l.token, "SVCB key can't contain doubl e quotes", l} return &ParseError{l.token, "SVCB key can't contain doubl e quotes", l}
case zBlank: case zBlank:
canHaveNextKey = true canHaveNextKey = true
default: default:
return &ParseError{l.token, "bad SVCB values", l} return &ParseError{l.token, "bad SVCB values", l}
} }
l, _ = c.Next() l, _ = c.Next()
} }
// "In AliasMode, records SHOULD NOT include any SvcParams, and recipient
s MUST
// ignore any SvcParams that are present."
// However, we don't check rr.Priority == 0 && len(xs) > 0 here
// It is the responsibility of the user of the library to check this.
// This is to encourage the fixing of the source of this error.
rr.Value = xs rr.Value = xs
if rr.Priority == 0 && len(xs) > 0 {
return &ParseError{l.token, "SVCB aliasform can't have values", l
}
}
return nil return nil
} }
// makeSVCBKeyValue returns an SVCBKeyValue struct with the key or nil for reser ved keys. // makeSVCBKeyValue returns an SVCBKeyValue struct with the key or nil for reser ved keys.
func makeSVCBKeyValue(key SVCBKey) SVCBKeyValue { func makeSVCBKeyValue(key SVCBKey) SVCBKeyValue {
switch key { switch key {
case SVCB_MANDATORY: case SVCB_MANDATORY:
return new(SVCBMandatory) return new(SVCBMandatory)
case SVCB_ALPN: case SVCB_ALPN:
return new(SVCBAlpn) return new(SVCBAlpn)
skipping to change at line 203 skipping to change at line 208
return new(SVCBIPv6Hint) return new(SVCBIPv6Hint)
case svcb_RESERVED: case svcb_RESERVED:
return nil return nil
default: default:
e := new(SVCBLocal) e := new(SVCBLocal)
e.KeyCode = key e.KeyCode = key
return e return e
} }
} }
// SVCB RR. See RFC xxxx (https://tools.ietf.org/html/draft-ietf-dnsop-svcb-http s-01). // SVCB RR. See RFC xxxx (https://tools.ietf.org/html/draft-ietf-dnsop-svcb-http s-08).
type SVCB struct { type SVCB struct {
Hdr RR_Header Hdr RR_Header
Priority uint16 Priority uint16 // If zero, Value must be empty or discarded by t he user of this library
Target string `dns:"domain-name"` Target string `dns:"domain-name"`
Value []SVCBKeyValue `dns:"pairs"` // Value must be empty if Priority is zero. Value []SVCBKeyValue `dns:"pairs"`
} }
// HTTPS RR. Everything valid for SVCB applies to HTTPS as well. // HTTPS RR. Everything valid for SVCB applies to HTTPS as well.
// Except that the HTTPS record is intended for use with the HTTP and HTTPS prot ocols. // Except that the HTTPS record is intended for use with the HTTP and HTTPS prot ocols.
type HTTPS struct { type HTTPS struct {
SVCB SVCB
} }
func (rr *HTTPS) String() string { func (rr *HTTPS) String() string {
return rr.SVCB.String() return rr.SVCB.String()
skipping to change at line 238 skipping to change at line 243
Key() SVCBKey // Key returns the numerical key code. Key() SVCBKey // Key returns the numerical key code.
pack() ([]byte, error) // pack returns the encoded value. pack() ([]byte, error) // pack returns the encoded value.
unpack([]byte) error // unpack sets the value. unpack([]byte) error // unpack sets the value.
String() string // String returns the string representation of the value. String() string // String returns the string representation of the value.
parse(string) error // parse sets the value to the given string repres entation of the value. parse(string) error // parse sets the value to the given string repres entation of the value.
copy() SVCBKeyValue // copy returns a deep-copy of the pair. copy() SVCBKeyValue // copy returns a deep-copy of the pair.
len() int // len returns the length of value in the wire for mat. len() int // len returns the length of value in the wire for mat.
} }
// SVCBMandatory pair adds to required keys that must be interpreted for the RR // SVCBMandatory pair adds to required keys that must be interpreted for the RR
// to be functional. // to be functional. If ignored, the whole RRSet must be ignored.
// "port" and "no-default-alpn" are mandatory by default if present,
// so they shouldn't be included here.
//
// It is incumbent upon the user of this library to reject the RRSet if
// or avoid constructing such an RRSet that:
// - "mandatory" is included as one of the keys of mandatory
// - no key is listed multiple times in mandatory
// - all keys listed in mandatory are present
// - escape sequences are not used in mandatory
// - mandatory, when present, lists at least one key
//
// Basic use pattern for creating a mandatory option: // Basic use pattern for creating a mandatory option:
// //
// s := &dns.SVCB{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeSVCB, Class: dns.ClassINET}} // s := &dns.SVCB{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeSVCB, Class: dns.ClassINET}}
// e := new(dns.SVCBMandatory) // e := new(dns.SVCBMandatory)
// e.Code = []uint16{65403} // e.Code = []uint16{dns.SVCB_ALPN}
// s.Value = append(s.Value, e) // s.Value = append(s.Value, e)
// t := new(dns.SVCBAlpn)
// t.Alpn = []string{"xmpp-client"}
// s.Value = append(s.Value, t)
type SVCBMandatory struct { type SVCBMandatory struct {
Code []SVCBKey // Must not include mandatory Code []SVCBKey
} }
func (*SVCBMandatory) Key() SVCBKey { return SVCB_MANDATORY } func (*SVCBMandatory) Key() SVCBKey { return SVCB_MANDATORY }
func (s *SVCBMandatory) String() string { func (s *SVCBMandatory) String() string {
str := make([]string, len(s.Code)) str := make([]string, len(s.Code))
for i, e := range s.Code { for i, e := range s.Code {
str[i] = e.String() str[i] = e.String()
} }
return strings.Join(str, ",") return strings.Join(str, ",")
skipping to change at line 305 skipping to change at line 324
return 2 * len(s.Code) return 2 * len(s.Code)
} }
func (s *SVCBMandatory) copy() SVCBKeyValue { func (s *SVCBMandatory) copy() SVCBKeyValue {
return &SVCBMandatory{ return &SVCBMandatory{
append([]SVCBKey(nil), s.Code...), append([]SVCBKey(nil), s.Code...),
} }
} }
// SVCBAlpn pair is used to list supported connection protocols. // SVCBAlpn pair is used to list supported connection protocols.
// Protocol ids can be found at: // The user of this library must ensure that at least one protocol is listed whe
n alpn is present.
// Protocol IDs can be found at:
// https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-v alues.xhtml#alpn-protocol-ids // https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-v alues.xhtml#alpn-protocol-ids
// Basic use pattern for creating an alpn option: // Basic use pattern for creating an alpn option:
// //
// h := new(dns.HTTPS) // h := new(dns.HTTPS)
// h.Hdr = dns.RR_Header{Name: ".", Rrtype: dns.TypeHTTPS, Class: dns.ClassI NET} // h.Hdr = dns.RR_Header{Name: ".", Rrtype: dns.TypeHTTPS, Class: dns.ClassI NET}
// e := new(dns.SVCBAlpn) // e := new(dns.SVCBAlpn)
// e.Alpn = []string{"h2", "http/1.1"} // e.Alpn = []string{"h2", "http/1.1"}
// h.Value = append(o.Value, e) // h.Value = append(o.Value, e)
type SVCBAlpn struct { type SVCBAlpn struct {
Alpn []string Alpn []string
skipping to change at line 373 skipping to change at line 393
return l return l
} }
func (s *SVCBAlpn) copy() SVCBKeyValue { func (s *SVCBAlpn) copy() SVCBKeyValue {
return &SVCBAlpn{ return &SVCBAlpn{
append([]string(nil), s.Alpn...), append([]string(nil), s.Alpn...),
} }
} }
// SVCBNoDefaultAlpn pair signifies no support for default connection protocols. // SVCBNoDefaultAlpn pair signifies no support for default connection protocols.
// Should be used in conjunction with alpn.
// Basic use pattern for creating a no-default-alpn option: // Basic use pattern for creating a no-default-alpn option:
// //
// s := &dns.SVCB{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeSVCB, Class: dns.ClassINET}} // s := &dns.SVCB{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeSVCB, Class: dns.ClassINET}}
// t := new(dns.SVCBAlpn)
// t.Alpn = []string{"xmpp-client"}
// s.Value = append(s.Value, t)
// e := new(dns.SVCBNoDefaultAlpn) // e := new(dns.SVCBNoDefaultAlpn)
// s.Value = append(s.Value, e) // s.Value = append(s.Value, e)
type SVCBNoDefaultAlpn struct{} type SVCBNoDefaultAlpn struct{}
func (*SVCBNoDefaultAlpn) Key() SVCBKey { return SVCB_NO_DEFAULT_ALPN } func (*SVCBNoDefaultAlpn) Key() SVCBKey { return SVCB_NO_DEFAULT_ALPN }
func (*SVCBNoDefaultAlpn) copy() SVCBKeyValue { return &SVCBNoDefaultAlpn{} } func (*SVCBNoDefaultAlpn) copy() SVCBKeyValue { return &SVCBNoDefaultAlpn{} }
func (*SVCBNoDefaultAlpn) pack() ([]byte, error) { return []byte{}, nil } func (*SVCBNoDefaultAlpn) pack() ([]byte, error) { return []byte{}, nil }
func (*SVCBNoDefaultAlpn) String() string { return "" } func (*SVCBNoDefaultAlpn) String() string { return "" }
func (*SVCBNoDefaultAlpn) len() int { return 0 } func (*SVCBNoDefaultAlpn) len() int { return 0 }
func (*SVCBNoDefaultAlpn) unpack(b []byte) error { func (*SVCBNoDefaultAlpn) unpack(b []byte) error {
if len(b) != 0 { if len(b) != 0 {
return errors.New("dns: svcbnodefaultalpn: no_default_alpn must h ave no value") return errors.New("dns: svcbnodefaultalpn: no-default-alpn must h ave no value")
} }
return nil return nil
} }
func (*SVCBNoDefaultAlpn) parse(b string) error { func (*SVCBNoDefaultAlpn) parse(b string) error {
if b != "" { if b != "" {
return errors.New("dns: svcbnodefaultalpn: no_default_alpn must h ave no value") return errors.New("dns: svcbnodefaultalpn: no-default-alpn must h ave no value")
} }
return nil return nil
} }
// SVCBPort pair defines the port for connection. // SVCBPort pair defines the port for connection.
// Basic use pattern for creating a port option: // Basic use pattern for creating a port option:
// //
// s := &dns.SVCB{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeSVCB, Class: dns.ClassINET}} // s := &dns.SVCB{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeSVCB, Class: dns.ClassINET}}
// e := new(dns.SVCBPort) // e := new(dns.SVCBPort)
// e.Port = 80 // e.Port = 80
skipping to change at line 526 skipping to change at line 550
for i, ip := range s.Hint { for i, ip := range s.Hint {
hint[i] = copyIP(ip) hint[i] = copyIP(ip)
} }
return &SVCBIPv4Hint{ return &SVCBIPv4Hint{
Hint: hint, Hint: hint,
} }
} }
// SVCBECHConfig pair contains the ECHConfig structure defined in draft-ietf-tls -esni [RFC xxxx]. // SVCBECHConfig pair contains the ECHConfig structure defined in draft-ietf-tls -esni [RFC xxxx].
// Basic use pattern for creating an echconfig option: // Basic use pattern for creating an ech option:
// //
// h := new(dns.HTTPS) // h := new(dns.HTTPS)
// h.Hdr = dns.RR_Header{Name: ".", Rrtype: dns.TypeHTTPS, Class: dns.ClassI NET} // h.Hdr = dns.RR_Header{Name: ".", Rrtype: dns.TypeHTTPS, Class: dns.ClassI NET}
// e := new(dns.SVCBECHConfig) // e := new(dns.SVCBECHConfig)
// e.ECH = []byte{0xfe, 0x08, ...} // e.ECH = []byte{0xfe, 0x08, ...}
// h.Value = append(h.Value, e) // h.Value = append(h.Value, e)
type SVCBECHConfig struct { type SVCBECHConfig struct {
ECH []byte ECH []byte // Specifically ECHConfigList including the redundant length p refix
} }
func (*SVCBECHConfig) Key() SVCBKey { return SVCB_ECHCONFIG } func (*SVCBECHConfig) Key() SVCBKey { return SVCB_ECHCONFIG }
func (s *SVCBECHConfig) String() string { return toBase64(s.ECH) } func (s *SVCBECHConfig) String() string { return toBase64(s.ECH) }
func (s *SVCBECHConfig) len() int { return len(s.ECH) } func (s *SVCBECHConfig) len() int { return len(s.ECH) }
func (s *SVCBECHConfig) pack() ([]byte, error) { func (s *SVCBECHConfig) pack() ([]byte, error) {
return append([]byte(nil), s.ECH...), nil return append([]byte(nil), s.ECH...), nil
} }
skipping to change at line 558 skipping to change at line 582
} }
} }
func (s *SVCBECHConfig) unpack(b []byte) error { func (s *SVCBECHConfig) unpack(b []byte) error {
s.ECH = append([]byte(nil), b...) s.ECH = append([]byte(nil), b...)
return nil return nil
} }
func (s *SVCBECHConfig) parse(b string) error { func (s *SVCBECHConfig) parse(b string) error {
x, err := fromBase64([]byte(b)) x, err := fromBase64([]byte(b))
if err != nil { if err != nil {
return errors.New("dns: svcbechconfig: bad base64 echconfig") return errors.New("dns: svcbech: bad base64 ech")
} }
s.ECH = x s.ECH = x
return nil return nil
} }
// SVCBIPv6Hint pair suggests an IPv6 address which may be used to open connecti ons // SVCBIPv6Hint pair suggests an IPv6 address which may be used to open connecti ons
// if A and AAAA record responses for SVCB's Target domain haven't been received . // if A and AAAA record responses for SVCB's Target domain haven't been received .
// In that case, optionally, A and AAAA requests can be made, after which the // In that case, optionally, A and AAAA requests can be made, after which the
// connection to the hinted IP address may be terminated and a new connection ma y be opened. // connection to the hinted IP address may be terminated and a new connection ma y be opened.
// Basic use pattern for creating an ipv6hint option: // Basic use pattern for creating an ipv6hint option:
skipping to change at line 621 skipping to change at line 645
for i, e := range s.Hint { for i, e := range s.Hint {
if x := e.To4(); x != nil { if x := e.To4(); x != nil {
return "<nil>" return "<nil>"
} }
str[i] = e.String() str[i] = e.String()
} }
return strings.Join(str, ",") return strings.Join(str, ",")
} }
func (s *SVCBIPv6Hint) parse(b string) error { func (s *SVCBIPv6Hint) parse(b string) error {
if strings.Contains(b, ".") {
return errors.New("dns: svcbipv6hint: expected ipv6, got ipv4")
}
str := strings.Split(b, ",") str := strings.Split(b, ",")
dst := make([]net.IP, len(str)) dst := make([]net.IP, len(str))
for i, e := range str { for i, e := range str {
ip := net.ParseIP(e) ip := net.ParseIP(e)
if ip == nil { if ip == nil {
return errors.New("dns: svcbipv6hint: bad ip") return errors.New("dns: svcbipv6hint: bad ip")
} }
if ip.To4() != nil {
return errors.New("dns: svcbipv6hint: expected ipv6, got
ipv4-mapped-ipv6")
}
dst[i] = ip dst[i] = ip
} }
s.Hint = dst s.Hint = dst
return nil return nil
} }
func (s *SVCBIPv6Hint) copy() SVCBKeyValue { func (s *SVCBIPv6Hint) copy() SVCBKeyValue {
hint := make([]net.IP, len(s.Hint)) hint := make([]net.IP, len(s.Hint))
for i, ip := range s.Hint { for i, ip := range s.Hint {
hint[i] = copyIP(ip) hint[i] = copyIP(ip)
 End of changes. 22 change blocks. 
29 lines changed or deleted 55 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)