diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-11-13 09:09:58 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 09:09:58 -0800 |
commit | 1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 (patch) | |
tree | 93cbf354ab894a560fc2cef8ef685d681b4ff889 /vendor/github.com/miekg/dns/edns.go | |
parent | 7304a61ef597970be3031b14e652fb3a4df44304 (diff) | |
download | chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.gz chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.bz2 chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.zip |
Updating server dependancies. (#7816)
Diffstat (limited to 'vendor/github.com/miekg/dns/edns.go')
-rw-r--r-- | vendor/github.com/miekg/dns/edns.go | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/vendor/github.com/miekg/dns/edns.go b/vendor/github.com/miekg/dns/edns.go index 718842f28..a6a36bdf2 100644 --- a/vendor/github.com/miekg/dns/edns.go +++ b/vendor/github.com/miekg/dns/edns.go @@ -106,15 +106,12 @@ func (rr *OPT) SetVersion(v uint8) { // ExtendedRcode returns the EDNS extended RCODE field (the upper 8 bits of the TTL). func (rr *OPT) ExtendedRcode() int { - return int((rr.Hdr.Ttl&0xFF000000)>>24) + 15 + return int((rr.Hdr.Ttl & 0xFF000000) >> 24) } // SetExtendedRcode sets the EDNS extended RCODE field. func (rr *OPT) SetExtendedRcode(v uint8) { - if v < RcodeBadVers { // Smaller than 16.. Use the 4 bits you have! - return - } - rr.Hdr.Ttl = rr.Hdr.Ttl&0x00FFFFFF | (uint32(v-15) << 24) + rr.Hdr.Ttl = rr.Hdr.Ttl&0x00FFFFFF | (uint32(v) << 24) } // UDPSize returns the UDP buffer size. @@ -185,7 +182,8 @@ func (e *EDNS0_NSID) pack() ([]byte, error) { return h, nil } -func (e *EDNS0_NSID) Option() uint16 { return EDNS0NSID } +// Option implements the EDNS0 interface. +func (e *EDNS0_NSID) Option() uint16 { return EDNS0NSID } // Option returns the option code. func (e *EDNS0_NSID) unpack(b []byte) error { e.Nsid = hex.EncodeToString(b); return nil } func (e *EDNS0_NSID) String() string { return string(e.Nsid) } @@ -219,6 +217,7 @@ type EDNS0_SUBNET struct { DraftOption bool // Set to true if using the old (0x50fa) option code } +// Option implements the EDNS0 interface. func (e *EDNS0_SUBNET) Option() uint16 { if e.DraftOption { return EDNS0SUBNETDRAFT @@ -232,6 +231,12 @@ func (e *EDNS0_SUBNET) pack() ([]byte, error) { b[2] = e.SourceNetmask b[3] = e.SourceScope switch e.Family { + case 0: + // "dig" sets AddressFamily to 0 if SourceNetmask is also 0 + // We might don't need to complain either + if e.SourceNetmask != 0 { + return nil, errors.New("dns: bad address family") + } case 1: if e.SourceNetmask > net.IPv4len*8 { return nil, errors.New("dns: bad netmask") @@ -266,6 +271,13 @@ func (e *EDNS0_SUBNET) unpack(b []byte) error { e.SourceNetmask = b[2] e.SourceScope = b[3] switch e.Family { + case 0: + // "dig" sets AddressFamily to 0 if SourceNetmask is also 0 + // It's okay to accept such a packet + if e.SourceNetmask != 0 { + return errors.New("dns: bad address family") + } + e.Address = net.IPv4(0, 0, 0, 0) case 1: if e.SourceNetmask > net.IPv4len*8 || e.SourceScope > net.IPv4len*8 { return errors.New("dns: bad netmask") @@ -335,6 +347,7 @@ func (e *EDNS0_COOKIE) pack() ([]byte, error) { return h, nil } +// Option implements the EDNS0 interface. func (e *EDNS0_COOKIE) Option() uint16 { return EDNS0COOKIE } func (e *EDNS0_COOKIE) unpack(b []byte) error { e.Cookie = hex.EncodeToString(b); return nil } func (e *EDNS0_COOKIE) String() string { return e.Cookie } @@ -356,6 +369,7 @@ type EDNS0_UL struct { Lease uint32 } +// Option implements the EDNS0 interface. func (e *EDNS0_UL) Option() uint16 { return EDNS0UL } func (e *EDNS0_UL) String() string { return strconv.FormatUint(uint64(e.Lease), 10) } @@ -385,6 +399,7 @@ type EDNS0_LLQ struct { LeaseLife uint32 } +// Option implements the EDNS0 interface. func (e *EDNS0_LLQ) Option() uint16 { return EDNS0LLQ } func (e *EDNS0_LLQ) pack() ([]byte, error) { @@ -421,6 +436,7 @@ type EDNS0_DAU struct { AlgCode []uint8 } +// Option implements the EDNS0 interface. func (e *EDNS0_DAU) Option() uint16 { return EDNS0DAU } func (e *EDNS0_DAU) pack() ([]byte, error) { return e.AlgCode, nil } func (e *EDNS0_DAU) unpack(b []byte) error { e.AlgCode = b; return nil } @@ -442,6 +458,7 @@ type EDNS0_DHU struct { AlgCode []uint8 } +// Option implements the EDNS0 interface. func (e *EDNS0_DHU) Option() uint16 { return EDNS0DHU } func (e *EDNS0_DHU) pack() ([]byte, error) { return e.AlgCode, nil } func (e *EDNS0_DHU) unpack(b []byte) error { e.AlgCode = b; return nil } @@ -463,6 +480,7 @@ type EDNS0_N3U struct { AlgCode []uint8 } +// Option implements the EDNS0 interface. func (e *EDNS0_N3U) Option() uint16 { return EDNS0N3U } func (e *EDNS0_N3U) pack() ([]byte, error) { return e.AlgCode, nil } func (e *EDNS0_N3U) unpack(b []byte) error { e.AlgCode = b; return nil } @@ -485,6 +503,7 @@ type EDNS0_EXPIRE struct { Expire uint32 } +// Option implements the EDNS0 interface. func (e *EDNS0_EXPIRE) Option() uint16 { return EDNS0EXPIRE } func (e *EDNS0_EXPIRE) String() string { return strconv.FormatUint(uint64(e.Expire), 10) } @@ -523,6 +542,7 @@ type EDNS0_LOCAL struct { Data []byte } +// Option implements the EDNS0 interface. func (e *EDNS0_LOCAL) Option() uint16 { return e.Code } func (e *EDNS0_LOCAL) String() string { return strconv.FormatInt(int64(e.Code), 10) + ":0x" + hex.EncodeToString(e.Data) @@ -554,6 +574,7 @@ type EDNS0_TCP_KEEPALIVE struct { Timeout uint16 // an idle timeout value for the TCP connection, specified in units of 100 milliseconds, encoded in network byte order. } +// Option implements the EDNS0 interface. func (e *EDNS0_TCP_KEEPALIVE) Option() uint16 { return EDNS0TCPKEEPALIVE } func (e *EDNS0_TCP_KEEPALIVE) pack() ([]byte, error) { @@ -606,7 +627,8 @@ type EDNS0_PADDING struct { Padding []byte } -func (e *EDNS0_PADDING) pack() ([]byte, error) { return e.Padding, nil } +// Option implements the EDNS0 interface. func (e *EDNS0_PADDING) Option() uint16 { return EDNS0PADDING } +func (e *EDNS0_PADDING) pack() ([]byte, error) { return e.Padding, nil } func (e *EDNS0_PADDING) unpack(b []byte) error { e.Padding = b; return nil } func (e *EDNS0_PADDING) String() string { return fmt.Sprintf("%0X", e.Padding) } |