summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/option_4rd.go40
-rw-r--r--dhcpv6/option_4rd_test.go14
2 files changed, 27 insertions, 27 deletions
diff --git a/dhcpv6/option_4rd.go b/dhcpv6/option_4rd.go
index 2faea25..34e1fb9 100644
--- a/dhcpv6/option_4rd.go
+++ b/dhcpv6/option_4rd.go
@@ -32,12 +32,10 @@ func (op *Opt4RD) LongString(indentSpace int) string {
return fmt.Sprintf("%s: Options=%v", op.Code(), op.Options.LongString(indentSpace))
}
-// ParseOpt4RD builds an Opt4RD structure from a sequence of bytes.
+// FromBytes builds an Opt4RD structure from a sequence of bytes.
// The input data does not include option code and length bytes
-func ParseOpt4RD(data []byte) (*Opt4RD, error) {
- var opt Opt4RD
- err := opt.Options.FromBytes(data)
- return &opt, err
+func (op *Opt4RD) FromBytes(data []byte) error {
+ return op.Options.FromBytes(data)
}
// Opt4RDMapRule represents a 4RD Mapping Rule option
@@ -105,18 +103,17 @@ func (op *Opt4RDMapRule) String() string {
op.Code(), op.Prefix4.String(), op.Prefix6.String(), op.EABitsLength, op.WKPAuthorized)
}
-// ParseOpt4RDMapRule builds an Opt4RDMapRule structure from a sequence of bytes.
+// FromBytes builds an Opt4RDMapRule structure from a sequence of bytes.
// The input data does not include option code and length bytes.
-func ParseOpt4RDMapRule(data []byte) (*Opt4RDMapRule, error) {
- var opt Opt4RDMapRule
+func (op *Opt4RDMapRule) FromBytes(data []byte) error {
buf := uio.NewBigEndianBuffer(data)
- opt.Prefix4.Mask = net.CIDRMask(int(buf.Read8()), 32)
- opt.Prefix6.Mask = net.CIDRMask(int(buf.Read8()), 128)
- opt.EABitsLength = buf.Read8()
- opt.WKPAuthorized = (buf.Read8() & opt4RDWKPAuthorizedMask) != 0
- opt.Prefix4.IP = net.IP(buf.CopyN(net.IPv4len))
- opt.Prefix6.IP = net.IP(buf.CopyN(net.IPv6len))
- return &opt, buf.FinError()
+ op.Prefix4.Mask = net.CIDRMask(int(buf.Read8()), 32)
+ op.Prefix6.Mask = net.CIDRMask(int(buf.Read8()), 128)
+ op.EABitsLength = buf.Read8()
+ op.WKPAuthorized = (buf.Read8() & opt4RDWKPAuthorizedMask) != 0
+ op.Prefix4.IP = net.IP(buf.CopyN(net.IPv4len))
+ op.Prefix6.IP = net.IP(buf.CopyN(net.IPv6len))
+ return buf.FinError()
}
// Opt4RDNonMapRule represents 4RD parameters other than mapping rules
@@ -165,21 +162,20 @@ func (op *Opt4RDNonMapRule) String() string {
op.Code(), op.HubAndSpoke, tClass, op.DomainPMTU)
}
-// ParseOpt4RDNonMapRule builds an Opt4RDNonMapRule structure from a sequence of bytes.
+// FromBytes builds an Opt4RDNonMapRule structure from a sequence of bytes.
// The input data does not include option code and length bytes
-func ParseOpt4RDNonMapRule(data []byte) (*Opt4RDNonMapRule, error) {
- var opt Opt4RDNonMapRule
+func (op *Opt4RDNonMapRule) FromBytes(data []byte) error {
buf := uio.NewBigEndianBuffer(data)
flags := buf.Read8()
- opt.HubAndSpoke = flags&opt4RDHubAndSpokeMask != 0
+ op.HubAndSpoke = flags&opt4RDHubAndSpokeMask != 0
tClass := buf.Read8()
if flags&opt4RDTrafficClassMask != 0 {
- opt.TrafficClass = &tClass
+ op.TrafficClass = &tClass
}
- opt.DomainPMTU = buf.Read16()
+ op.DomainPMTU = buf.Read16()
- return &opt, buf.FinError()
+ return buf.FinError()
}
diff --git a/dhcpv6/option_4rd_test.go b/dhcpv6/option_4rd_test.go
index ad72445..6af9b67 100644
--- a/dhcpv6/option_4rd_test.go
+++ b/dhcpv6/option_4rd_test.go
@@ -9,7 +9,8 @@ import (
func TestOpt4RDNonMapRuleParse(t *testing.T) {
data := []byte{0x81, 0xaa, 0x05, 0xd4}
- opt, err := ParseOpt4RDNonMapRule(data)
+ var opt Opt4RDNonMapRule
+ err := opt.FromBytes(data)
require.NoError(t, err)
require.True(t, opt.HubAndSpoke)
require.NotNil(t, opt.TrafficClass)
@@ -18,7 +19,8 @@ func TestOpt4RDNonMapRuleParse(t *testing.T) {
// Remove the TrafficClass flag and check value is ignored
data[0] = 0x80
- opt, err = ParseOpt4RDNonMapRule(data)
+ opt = Opt4RDNonMapRule{}
+ err = opt.FromBytes(data)
require.NoError(t, err)
require.True(t, opt.HubAndSpoke)
require.Nil(t, opt.TrafficClass)
@@ -77,7 +79,8 @@ func TestOpt4RDMapRuleParse(t *testing.T) {
append(ip4addr.To4(), ip6addr...)...,
)
- opt, err := ParseOpt4RDMapRule(data)
+ var opt Opt4RDMapRule
+ err = opt.FromBytes(data)
require.NoError(t, err)
require.EqualValues(t, *ip6net, opt.Prefix6)
require.EqualValues(t, *ip4net, opt.Prefix4)
@@ -162,9 +165,10 @@ func TestOpt4RDRoundTrip(t *testing.T) {
},
}
- rtOpt, err := ParseOpt4RD(opt.ToBytes())
+ var rtOpt Opt4RD
+ err := rtOpt.FromBytes(opt.ToBytes())
require.NoError(t, err)
require.NotNil(t, rtOpt)
- require.Equal(t, opt, *rtOpt)
+ require.Equal(t, opt, rtOpt)
}