From a94557d0caf7f713e9ccf487e7e9632de7b2bf0e Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Fri, 23 Oct 2026 12:10:01 +0200 Subject: [PATCH] =?UTF-8?q?f-56:=20agent:=20MTU=20unique=20network.mtu=5Fv?= =?UTF-8?q?m,=20underlay=20=C3=A0=209000=20contr=C3=B4l=C3=A9=20=C3=A0=20l?= =?UTF-8?q?a=20cr=C3=A9ation,=20option=20DHCP=2026=20et=20host=5Fmtu=20#56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GnomeZworc --- conf/agent/config.exemple.yml | 12 +++ internal/api/agent/helpers_test.go | 4 + internal/api/dhcp/convert.go | 3 +- internal/api/dhcp/digest.go | 2 +- internal/api/dhcp/models.go | 2 + internal/api/dhcp/mtu_test.go | 44 +++++++++ internal/api/dhcp/server.go | 3 + internal/config/agent/network.go | 52 +++++++++++ internal/config/agent/network_test.go | 98 ++++++++++++++++++++ internal/config/agent/struct.go | 7 ++ internal/dhcp/generate.go | 8 ++ internal/dhcp/mtu_test.go | 20 ++++ internal/dhcp/struct.go | 1 + internal/dhcpbackend/backend.go | 1 + internal/dhcpbackend/dnsmasq.go | 1 + internal/dhcpbackend/dnsmasq_test.go | 6 ++ internal/dhcpbackend/two.go | 1 + internal/dhcpbackend/two_test.go | 12 +++ internal/dhcpd/dhcpd.go | 8 ++ internal/dhcpd/mtu_test.go | 68 ++++++++++++++ internal/dhcpd/reply.go | 1 + internal/dhcpd/store.go | 4 +- internal/dispatcher/agent/helpers_test.go | 4 + internal/dispatcher/agent/mtu_test.go | 88 ++++++++++++++++++ internal/dispatcher/agent/subnet_commands.go | 10 ++ internal/dispatcher/agent/vpc_commands.go | 22 +++++ internal/l3vni/l3.go | 9 +- internal/l3vni/l3_test.go | 10 +- internal/netif/link.go | 8 ++ internal/netif/tap_linux.go | 4 +- internal/netif/tap_other.go | 2 +- internal/qemu/args.go | 6 +- internal/qemu/args_test.go | 5 +- internal/qemu/config.go | 1 + internal/subnet/create.go | 10 +- internal/subnet/data.go | 1 + internal/vm/create.go | 4 +- 37 files changed, 518 insertions(+), 24 deletions(-) create mode 100644 internal/api/dhcp/mtu_test.go create mode 100644 internal/config/agent/network.go create mode 100644 internal/config/agent/network_test.go create mode 100644 internal/dhcp/mtu_test.go create mode 100644 internal/dhcpd/mtu_test.go create mode 100644 internal/dispatcher/agent/mtu_test.go diff --git a/conf/agent/config.exemple.yml b/conf/agent/config.exemple.yml index a31a58d..19a09f9 100644 --- a/conf/agent/config.exemple.yml +++ b/conf/agent/config.exemple.yml @@ -35,6 +35,18 @@ interfaces: internet: br-000000 admin: br-000000 +# MTU, identical on every hypervisor. +# mtu_vm: MTU of the VMs and of every bridge, veth, tap and VXLAN the agent creates, +# announced by DHCP option 26 and QEMU host_mtu. 1500 at most; below 1500 only with +# allow_mtu_vm_below_1500, never below 1280. +# allow_mtu_underlay_below_9000: a vxlan subnet (or a VPC with l3vni) is refused when +# its underlay is not at exactly 9000, unless this is true. The underlay must always +# carry mtu_vm plus 50 bytes of VXLAN header. +network: + mtu_vm: 1500 + allow_mtu_vm_below_1500: false + allow_mtu_underlay_below_9000: false + # BGP control plane of the hypervisor (optional). # Absent: the agent leaves FRR alone. Present: at every start, before serving its # API, the agent applies the base BGP configuration through vtysh (router-id = the diff --git a/internal/api/agent/helpers_test.go b/internal/api/agent/helpers_test.go index 69adfb2..d3808ce 100644 --- a/internal/api/agent/helpers_test.go +++ b/internal/api/agent/helpers_test.go @@ -29,3 +29,7 @@ func newTestServerWith(t *testing.T, cfg *configuration.Config) (*Server, *badge d := dispatcher.New(q, db, cfg, logger) return New(d, db, logger, "127.0.0.1:0"), db } + +func init() { + dispatcher.LinkMTU = func(string) (int, error) { return 9000, nil } +} diff --git a/internal/api/dhcp/convert.go b/internal/api/dhcp/convert.go index 77dd7c4..88d3c2f 100644 --- a/internal/api/dhcp/convert.go +++ b/internal/api/dhcp/convert.go @@ -17,7 +17,7 @@ func (s Subnet) toConfig() (dhcpd.SubnetConfig, error) { return dhcpd.SubnetConfig{}, fmt.Errorf("invalid interface ip %q", s.InterfaceIP) } - c := dhcpd.SubnetConfig{Network: network, InterfaceIP: interfaceIP} + c := dhcpd.SubnetConfig{Network: network, InterfaceIP: interfaceIP, MTU: s.MTU} if s.VPCRoute != "" { if _, c.VPCRoute, err = net.ParseCIDR(s.VPCRoute); err != nil { @@ -48,6 +48,7 @@ func subnetFromConfig(c dhcpd.SubnetConfig) Subnet { s := Subnet{ Network: c.Network.String(), InterfaceIP: c.InterfaceIP.String(), + MTU: c.MTU, } if c.VPCRoute != nil { s.VPCRoute = c.VPCRoute.String() diff --git a/internal/api/dhcp/digest.go b/internal/api/dhcp/digest.go index f311b22..4cc0c25 100644 --- a/internal/api/dhcp/digest.go +++ b/internal/api/dhcp/digest.go @@ -47,7 +47,7 @@ func CanonicalSubnet(s Subnet) (Subnet, error) { return Subnet{}, err } - out := Subnet{Network: network, InterfaceIP: interfaceIP} + out := Subnet{Network: network, InterfaceIP: interfaceIP, MTU: s.MTU} if s.VPCRoute != "" { if out.VPCRoute, err = canonicalCIDR(s.VPCRoute); err != nil { diff --git a/internal/api/dhcp/models.go b/internal/api/dhcp/models.go index d454194..7fc3933 100644 --- a/internal/api/dhcp/models.go +++ b/internal/api/dhcp/models.go @@ -17,6 +17,7 @@ type Subnet struct { InterfaceIP string `json:"interface_ip"` VPCRoute string `json:"vpc_route,omitempty"` DefaultGateway string `json:"default_gateway,omitempty"` + MTU int `json:"mtu,omitempty"` } type Host struct { @@ -38,6 +39,7 @@ type Lease struct { Router string `json:"router,omitempty"` DNS []string `json:"dns"` Routes []string `json:"routes"` + MTU uint16 `json:"mtu,omitempty"` LeaseSeconds uint32 `json:"lease_seconds"` } diff --git a/internal/api/dhcp/mtu_test.go b/internal/api/dhcp/mtu_test.go new file mode 100644 index 0000000..5131f08 --- /dev/null +++ b/internal/api/dhcp/mtu_test.go @@ -0,0 +1,44 @@ +package dhcpapi + +import ( + "net" + "testing" + + "git.g3e.fr/syonad/two/internal/dhcpd" + "github.com/insomniacslk/dhcp/dhcpv4" +) + +func TestSubnet_MTUSurvivesTheConversions(t *testing.T) { + c, err := Subnet{Network: "10.0.5.0/24", InterfaceIP: "10.0.5.1", MTU: 1450}.toConfig() + if err != nil { + t.Fatalf("toConfig : %v", err) + } + if c.MTU != 1450 { + t.Errorf("toConfig : mtu %d", c.MTU) + } + if got := subnetFromConfig(c).MTU; got != 1450 { + t.Errorf("subnetFromConfig : mtu %d", got) + } + canonical, err := CanonicalSubnet(Subnet{Network: "10.0.5.0/24", InterfaceIP: "10.0.5.1", MTU: 1450}) + if err != nil || canonical.MTU != 1450 { + t.Errorf("CanonicalSubnet : %+v, %v", canonical, err) + } +} + +func TestLeaseFromReply_ShowsTheMTU(t *testing.T) { + _, network, _ := net.ParseCIDR("10.0.5.0/24") + mac, _ := net.ParseMAC("00:22:33:00:00:0a") + c := dhcpd.SubnetConfig{Network: network, InterfaceIP: net.ParseIP("10.0.5.1"), MTU: 1450} + h := dhcpd.Host{MAC: mac, IP: net.ParseIP("10.0.5.10")} + req, err := dhcpv4.New(dhcpv4.WithMessageType(dhcpv4.MessageTypeRequest), dhcpv4.WithHwAddr(mac)) + if err != nil { + t.Fatal(err) + } + reply, err := dhcpd.BuildReply(c, h, req) + if err != nil { + t.Fatalf("BuildReply : %v", err) + } + if got := leaseFromReply(mac, reply).MTU; got != 1450 { + t.Errorf("lease.MTU = %d, attendu 1450", got) + } +} diff --git a/internal/api/dhcp/server.go b/internal/api/dhcp/server.go index 879ac58..7ec50d4 100644 --- a/internal/api/dhcp/server.go +++ b/internal/api/dhcp/server.go @@ -186,5 +186,8 @@ func leaseFromReply(mac net.HardwareAddr, reply *dhcpv4.DHCPv4) *Lease { for _, route := range reply.ClasslessStaticRoute() { lease.Routes = append(lease.Routes, route.Dest.String()+" via "+route.Router.String()) } + if mtu, err := dhcpv4.GetUint16(dhcpv4.OptionInterfaceMTU, reply.Options); err == nil { + lease.MTU = mtu + } return lease } diff --git a/internal/config/agent/network.go b/internal/config/agent/network.go new file mode 100644 index 0000000..7ee02e0 --- /dev/null +++ b/internal/config/agent/network.go @@ -0,0 +1,52 @@ +package configuration + +import "fmt" + +const ( + MTUVM = 1500 + MinMTUVM = 1280 + MTUUnderlay = 9000 + VXLANOverhead = 50 +) + +type Network struct { + MTUVM int `mapstructure:"mtu_vm"` + AllowMTUVMBelow1500 bool `mapstructure:"allow_mtu_vm_below_1500"` + AllowMTUUnderlayBelow9000 bool `mapstructure:"allow_mtu_underlay_below_9000"` +} + +func (n Network) VM() int { + if n.MTUVM == 0 { + return MTUVM + } + return n.MTUVM +} + +func (n Network) Validate() error { + switch { + case n.MTUVM > MTUVM: + return fmt.Errorf("network.mtu_vm %d is above %d", n.MTUVM, MTUVM) + case n.MTUVM < MinMTUVM: + return fmt.Errorf("network.mtu_vm %d is below the minimum %d", n.MTUVM, MinMTUVM) + case n.MTUVM < MTUVM && !n.AllowMTUVMBelow1500: + return fmt.Errorf("network.mtu_vm %d is below %d: set network.allow_mtu_vm_below_1500 to allow it", n.MTUVM, MTUVM) + } + return nil +} + +func (n Network) CheckUnderlay(iface string, mtu int) error { + if mtu != MTUUnderlay && !n.AllowMTUUnderlayBelow9000 { + return fmt.Errorf("underlay %s has mtu %d, %d expected: set network.allow_mtu_underlay_below_9000 to allow another value", iface, mtu, MTUUnderlay) + } + if mtu < n.VM()+VXLANOverhead { + return fmt.Errorf("underlay %s has mtu %d, below network.mtu_vm %d plus %d bytes of vxlan header", iface, mtu, n.VM(), VXLANOverhead) + } + return nil +} + +func (n Network) CheckBridge(iface string, mtu int) error { + if mtu < n.VM() { + return fmt.Errorf("bridge %s has mtu %d, below network.mtu_vm %d", iface, mtu, n.VM()) + } + return nil +} diff --git a/internal/config/agent/network_test.go b/internal/config/agent/network_test.go new file mode 100644 index 0000000..6c475dd --- /dev/null +++ b/internal/config/agent/network_test.go @@ -0,0 +1,98 @@ +package configuration + +import ( + "strings" + "testing" +) + +func TestLoadConfig_NetworkDefauts(t *testing.T) { + cfg, err := LoadConfig(writeYAML(t, "")) + if err != nil { + t.Fatalf("LoadConfig a échoué : %v", err) + } + if cfg.Network.MTUVM != 1500 || cfg.Network.AllowMTUVMBelow1500 || cfg.Network.AllowMTUUnderlayBelow9000 { + t.Errorf("network par défaut : %+v", cfg.Network) + } +} + +func TestLoadConfig_MTUVMRefuseSansOption(t *testing.T) { + if _, err := LoadConfig(writeYAML(t, "network:\n mtu_vm: 1450\n")); err == nil || !strings.Contains(err.Error(), "allow_mtu_vm_below_1500") { + t.Errorf("mtu_vm 1450 sans option : %v", err) + } + cfg, err := LoadConfig(writeYAML(t, "network:\n mtu_vm: 1450\n allow_mtu_vm_below_1500: true\n")) + if err != nil || cfg.Network.MTUVM != 1450 { + t.Errorf("mtu_vm 1450 avec option : %v, %+v", err, cfg) + } +} + +func TestNetworkValidate(t *testing.T) { + cases := []struct { + n Network + ok bool + }{ + {Network{MTUVM: 1500}, true}, + {Network{MTUVM: 1501}, false}, + {Network{MTUVM: 9000, AllowMTUVMBelow1500: true}, false}, + {Network{MTUVM: 1499}, false}, + {Network{MTUVM: 1499, AllowMTUVMBelow1500: true}, true}, + {Network{MTUVM: 1280, AllowMTUVMBelow1500: true}, true}, + {Network{MTUVM: 1279, AllowMTUVMBelow1500: true}, false}, + {Network{MTUVM: 0, AllowMTUVMBelow1500: true}, false}, + } + for _, c := range cases { + if err := c.n.Validate(); (err == nil) != c.ok { + t.Errorf("Validate(%+v) = %v", c.n, err) + } + } +} + +func TestNetworkCheckUnderlay(t *testing.T) { + n := Network{MTUVM: 1500} + if err := n.CheckUnderlay("br-000000", 9000); err != nil { + t.Errorf("9000 : %v", err) + } + for _, m := range []int{9216, 8999, 1550} { + if err := n.CheckUnderlay("br-000000", m); err == nil || !strings.Contains(err.Error(), "allow_mtu_underlay_below_9000") { + t.Errorf("%d sans option : %v", m, err) + } + } + n.AllowMTUUnderlayBelow9000 = true + if err := n.CheckUnderlay("br-000000", 1550); err != nil { + t.Errorf("1550 avec option : %v", err) + } + if err := n.CheckUnderlay("br-000000", 1549); err == nil || !strings.Contains(err.Error(), "vxlan header") { + t.Errorf("1549 avec option, mtu_vm 1500 : %v", err) + } + n.MTUVM = 1400 + if err := n.CheckUnderlay("br-000000", 1450); err != nil { + t.Errorf("1450 pour mtu_vm 1400 : %v", err) + } + if err := (Network{MTUVM: 8960}).CheckUnderlay("br-000000", 9000); err == nil { + t.Error("mtu_vm 8960 + 50 dépasse 9000") + } +} + +func TestNetworkVMIs1500WhenUnset(t *testing.T) { + if got := (Network{}).VM(); got != 1500 { + t.Errorf("VM() d'une section vide = %d", got) + } + if got := (Network{MTUVM: 1400}).VM(); got != 1400 { + t.Errorf("VM() = %d, attendu 1400", got) + } + if err := (Network{}).CheckUnderlay("br-000000", 1549); err == nil { + t.Error("section vide : 1549 doit être refusé (mtu_vm 1500 + 50)") + } +} + +func TestNetworkCheckBridge(t *testing.T) { + n := Network{MTUVM: 1500} + if err := n.CheckBridge("br-lan", 1500); err != nil { + t.Errorf("1500 : %v", err) + } + if err := n.CheckBridge("br-000000", 9000); err != nil { + t.Errorf("9000 : %v", err) + } + if err := n.CheckBridge("br-lan", 1499); err == nil || !strings.Contains(err.Error(), "br-lan") { + t.Errorf("1499 : %v", err) + } +} diff --git a/internal/config/agent/struct.go b/internal/config/agent/struct.go index 17ddd43..86a6fd7 100644 --- a/internal/config/agent/struct.go +++ b/internal/config/agent/struct.go @@ -55,6 +55,7 @@ type Config struct { Enabled bool `mapstructure:"enabled"` IntervalSeconds int `mapstructure:"interval_seconds"` } `mapstructure:"watchdog"` + Network Network `mapstructure:"network"` BGP BGP `mapstructure:"bgp"` DefaultInterface string `mapstructure:"default_interface"` Interfaces map[string]string `mapstructure:"interfaces"` @@ -90,6 +91,9 @@ func LoadConfig(path string) (*Config, error) { v.SetDefault("default_interface", "br-000000") v.SetDefault("logger.level", "info") v.SetDefault("logger.debug", false) + v.SetDefault("network.mtu_vm", MTUVM) + v.SetDefault("network.allow_mtu_vm_below_1500", false) + v.SetDefault("network.allow_mtu_underlay_below_9000", false) if err := v.ReadInConfig(); err != nil && !errors.Is(err, os.ErrNotExist) { return nil, fmt.Errorf("read %s: %w", path, err) @@ -99,6 +103,9 @@ func LoadConfig(path string) (*Config, error) { if err := v.Unmarshal(&cfg); err != nil { return nil, err } + if err := cfg.Network.Validate(); err != nil { + return nil, fmt.Errorf("%s: %w", path, err) + } return &cfg, nil } diff --git a/internal/dhcp/generate.go b/internal/dhcp/generate.go index 6724b62..ccd39b3 100644 --- a/internal/dhcp/generate.go +++ b/internal/dhcp/generate.go @@ -31,6 +31,7 @@ func GenerateConfig(c Config) (string, error) { fmt.Fprintf(&sb, "dhcp-option=3\n") } fmt.Fprintf(&sb, "dhcp-option=6,1.1.1.1,8.8.8.8\n") + fmt.Fprintf(&sb, "dhcp-option=26,%d\n", c.interfaceMTU()) fmt.Fprintf(&sb, "dhcp-hostsdir=%s\n", HostsDir(c.ConfDir, c.Name)) fmt.Fprintf(&sb, "dhcp-optsdir=%s\n", OptsDir(c.ConfDir, c.Name)) @@ -44,6 +45,13 @@ func GenerateConfig(c Config) (string, error) { return outPath, os.WriteFile(outPath, []byte(sb.String()), 0644) } +func (c Config) interfaceMTU() int { + if c.MTU == 0 { + return 1500 + } + return c.MTU +} + func classlessRoutes(c Config) []string { nextHop := c.InterfaceIP.String() diff --git a/internal/dhcp/mtu_test.go b/internal/dhcp/mtu_test.go new file mode 100644 index 0000000..e4ea54f --- /dev/null +++ b/internal/dhcp/mtu_test.go @@ -0,0 +1,20 @@ +package dhcp + +import ( + "strings" + "testing" +) + +func TestGenerateConfig_CarriesTheInterfaceMTU(t *testing.T) { + c := newConf(t, "192.168.1.0/29") + c.MTU = 1450 + if content := confLines(t, c); !strings.Contains(content, "dhcp-option=26,1450\n") { + t.Errorf("option 26 absente :\n%s", content) + } +} + +func TestGenerateConfig_InterfaceMTUIs1500WhenUnset(t *testing.T) { + if content := confLines(t, newConf(t, "192.168.1.0/29")); !strings.Contains(content, "dhcp-option=26,1500\n") { + t.Errorf("option 26 absente :\n%s", content) + } +} diff --git a/internal/dhcp/struct.go b/internal/dhcp/struct.go index 44d51a7..1d8ca11 100644 --- a/internal/dhcp/struct.go +++ b/internal/dhcp/struct.go @@ -15,4 +15,5 @@ type Config struct { ConfDir string Listen string Except string + MTU int } diff --git a/internal/dhcpbackend/backend.go b/internal/dhcpbackend/backend.go index 9d61510..cfdf47c 100644 --- a/internal/dhcpbackend/backend.go +++ b/internal/dhcpbackend/backend.go @@ -16,6 +16,7 @@ type Subnet struct { InterfaceIP net.IP VPCRoute *net.IPNet DefaultGateway net.IP + MTU int } func (s Subnet) Instance() string { diff --git a/internal/dhcpbackend/dnsmasq.go b/internal/dhcpbackend/dnsmasq.go index e6ac72b..c21df2e 100644 --- a/internal/dhcpbackend/dnsmasq.go +++ b/internal/dhcpbackend/dnsmasq.go @@ -35,6 +35,7 @@ func (b Dnsmasq) config(s Subnet) dhcp.Config { InterfaceIP: s.InterfaceIP, VPCRoute: s.VPCRoute, DefaultGateway: s.DefaultGateway, + MTU: s.MTU, } if s.Listen != "" && s.Listen != s.Bridge { c.Listen = s.Listen diff --git a/internal/dhcpbackend/dnsmasq_test.go b/internal/dhcpbackend/dnsmasq_test.go index 4f2a69a..d83a506 100644 --- a/internal/dhcpbackend/dnsmasq_test.go +++ b/internal/dhcpbackend/dnsmasq_test.go @@ -112,6 +112,12 @@ func TestDnsmasqSetVM_RejectsAVMWithoutReservation(t *testing.T) { } } +func TestDnsmasqConfig_CarriesTheMTU(t *testing.T) { + if c := (Dnsmasq{}).config(Subnet{VPC: "vp-s9", Bridge: "br-s9r1", MTU: 1450}); c.MTU != 1450 { + t.Errorf("mtu = %d, want 1450", c.MTU) + } +} + func TestDnsmasqConfig_ListenOnGatewayExcludesTheBridge(t *testing.T) { c := Dnsmasq{}.config(Subnet{VPC: "vp-s9", Bridge: "br-s9r1", Listen: "gw-s9r1"}) if c.Listen != "gw-s9r1" || c.Except != "br-s9r1" { diff --git a/internal/dhcpbackend/two.go b/internal/dhcpbackend/two.go index ec501e2..6c780cd 100644 --- a/internal/dhcpbackend/two.go +++ b/internal/dhcpbackend/two.go @@ -79,6 +79,7 @@ func (b Two) pushSubnet(s Subnet) error { subnet := dhcpapi.Subnet{ Network: s.Network.String(), InterfaceIP: s.InterfaceIP.String(), + MTU: s.MTU, } if s.VPCRoute != nil { subnet.VPCRoute = s.VPCRoute.String() diff --git a/internal/dhcpbackend/two_test.go b/internal/dhcpbackend/two_test.go index a63521c..21df32d 100644 --- a/internal/dhcpbackend/two_test.go +++ b/internal/dhcpbackend/two_test.go @@ -93,6 +93,18 @@ func TestTwoPushSubnet_ReachesTheStore(t *testing.T) { } } +func TestTwoPushSubnet_CarriesTheMTU(t *testing.T) { + b, s, store := twoBackend(t) + s.MTU = 1450 + + if err := b.pushSubnet(s); err != nil { + t.Fatalf("pushSubnet: %v", err) + } + if got, _ := store.Subnet(); got.MTU != 1450 { + t.Errorf("mtu = %d, want 1450", got.MTU) + } +} + func TestTwoPushSubnet_OmitsAnAbsentVPCRouteAndGateway(t *testing.T) { b, s, store := twoBackend(t) s.VPCRoute = nil diff --git a/internal/dhcpd/dhcpd.go b/internal/dhcpd/dhcpd.go index 3d1f95b..c2db3dd 100644 --- a/internal/dhcpd/dhcpd.go +++ b/internal/dhcpd/dhcpd.go @@ -19,6 +19,14 @@ type SubnetConfig struct { InterfaceIP net.IP VPCRoute *net.IPNet DefaultGateway net.IP + MTU int +} + +func (c SubnetConfig) InterfaceMTU() int { + if c.MTU == 0 { + return 1500 + } + return c.MTU } type Host struct { diff --git a/internal/dhcpd/mtu_test.go b/internal/dhcpd/mtu_test.go new file mode 100644 index 0000000..4691191 --- /dev/null +++ b/internal/dhcpd/mtu_test.go @@ -0,0 +1,68 @@ +package dhcpd + +import ( + "os" + "testing" + + "github.com/insomniacslk/dhcp/dhcpv4" +) + +func replyMTU(t *testing.T, c SubnetConfig) uint16 { + t.Helper() + h := testHost(t) + reply, err := BuildReply(c, h, request(t, dhcpv4.MessageTypeRequest, h.MAC)) + if err != nil { + t.Fatalf("BuildReply: %v", err) + } + m, err := dhcpv4.GetUint16(dhcpv4.OptionInterfaceMTU, reply.Options) + if err != nil { + t.Fatalf("option 26 absente : %v", err) + } + return m +} + +func TestBuildReply_CarriesTheInterfaceMTU(t *testing.T) { + c := testConfig(t) + c.MTU = 1450 + if got := replyMTU(t, c); got != 1450 { + t.Errorf("option 26 = %d, attendu 1450", got) + } +} + +func TestBuildReply_InterfaceMTUIs1500WhenUnset(t *testing.T) { + if got := replyMTU(t, testConfig(t)); got != 1500 { + t.Errorf("option 26 = %d, attendu 1500", got) + } +} + +func TestStore_MTUIsPersisted(t *testing.T) { + s, path := loadedStore(t) + c := fullConfig(t) + c.MTU = 1450 + if err := s.SetSubnet(c); err != nil { + t.Fatalf("SetSubnet: %v", err) + } + reloaded := NewStore(path) + if err := reloaded.Load(); err != nil { + t.Fatalf("Load: %v", err) + } + if got, _ := reloaded.Subnet(); got.MTU != 1450 { + t.Errorf("mtu relu = %d, attendu 1450", got.MTU) + } +} + +func TestStore_StateWithoutMTUIsServedAt1500(t *testing.T) { + path := statePath(t) + legacy := `{"subnet":{"network":"10.0.5.0/24","interface_ip":"10.0.5.1"},"hosts":[]}` + if err := os.WriteFile(path, []byte(legacy), 0600); err != nil { + t.Fatal(err) + } + s := NewStore(path) + if err := s.Load(); err != nil { + t.Fatalf("Load: %v", err) + } + c, _ := s.Subnet() + if got := replyMTU(t, c); got != 1500 { + t.Errorf("ancien état sans mtu : option 26 = %d, attendu 1500", got) + } +} diff --git a/internal/dhcpd/reply.go b/internal/dhcpd/reply.go index a603b41..cc340e1 100644 --- a/internal/dhcpd/reply.go +++ b/internal/dhcpd/reply.go @@ -88,6 +88,7 @@ func BuildReply(c SubnetConfig, h Host, req *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, err dhcpv4.WithOption(dhcpv4.OptServerIdentifier(c.InterfaceIP)), dhcpv4.WithOption(dhcpv4.OptDNS(DNSServers()...)), dhcpv4.WithOption(dhcpv4.OptClasslessStaticRoute(routes...)), + dhcpv4.WithOption(dhcpv4.OptGeneric(dhcpv4.OptionInterfaceMTU, dhcpv4.Uint16(c.InterfaceMTU()).ToBytes())), } if h.DefaultRoute && c.DefaultGateway != nil { mods = append(mods, dhcpv4.WithOption(dhcpv4.OptRouter(c.DefaultGateway))) diff --git a/internal/dhcpd/store.go b/internal/dhcpd/store.go index 86b756d..d8d84e0 100644 --- a/internal/dhcpd/store.go +++ b/internal/dhcpd/store.go @@ -20,6 +20,7 @@ type diskSubnet struct { InterfaceIP string `json:"interface_ip"` VPCRoute string `json:"vpc_route,omitempty"` DefaultGateway string `json:"default_gateway,omitempty"` + MTU int `json:"mtu,omitempty"` } type diskHost struct { @@ -98,7 +99,7 @@ func subnetFromDisk(d diskSubnet) (SubnetConfig, error) { return SubnetConfig{}, ErrNoInterfaceIP } - c := SubnetConfig{Network: network, InterfaceIP: interfaceIP} + c := SubnetConfig{Network: network, InterfaceIP: interfaceIP, MTU: d.MTU} if d.VPCRoute != "" { if _, c.VPCRoute, err = net.ParseCIDR(d.VPCRoute); err != nil { @@ -232,6 +233,7 @@ func (s *Store) persist() error { sub := diskSubnet{ Network: s.subnet.Network.String(), InterfaceIP: s.subnet.InterfaceIP.String(), + MTU: s.subnet.MTU, } if s.subnet.VPCRoute != nil { sub.VPCRoute = s.subnet.VPCRoute.String() diff --git a/internal/dispatcher/agent/helpers_test.go b/internal/dispatcher/agent/helpers_test.go index 2e6cbcc..d404d99 100644 --- a/internal/dispatcher/agent/helpers_test.go +++ b/internal/dispatcher/agent/helpers_test.go @@ -45,3 +45,7 @@ func (m mockCmd) Prepare(db *badger.DB, cfg *configuration.Config) error { func (m mockCmd) Execute(db *badger.DB, cfg *configuration.Config) error { return m.executeFn(db, cfg) } + +func init() { + LinkMTU = func(string) (int, error) { return 9000, nil } +} diff --git a/internal/dispatcher/agent/mtu_test.go b/internal/dispatcher/agent/mtu_test.go new file mode 100644 index 0000000..2313284 --- /dev/null +++ b/internal/dispatcher/agent/mtu_test.go @@ -0,0 +1,88 @@ +package dispatcher + +import ( + "strings" + "testing" + + "git.g3e.fr/syonad/two/pkg/db/kv" +) + +func withLinkMTU(t *testing.T, mtus map[string]int) { + t.Helper() + previous := LinkMTU + LinkMTU = func(name string) (int, error) { return mtus[name], nil } + t.Cleanup(func() { LinkMTU = previous }) +} + +func TestCreateSubnetCommand_Prepare_VxlanRefusesAnUnderlayOtherThan9000(t *testing.T) { + withLinkMTU(t, map[string]int{"br-vms": 1500, "br-default": 9000}) + _, db := newTestDispatcher(t) + kv.AddInDB(db, "vpc/vpc-1/state", "running") + + cmd := CreateSubnetCommand{Name: "sn-1", VPC: "vpc-1", VxlanID: 100, IfaceType: "vms", CIDR: "10.0.0.0/24"} + err := cmd.Prepare(db, testCfg()) + if err == nil || !strings.Contains(err.Error(), "underlay br-vms has mtu 1500") { + t.Fatalf("underlay br-vms à 1500 : %v", err) + } + if _, err := kv.GetFromDB(db, "subnet/sn-1/state"); err == nil { + t.Error("aucune clé ne doit être écrite après un refus") + } + + cmd.IfaceType = "" + if err := cmd.Prepare(db, testCfg()); err != nil { + t.Errorf("default_interface à 9000 : %v", err) + } +} + +func TestCreateSubnetCommand_Prepare_VxlanUnderlayBelow9000WithTheOption(t *testing.T) { + withLinkMTU(t, map[string]int{"br-vms": 1549}) + cfg := testCfg() + cfg.Network.AllowMTUUnderlayBelow9000 = true + _, db := newTestDispatcher(t) + kv.AddInDB(db, "vpc/vpc-1/state", "running") + + cmd := CreateSubnetCommand{Name: "sn-1", VPC: "vpc-1", VxlanID: 100, IfaceType: "vms", CIDR: "10.0.0.0/24"} + if err := cmd.Prepare(db, cfg); err == nil || !strings.Contains(err.Error(), "vxlan header") { + t.Fatalf("1549 pour mtu_vm 1500 : %v", err) + } + cfg.Network.MTUVM = 1499 + if err := cmd.Prepare(db, cfg); err != nil { + t.Errorf("1549 pour mtu_vm 1499 : %v", err) + } +} + +func TestCreateSubnetCommand_Prepare_BridgeChecksTheBridgeWithoutVxlanHeader(t *testing.T) { + withLinkMTU(t, map[string]int{"br-vms": 1500, "br-default": 1499}) + _, db := newTestDispatcher(t) + kv.AddInDB(db, "vpc/vpc-1/state", "running") + + ok := CreateSubnetCommand{Name: "sn-1", VPC: "vpc-1", Mode: "bridge", IfaceType: "vms", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24"} + if err := ok.Prepare(db, testCfg()); err != nil { + t.Errorf("bridge br-vms à 1500 : %v", err) + } + small := CreateSubnetCommand{Name: "sn-2", VPC: "vpc-1", Mode: "bridge", InterfaceIP: "10.0.1.1", CIDR: "10.0.1.0/24"} + if err := small.Prepare(db, testCfg()); err == nil || !strings.Contains(err.Error(), "bridge br-default has mtu 1499") { + t.Errorf("bridge br-default à 1499 : %v", err) + } + if _, err := kv.GetFromDB(db, "subnet/sn-2/state"); err == nil { + t.Error("aucune clé ne doit être écrite après un refus") + } +} + +func TestCreateVPCCommand_Prepare_L3VNIChecksTheUnderlay(t *testing.T) { + cfg := bgpConfig() + cfg.DefaultInterface = "br-000000" + withLinkMTU(t, map[string]int{"br-000000": 1500}) + _, db := newTestDispatcher(t) + + err := (CreateVPCCommand{Name: "vpc-1", CIDR: "10.0.0.0/16", L3VNI: 4001}).Prepare(db, cfg) + if err == nil || !strings.Contains(err.Error(), "underlay br-000000") { + t.Fatalf("underlay br-000000 à 1500 : %v", err) + } + if _, err := kv.GetFromDB(db, "vpc/vpc-1/state"); err == nil { + t.Error("aucune clé ne doit être écrite après un refus") + } + if err := (CreateVPCCommand{Name: "vpc-2", CIDR: "10.0.0.0/16"}).Prepare(db, cfg); err != nil { + t.Errorf("un VPC sans l3vni ne contrôle pas l'underlay : %v", err) + } +} diff --git a/internal/dispatcher/agent/subnet_commands.go b/internal/dispatcher/agent/subnet_commands.go index e5807ba..d97de05 100644 --- a/internal/dispatcher/agent/subnet_commands.go +++ b/internal/dispatcher/agent/subnet_commands.go @@ -63,6 +63,16 @@ func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) e if !ok { localIface = cfg.DefaultInterface } + switch c.Mode { + case subnet.ModeVxlan: + if err := checkUnderlay(cfg, localIface); err != nil { + return err + } + case subnet.ModeBridge: + if err := checkBridge(cfg, localIface); err != nil { + return err + } + } state.Set(db, c.Key(), state.Creating) kv.AddInDB(db, "subnet/"+c.Name+"/vpc", c.VPC) kv.AddInDB(db, "subnet/"+c.Name+"/mode", c.Mode) diff --git a/internal/dispatcher/agent/vpc_commands.go b/internal/dispatcher/agent/vpc_commands.go index 7404342..df87004 100644 --- a/internal/dispatcher/agent/vpc_commands.go +++ b/internal/dispatcher/agent/vpc_commands.go @@ -9,6 +9,7 @@ import ( configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/internal/l3vni" + "git.g3e.fr/syonad/two/internal/netif" "git.g3e.fr/syonad/two/internal/state" "git.g3e.fr/syonad/two/internal/vpc" "git.g3e.fr/syonad/two/pkg/db/kv" @@ -34,6 +35,9 @@ func (c CreateVPCCommand) Prepare(db *badger.DB, cfg *configuration.Config) erro if err := c.checkL3VNI(db, cfg); err != nil { return err } + if err := checkUnderlay(cfg, cfg.DefaultInterface); err != nil { + return err + } } if err := kv.AddInDB(db, "vpc/"+c.Name+"/cidr", c.CIDR); err != nil { return err @@ -46,6 +50,24 @@ func (c CreateVPCCommand) Prepare(db *badger.DB, cfg *configuration.Config) erro return state.Set(db, c.Key(), state.Creating) } +var LinkMTU = netif.LinkMTU + +func checkUnderlay(cfg *configuration.Config, iface string) error { + m, err := LinkMTU(iface) + if err != nil { + return fmt.Errorf("read mtu of underlay %s: %w", iface, err) + } + return cfg.Network.CheckUnderlay(iface, m) +} + +func checkBridge(cfg *configuration.Config, iface string) error { + m, err := LinkMTU(iface) + if err != nil { + return fmt.Errorf("read mtu of bridge %s: %w", iface, err) + } + return cfg.Network.CheckBridge(iface, m) +} + func (c CreateVPCCommand) checkL3VNI(db *badger.DB, cfg *configuration.Config) error { if err := l3vni.Valid(c.L3VNI); err != nil { return err diff --git a/internal/l3vni/l3.go b/internal/l3vni/l3.go index 3558274..65bd453 100644 --- a/internal/l3vni/l3.go +++ b/internal/l3vni/l3.go @@ -14,8 +14,6 @@ import ( "github.com/dgraph-io/badger/v4" ) -const l3MTU = 1500 - var ( transitHost = &net.IPNet{IP: net.IPv4(169, 254, 0, 1).To4(), Mask: net.CIDRMask(30, 32)} transitNetns = &net.IPNet{IP: net.IPv4(169, 254, 0, 2).To4(), Mask: net.CIDRMask(30, 32)} @@ -76,6 +74,7 @@ func createL3(h host, cfg *configuration.Config, v l3VPC) error { if err != nil { return fmt.Errorf("vtep: %w", err) } + mtu := cfg.Network.VM() rmac, err := RouterMAC(vtep) if err != nil { return err @@ -85,12 +84,12 @@ func createL3(h host, cfg *configuration.Config, v l3VPC) error { run func() error }{ {"create " + v.vrf(), func() error { return h.CreateVRF(v.vrf(), v.vni) }}, - {"create " + v.bridge(), func() error { return h.CreateBridge(v.bridge(), l3MTU, rmac) }}, + {"create " + v.bridge(), func() error { return h.CreateBridge(v.bridge(), mtu, rmac) }}, {"attach " + v.bridge(), func() error { return h.SetMaster(v.bridge(), v.vrf()) }}, - {"create " + v.vxlan(), func() error { return h.CreateVxlan(v.vxlan(), int(v.vni), cfg.DefaultInterface, l3MTU) }}, + {"create " + v.vxlan(), func() error { return h.CreateVxlan(v.vxlan(), int(v.vni), cfg.DefaultInterface, mtu) }}, {"attach " + v.vxlan(), func() error { return h.SetMaster(v.vxlan(), v.bridge()) }}, {"set up " + v.vxlan(), func() error { return h.LinkUp("", v.vxlan()) }}, - {"create " + v.vethHost(), func() error { return h.CreateVeth(v.vethHost(), v.vethNetns(), v.netns, l3MTU) }}, + {"create " + v.vethHost(), func() error { return h.CreateVeth(v.vethHost(), v.vethNetns(), v.netns, mtu) }}, {"attach " + v.vethHost(), func() error { return h.SetMaster(v.vethHost(), v.vrf()) }}, {"address " + v.vethHost(), func() error { return h.AddrAdd("", v.vethHost(), transitHost) }}, {"set up " + v.vethHost(), func() error { return h.LinkUp("", v.vethHost()) }}, diff --git a/internal/l3vni/l3_test.go b/internal/l3vni/l3_test.go index ee3f9bc..17e0c8c 100644 --- a/internal/l3vni/l3_test.go +++ b/internal/l3vni/l3_test.go @@ -113,18 +113,20 @@ func labL3(t *testing.T) l3VPC { func TestCreateL3FollowsTheLabRecipe(t *testing.T) { f := &fakeHost{} - if err := createL3(f, bgpConfig(), labL3(t)); err != nil { + cfg := bgpConfig() + cfg.Network.MTUVM = 1450 + if err := createL3(f, cfg, labL3(t)); err != nil { t.Fatal(err) } want := []string{ "vtep br-000000", "vrf vrf-s7 table 2700", - "bridge brl3-s7 mtu 1500 mac 02:02:c0:a8:0e:0b", + "bridge brl3-s7 mtu 1450 mac 02:02:c0:a8:0e:0b", "master brl3-s7 vrf-s7", - "vxlan vxl3-s7 id 2700 dev br-000000 mtu 1500", + "vxlan vxl3-s7 id 2700 dev br-000000 mtu 1450", "master vxl3-s7 brl3-s7", "up [] vxl3-s7", - "veth l3-s7-o peer l3-s7-i netns vp-s7 mtu 1500", + "veth l3-s7-o peer l3-s7-i netns vp-s7 mtu 1450", "master l3-s7-o vrf-s7", "addr [] l3-s7-o 169.254.0.1/30", "up [] l3-s7-o", diff --git a/internal/netif/link.go b/internal/netif/link.go index ff76352..56fdb87 100644 --- a/internal/netif/link.go +++ b/internal/netif/link.go @@ -38,3 +38,11 @@ func LinkIPv4(name string) ([]net.IP, error) { } return ips, nil } + +func LinkMTU(name string) (int, error) { + link, err := netlink.LinkByName(name) + if err != nil { + return 0, err + } + return link.Attrs().MTU, nil +} diff --git a/internal/netif/tap_linux.go b/internal/netif/tap_linux.go index 15313af..e9f7a8c 100644 --- a/internal/netif/tap_linux.go +++ b/internal/netif/tap_linux.go @@ -9,12 +9,12 @@ import ( "github.com/vishvananda/netlink" ) -func CreateTap(tapID int, bridgeName, vpcName string) error { +func CreateTap(tapID int, bridgeName, vpcName string, mtu int) error { name := fmt.Sprintf("tap%d", tapID) return netns.Call(vpcName, func() error { tap := &netlink.Tuntap{ - LinkAttrs: netlink.LinkAttrs{Name: name}, + LinkAttrs: netlink.LinkAttrs{Name: name, MTU: mtu}, Mode: netlink.TUNTAP_MODE_TAP, } if err := netlink.LinkAdd(tap); err != nil { diff --git a/internal/netif/tap_other.go b/internal/netif/tap_other.go index 18afcbe..7257f22 100644 --- a/internal/netif/tap_other.go +++ b/internal/netif/tap_other.go @@ -4,7 +4,7 @@ package netif import "errors" -func CreateTap(_ int, _, _ string) error { +func CreateTap(_ int, _, _ string, _ int) error { return errors.New("netif: tap not supported on this platform") } diff --git a/internal/qemu/args.go b/internal/qemu/args.go index 4aa7327..f97a265 100644 --- a/internal/qemu/args.go +++ b/internal/qemu/args.go @@ -102,9 +102,13 @@ func buildArgs(cfg Config) ([]string, error) { return nil, fmt.Errorf("vm %s has %d interfaces, the pci map holds %d", cfg.Name, len(cfg.NICs), maxNICs) } for i, n := range cfg.NICs { + device := fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s,bus=pci.0,addr=0x%02x", i, n.Mac, firstNICSlot+i) + if n.MTU > 0 { + device += fmt.Sprintf(",host_mtu=%d", n.MTU) + } args = append(args, "-netdev", fmt.Sprintf("tap,id=net%d,ifname=tap%d,script=no,downscript=no", i, n.TapID), - "-device", fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s,bus=pci.0,addr=0x%02x", i, n.Mac, firstNICSlot+i), + "-device", device, ) } diff --git a/internal/qemu/args_test.go b/internal/qemu/args_test.go index 6864994..58a91ee 100644 --- a/internal/qemu/args_test.go +++ b/internal/qemu/args_test.go @@ -17,7 +17,7 @@ func devicesOf(args []string) []string { func TestBuildArgs_DiskSerialIsDeclaredDev(t *testing.T) { args, err := buildArgs(Config{ Name: "vm1", - NICs: []NICConfig{{TapID: 1, Mac: "52:54:00:00:00:01"}}, + NICs: []NICConfig{{TapID: 1, Mac: "52:54:00:00:00:01", MTU: 1450}, {TapID: 2, Mac: "52:54:00:00:00:02"}}, Disks: []DiskConfig{ {Path: "/v/b.qcow2", Dev: "xvdb"}, {Path: "/v/root.qcow2", Dev: "vda"}, @@ -33,7 +33,8 @@ func TestBuildArgs_DiskSerialIsDeclaredDev(t *testing.T) { "virtio-blk-pci,drive=vda,bus=pci.0,addr=0x1f,bootindex=1,serial=vda", "scsi-hd,drive=xvda,bus=scsi0.0,scsi-id=0,bootindex=2,serial=xvda", "scsi-hd,drive=xvdb,bus=scsi0.0,scsi-id=1,bootindex=3,serial=xvdb", - "virtio-net-pci,netdev=net0,mac=52:54:00:00:00:01,bus=pci.0,addr=0x03", + "virtio-net-pci,netdev=net0,mac=52:54:00:00:00:01,bus=pci.0,addr=0x03,host_mtu=1450", + "virtio-net-pci,netdev=net1,mac=52:54:00:00:00:02,bus=pci.0,addr=0x04", } got := devicesOf(args) if len(got) != len(want) { diff --git a/internal/qemu/config.go b/internal/qemu/config.go index ed4f445..684223e 100644 --- a/internal/qemu/config.go +++ b/internal/qemu/config.go @@ -14,6 +14,7 @@ type DiskConfig struct { type NICConfig struct { TapID int Mac string + MTU int } type Config struct { diff --git a/internal/subnet/create.go b/internal/subnet/create.go index 5805605..c807a5e 100644 --- a/internal/subnet/create.go +++ b/internal/subnet/create.go @@ -28,6 +28,7 @@ func CreateSubnet(db *badger.DB, subnetName string, cfg *configuration.Config) e if err != nil { return err } + d.mtu = cfg.Network.VM() backend, err := dhcpbackend.New(cfg) if err != nil { @@ -51,7 +52,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba vethE := "v-" + d.subnetID + "-e" vethI := "v-" + d.subnetID + "-i" - if err := netif.CreateVethToNetns(vethE, vethI, "/var/run/netns/"+d.vpc, 1500); err != nil { + if err := netif.CreateVethToNetns(vethE, vethI, "/var/run/netns/"+d.vpc, d.mtu); err != nil { return fmt.Errorf("create veth: %w", err) } @@ -85,7 +86,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba } if err := netns.Call(d.vpc, func() error { - if err := netif.CreateBridge(d.bridge, 1500, gatewayMAC); err != nil { + if err := netif.CreateBridge(d.bridge, d.mtu, gatewayMAC); err != nil { return fmt.Errorf("create bridge: %w", err) } return netif.BridgeSetMaster(vethI, d.bridge) @@ -144,10 +145,10 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba func setupVxlanHost(d subnetData, vethE string) error { vxlanIface := fmt.Sprintf("vxlan-%d", d.vxlanID) - if err := netif.CreateBridge(d.bridge, 1500, nil); err != nil { + if err := netif.CreateBridge(d.bridge, d.mtu, nil); err != nil { return fmt.Errorf("create bridge: %w", err) } - if err := netif.CreateVxlan(vxlanIface, d.vxlanID, d.localIface, 1500); err != nil { + if err := netif.CreateVxlan(vxlanIface, d.vxlanID, d.localIface, d.mtu); err != nil { return fmt.Errorf("create vxlan: %w", err) } if err := netif.BridgeSetMaster(vethE, d.bridge); err != nil { @@ -183,5 +184,6 @@ func startDHCP(subnetName string, d subnetData, backend dhcpbackend.Backend) err InterfaceIP: d.interfaceIP, VPCRoute: vpcRoute, DefaultGateway: defaultGateway, + MTU: d.mtu, }) } diff --git a/internal/subnet/data.go b/internal/subnet/data.go index 43a5cf0..d5caaaa 100644 --- a/internal/subnet/data.go +++ b/internal/subnet/data.go @@ -23,6 +23,7 @@ type subnetData struct { vpcCIDR *net.IPNet defaultRoute bool gateway net.IP + mtu int } func loadSubnet(db *badger.DB, name string) (subnetData, error) { diff --git a/internal/vm/create.go b/internal/vm/create.go index fc2bf0c..17c709d 100644 --- a/internal/vm/create.go +++ b/internal/vm/create.go @@ -42,7 +42,7 @@ func StartVM(db *badger.DB, name string, cfg *configuration.Config) error { } for _, n := range d.nics { - if err := netif.CreateTap(n.tapID, n.bridge, n.vpcName); err != nil { + if err := netif.CreateTap(n.tapID, n.bridge, n.vpcName, cfg.Network.VM()); err != nil { return fmt.Errorf("create tap of interface %d: %w", n.index, err) } } @@ -85,7 +85,7 @@ func StartVM(db *badger.DB, name string, cfg *configuration.Config) error { qNICs := make([]qemu.NICConfig, len(d.nics)) for i, n := range d.nics { - qNICs[i] = qemu.NICConfig{TapID: n.tapID, Mac: n.mac} + qNICs[i] = qemu.NICConfig{TapID: n.tapID, Mac: n.mac, MTU: cfg.Network.VM()} } qcfg := qemu.Config{