diff options
author | Chris Koch <chrisko@google.com> | 2019-12-28 04:05:29 -0800 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2020-03-11 13:52:51 -0700 |
commit | 4d26b5e0b42f27fa41d872b15a7d2bc867787975 (patch) | |
tree | 08b8a584619b1ba4d1245fc1c0c8a184e193fdef /dhcpv6/option_iapd.go | |
parent | 6469ef2f3d85469f0f7cbf3cb40c2f931e406397 (diff) |
v6: rename IAPD option to be shorter
Also removes superfluous GetOne/Del proxy functions.
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6/option_iapd.go')
-rw-r--r-- | dhcpv6/option_iapd.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/dhcpv6/option_iapd.go b/dhcpv6/option_iapd.go new file mode 100644 index 0000000..03f3744 --- /dev/null +++ b/dhcpv6/option_iapd.go @@ -0,0 +1,61 @@ +package dhcpv6 + +import ( + "fmt" + "time" + + "github.com/u-root/u-root/pkg/uio" +) + +// OptIAPD implements the identity association for prefix +// delegation option defined by RFC 3633, Section 9. +type OptIAPD struct { + IaId [4]byte + T1 time.Duration + T2 time.Duration + Options Options +} + +// Code returns the option code +func (op *OptIAPD) Code() OptionCode { + return OptionIAPD +} + +// ToBytes serializes the option and returns it as a sequence of bytes +func (op *OptIAPD) ToBytes() []byte { + buf := uio.NewBigEndianBuffer(nil) + buf.WriteBytes(op.IaId[:]) + + t1 := Duration{op.T1} + t1.Marshal(buf) + t2 := Duration{op.T2} + t2.Marshal(buf) + + buf.WriteBytes(op.Options.ToBytes()) + return buf.Data() +} + +// String returns a string representation of the OptIAPD data +func (op *OptIAPD) String() string { + return fmt.Sprintf("OptIAPD{IAID=%v, t1=%v, t2=%v, options=%v}", + op.IaId, op.T1, op.T2, op.Options) +} + +// ParseOptIAPD builds an OptIAPD structure from a sequence of bytes. +// The input data does not include option code and length bytes. +func ParseOptIAPD(data []byte) (*OptIAPD, error) { + var opt OptIAPD + buf := uio.NewBigEndianBuffer(data) + buf.ReadBytes(opt.IaId[:]) + + var t1, t2 Duration + t1.Unmarshal(buf) + t2.Unmarshal(buf) + opt.T1 = t1.Duration + opt.T2 = t2.Duration + + if err := opt.Options.FromBytes(buf.ReadAll()); err != nil { + return nil, err + } + return &opt, buf.FinError() +} |