summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4
diff options
context:
space:
mode:
authorSean Karlage <skarlage@fb.com>2018-08-15 12:58:22 -0700
committerSean Karlage <skarlage@fb.com>2018-08-15 12:58:22 -0700
commite9d346cb0e0f5797dfdd5396456afbdd66659f01 (patch)
tree6f0ede442cf3e6f0e680f4bc92cdc630baf5f2a1 /dhcpv4
parent84e8b02b92b2cc35bd4fb044522b3d00f80cab74 (diff)
Put back NewInformListForInterface to maintain compat
Diffstat (limited to 'dhcpv4')
-rw-r--r--dhcpv4/bsdp/bsdp.go22
-rw-r--r--dhcpv4/bsdp/client.go18
2 files changed, 23 insertions, 17 deletions
diff --git a/dhcpv4/bsdp/bsdp.go b/dhcpv4/bsdp/bsdp.go
index 42edf7f..bf84508 100644
--- a/dhcpv4/bsdp/bsdp.go
+++ b/dhcpv4/bsdp/bsdp.go
@@ -37,6 +37,28 @@ func needsReplyPort(replyPort uint16) bool {
return replyPort != 0 && replyPort != dhcpv4.ClientPort
}
+// NewInformListForInterface creates a new INFORM packet for interface ifname
+// with configuration options specified by config.
+func NewInformListForInterface(ifname string, replyPort uint16) (*dhcpv4.DHCPv4, error) {
+ iface, err := net.InterfaceByName(ifname)
+ if err != nil {
+ return nil, err
+ }
+ // Get currently configured IP.
+ addrs, err := iface.Addrs()
+ if err != nil {
+ return nil, err
+ }
+ localIPs, err := dhcpv4.GetExternalIPv4Addrs(addrs)
+ if err != nil {
+ return nil, fmt.Errorf("could not get local IPv4 addr for %s: %v", iface.Name, err)
+ }
+ if localIPs == nil || len(localIPs) == 0 {
+ return nil, fmt.Errorf("could not get local IPv4 addr for %s", iface.Name)
+ }
+ return NewInformList(iface.HardwareAddr, localIPs[0], replyPort)
+}
+
// NewInformList creates a new INFORM packet for interface with hardware address
// `hwaddr` and IP `localIP`. Packet will be sent out on port `replyPort`.
func NewInformList(hwaddr net.HardwareAddr, localIP net.IP, replyPort uint16) (*dhcpv4.DHCPv4, error) {
diff --git a/dhcpv4/bsdp/client.go b/dhcpv4/bsdp/client.go
index 38de094..255d54b 100644
--- a/dhcpv4/bsdp/client.go
+++ b/dhcpv4/bsdp/client.go
@@ -2,8 +2,6 @@ package bsdp
import (
"errors"
- "fmt"
- "net"
"github.com/insomniacslk/dhcp/dhcpv4"
)
@@ -51,24 +49,10 @@ func (c *Client) Exchange(ifname string, informList *dhcpv4.DHCPv4) ([]*dhcpv4.D
if err != nil {
return conversation, err
}
- iface, err := net.InterfaceByName(ifname)
- if err != nil {
- return conversation, err
- }
-
- // Get currently configured IP.
- addrs, err := iface.Addrs()
- if err != nil {
- return conversation, err
- }
- localIPs, err := dhcpv4.GetExternalIPv4Addrs(addrs)
- if err != nil {
- return conversation, fmt.Errorf("could not get local IPv4 addr for %s: %v", iface.Name, err)
- }
// INFORM[LIST]
if informList == nil {
- informList, err = NewInformList(iface.HardwareAddr, localIPs[0], dhcpv4.ClientPort)
+ informList, err = NewInformListForInterface(ifname, dhcpv4.ClientPort)
if err != nil {
return conversation, err
}