Skip to content

Commit d22e49b

Browse files
committed
zedrouter/ipam: drop interface number that produces IP outside DHCP range
If number allocated for app interface (aka application underlay network) produces IP address outside of DHCP range (meaning that there is no free IP address left at the moment), then the number should be freed before trying to create the app again after another app was deleted. This way zedrouter will reuse interface number from the deleted app and therefore it will also reuse freed IP address (and the retry attempt to create the new app will succeed). Otherwise, zedrouter would just try to use the same IP address outside the DHCP range and fail repeatedly, even if there is a free IP available after deletion of another app. Signed-off-by: Milan Lenco <[email protected]> (cherry picked from commit 7bf73ae)
1 parent 0e842bb commit d22e49b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/pillar/cmd/zedrouter/ipam.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ func (z *zedrouter) lookupOrAllocateIPv4ForVIF(niStatus *types.NetworkInstanceSt
134134
niStatus.DhcpRange.Start, niStatus.DhcpRange.End)
135135
z.log.Errorf("lookupOrAllocateIPv4(NI:%v, app:%v): %v",
136136
networkID, appID, err)
137+
// Release this interface number, it produces IP address outside the range
138+
// anyway. Once another already deployed app is deleted and its IP allocations
139+
// are freed, retryTimer will call handleAppNetworkCreate for this app
140+
// again and it will reuse interface number(s) of the deleted app, which
141+
// will then produce a valid IP address fitting the DHCP range.
142+
// Otherwise, zedrouter would just try to use the same IP address outside
143+
// the DHCP range and fail repeatedly, even after there is free IP available.
144+
err2 := z.freeAppIntfNum(networkID, appID, ulStatus.IfIdx)
145+
if err2 != nil {
146+
// Should be unreachable.
147+
z.log.Error(err2)
148+
}
137149
return nil, err
138150
}
139151
}

0 commit comments

Comments
 (0)