summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/option_statuscode.go16
-rw-r--r--dhcpv6/option_userclass.go55
2 files changed, 67 insertions, 4 deletions
diff --git a/dhcpv6/option_statuscode.go b/dhcpv6/option_statuscode.go
index 017a26f..7740f4d 100644
--- a/dhcpv6/option_statuscode.go
+++ b/dhcpv6/option_statuscode.go
@@ -8,15 +8,18 @@ import (
"fmt"
)
+// OptStatusCode represents a DHCPv6 Status Code option
type OptStatusCode struct {
statusCode uint16
statusMessage []byte
}
+// Code returns the option code
func (op *OptStatusCode) Code() OptionCode {
return OPTION_STATUS_CODE
}
+// ToBytes serializes the option and returns it as a sequence of bytes
func (op *OptStatusCode) ToBytes() []byte {
buf := make([]byte, 6)
binary.BigEndian.PutUint16(buf[0:2], uint16(OPTION_STATUS_CODE))
@@ -26,22 +29,27 @@ func (op *OptStatusCode) ToBytes() []byte {
return buf
}
+// StatusCode returns the status code
func (op *OptStatusCode) StatusCode() uint16 {
return op.statusCode
}
+// SetStatusCode sets the status code
func (op *OptStatusCode) SetStatusCode(code uint16) {
op.statusCode = code
}
-func (op *OptStatusCode) StatusMessage() uint16 {
- return op.statusCode
+// StatusMessage returns the status message
+func (op *OptStatusCode) StatusMessage() []byte {
+ return op.statusMessage
}
+// SetStatusMessage sets the status message
func (op *OptStatusCode) SetStatusMessage(message []byte) {
op.statusMessage = message
}
+// Length returns the option length
func (op *OptStatusCode) Length() int {
return 2 + len(op.statusMessage)
}
@@ -50,8 +58,8 @@ func (op *OptStatusCode) String() string {
return fmt.Sprintf("OptStatusCode{code=%v, message=%v}", op.statusCode, string(op.statusMessage))
}
-// build an OptStatusCode structure from a sequence of bytes.
-// The input data does not include option code and length bytes.
+// ParseOptStatusCode builds an OptStatusCode structure from a sequence of
+// bytes. The input data does not include option code and length bytes.
func ParseOptStatusCode(data []byte) (*OptStatusCode, error) {
if len(data) < 2 {
return nil, fmt.Errorf("Invalid OptStatusCode data: length is shorter than 2")
diff --git a/dhcpv6/option_userclass.go b/dhcpv6/option_userclass.go
new file mode 100644
index 0000000..a9fde46
--- /dev/null
+++ b/dhcpv6/option_userclass.go
@@ -0,0 +1,55 @@
+package dhcpv6
+
+// This module defines the OptUserClass structure.
+// https://www.ietf.org/rfc/rfc3315.txt
+
+import (
+ "encoding/binary"
+ "fmt"
+)
+
+// OptUserClass represent a DHCPv6 User Class option
+type OptUserClass struct {
+ userClass []byte
+}
+
+// Code returns the option code
+func (op *OptUserClass) Code() OptionCode {
+ return OPTION_USER_CLASS
+}
+
+// ToBytes serializes the option and returns it as a sequence of bytes
+func (op *OptUserClass) ToBytes() []byte {
+ buf := make([]byte, 6)
+ binary.BigEndian.PutUint16(buf[0:2], uint16(OPTION_USER_CLASS))
+ binary.BigEndian.PutUint16(buf[2:4], uint16(op.Length()))
+ buf = append(buf, op.userClass...)
+ return buf
+}
+
+// UserClass returns the user class as a sequence of bytes
+func (op *OptUserClass) UserClass() []byte {
+ return op.userClass
+}
+
+// SetUserClass sets the user class from a sequence of bytes
+func (op *OptUserClass) SetUserClass(userClass []byte) {
+ op.userClass = userClass
+}
+
+// Length returns the option length
+func (op *OptUserClass) Length() int {
+ return len(op.userClass)
+}
+
+func (op *OptUserClass) String() string {
+ return fmt.Sprintf("OptUserClass{userclass=%s}", string(op.userClass))
+}
+
+// ParseOptUserClass builds an OptUserClass structure from a sequence of
+// bytes. The input data does not include option code and length bytes.
+func ParseOptUserClass(data []byte) (*OptUserClass, error) {
+ opt := OptUserClass{}
+ opt.userClass = append(opt.userClass, data...)
+ return &opt, nil
+}