mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Network: Simple random IP allocation on the bridge network.
This commit is contained in:
parent
5039d4a280
commit
6124c5eb31
1 changed files with 6 additions and 3 deletions
|
@ -2,6 +2,7 @@ package docker
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
)
|
||||
|
||||
|
@ -15,8 +16,10 @@ type NetworkInterface struct {
|
|||
Gateway net.IP
|
||||
}
|
||||
|
||||
func allocateIPAddress() string {
|
||||
return "10.0.3.2"
|
||||
func allocateIPAddress(network *net.IPNet) net.IP {
|
||||
ip := network.IP.Mask(network.Mask)
|
||||
ip[3] = byte(rand.Intn(254))
|
||||
return ip
|
||||
}
|
||||
|
||||
func getBridgeAddr(name string) (net.Addr, error) {
|
||||
|
@ -52,7 +55,7 @@ func allocateNetwork() (*NetworkInterface, error) {
|
|||
bridge := bridgeAddr.(*net.IPNet)
|
||||
ipPrefixLen, _ := bridge.Mask.Size()
|
||||
iface := &NetworkInterface{
|
||||
IpAddress: allocateIPAddress(),
|
||||
IpAddress: allocateIPAddress(bridge).String(),
|
||||
IpPrefixLen: ipPrefixLen,
|
||||
Gateway: bridge.IP,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue