mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #3273 from crosbymichael/set-mtu-in-dockerinit
Move MTU setting outside of lxc and set with netlink
This commit is contained in:
commit
93abcc3a3b
5 changed files with 42 additions and 2 deletions
|
@ -582,6 +582,7 @@ func (container *Container) Start() (err error) {
|
||||||
params = append(params,
|
params = append(params,
|
||||||
"-g", network.Gateway,
|
"-g", network.Gateway,
|
||||||
"-i", fmt.Sprintf("%s/%d", network.IPAddress, network.IPPrefixLen),
|
"-i", fmt.Sprintf("%s/%d", network.IPAddress, network.IPPrefixLen),
|
||||||
|
"-mtu", "1500",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ lxc.network.type = empty
|
||||||
lxc.network.type = veth
|
lxc.network.type = veth
|
||||||
lxc.network.link = {{.NetworkSettings.Bridge}}
|
lxc.network.link = {{.NetworkSettings.Bridge}}
|
||||||
lxc.network.name = eth0
|
lxc.network.name = eth0
|
||||||
lxc.network.mtu = 1500
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
# root filesystem
|
# root filesystem
|
||||||
|
|
|
@ -25,3 +25,7 @@ func AddDefaultGw(ip net.IP) error {
|
||||||
return fmt.Errorf("Not implemented")
|
return fmt.Errorf("Not implemented")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NetworkSetMTU(iface *net.Interface, mtu int) error {
|
||||||
|
return fmt.Errorf("Not implemented")
|
||||||
|
}
|
||||||
|
|
|
@ -328,7 +328,6 @@ func AddDefaultGw(ip net.IP) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.HandleAck(wb.Seq)
|
return s.HandleAck(wb.Seq)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bring up a particular network interface
|
// Bring up a particular network interface
|
||||||
|
@ -354,6 +353,37 @@ func NetworkLinkUp(iface *net.Interface) error {
|
||||||
return s.HandleAck(wb.Seq)
|
return s.HandleAck(wb.Seq)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NetworkSetMTU(iface *net.Interface, mtu int) error {
|
||||||
|
s, err := getNetlinkSocket()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
wb := newNetlinkRequest(syscall.RTM_SETLINK, syscall.NLM_F_ACK)
|
||||||
|
|
||||||
|
msg := newIfInfomsg(syscall.AF_UNSPEC)
|
||||||
|
msg.Type = syscall.RTM_SETLINK
|
||||||
|
msg.Flags = syscall.NLM_F_REQUEST
|
||||||
|
msg.Index = int32(iface.Index)
|
||||||
|
msg.Change = 0xFFFFFFFF
|
||||||
|
wb.AddData(msg)
|
||||||
|
|
||||||
|
var (
|
||||||
|
b = make([]byte, 4)
|
||||||
|
native = nativeEndian()
|
||||||
|
)
|
||||||
|
native.PutUint32(b, uint32(mtu))
|
||||||
|
|
||||||
|
data := newRtAttr(syscall.IFLA_MTU, b)
|
||||||
|
wb.AddData(data)
|
||||||
|
|
||||||
|
if err := s.Send(wb); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return s.HandleAck(wb.Seq)
|
||||||
|
}
|
||||||
|
|
||||||
// Add an Ip address to an interface. This is identical to:
|
// Add an Ip address to an interface. This is identical to:
|
||||||
// ip addr add $ip/$ipNet dev $iface
|
// ip addr add $ip/$ipNet dev $iface
|
||||||
func NetworkLinkAddIp(iface *net.Interface, ip net.IP, ipNet *net.IPNet) error {
|
func NetworkLinkAddIp(iface *net.Interface, ip net.IP, ipNet *net.IPNet) error {
|
||||||
|
|
|
@ -25,6 +25,7 @@ type DockerInitArgs struct {
|
||||||
privileged bool
|
privileged bool
|
||||||
env []string
|
env []string
|
||||||
args []string
|
args []string
|
||||||
|
mtu int
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupHostname(args *DockerInitArgs) error {
|
func setupHostname(args *DockerInitArgs) error {
|
||||||
|
@ -50,6 +51,9 @@ func setupNetworking(args *DockerInitArgs) error {
|
||||||
if err := netlink.NetworkLinkAddIp(iface, ip, ipNet); err != nil {
|
if err := netlink.NetworkLinkAddIp(iface, ip, ipNet); err != nil {
|
||||||
return fmt.Errorf("Unable to set up networking: %v", err)
|
return fmt.Errorf("Unable to set up networking: %v", err)
|
||||||
}
|
}
|
||||||
|
if err := netlink.NetworkSetMTU(iface, args.mtu); err != nil {
|
||||||
|
return fmt.Errorf("Unable to set MTU: %v", err)
|
||||||
|
}
|
||||||
if err := netlink.NetworkLinkUp(iface); err != nil {
|
if err := netlink.NetworkLinkUp(iface); err != nil {
|
||||||
return fmt.Errorf("Unable to set up networking: %v", err)
|
return fmt.Errorf("Unable to set up networking: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -227,6 +231,7 @@ func SysInit() {
|
||||||
ip := flag.String("i", "", "ip address")
|
ip := flag.String("i", "", "ip address")
|
||||||
workDir := flag.String("w", "", "workdir")
|
workDir := flag.String("w", "", "workdir")
|
||||||
privileged := flag.Bool("privileged", false, "privileged mode")
|
privileged := flag.Bool("privileged", false, "privileged mode")
|
||||||
|
mtu := flag.Int("mtu", 1500, "interface mtu")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Get env
|
// Get env
|
||||||
|
@ -250,6 +255,7 @@ func SysInit() {
|
||||||
privileged: *privileged,
|
privileged: *privileged,
|
||||||
env: env,
|
env: env,
|
||||||
args: flag.Args(),
|
args: flag.Args(),
|
||||||
|
mtu: *mtu,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := executeProgram(args); err != nil {
|
if err := executeProgram(args); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue