summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/client.go24
-rw-r--r--dhcpv6/dhcpv6.go6
-rw-r--r--dhcpv6/dhcpv6_test.go46
-rw-r--r--dhcpv6/dhcpv6message.go20
-rw-r--r--dhcpv6/dhcpv6relay.go4
-rw-r--r--dhcpv6/dhcpv6relay_test.go26
-rw-r--r--dhcpv6/option_relaymsg_test.go16
-rw-r--r--dhcpv6/types.go80
-rw-r--r--dhcpv6/utils_test.go2
9 files changed, 115 insertions, 109 deletions
diff --git a/dhcpv6/client.go b/dhcpv6/client.go
index 8431482..3492a47 100644
--- a/dhcpv6/client.go
+++ b/dhcpv6/client.go
@@ -81,16 +81,16 @@ func (c *Client) sendReceive(ifname string, packet DHCPv6, expectedType MessageT
if packet == nil {
return nil, fmt.Errorf("Packet to send cannot be nil")
}
- if expectedType == MSGTYPE_NONE {
+ if expectedType == MessageTypeNone {
// infer the expected type from the packet being sent
- if packet.Type() == SOLICIT {
- expectedType = ADVERTISE
- } else if packet.Type() == REQUEST {
- expectedType = REPLY
- } else if packet.Type() == RELAY_FORW {
- expectedType = RELAY_REPL
- } else if packet.Type() == LEASEQUERY {
- expectedType = LEASEQUERY_REPLY
+ if packet.Type() == MessageTypeSolicit {
+ expectedType = MessageTypeAdvertise
+ } else if packet.Type() == MessageTypeRequest {
+ expectedType = MessageTypeReply
+ } else if packet.Type() == MessageTypeRelayForward {
+ expectedType = MessageTypeRelayReply
+ } else if packet.Type() == MessageTypeLeaseQuery {
+ expectedType = MessageTypeLeaseQueryReply
} // and probably more
}
// if no LocalAddr is specified, get the interface's link-local address
@@ -167,7 +167,7 @@ func (c *Client) sendReceive(ifname string, packet DHCPv6, expectedType MessageT
continue
}
}
- if expectedType == MSGTYPE_NONE {
+ if expectedType == MessageTypeNone {
// just take whatever arrived
break
} else if adv.Type() == expectedType {
@@ -190,7 +190,7 @@ func (c *Client) Solicit(ifname string, solicit DHCPv6, modifiers ...Modifier) (
for _, mod := range modifiers {
solicit = mod(solicit)
}
- advertise, err := c.sendReceive(ifname, solicit, MSGTYPE_NONE)
+ advertise, err := c.sendReceive(ifname, solicit, MessageTypeNone)
return solicit, advertise, err
}
@@ -207,6 +207,6 @@ func (c *Client) Request(ifname string, advertise, request DHCPv6, modifiers ...
for _, mod := range modifiers {
request = mod(request)
}
- reply, err := c.sendReceive(ifname, request, MSGTYPE_NONE)
+ reply, err := c.sendReceive(ifname, request, MessageTypeNone)
return request, reply, err
}
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go
index b424101..253a635 100644
--- a/dhcpv6/dhcpv6.go
+++ b/dhcpv6/dhcpv6.go
@@ -30,7 +30,7 @@ func FromBytes(data []byte) (DHCPv6, error) {
headerSize int
messageType = MessageType(data[0])
)
- if messageType == RELAY_FORW || messageType == RELAY_REPL {
+ if messageType == MessageTypeRelayForward || messageType == MessageTypeRelayReply {
isRelay = true
}
if isRelay {
@@ -85,7 +85,7 @@ func NewMessage(modifiers ...Modifier) (DHCPv6, error) {
return nil, err
}
msg := DHCPv6Message{
- messageType: SOLICIT,
+ messageType: MessageTypeSolicit,
transactionID: *tid,
}
// apply modifiers
@@ -181,7 +181,7 @@ func DecapsulateRelayIndex(l DHCPv6, index int) (DHCPv6, error) {
// message as payload. The passed message type must be either RELAY_FORW or
// RELAY_REPL
func EncapsulateRelay(d DHCPv6, mType MessageType, linkAddr, peerAddr net.IP) (DHCPv6, error) {
- if mType != RELAY_FORW && mType != RELAY_REPL {
+ if mType != MessageTypeRelayForward && mType != MessageTypeRelayReply {
return nil, fmt.Errorf("Message type must be either RELAY_FORW or RELAY_REPL")
}
outer := DHCPv6Relay{
diff --git a/dhcpv6/dhcpv6_test.go b/dhcpv6/dhcpv6_test.go
index 3e2b6bc..656c62f 100644
--- a/dhcpv6/dhcpv6_test.go
+++ b/dhcpv6/dhcpv6_test.go
@@ -33,18 +33,18 @@ func TestNewMessage(t *testing.T) {
d, err := NewMessage()
require.NoError(t, err)
require.NotNil(t, d)
- require.Equal(t, SOLICIT, d.Type())
+ require.Equal(t, MessageTypeSolicit, d.Type())
require.NotEqual(t, 0, d.(*DHCPv6Message).transactionID)
require.Empty(t, d.(*DHCPv6Message).options)
}
func TestDecapsulateRelayIndex(t *testing.T) {
m := DHCPv6Message{}
- r1, err := EncapsulateRelay(&m, RELAY_FORW, net.IPv6linklocalallnodes, net.IPv6interfacelocalallnodes)
+ r1, err := EncapsulateRelay(&m, MessageTypeRelayForward, net.IPv6linklocalallnodes, net.IPv6interfacelocalallnodes)
require.NoError(t, err)
- r2, err := EncapsulateRelay(r1, RELAY_FORW, net.IPv6loopback, net.IPv6linklocalallnodes)
+ r2, err := EncapsulateRelay(r1, MessageTypeRelayForward, net.IPv6loopback, net.IPv6linklocalallnodes)
require.NoError(t, err)
- r3, err := EncapsulateRelay(r2, RELAY_FORW, net.IPv6unspecified, net.IPv6linklocalallrouters)
+ r3, err := EncapsulateRelay(r2, MessageTypeRelayForward, net.IPv6unspecified, net.IPv6linklocalallrouters)
require.NoError(t, err)
first, err := DecapsulateRelayIndex(r3, 0)
@@ -83,10 +83,10 @@ func TestDecapsulateRelayIndex(t *testing.T) {
func TestSettersAndGetters(t *testing.T) {
d := DHCPv6Message{}
// Message
- d.SetMessage(SOLICIT)
- require.Equal(t, SOLICIT, d.Type())
- d.SetMessage(ADVERTISE)
- require.Equal(t, ADVERTISE, d.Type())
+ d.SetMessage(MessageTypeSolicit)
+ require.Equal(t, MessageTypeSolicit, d.Type())
+ d.SetMessage(MessageTypeAdvertise)
+ require.Equal(t, MessageTypeAdvertise, d.Type())
// TransactionID
d.SetTransactionID(12345)
@@ -109,7 +109,7 @@ func TestAddOption(t *testing.T) {
func TestToBytes(t *testing.T) {
d := DHCPv6Message{}
- d.SetMessage(SOLICIT)
+ d.SetMessage(MessageTypeSolicit)
d.SetTransactionID(0xabcdef)
opt := OptionGeneric{OptionCode: 0, OptionData: []byte{}}
d.AddOption(&opt)
@@ -128,7 +128,7 @@ func TestFromAndToBytes(t *testing.T) {
func TestNewAdvertiseFromSolicit(t *testing.T) {
s := DHCPv6Message{}
- s.SetMessage(SOLICIT)
+ s.SetMessage(MessageTypeSolicit)
s.SetTransactionID(0xabcdef)
cid := OptClientId{}
s.AddOption(&cid)
@@ -137,7 +137,7 @@ func TestNewAdvertiseFromSolicit(t *testing.T) {
a, err := NewAdvertiseFromSolicit(&s, WithServerID(duid))
require.NoError(t, err)
require.Equal(t, a.(*DHCPv6Message).TransactionID(), s.TransactionID())
- require.Equal(t, a.Type(), ADVERTISE)
+ require.Equal(t, a.Type(), MessageTypeAdvertise)
}
func TestNewReplyFromDHCPv6Message(t *testing.T) {
@@ -150,31 +150,31 @@ func TestNewReplyFromDHCPv6Message(t *testing.T) {
sid.Sid = duid
msg.AddOption(&sid)
- msg.SetMessage(CONFIRM)
+ msg.SetMessage(MessageTypeConfirm)
rep, err := NewReplyFromDHCPv6Message(&msg, WithServerID(duid))
require.NoError(t, err)
require.Equal(t, rep.(*DHCPv6Message).TransactionID(), msg.TransactionID())
- require.Equal(t, rep.Type(), REPLY)
+ require.Equal(t, rep.Type(), MessageTypeReply)
- msg.SetMessage(RENEW)
+ msg.SetMessage(MessageTypeRenew)
rep, err = NewReplyFromDHCPv6Message(&msg, WithServerID(duid))
require.NoError(t, err)
require.Equal(t, rep.(*DHCPv6Message).TransactionID(), msg.TransactionID())
- require.Equal(t, rep.Type(), REPLY)
+ require.Equal(t, rep.Type(), MessageTypeReply)
- msg.SetMessage(REBIND)
+ msg.SetMessage(MessageTypeRebind)
rep, err = NewReplyFromDHCPv6Message(&msg, WithServerID(duid))
require.NoError(t, err)
require.Equal(t, rep.(*DHCPv6Message).TransactionID(), msg.TransactionID())
- require.Equal(t, rep.Type(), REPLY)
+ require.Equal(t, rep.Type(), MessageTypeReply)
- msg.SetMessage(RELEASE)
+ msg.SetMessage(MessageTypeRelease)
rep, err = NewReplyFromDHCPv6Message(&msg, WithServerID(duid))
require.NoError(t, err)
require.Equal(t, rep.(*DHCPv6Message).TransactionID(), msg.TransactionID())
- require.Equal(t, rep.Type(), REPLY)
+ require.Equal(t, rep.Type(), MessageTypeReply)
- msg.SetMessage(SOLICIT)
+ msg.SetMessage(MessageTypeSolicit)
rep, err = NewReplyFromDHCPv6Message(&msg)
require.Error(t, err)
@@ -183,7 +183,7 @@ func TestNewReplyFromDHCPv6Message(t *testing.T) {
require.Error(t, err)
}
-func TestNewSolicitWithCID(t *testing.T) {
+func TestNewMessageTypeSolicitWithCID(t *testing.T) {
hwAddr, err := net.ParseMAC("24:0A:9E:9F:EB:2B")
require.NoError(t, err)
@@ -196,7 +196,7 @@ func TestNewSolicitWithCID(t *testing.T) {
s, err := NewSolicitWithCID(duid)
require.NoError(t, err)
- require.Equal(t, s.Type(), SOLICIT)
+ require.Equal(t, s.Type(), MessageTypeSolicit)
// Check CID
cidOption := s.GetOneOption(OPTION_CLIENTID)
require.NotNil(t, cidOption)
@@ -215,5 +215,5 @@ func TestNewSolicitWithCID(t *testing.T) {
require.Equal(t, len(opts), 2)
}
-// TODO test NewSolicit
+// TODO test NewMessageTypeSolicit
// test String and Summary
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go
index 0b84dae..be413f5 100644
--- a/dhcpv6/dhcpv6message.go
+++ b/dhcpv6/dhcpv6message.go
@@ -71,7 +71,7 @@ func NewSolicitWithCID(duid Duid, modifiers ...Modifier) (DHCPv6, error) {
if err != nil {
return nil, err
}
- d.(*DHCPv6Message).SetMessage(SOLICIT)
+ d.(*DHCPv6Message).SetMessage(MessageTypeSolicit)
d.AddOption(&OptClientId{Cid: duid})
oro := new(OptRequestedOption)
oro.SetRequestedOptions([]OptionCode{
@@ -114,7 +114,7 @@ func NewAdvertiseFromSolicit(solicit DHCPv6, modifiers ...Modifier) (DHCPv6, err
if solicit == nil {
return nil, errors.New("SOLICIT cannot be nil")
}
- if solicit.Type() != SOLICIT {
+ if solicit.Type() != MessageTypeSolicit {
return nil, errors.New("The passed SOLICIT must have SOLICIT type set")
}
sol, ok := solicit.(*DHCPv6Message)
@@ -123,7 +123,7 @@ func NewAdvertiseFromSolicit(solicit DHCPv6, modifiers ...Modifier) (DHCPv6, err
}
// build ADVERTISE from SOLICIT
adv := DHCPv6Message{}
- adv.SetMessage(ADVERTISE)
+ adv.SetMessage(MessageTypeAdvertise)
adv.SetTransactionID(sol.TransactionID())
// add Client ID
cid := sol.GetOneOption(OPTION_CLIENTID)
@@ -146,7 +146,7 @@ func NewRequestFromAdvertise(advertise DHCPv6, modifiers ...Modifier) (DHCPv6, e
if advertise == nil {
return nil, fmt.Errorf("ADVERTISE cannot be nil")
}
- if advertise.Type() != ADVERTISE {
+ if advertise.Type() != MessageTypeAdvertise {
return nil, fmt.Errorf("The passed ADVERTISE must have ADVERTISE type set")
}
adv, ok := advertise.(*DHCPv6Message)
@@ -155,7 +155,7 @@ func NewRequestFromAdvertise(advertise DHCPv6, modifiers ...Modifier) (DHCPv6, e
}
// build REQUEST from ADVERTISE
req := DHCPv6Message{}
- req.SetMessage(REQUEST)
+ req.SetMessage(MessageTypeRequest)
req.SetTransactionID(adv.TransactionID())
// add Client ID
cid := adv.GetOneOption(OPTION_CLIENTID)
@@ -207,9 +207,9 @@ func NewReplyFromDHCPv6Message(message DHCPv6, modifiers ...Modifier) (DHCPv6, e
return nil, errors.New("DHCPv6Message cannot be nil")
}
switch message.Type() {
- case REQUEST, CONFIRM, RENEW, REBIND, RELEASE:
- default:
- return nil, errors.New("Cannot create REPLY from the passed message type set")
+ case MessageTypeRequest, MessageTypeConfirm, MessageTypeRenew, MessageTypeRebind, MessageTypeRelease:
+ default:
+ return nil, errors.New("Cannot create REPLY from the passed message type set")
}
msg, ok := message.(*DHCPv6Message)
if !ok {
@@ -217,7 +217,7 @@ func NewReplyFromDHCPv6Message(message DHCPv6, modifiers ...Modifier) (DHCPv6, e
}
// build REPLY from MESSAGE
rep := DHCPv6Message{}
- rep.SetMessage(REPLY)
+ rep.SetMessage(MessageTypeReply)
rep.SetTransactionID(msg.TransactionID())
// add Client ID
cid := message.GetOneOption(OPTION_CLIENTID)
@@ -243,7 +243,7 @@ func (d *DHCPv6Message) SetMessage(messageType MessageType) {
if msgString == "" {
log.Printf("Warning: unknown DHCPv6 message type: %v", messageType)
}
- if messageType == RELAY_FORW || messageType == RELAY_REPL {
+ if messageType == MessageTypeRelayForward || messageType == MessageTypeRelayReply {
log.Printf("Warning: using a RELAY message type with a non-relay message: %v (%v)",
msgString, messageType)
}
diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go
index 1bde354..221c65e 100644
--- a/dhcpv6/dhcpv6relay.go
+++ b/dhcpv6/dhcpv6relay.go
@@ -173,7 +173,7 @@ func NewRelayReplFromRelayForw(relayForw, msg DHCPv6) (DHCPv6, error) {
if !ok {
return nil, errors.New("Not a DHCPv6Relay")
}
- if relay.Type() != RELAY_FORW {
+ if relay.Type() != MessageTypeRelayForward {
return nil, errors.New("The passed packet is not of type RELAY_FORW")
}
if msg == nil {
@@ -197,7 +197,7 @@ func NewRelayReplFromRelayForw(relayForw, msg DHCPv6) (DHCPv6, error) {
}
}
for i := len(linkAddr) - 1; i >= 0; i-- {
- msg, err = EncapsulateRelay(msg, RELAY_REPL, linkAddr[i], peerAddr[i])
+ msg, err = EncapsulateRelay(msg, MessageTypeRelayReply, linkAddr[i], peerAddr[i])
if opt := optiids[i]; opt != nil {
msg.AddOption(opt)
}
diff --git a/dhcpv6/dhcpv6relay_test.go b/dhcpv6/dhcpv6relay_test.go
index e08e6a4..afb4086 100644
--- a/dhcpv6/dhcpv6relay_test.go
+++ b/dhcpv6/dhcpv6relay_test.go
@@ -12,15 +12,15 @@ func TestDHCPv6Relay(t *testing.T) {
ll := net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, 0xff, 0xfe, 0xdd, 0xee, 0xff}
ma := net.IP{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
r := DHCPv6Relay{
- messageType: RELAY_FORW,
+ messageType: MessageTypeRelayForward,
hopCount: 10,
linkAddr: ll,
peerAddr: ma,
// options is left empty here for testing purposes, even if it's
// mandatory to have at least a relay message option
}
- if mt := r.MessageType(); mt != RELAY_FORW {
- t.Fatalf("Invalid message type. Expected %v, got %v", RELAY_FORW, mt)
+ if mt := r.MessageType(); mt != MessageTypeRelayForward {
+ t.Fatalf("Invalid message type. Expected %v, got %v", MessageTypeRelayForward, mt)
}
if hc := r.HopCount(); hc != 10 {
t.Fatalf("Invalid hop count. Expected 10, got %v", hc)
@@ -39,9 +39,9 @@ func TestDHCPv6Relay(t *testing.T) {
func TestDHCPv6RelaySettersAndGetters(t *testing.T) {
r := DHCPv6Relay{}
// set and get message type
- r.SetMessageType(RELAY_REPL)
- if mt := r.MessageType(); mt != RELAY_REPL {
- t.Fatalf("Invalid message type. Expected %v, got %v", RELAY_REPL, mt)
+ r.SetMessageType(MessageTypeRelayReply)
+ if mt := r.MessageType(); mt != MessageTypeRelayReply {
+ t.Fatalf("Invalid message type. Expected %v, got %v", MessageTypeRelayReply, mt)
}
// set and get hop count
r.SetHopCount(5)
@@ -68,7 +68,7 @@ func TestDHCPv6RelaySettersAndGetters(t *testing.T) {
func TestDHCPv6RelayToBytes(t *testing.T) {
expected := []byte{
- 12, // RELAY_FORW
+ 12, // MessageTypeRelayForward
1, // hop count
0xff, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, // link addr
0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02, // peer addr
@@ -76,7 +76,7 @@ func TestDHCPv6RelayToBytes(t *testing.T) {
0, 9, // relay msg
0, 10, // option length
// inner dhcp solicit
- 1, // SOLICIT
+ 1, // MessageTypeSolicit
0xaa, 0xbb, 0xcc, // transaction ID
// inner option - elapsed time
0, 8, // elapsed time
@@ -84,14 +84,14 @@ func TestDHCPv6RelayToBytes(t *testing.T) {
0, 0,
}
r := DHCPv6Relay{
- messageType: RELAY_FORW,
+ messageType: MessageTypeRelayForward,
hopCount: 1,
linkAddr: net.IPv6interfacelocalallnodes,
peerAddr: net.IPv6linklocalallrouters,
}
opt := OptRelayMsg{
relayMessage: &DHCPv6Message{
- messageType: SOLICIT,
+ messageType: MessageTypeSolicit,
transactionID: 0xaabbcc,
options: []Option{
&OptElapsedTime{
@@ -109,12 +109,12 @@ func TestDHCPv6RelayToBytes(t *testing.T) {
func TestNewRelayRepFromRelayForw(t *testing.T) {
rf := DHCPv6Relay{}
- rf.SetMessageType(RELAY_FORW)
+ rf.SetMessageType(MessageTypeRelayForward)
rf.SetPeerAddr(net.IPv6linklocalallrouters)
rf.SetLinkAddr(net.IPv6interfacelocalallnodes)
oro := OptRelayMsg{}
s := DHCPv6Message{}
- s.SetMessage(SOLICIT)
+ s.SetMessage(MessageTypeSolicit)
cid := OptClientId{}
s.AddOption(&cid)
oro.SetRelayMessage(&s)
@@ -125,7 +125,7 @@ func TestNewRelayRepFromRelayForw(t *testing.T) {
rr, err := NewRelayReplFromRelayForw(&rf, a)
require.NoError(t, err)
relay := rr.(*DHCPv6Relay)
- require.Equal(t, rr.Type(), RELAY_REPL)
+ require.Equal(t, rr.Type(), MessageTypeRelayReply)
require.Equal(t, relay.HopCount(), rf.HopCount())
require.Equal(t, relay.PeerAddr(), rf.PeerAddr())
require.Equal(t, relay.LinkAddr(), rf.LinkAddr())
diff --git a/dhcpv6/option_relaymsg_test.go b/dhcpv6/option_relaymsg_test.go
index 6d9d6a6..6376813 100644
--- a/dhcpv6/option_relaymsg_test.go
+++ b/dhcpv6/option_relaymsg_test.go
@@ -7,7 +7,7 @@ import (
func TestRelayMsgParseOptRelayMsg(t *testing.T) {
opt, err := ParseOptRelayMsg([]byte{
- 1, // SOLICIT
+ 1, // MessageTypeSolicit
0xaa, 0xbb, 0xcc, // transaction ID
0, 8, // option: elapsed time
0, 2, // option length
@@ -27,7 +27,7 @@ func TestRelayMsgOptionsFromBytes(t *testing.T) {
opts, err := OptionsFromBytes([]byte{
0, 9, // option: relay message
0, 10, // relayed message length
- 1, // SOLICIT
+ 1, // MessageTypeSolicit
0xaa, 0xbb, 0xcc, // transaction ID
0, 8, // option: elapsed time
0, 2, // option length
@@ -55,7 +55,7 @@ func TestRelayMsgParseOptRelayMsgSingleEncapsulation(t *testing.T) {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, // peerAddr
0, 9, // option: relay message
0, 10, // relayed message length
- 1, // SOLICIT
+ 1, // MessageTypeSolicit
0xaa, 0xbb, 0xcc, // transaction ID
0, 8, // option: elapsed time
0, 2, // option length
@@ -70,8 +70,8 @@ func TestRelayMsgParseOptRelayMsgSingleEncapsulation(t *testing.T) {
reflect.TypeOf(d),
)
}
- if mType := r.Type(); mType != RELAY_FORW {
- t.Fatalf("Invalid messge type for relay. Expected %v, got %v", RELAY_FORW, mType)
+ if mType := r.Type(); mType != MessageTypeRelayForward {
+ t.Fatalf("Invalid messge type for relay. Expected %v, got %v", MessageTypeRelayForward, mType)
}
if len(r.options) != 1 {
t.Fatalf("Invalid number of options. Expected 1, got %v", len(r.options))
@@ -94,9 +94,9 @@ func TestRelayMsgParseOptRelayMsgSingleEncapsulation(t *testing.T) {
reflect.TypeOf(innerDHCP),
)
}
- if dType := innerDHCP.Type(); dType != SOLICIT {
- t.Fatalf("Invalid inner DHCP type. Expected SOLICIT (%v), got %v",
- SOLICIT, dType,
+ if dType := innerDHCP.Type(); dType != MessageTypeSolicit {
+ t.Fatalf("Invalid inner DHCP type. Expected MessageTypeSolicit (%v), got %v",
+ MessageTypeSolicit, dType,
)
}
if tID := innerDHCP.TransactionID(); tID != 0xaabbcc {
diff --git a/dhcpv6/types.go b/dhcpv6/types.go
index 795a284..1ef5938 100644
--- a/dhcpv6/types.go
+++ b/dhcpv6/types.go
@@ -2,53 +2,59 @@ package dhcpv6
// from http://www.networksorcery.com/enp/protocol/dhcpv6.htm
+// MessageType represents the kind of DHCPv6 message.
type MessageType uint8
+// The different kinds of DHCPv6 message types.
const (
- // MSGTYPE_NONE is used internally and is not part of the RFC
- MSGTYPE_NONE MessageType = 0
- SOLICIT MessageType = 1
- ADVERTISE MessageType = 2
- REQUEST MessageType = 3
- CONFIRM MessageType = 4
- RENEW MessageType = 5
- REBIND MessageType = 6
- REPLY MessageType = 7
- RELEASE MessageType = 8
- DECLINE MessageType = 9
- RECONFIGURE MessageType = 10
- INFORMATION_REQUEST MessageType = 11
- RELAY_FORW MessageType = 12
- RELAY_REPL MessageType = 13
- LEASEQUERY MessageType = 14
- LEASEQUERY_REPLY MessageType = 15
- LEASEQUERY_DONE MessageType = 16
- LEASEQUERY_DATA MessageType = 17
+ // MessageTypeNone is used internally and is not part of the RFC
+ MessageTypeNone MessageType = 0
+ MessageTypeSolicit MessageType = 1
+ MessageTypeAdvertise MessageType = 2
+ MessageTypeRequest MessageType = 3
+ MessageTypeConfirm MessageType = 4
+ MessageTypeRenew MessageType = 5
+ MessageTypeRebind MessageType = 6
+ MessageTypeReply MessageType = 7
+ MessageTypeRelease MessageType = 8
+ MessageTypeDecline MessageType = 9
+ MessageTypeReconfigure MessageType = 10
+ MessageTypeInformationRequest MessageType = 11
+ MessageTypeRelayForward MessageType = 12
+ MessageTypeRelayReply MessageType = 13
+ MessageTypeLeaseQuery MessageType = 14
+ MessageTypeLeaseQueryReply MessageType = 15
+ MessageTypeLeaseQueryDone MessageType = 16
+ MessageTypeLeaseQueryData MessageType = 17
)
+// MessageTypeToString converts a MessageType to a human-readable string
+// representation.
func MessageTypeToString(t MessageType) string {
- if m := MessageTypeToStringMap[t]; m != "" {
+ if m, ok := MessageTypeToStringMap[t]; ok {
return m
}
return "Unknown"
}
+// MessageTypeToStringMap contains the mapping of MessageTypes to human-readable
+// strings.
var MessageTypeToStringMap = map[MessageType]string{
- SOLICIT: "SOLICIT",
- ADVERTISE: "ADVERTISE",
- REQUEST: "REQUEST",
- CONFIRM: "CONFIRM",
- RENEW: "RENEW",
- REBIND: "REBIND",
- REPLY: "REPLY",
- RELEASE: "RELEASE",
- DECLINE: "DECLINE",
- RECONFIGURE: "RECONFIGURE",
- INFORMATION_REQUEST: "INFORMATION-REQUEST",
- RELAY_FORW: "RELAY-FORW",
- RELAY_REPL: "RELAY-REPL",
- LEASEQUERY: "LEASEQUERY",
- LEASEQUERY_REPLY: "LEASEQUERY-REPLY",
- LEASEQUERY_DONE: "LEASEQUERY-DONE",
- LEASEQUERY_DATA: "LEASEQUERY-DATA",
+ MessageTypeSolicit: "SOLICIT",
+ MessageTypeAdvertise: "ADVERTISE",
+ MessageTypeRequest: "REQUEST",
+ MessageTypeConfirm: "CONFIRM",
+ MessageTypeRenew: "RENEW",
+ MessageTypeRebind: "REBIND",
+ MessageTypeReply: "REPLY",
+ MessageTypeRelease: "RELEASE",
+ MessageTypeDecline: "DECLINE",
+ MessageTypeReconfigure: "RECONFIGURE",
+ MessageTypeInformationRequest: "INFORMATION-REQUEST",
+ MessageTypeRelayForward: "RELAY-FORW",
+ MessageTypeRelayReply: "RELAY-REPL",
+ MessageTypeLeaseQuery: "LEASEQUERY",
+ MessageTypeLeaseQueryReply: "LEASEQUERY-REPLY",
+ MessageTypeLeaseQueryDone: "LEASEQUERY-DONE",
+ MessageTypeLeaseQueryData: "LEASEQUERY-DATA",
}
diff --git a/dhcpv6/utils_test.go b/dhcpv6/utils_test.go
index 77205b4..36b1683 100644
--- a/dhcpv6/utils_test.go
+++ b/dhcpv6/utils_test.go
@@ -61,7 +61,7 @@ func TestGetTransactionIDMessage(t *testing.T) {
func TestGetTransactionIDRelay(t *testing.T) {
message, err := NewMessage()
require.NoError(t, err)
- relay, err := EncapsulateRelay(message, RELAY_FORW, nil, nil)
+ relay, err := EncapsulateRelay(message, MessageTypeRelayForward, nil, nil)
require.NoError(t, err)
transactionID, err := GetTransactionID(relay)
require.NoError(t, err)