diff options
-rw-r--r-- | dhcpv6/client.go | 5 | ||||
-rw-r--r-- | dhcpv6/dhcpv6.go | 5 | ||||
-rw-r--r-- | dhcpv6/dhcpv6_test.go | 13 | ||||
-rw-r--r-- | dhcpv6/dhcpv6message.go | 27 | ||||
-rw-r--r-- | dhcpv6/dhcpv6relay.go | 3 | ||||
-rw-r--r-- | dhcpv6/option_clientid.go (renamed from dhcpv6/options/clientid.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_dnsrecursivenameserver.go (renamed from dhcpv6/options/dnsrecursivenameserver.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_domainsearchlist.go (renamed from dhcpv6/options/domainsearchlist.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_duid.go (renamed from dhcpv6/options/duid.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_elapsedtime.go (renamed from dhcpv6/options/elapsedtime.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_elapsedtime_test.go (renamed from dhcpv6/options/elapsedtime_test.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_iaaddress.go (renamed from dhcpv6/options/iaaddress.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_iaprefix.go (renamed from dhcpv6/options/iaprefix.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_nontemporaryaddress.go (renamed from dhcpv6/options/nontemporaryaddress.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_prefixdelegation.go (renamed from dhcpv6/options/prefixdelegation.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_relaymsg.go (renamed from dhcpv6/options/relaymsg.go) | 18 | ||||
-rw-r--r-- | dhcpv6/option_requestedoption.go (renamed from dhcpv6/options/requestedoption.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_rfc1035label.go (renamed from dhcpv6/options/rfc1035label.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_rfc1035label_test.go (renamed from dhcpv6/options/rfc1035label_test.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_serverid.go (renamed from dhcpv6/options/serverid.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_statuscode.go (renamed from dhcpv6/options/statuscode.go) | 2 | ||||
-rw-r--r-- | dhcpv6/option_types.go (renamed from dhcpv6/options/types.go) | 2 | ||||
-rw-r--r-- | dhcpv6/options.go (renamed from dhcpv6/options/options.go) | 4 |
23 files changed, 54 insertions, 53 deletions
diff --git a/dhcpv6/client.go b/dhcpv6/client.go index 6bb1a91..2f7a64f 100644 --- a/dhcpv6/client.go +++ b/dhcpv6/client.go @@ -37,7 +37,7 @@ func (c *Client) Exchange(ifname string, solicit DHCPv6) ([]DHCPv6, error) { } } conversation = append(conversation, solicit) - advertise, err := c.ExchangeSolicitAdvertise(ifname, solicit) + advertise, err := c.Solicit(ifname, solicit) if err != nil { return conversation, err } @@ -47,7 +47,8 @@ func (c *Client) Exchange(ifname string, solicit DHCPv6) ([]DHCPv6, error) { return conversation, nil } -func (c *Client) ExchangeSolicitAdvertise(ifname string, solicit DHCPv6) (DHCPv6, error) { +// send a SOLICIT, return a response, or nil +func (c *Client) Solicit(ifname string, solicit DHCPv6) (DHCPv6, error) { // if no LocalAddr is specified, get the interface's link-local address var laddr net.UDPAddr if c.LocalAddr == nil { diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go index de5ebf4..fe096a6 100644 --- a/dhcpv6/dhcpv6.go +++ b/dhcpv6/dhcpv6.go @@ -2,7 +2,6 @@ package dhcpv6 import ( "fmt" - "github.com/insomniacslk/dhcp/dhcpv6/options" ) type DHCPv6 interface { @@ -35,7 +34,7 @@ func FromBytes(data []byte) (DHCPv6, error) { linkAddr: append(data[2:18]), peerAddr: append(data[18:34]), } - options, err := options.FromBytes(data[34:]) + options, err := OptionsFromBytes(data[34:]) if err != nil { return nil, err } @@ -50,7 +49,7 @@ func FromBytes(data []byte) (DHCPv6, error) { messageType: messageType, transactionID: *tid, } - options, err := options.FromBytes(data[4:]) + options, err := OptionsFromBytes(data[4:]) if err != nil { return nil, err } diff --git a/dhcpv6/dhcpv6_test.go b/dhcpv6/dhcpv6_test.go index 3d0c5fc..770d2c4 100644 --- a/dhcpv6/dhcpv6_test.go +++ b/dhcpv6/dhcpv6_test.go @@ -2,7 +2,6 @@ package dhcpv6 import ( "bytes" - "github.com/insomniacslk/dhcp/dhcpv6/options" "testing" ) @@ -88,13 +87,13 @@ func TestSettersAndGetters(t *testing.T) { if len(opts) != 0 { t.Fatalf("Invalid Options. Expected empty array, got %v", opts) } - opt := options.OptionGeneric{OptionCode: 0, OptionData: []byte{}} - d.SetOptions([]options.Option{&opt}) + opt := OptionGeneric{OptionCode: 0, OptionData: []byte{}} + d.SetOptions([]Option{&opt}) opts = d.Options() if len(opts) != 1 { t.Fatalf("Invalid Options. Expected one-element array, got %v", len(opts)) } - if _, ok := opts[0].(*options.OptionGeneric); !ok { + if _, ok := opts[0].(*OptionGeneric); !ok { t.Fatalf("Invalid Options. Expected one OptionGeneric, got %v", opts[0]) } } @@ -105,13 +104,13 @@ func TestAddOption(t *testing.T) { if len(opts) != 0 { t.Fatalf("Invalid Options. Expected empty array, got %v", opts) } - opt := options.OptionGeneric{OptionCode: 0, OptionData: []byte{}} + opt := OptionGeneric{OptionCode: 0, OptionData: []byte{}} d.AddOption(&opt) opts = d.Options() if len(opts) != 1 { t.Fatalf("Invalid Options. Expected one-element array, got %v", len(opts)) } - if _, ok := opts[0].(*options.OptionGeneric); !ok { + if _, ok := opts[0].(*OptionGeneric); !ok { t.Fatalf("Invalid Options. Expected one OptionGeneric, got %v", opts[0]) } } @@ -120,7 +119,7 @@ func TestToBytes(t *testing.T) { d := DHCPv6Message{} d.SetMessage(SOLICIT) d.SetTransactionID(0xabcdef) - opt := options.OptionGeneric{OptionCode: 0, OptionData: []byte{}} + opt := OptionGeneric{OptionCode: 0, OptionData: []byte{}} d.AddOption(&opt) toBytes := d.ToBytes() expected := []byte{01, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00} diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index f1ba601..417c46d 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "encoding/binary" "fmt" - "github.com/insomniacslk/dhcp/dhcpv6/options" "github.com/insomniacslk/dhcp/iana" "log" "net" @@ -16,7 +15,7 @@ const MessageHeaderSize = 4 type DHCPv6Message struct { messageType MessageType transactionID uint32 // only 24 bits are used though - options []options.Option + options []Option } func BytesToTransactionID(data []byte) (*uint32, error) { @@ -76,24 +75,24 @@ func NewSolicitForInterface(ifname string) (*DHCPv6Message, error) { if err != nil { return nil, err } - cid := options.OptClientId{} - cid.SetClientID(options.Duid{ - Type: options.DUID_LLT, + cid := OptClientId{} + cid.SetClientID(Duid{ + Type: DUID_LLT, HwType: iana.HwTypeEthernet, Time: GetTime(), LinkLayerAddr: iface.HardwareAddr, }) d.AddOption(&cid) - oro := options.OptRequestedOption{} - oro.SetRequestedOptions([]options.OptionCode{ - options.DNS_RECURSIVE_NAME_SERVER, - options.DOMAIN_SEARCH_LIST, + oro := OptRequestedOption{} + oro.SetRequestedOptions([]OptionCode{ + DNS_RECURSIVE_NAME_SERVER, + DOMAIN_SEARCH_LIST, }) d.AddOption(&oro) - d.AddOption(&options.OptElapsedTime{}) + d.AddOption(&OptElapsedTime{}) // FIXME use real values for IA_NA - iaNa := options.OptIANA{} + iaNa := OptIANA{} iaNa.SetIAID([4]byte{0x27, 0xfe, 0x8f, 0x95}) iaNa.SetT1(0xe10) iaNa.SetT2(0x1518) @@ -133,15 +132,15 @@ func (d *DHCPv6Message) SetTransactionID(tid uint32) { d.transactionID = ttid } -func (d *DHCPv6Message) Options() []options.Option { +func (d *DHCPv6Message) Options() []Option { return d.options } -func (d *DHCPv6Message) SetOptions(options []options.Option) { +func (d *DHCPv6Message) SetOptions(options []Option) { d.options = options } -func (d *DHCPv6Message) AddOption(option options.Option) { +func (d *DHCPv6Message) AddOption(option Option) { d.options = append(d.options, option) } diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go index 100a878..12b677a 100644 --- a/dhcpv6/dhcpv6relay.go +++ b/dhcpv6/dhcpv6relay.go @@ -2,7 +2,6 @@ package dhcpv6 import ( "fmt" - "github.com/insomniacslk/dhcp/dhcpv6/options" "net" ) @@ -13,7 +12,7 @@ type DHCPv6Relay struct { hopCount uint8 linkAddr net.IP peerAddr net.IP - options []options.Option + options []Option } func (r *DHCPv6Relay) Type() MessageType { diff --git a/dhcpv6/options/clientid.go b/dhcpv6/option_clientid.go index 71422d7..1a61047 100644 --- a/dhcpv6/options/clientid.go +++ b/dhcpv6/option_clientid.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptClientId and DUID structures. // https://www.ietf.org/rfc/rfc3315.txt diff --git a/dhcpv6/options/dnsrecursivenameserver.go b/dhcpv6/option_dnsrecursivenameserver.go index a28fd1d..ef3c690 100644 --- a/dhcpv6/options/dnsrecursivenameserver.go +++ b/dhcpv6/option_dnsrecursivenameserver.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptDNSRecursiveNameServer structure. // https://www.ietf.org/rfc/rfc3646.txt diff --git a/dhcpv6/options/domainsearchlist.go b/dhcpv6/option_domainsearchlist.go index 048384f..e3e9c17 100644 --- a/dhcpv6/options/domainsearchlist.go +++ b/dhcpv6/option_domainsearchlist.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptDomainSearchList structure. // https://www.ietf.org/rfc/rfc3646.txt diff --git a/dhcpv6/options/duid.go b/dhcpv6/option_duid.go index 0fc3e33..1cb5fe6 100644 --- a/dhcpv6/options/duid.go +++ b/dhcpv6/option_duid.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 import ( "encoding/binary" diff --git a/dhcpv6/options/elapsedtime.go b/dhcpv6/option_elapsedtime.go index e95185d..1f5fd03 100644 --- a/dhcpv6/options/elapsedtime.go +++ b/dhcpv6/option_elapsedtime.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptElapsedTime structure. // https://www.ietf.org/rfc/rfc3315.txt diff --git a/dhcpv6/options/elapsedtime_test.go b/dhcpv6/option_elapsedtime_test.go index 402d62b..8e99fa8 100644 --- a/dhcpv6/options/elapsedtime_test.go +++ b/dhcpv6/option_elapsedtime_test.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 import ( "bytes" diff --git a/dhcpv6/options/iaaddress.go b/dhcpv6/option_iaaddress.go index 24f28ad..7d0f4a6 100644 --- a/dhcpv6/options/iaaddress.go +++ b/dhcpv6/option_iaaddress.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptIAAddress structure. // https://www.ietf.org/rfc/rfc3633.txt diff --git a/dhcpv6/options/iaprefix.go b/dhcpv6/option_iaprefix.go index d91df2a..b4adacb 100644 --- a/dhcpv6/options/iaprefix.go +++ b/dhcpv6/option_iaprefix.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptIAPrefix structure. // https://www.ietf.org/rfc/rfc3633.txt diff --git a/dhcpv6/options/nontemporaryaddress.go b/dhcpv6/option_nontemporaryaddress.go index 703b8cc..b387e43 100644 --- a/dhcpv6/options/nontemporaryaddress.go +++ b/dhcpv6/option_nontemporaryaddress.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptIANA structure. // https://www.ietf.org/rfc/rfc3633.txt diff --git a/dhcpv6/options/prefixdelegation.go b/dhcpv6/option_prefixdelegation.go index 1c02433..2a211c0 100644 --- a/dhcpv6/options/prefixdelegation.go +++ b/dhcpv6/option_prefixdelegation.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptIAForPrefixDelegation structure. // https://www.ietf.org/rfc/rfc3633.txt diff --git a/dhcpv6/options/relaymsg.go b/dhcpv6/option_relaymsg.go index 4384c30..b0a69a5 100644 --- a/dhcpv6/options/relaymsg.go +++ b/dhcpv6/option_relaymsg.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptRelayMsg structure. // https://www.ietf.org/rfc/rfc3315.txt @@ -8,7 +8,7 @@ import ( ) type OptRelayMsg struct { - relayMessage []byte // FIXME this has to become []DHCPv6 + relayMessage DHCPv6 } func (op *OptRelayMsg) Code() OptionCode { @@ -16,19 +16,19 @@ func (op *OptRelayMsg) Code() OptionCode { } func (op *OptRelayMsg) ToBytes() []byte { - return []byte(op.relayMessage) + return op.relayMessage.ToBytes() } -func (op *OptRelayMsg) RelayMessage() []byte { +func (op *OptRelayMsg) RelayMessage() DHCPv6 { return op.relayMessage } -func (op *OptRelayMsg) SetRelayMessage(relayMessage []byte) { +func (op *OptRelayMsg) SetRelayMessage(relayMessage DHCPv6) { op.relayMessage = relayMessage } func (op *OptRelayMsg) Length() int { - return len(op.relayMessage) + return len(op.relayMessage.ToBytes()) } func (op *OptRelayMsg) String() string { @@ -38,7 +38,11 @@ func (op *OptRelayMsg) String() string { // build an OptRelayMsg structure from a sequence of bytes. // The input data does not include option code and length bytes. func ParseOptRelayMsg(data []byte) (*OptRelayMsg, error) { + var err error opt := OptRelayMsg{} - opt.relayMessage = []byte(data) + opt.relayMessage, err = FromBytes(data) + if err != nil { + return nil, err + } return &opt, nil } diff --git a/dhcpv6/options/requestedoption.go b/dhcpv6/option_requestedoption.go index 88e9ff3..64c123e 100644 --- a/dhcpv6/options/requestedoption.go +++ b/dhcpv6/option_requestedoption.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptRequestedOption structure. // https://www.ietf.org/rfc/rfc3315.txt diff --git a/dhcpv6/options/rfc1035label.go b/dhcpv6/option_rfc1035label.go index 0d2cff3..06870b5 100644 --- a/dhcpv6/options/rfc1035label.go +++ b/dhcpv6/option_rfc1035label.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 import ( "fmt" diff --git a/dhcpv6/options/rfc1035label_test.go b/dhcpv6/option_rfc1035label_test.go index 4e1debb..f99c209 100644 --- a/dhcpv6/options/rfc1035label_test.go +++ b/dhcpv6/option_rfc1035label_test.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 import ( "bytes" diff --git a/dhcpv6/options/serverid.go b/dhcpv6/option_serverid.go index a66f4b4..75aea9b 100644 --- a/dhcpv6/options/serverid.go +++ b/dhcpv6/option_serverid.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptServerId and DUID structures. // https://www.ietf.org/rfc/rfc3315.txt diff --git a/dhcpv6/options/statuscode.go b/dhcpv6/option_statuscode.go index 60f6f71..017a26f 100644 --- a/dhcpv6/options/statuscode.go +++ b/dhcpv6/option_statuscode.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 // This module defines the OptStatusCode structure. // https://www.ietf.org/rfc/rfc3315.txt diff --git a/dhcpv6/options/types.go b/dhcpv6/option_types.go index 48f1003..35fe1a7 100644 --- a/dhcpv6/options/types.go +++ b/dhcpv6/option_types.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 const ( _ OptionCode = iota // skip 0 diff --git a/dhcpv6/options/options.go b/dhcpv6/options.go index 2eeaa44..e4e9b8b 100644 --- a/dhcpv6/options/options.go +++ b/dhcpv6/options.go @@ -1,4 +1,4 @@ -package options +package dhcpv6 import ( "encoding/binary" @@ -99,7 +99,7 @@ func ParseOption(dataStart []byte) (Option, error) { return opt, nil } -func FromBytes(data []byte) ([]Option, error) { +func OptionsFromBytes(data []byte) ([]Option, error) { // Parse a sequence of bytes until the end and build a list of options from // it. Returns an error if any invalid option or length is found. if len(data) < 4 { |