@@ -87,44 +87,44 @@ func (s *Socket) Close() error {
8787func (c * DHCP ) getIPv4InterfaceAddresses (ifName string ) ([]net.IP , error ) {
8888 nic , err := c .netioClient .GetNetworkInterfaceByName (ifName )
8989 if err != nil {
90- return []net.IP {}, err
90+ return []net.IP {}, errors . Wrap ( err , "failed to get interface by name to find ipv4 addresses" )
9191 }
9292 addresses , err := c .netioClient .GetNetworkInterfaceAddrs (nic )
9393 if err != nil {
94- return []net.IP {}, err
94+ return []net.IP {}, errors . Wrap ( err , "failed to get interface addresses" )
9595 }
9696 ret := []net.IP {}
9797 for _ , address := range addresses {
9898 // check if the ip is ipv4 and parse it
99- ip , _ , err := net .ParseCIDR (address .String ())
100- if err != nil || ip .To4 () == nil {
99+ ip , _ , cidrErr := net .ParseCIDR (address .String ())
100+ if cidrErr != nil || ip .To4 () == nil {
101101 continue
102102 }
103103 ret = append (ret , ip )
104104 }
105105
106106 c .logger .Info ("Interface addresses found" , zap .Any ("foundIPs" , addresses ), zap .Any ("selectedIPs" , ret ))
107- return ret , err
107+ return ret , nil
108108}
109109
110- func (c * DHCP ) verifyIPv4InterfaceAddressCount (ifName string , count , maxRuns int , sleep time.Duration ) error {
110+ func (c * DHCP ) verifyIPv4InterfaceAddressCount (ctx context. Context , ifName string , count , numRetries int , sleep time.Duration ) error {
111111 retrier := retry.Retrier {
112- Cooldown : retry .Max (maxRuns , retry .Fixed (sleep )),
112+ Cooldown : retry .Max (numRetries , retry .Fixed (sleep )),
113113 }
114- addressCountErr := retrier .Do (context . Background () , func () error {
114+ addressCountErr := retrier .Do (ctx , func () error {
115115 addresses , err := c .getIPv4InterfaceAddresses (ifName )
116116 if err != nil || len (addresses ) != count {
117117 return errIncorrectAddressCount
118118 }
119119 return nil
120120 })
121- return addressCountErr
121+ return errors . Wrap ( addressCountErr , "failed to verify interface ipv4 address count" )
122122}
123123
124124// issues a dhcp discover request on an interface by finding the secondary's ip and sending on its ip
125125func (c * DHCP ) DiscoverRequest (ctx context.Context , macAddress net.HardwareAddr , ifName string ) error {
126126 // Find the ipv4 address of the secondary interface (we're betting that this gets autoconfigured)
127- err := c .verifyIPv4InterfaceAddressCount (ifName , 1 , retryCount , ipAssignRetryDelay )
127+ err := c .verifyIPv4InterfaceAddressCount (ctx , ifName , 1 , retryCount , ipAssignRetryDelay )
128128 if err != nil {
129129 return errors .Wrap (err , "failed to get auto ip config assigned in apipa range in time" )
130130 }
@@ -181,7 +181,7 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
181181 Cooldown : retry .Max (retryCount , retry .Fixed (retryDelay )),
182182 }
183183 // retry sending the packet until it succeeds
184- err = retrier .Do (context . Background () , func () error {
184+ err = retrier .Do (ctx , func () error {
185185 _ , sockErr := sock .Write (bytesToSend )
186186 return sockErr
187187 })
0 commit comments