implementing SetInterfaceMac

Docker-DCO-1.1-Signed-off-by: Malte Janduda <mail@janduda.net> (github: MalteJ)
This commit is contained in:
Malte Janduda 2014-09-29 23:51:53 +02:00
parent 30e50af760
commit bf54bdfd7f
3 changed files with 16 additions and 0 deletions

View File

@ -68,6 +68,14 @@ func SetDefaultGateway(ip, ifaceName string) error {
return netlink.AddDefaultGw(ip, ifaceName)
}
func SetInterfaceMac(name string, macaddr string) error {
iface, err := net.InterfaceByName(name)
if err != nil {
return err
}
return netlink.NetworkSetMacAddress(iface, macaddr)
}
func SetInterfaceIp(name string, rawIp string) error {
iface, err := net.InterfaceByName(name)
if err != nil {

View File

@ -17,6 +17,9 @@ type Network struct {
// Prefix for the veth interfaces.
VethPrefix string `json:"veth_prefix,omitempty"`
// MACAddress contains the MAC address to set on the network interface
MACAddress string `json:"mac_address,omitempty"`
// Address contains the IPv4 and mask to set on the network interface
Address string `json:"address,omitempty"`

View File

@ -60,6 +60,11 @@ func (v *Veth) Initialize(config *Network, networkState *NetworkState) error {
if err := ChangeInterfaceName(vethChild, defaultDevice); err != nil {
return fmt.Errorf("change %s to %s %s", vethChild, defaultDevice, err)
}
if config.MACAddress != "" {
if err := SetInterfaceMac(defaultDevice, config.MACAddress); err != nil {
return fmt.Errorf("set %s mac %s", defaultDevice, err)
}
}
if err := SetInterfaceIp(defaultDevice, config.Address); err != nil {
return fmt.Errorf("set %s ip %s", defaultDevice, err)
}