summaryrefslogtreecommitdiffhomepage
path: root/netboot
diff options
context:
space:
mode:
authorAvi B <474746+abrender@users.noreply.github.com>2022-11-10 21:13:01 -0500
committerAvi <avibrender@gmail.com>2022-11-10 21:16:07 -0500
commit68ec6dab8c733b92772dace938a4a9eba6ce3494 (patch)
treefc3521767826e963a15c95e62dd9984fbd106927 /netboot
parent5308ebe5334c1fbefc2a12a6fae01e3c75b3c2cf (diff)
Return error from RequestNetbootv4
The current behavior of `RequestNetbootv4` is potentially dangerous because when it reaches the max number of retries, it returns `conversation, nil` (line 91) back to the caller, even if `client.Exchange()` (line 77) returned an `err`. This leads to a situation where the caller will see `err == nil` but incorrect data returned via the other parameter. This changes the behavior to match the behavior of `RequestNetbootv6`. If this change isn't allowed because it's not backwards compatible then we should at least consider returning `nil, nil` instead of `conversation, nil` on the final retry. Signed-off-by: Avi <avibrender@gmail.com>
Diffstat (limited to 'netboot')
-rw-r--r--netboot/netboot.go4
1 files changed, 1 insertions, 3 deletions
diff --git a/netboot/netboot.go b/netboot/netboot.go
index b32f69e..adfc7f3 100644
--- a/netboot/netboot.go
+++ b/netboot/netboot.go
@@ -48,7 +48,6 @@ func RequestNetbootv6(ifname string, timeout time.Duration, retries int, modifie
if err != nil {
log.Printf("Client.Exchange failed: %v", err)
if i >= retries {
- // don't wait at the end of the last attempt
return nil, fmt.Errorf("netboot failed after %d attempts: %v", retries+1, err)
}
log.Printf("sleeping %v before retrying", delay)
@@ -80,8 +79,7 @@ func RequestNetbootv4(ifname string, timeout time.Duration, retries int, modifie
log.Printf("Client.Exchange failed: %v", err)
log.Printf("sleeping %v before retrying", delay)
if i >= retries {
- // don't wait at the end of the last attempt
- break
+ return nil, fmt.Errorf("netboot failed after %d attempts: %v", retries+1, err)
}
sleeper(delay)
// TODO add random splay