Fix EDNS Extended RCODE (#517)
* Fix EDNS Extended RCODE Issue #516 * Fix EDNS Extended RCODE Issue #516
This commit is contained in:
parent
be519e51ff
commit
6f3c0a126c
7
edns.go
7
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.
|
||||
|
|
|
@ -63,6 +63,6 @@ func TestOPTTtl(t *testing.T) {
|
|||
|
||||
e.SetExtendedRcode(42)
|
||||
if e.ExtendedRcode() != 42 {
|
||||
t.Errorf("set 42, expected %d, got %d", 42-15, e.ExtendedRcode())
|
||||
t.Errorf("set 42, expected %d, got %d", 42, e.ExtendedRcode())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue