summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dhcpv6/option_domainsearchlist.go19
-rw-r--r--dhcpv6/option_domainsearchlist_test.go35
-rw-r--r--netboot/netconf.go2
3 files changed, 42 insertions, 14 deletions
diff --git a/dhcpv6/option_domainsearchlist.go b/dhcpv6/option_domainsearchlist.go
index e3e9c17..402c68e 100644
--- a/dhcpv6/option_domainsearchlist.go
+++ b/dhcpv6/option_domainsearchlist.go
@@ -8,8 +8,9 @@ import (
"fmt"
)
+// OptDomainSearchList list implements a DOMAIN_SEARCH_LIST option
type OptDomainSearchList struct {
- domainSearchList []string
+ DomainSearchList []string
}
func (op *OptDomainSearchList) Code() OptionCode {
@@ -20,28 +21,20 @@ func (op *OptDomainSearchList) ToBytes() []byte {
buf := make([]byte, 4)
binary.BigEndian.PutUint16(buf[0:2], uint16(DOMAIN_SEARCH_LIST))
binary.BigEndian.PutUint16(buf[2:4], uint16(op.Length()))
- buf = append(buf, LabelsToBytes(op.domainSearchList)...)
+ buf = append(buf, LabelsToBytes(op.DomainSearchList)...)
return buf
}
-func (op *OptDomainSearchList) DomainSearchList() []string {
- return op.domainSearchList
-}
-
-func (op *OptDomainSearchList) SetDomainSearchList(dsList []string) {
- op.domainSearchList = dsList
-}
-
func (op *OptDomainSearchList) Length() int {
var length int
- for _, label := range op.domainSearchList {
+ for _, label := range op.DomainSearchList {
length += len(label) + 2 // add the first and the last length bytes
}
return length
}
func (op *OptDomainSearchList) String() string {
- return fmt.Sprintf("OptDomainSearchList{searchlist=%v}", op.domainSearchList)
+ return fmt.Sprintf("OptDomainSearchList{searchlist=%v}", op.DomainSearchList)
}
// build an OptDomainSearchList structure from a sequence of bytes.
@@ -49,7 +42,7 @@ func (op *OptDomainSearchList) String() string {
func ParseOptDomainSearchList(data []byte) (*OptDomainSearchList, error) {
opt := OptDomainSearchList{}
var err error
- opt.domainSearchList, err = LabelsFromBytes(data)
+ opt.DomainSearchList, err = LabelsFromBytes(data)
if err != nil {
return nil, err
}
diff --git a/dhcpv6/option_domainsearchlist_test.go b/dhcpv6/option_domainsearchlist_test.go
new file mode 100644
index 0000000..d5b8bf7
--- /dev/null
+++ b/dhcpv6/option_domainsearchlist_test.go
@@ -0,0 +1,35 @@
+package dhcpv6
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestParseOptDomainSearchList(t *testing.T) {
+ data := []byte{
+ 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0,
+ 6, 's', 'u', 'b', 'n', 'e', 't', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'o', 'r', 'g', 0,
+ }
+ opt, err := ParseOptDomainSearchList(data)
+ require.NoError(t, err)
+ require.Equal(t, len(opt.DomainSearchList), 2)
+ require.Equal(t, opt.DomainSearchList[0], "example.com")
+ require.Equal(t, opt.DomainSearchList[1], "subnet.example.org")
+}
+
+func TestOptDomainSearchListToBytes(t *testing.T) {
+ expected := []byte{
+ 0, 24, // DOMAIN_SEARCH_LIST
+ 0, 33, // length
+ 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0,
+ 6, 's', 'u', 'b', 'n', 'e', 't', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'o', 'r', 'g', 0,
+ }
+ opt := OptDomainSearchList{
+ DomainSearchList: []string{
+ "example.com",
+ "subnet.example.org",
+ },
+ }
+ require.Equal(t, opt.ToBytes(), expected)
+}
diff --git a/netboot/netconf.go b/netboot/netconf.go
index 47ccdc4..f8488fb 100644
--- a/netboot/netconf.go
+++ b/netboot/netconf.go
@@ -69,7 +69,7 @@ func GetNetConfFromPacketv6(d *dhcpv6.DHCPv6Message) (*NetConf, error) {
}
odomains := opt.(*dhcpv6.OptDomainSearchList)
// TODO should this be copied?
- netconf.DNSSearchList = odomains.DomainSearchList()
+ netconf.DNSSearchList = odomains.DomainSearchList
return &netconf, nil
}