diff options
author | Tamir Duberstein <tamird@google.com> | 2019-03-04 17:16:35 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-03-04 17:17:30 -0800 |
commit | dcb634ce73f51a1c32e1632d5b5011b3cf56a862 (patch) | |
tree | 5cad73b8082569f83e244b141e1ce04f3ce0e940 /pkg/dhcp/client.go | |
parent | 0d683c9961a6d39d06896a230b8d52edfcf6e0cc (diff) |
Remove duplicate SetSockOpt call
Clean up some error handling, and add TODO explaining incorrect
behaviour with respect to broadcast on interfaces lacking an IP
address.
PiperOrigin-RevId: 236756233
Change-Id: I9662e7dc062c90565a32a3e153c4dbc98c55b522
Diffstat (limited to 'pkg/dhcp/client.go')
-rw-r--r-- | pkg/dhcp/client.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/pkg/dhcp/client.go b/pkg/dhcp/client.go index d759da2fc..fb3ae5b49 100644 --- a/pkg/dhcp/client.go +++ b/pkg/dhcp/client.go @@ -120,33 +120,34 @@ func (c *Client) Config() Config { // If the server sets a lease limit a timer is set to automatically // renew it. func (c *Client) Request(ctx context.Context, requestedAddr tcpip.Address) (cfg Config, reterr error) { + // TODO: remove calls to {Add,Remove}Address when they're no + // longer required to send and receive broadcast. if err := c.stack.AddAddressWithOptions(c.nicid, ipv4.ProtocolNumber, tcpipHeader.IPv4Any, stack.NeverPrimaryEndpoint); err != nil && err != tcpip.ErrDuplicateAddress { - return Config{}, fmt.Errorf("dhcp: %v", err) + return Config{}, fmt.Errorf("dhcp: AddAddressWithOptions(): %s", err) } defer c.stack.RemoveAddress(c.nicid, tcpipHeader.IPv4Any) var wq waiter.Queue ep, err := c.stack.NewEndpoint(udp.ProtocolNumber, ipv4.ProtocolNumber, &wq) if err != nil { - return Config{}, fmt.Errorf("dhcp: outbound endpoint: %v", err) + return Config{}, fmt.Errorf("dhcp: NewEndpoint(): %s", err) } defer ep.Close() if err := ep.SetSockOpt(tcpip.BroadcastOption(1)); err != nil { - return Config{}, fmt.Errorf("dhcp: setsockopt: %v", err) + return Config{}, fmt.Errorf("dhcp: SetSockOpt(BroadcastOption): %s", err) } if err := ep.Bind(tcpip.FullAddress{ Addr: tcpipHeader.IPv4Any, Port: ClientPort, NIC: c.nicid, }, nil); err != nil { - return Config{}, fmt.Errorf("dhcp: bind failed: %v", err) - } - if err := ep.SetSockOpt(tcpip.BroadcastOption(1)); err != nil { - return Config{}, fmt.Errorf("dhcp: setsockopt SO_BROADCAST: %v", err) + return Config{}, fmt.Errorf("dhcp: Bind(): %s", err) } var xid [4]byte - rand.Read(xid[:]) + if _, err := rand.Read(xid[:]); err != nil { + return Config{}, fmt.Errorf("dhcp: rand.Read(): %s", err) + } // DHCPDISCOVERY discOpts := options{ |