Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "auto" option to ipv4-subnet and ipv6-subnet
If we do not care about the assigned IPv4/IPv6 subnet for the container network, we let the container runtime allocate one for us. This guarantees to avoid a collision of the hardcoded range (172.20.20.0/24 and 2001:172:20:20::/64) with any existing container networks. This just works for the podman runtime. For the docker runtime we compute the IPv6 subnet manually because it can only pick addresses from the configured (global) subnet.
- Loading branch information
Showing
4 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package utils | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
) | ||
|
||
// GenerateIPv6ULASubnet creates a random /64 IPv6 subnet from the ULA (Unique Local Address) range | ||
func GenerateIPv6ULASubnet() (string, error) { | ||
ula := "fd00:" | ||
for i := 0; i < 3; i++ { | ||
// Generate a random 16-bit hex field | ||
bytes := make([]byte, 2) | ||
if _, err := rand.Read(bytes); err != nil { | ||
return "", err | ||
} | ||
ula += hex.EncodeToString(bytes) + ":" | ||
} | ||
ula += ":/64" | ||
return ula, nil | ||
} |