summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2019-01-28 00:53:04 +0000
committerinsomniac <insomniacslk@users.noreply.github.com>2019-01-28 11:21:18 +0000
commit51ac989e85d13beda9cb304fb85e0aff18e9cd98 (patch)
tree335f5968c0d0c55a5c8e1a65e997a0d331c2210a /dhcpv4/bsdp
parent82434691f0602844a2156a4d2037d43c51900b73 (diff)
dhcpv4: moved client into dhcpv4/client4
Diffstat (limited to 'dhcpv4/bsdp')
-rw-r--r--dhcpv4/bsdp/bsdp.go3
-rw-r--r--dhcpv4/bsdp/bsdp_test.go15
-rw-r--r--dhcpv4/bsdp/client.go13
3 files changed, 17 insertions, 14 deletions
diff --git a/dhcpv4/bsdp/bsdp.go b/dhcpv4/bsdp/bsdp.go
index c9f7c26..df44af9 100644
--- a/dhcpv4/bsdp/bsdp.go
+++ b/dhcpv4/bsdp/bsdp.go
@@ -6,6 +6,7 @@ import (
"net"
"github.com/insomniacslk/dhcp/dhcpv4"
+ "github.com/insomniacslk/dhcp/dhcpv4/client4"
)
// MaxDHCPMessageSize is the size set in DHCP option 57 (DHCP Maximum Message Size).
@@ -39,7 +40,7 @@ func ParseBootImageListFromAck(ack *dhcpv4.DHCPv4) ([]BootImage, error) {
}
func needsReplyPort(replyPort uint16) bool {
- return replyPort != 0 && replyPort != dhcpv4.ClientPort
+ return replyPort != 0 && replyPort != client4.ClientPort
}
// MessageTypeFromPacket extracts the BSDP message type (LIST, SELECT) from the
diff --git a/dhcpv4/bsdp/bsdp_test.go b/dhcpv4/bsdp/bsdp_test.go
index 05cd85c..d5e400b 100644
--- a/dhcpv4/bsdp/bsdp_test.go
+++ b/dhcpv4/bsdp/bsdp_test.go
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/insomniacslk/dhcp/dhcpv4"
+ "github.com/insomniacslk/dhcp/dhcpv4/client4"
"github.com/insomniacslk/dhcp/iana"
"github.com/stretchr/testify/require"
)
@@ -57,7 +58,7 @@ func TestParseBootImageListFromAckNoVendorOption(t *testing.T) {
func TestNeedsReplyPort(t *testing.T) {
require.True(t, needsReplyPort(123))
require.False(t, needsReplyPort(0))
- require.False(t, needsReplyPort(dhcpv4.ClientPort))
+ require.False(t, needsReplyPort(client4.ClientPort))
}
func TestNewInformList_NoReplyPort(t *testing.T) {
@@ -214,13 +215,13 @@ func TestInformSelectForAck_ReplyPort(t *testing.T) {
}
func TestNewReplyForInformList_NoDefaultImage(t *testing.T) {
- inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, dhcpv4.ClientPort)
+ inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, client4.ClientPort)
_, err := NewReplyForInformList(inform, ReplyConfig{})
require.Error(t, err)
}
func TestNewReplyForInformList_NoImages(t *testing.T) {
- inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, dhcpv4.ClientPort)
+ inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, client4.ClientPort)
fakeImage := BootImage{
ID: BootImageID{ImageType: BootImageTypeMacOSX},
}
@@ -238,7 +239,7 @@ func TestNewReplyForInformList_NoImages(t *testing.T) {
}
func TestNewReplyForInformList(t *testing.T) {
- inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, dhcpv4.ClientPort)
+ inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, client4.ClientPort)
images := []BootImage{
BootImage{
ID: BootImageID{
@@ -292,13 +293,13 @@ func TestNewReplyForInformList(t *testing.T) {
}
func TestNewReplyForInformSelect_NoSelectedImage(t *testing.T) {
- inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, dhcpv4.ClientPort)
+ inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, client4.ClientPort)
_, err := NewReplyForInformSelect(inform, ReplyConfig{})
require.Error(t, err)
}
func TestNewReplyForInformSelect_NoImages(t *testing.T) {
- inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, dhcpv4.ClientPort)
+ inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, client4.ClientPort)
fakeImage := BootImage{
ID: BootImageID{ImageType: BootImageTypeMacOSX},
}
@@ -316,7 +317,7 @@ func TestNewReplyForInformSelect_NoImages(t *testing.T) {
}
func TestNewReplyForInformSelect(t *testing.T) {
- inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, dhcpv4.ClientPort)
+ inform, _ := NewInformList(net.HardwareAddr{1, 2, 3, 4, 5, 6}, net.IP{1, 2, 3, 4}, client4.ClientPort)
images := []BootImage{
BootImage{
ID: BootImageID{
diff --git a/dhcpv4/bsdp/client.go b/dhcpv4/bsdp/client.go
index e8ca2ca..173291e 100644
--- a/dhcpv4/bsdp/client.go
+++ b/dhcpv4/bsdp/client.go
@@ -4,18 +4,19 @@ import (
"errors"
"github.com/insomniacslk/dhcp/dhcpv4"
+ "github.com/insomniacslk/dhcp/dhcpv4/client4"
)
// Client represents a BSDP client that can perform BSDP exchanges via the
// broadcast address.
type Client struct {
- dhcpv4.Client
+ client4.Client
}
// NewClient constructs a new client with default read and write timeouts from
// dhcpv4.Client.
func NewClient() *Client {
- return &Client{Client: dhcpv4.Client{}}
+ return &Client{Client: client4.Client{}}
}
// Exchange runs a full BSDP exchange (Inform[list], Ack, Inform[select],
@@ -24,17 +25,17 @@ func (c *Client) Exchange(ifname string) ([]*Packet, error) {
conversation := make([]*Packet, 0)
// Get our file descriptor for the broadcast socket.
- sendFd, err := dhcpv4.MakeBroadcastSocket(ifname)
+ sendFd, err := client4.MakeBroadcastSocket(ifname)
if err != nil {
return conversation, err
}
- recvFd, err := dhcpv4.MakeListeningSocket(ifname)
+ recvFd, err := client4.MakeListeningSocket(ifname)
if err != nil {
return conversation, err
}
// INFORM[LIST]
- informList, err := NewInformListForInterface(ifname, dhcpv4.ClientPort)
+ informList, err := NewInformListForInterface(ifname, client4.ClientPort)
if err != nil {
return conversation, err
}
@@ -59,7 +60,7 @@ func (c *Client) Exchange(ifname string) ([]*Packet, error) {
}
// INFORM[SELECT]
- informSelect, err := InformSelectForAck(PacketFor(ackForList), dhcpv4.ClientPort, bootImages[0])
+ informSelect, err := InformSelectForAck(PacketFor(ackForList), client4.ClientPort, bootImages[0])
if err != nil {
return conversation, err
}