summaryrefslogtreecommitdiffhomepage
path: root/pkg/dhcp
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/dhcp')
-rw-r--r--pkg/dhcp/client.go17
-rw-r--r--pkg/dhcp/server.go15
2 files changed, 29 insertions, 3 deletions
diff --git a/pkg/dhcp/client.go b/pkg/dhcp/client.go
index cf8472c5f..92c634a14 100644
--- a/pkg/dhcp/client.go
+++ b/pkg/dhcp/client.go
@@ -195,10 +195,23 @@ func (c *Client) Request(ctx context.Context, requestedAddr tcpip.Address) (cfg
wopts := tcpip.WriteOptions{
To: serverAddr,
}
- if _, err := ep.Write(tcpip.SlicePayload(h), wopts); err != nil {
+ var resCh <-chan struct{}
+ if _, resCh, err = ep.Write(tcpip.SlicePayload(h), wopts); err != nil && resCh == nil {
return Config{}, fmt.Errorf("dhcp discovery write: %v", err)
}
+ if resCh != nil {
+ select {
+ case <-resCh:
+ case <-ctx.Done():
+ return Config{}, fmt.Errorf("dhcp client address resolution: %v", tcpip.ErrAborted)
+ }
+
+ if _, _, err := ep.Write(tcpip.SlicePayload(h), wopts); err != nil {
+ return Config{}, fmt.Errorf("dhcp discovery write: %v", err)
+ }
+ }
+
we, ch := waiter.NewChannelEntry(nil)
wq.EventRegister(&we, waiter.EventIn)
defer wq.EventUnregister(&we)
@@ -289,7 +302,7 @@ func (c *Client) Request(ctx context.Context, requestedAddr tcpip.Address) (cfg
reqOpts = append(reqOpts, option{optClientID, clientID})
}
h.setOptions(reqOpts)
- if _, err := ep.Write(tcpip.SlicePayload(h), wopts); err != nil {
+ if _, _, err := ep.Write(tcpip.SlicePayload(h), wopts); err != nil {
return Config{}, fmt.Errorf("dhcp discovery write: %v", err)
}
diff --git a/pkg/dhcp/server.go b/pkg/dhcp/server.go
index 003e272b2..26700bdbc 100644
--- a/pkg/dhcp/server.go
+++ b/pkg/dhcp/server.go
@@ -95,9 +95,22 @@ func (c *epConn) Read() (buffer.View, tcpip.FullAddress, error) {
}
func (c *epConn) Write(b []byte, addr *tcpip.FullAddress) error {
- if _, err := c.ep.Write(tcpip.SlicePayload(b), tcpip.WriteOptions{To: addr}); err != nil {
+ _, resCh, err := c.ep.Write(tcpip.SlicePayload(b), tcpip.WriteOptions{To: addr})
+ if err != nil && resCh == nil {
return fmt.Errorf("write: %v", err)
}
+
+ if resCh != nil {
+ select {
+ case <-resCh:
+ case <-c.ctx.Done():
+ return fmt.Errorf("dhcp server address resolution: %v", tcpip.ErrAborted)
+ }
+
+ if _, _, err := c.ep.Write(tcpip.SlicePayload(b), tcpip.WriteOptions{To: addr}); err != nil {
+ return fmt.Errorf("write: %v", err)
+ }
+ }
return nil
}