more consistent naming
This commit is contained in:
parent
5bc0c4df68
commit
29365cc9d8
35
edns.go
35
edns.go
|
@ -9,10 +9,10 @@ import (
|
||||||
// EDNS0 Option codes.
|
// EDNS0 Option codes.
|
||||||
const (
|
const (
|
||||||
_ = iota
|
_ = iota
|
||||||
OptionLLQ // not used
|
EDNS0LLQ // not used
|
||||||
OptionUL // not used
|
EDNS0UL // not used
|
||||||
OptionNSID // NSID, RFC5001
|
EDNS0NSID // NSID, RFC5001
|
||||||
OptionSUBNET = 0x50fa // client-subnet draft
|
EDNS0SUBNET = 0x50fa // client-subnet draft
|
||||||
_DO = 1 << 7 // dnssec ok
|
_DO = 1 << 7 // dnssec ok
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func (rr *RR_OPT) String() string {
|
||||||
switch o.(type) {
|
switch o.(type) {
|
||||||
case *EDNS0_NSID:
|
case *EDNS0_NSID:
|
||||||
s += "\n; NSID: " + o.String()
|
s += "\n; NSID: " + o.String()
|
||||||
h, e := o.Bytes()
|
h, e := o.Pack()
|
||||||
var r string
|
var r string
|
||||||
if e == nil {
|
if e == nil {
|
||||||
for _, c := range h {
|
for _, c := range h {
|
||||||
|
@ -66,7 +66,7 @@ func (rr *RR_OPT) String() string {
|
||||||
func (rr *RR_OPT) Len() int {
|
func (rr *RR_OPT) Len() int {
|
||||||
l := rr.Hdr.Len()
|
l := rr.Hdr.Len()
|
||||||
for i := 0; i < len(rr.Option); i++ {
|
for i := 0; i < len(rr.Option); i++ {
|
||||||
lo, _ := rr.Option[i].Bytes()
|
lo, _ := rr.Option[i].Pack()
|
||||||
l += 2 + len(lo)
|
l += 2 + len(lo)
|
||||||
}
|
}
|
||||||
return l
|
return l
|
||||||
|
@ -120,25 +120,25 @@ func (rr *RR_OPT) SetDo() {
|
||||||
type EDNS0 interface {
|
type EDNS0 interface {
|
||||||
// Option return the option code for the option.
|
// Option return the option code for the option.
|
||||||
Option() uint16
|
Option() uint16
|
||||||
// Bytes returns the bytes of the option data.
|
// Pack returns the bytes of the option data.
|
||||||
Bytes() ([]byte, error)
|
Pack() ([]byte, error)
|
||||||
|
// Unpack sets the data as found in the packet. Is also sets
|
||||||
|
// the length of the slice as the length of the option data.
|
||||||
|
Unpack([]byte)
|
||||||
// String returns the string representation of the option.
|
// String returns the string representation of the option.
|
||||||
String() string
|
String() string
|
||||||
// SetBytes sets the data as found in the packet. Is also sets
|
|
||||||
// the length of the slice as the length of the option data.
|
|
||||||
SetBytes([]byte)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EDNS0_NSID struct {
|
type EDNS0_NSID struct {
|
||||||
Code uint16
|
Code uint16
|
||||||
Nsid string // This string must be encoded as Hex
|
Nsid string // This string needs to be hex encoded
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EDNS0_NSID) Option() uint16 {
|
func (e *EDNS0_NSID) Option() uint16 {
|
||||||
return e.Code
|
return e.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EDNS0_NSID) Bytes() ([]byte, error) {
|
func (e *EDNS0_NSID) Pack() ([]byte, error) {
|
||||||
h, err := hex.DecodeString(e.Nsid)
|
h, err := hex.DecodeString(e.Nsid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -146,13 +146,12 @@ func (e *EDNS0_NSID) Bytes() ([]byte, error) {
|
||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EDNS0_NSID) String() string {
|
func (e *EDNS0_NSID) Unpack(b []byte) {
|
||||||
return string(e.Nsid)
|
e.Nsid = hex.EncodeToString(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EDNS0_NSID) SetBytes(b []byte) {
|
func (e *EDNS0_NSID) String() string {
|
||||||
e.Code = OptionNSID
|
return string(e.Nsid)
|
||||||
e.Nsid = hex.EncodeToString(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EDNS0_SUBNET struct {
|
type EDNS0_SUBNET struct {
|
||||||
|
|
|
@ -173,7 +173,8 @@ Flags:
|
||||||
if *nsid {
|
if *nsid {
|
||||||
// Ask for it
|
// Ask for it
|
||||||
e := new(dns.EDNS0_NSID)
|
e := new(dns.EDNS0_NSID)
|
||||||
e.SetBytes([]byte(""))
|
e.Nsid = ""
|
||||||
|
e.Code = dns.EDNS0NSID
|
||||||
o.Option = append(o.Option, e)
|
o.Option = append(o.Option, e)
|
||||||
}
|
}
|
||||||
m.Extra = append(m.Extra, o)
|
m.Extra = append(m.Extra, o)
|
||||||
|
|
8
msg.go
8
msg.go
|
@ -402,7 +402,7 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str
|
||||||
case "opt": // edns
|
case "opt": // edns
|
||||||
for j := 0; j < val.Field(i).Len(); j++ {
|
for j := 0; j < val.Field(i).Len(); j++ {
|
||||||
element := val.Field(i).Index(j).Interface()
|
element := val.Field(i).Index(j).Interface()
|
||||||
b, e := element.(EDNS0).Bytes()
|
b, e := element.(EDNS0).Pack()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
println("dns: failure packing OTP")
|
println("dns: failure packing OTP")
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
|
@ -701,12 +701,12 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
}
|
}
|
||||||
switch code {
|
switch code {
|
||||||
case OptionNSID:
|
case EDNS0NSID:
|
||||||
e := new(EDNS0_NSID)
|
e := new(EDNS0_NSID)
|
||||||
e.SetBytes(msg[off1 : off1+int(optlen)])
|
e.Unpack(msg[off1 : off1+int(optlen)])
|
||||||
edns = append(edns, e)
|
edns = append(edns, e)
|
||||||
off = off1 + int(optlen)
|
off = off1 + int(optlen)
|
||||||
case OptionSUBNET:
|
case EDNS0SUBNET:
|
||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
fv.Set(reflect.ValueOf(edns))
|
fv.Set(reflect.ValueOf(edns))
|
||||||
|
|
Loading…
Reference in New Issue