Basic networking support with hardcoded addresses. Work in progress.

This commit is contained in:
Andrea Luzzardi 2013-02-20 17:47:09 -08:00
parent b9b66d0e1b
commit 5cecd548cd
3 changed files with 49 additions and 7 deletions

View file

@ -33,6 +33,7 @@ type Container struct {
Config *Config
Filesystem *Filesystem
Network *NetworkInterface
State *State
SysInitPath string
@ -87,6 +88,10 @@ func createContainer(id string, root string, command string, args []string, laye
if err := container.Filesystem.createMountPoints(); err != nil {
return nil, err
}
var err error
if container.Network, err = allocateNetwork(); err != nil {
return nil, err
}
if err := container.save(); err != nil {
return nil, err
}
@ -272,11 +277,19 @@ func (container *Container) Start() error {
"--",
"/sbin/init",
}
// Networking
params = append(params, "-g", container.Network.Gateway.String())
// User
if container.Config.User != "" {
params = append(params, "-u", container.Config.User)
}
// Program
params = append(params, "--", container.Path)
params = append(params, container.Args...)
container.cmd = exec.Command("/usr/bin/lxc-start", params...)
var err error

View file

@ -14,12 +14,12 @@ lxc.utsname = {{.Id}}
#lxc.aa_profile = unconfined
# network configuration
#lxc.network.type = veth
#lxc.network.flags = up
#lxc.network.link = br0
#lxc.network.name = eth0 # Internal container network interface name
#lxc.network.mtu = 1500
#lxc.network.ipv4 = {ip_address}/{ip_prefix_len}
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr0
lxc.network.name = eth0
lxc.network.mtu = 1500
lxc.network.ipv4 = {{.Network.IpAddress}}/{{.Network.IpPrefixLen}}
# root filesystem
{{$ROOTFS := .Filesystem.RootFS}}
@ -82,7 +82,7 @@ lxc.mount.entry = /etc/resolv.conf {{$ROOTFS}}/etc/resolv.conf none bind,ro 0 0
# drop linux capabilities (apply mainly to the user root in the container)
lxc.cap.drop = audit_control audit_write mac_admin mac_override mknod net_raw setfcap setpcap sys_admin sys_boot sys_module sys_nice sys_pacct sys_rawio sys_resource sys_time sys_tty_config
#lxc.cap.drop = audit_control audit_write mac_admin mac_override mknod net_raw setfcap setpcap sys_admin sys_boot sys_module sys_nice sys_pacct sys_rawio sys_resource sys_time sys_tty_config
# limits
{{if .Config.Ram}}

29
network.go Normal file
View file

@ -0,0 +1,29 @@
package docker
import (
"net"
)
const (
networkGateway = "10.0.3.1"
networkPrefixLen = 24
)
type NetworkInterface struct {
IpAddress string
IpPrefixLen int
Gateway net.IP
}
func allocateIPAddress() string {
return "10.0.3.2"
}
func allocateNetwork() (*NetworkInterface, error) {
iface := &NetworkInterface{
IpAddress: allocateIPAddress(),
IpPrefixLen: networkPrefixLen,
Gateway: net.ParseIP(networkGateway),
}
return iface, nil
}