1
0
mirror of https://github.com/rtr7/router7.git synced 2024-05-06 15:54:52 +00:00

netconfig: make the MTU configurable

Just in case we need to set it on an uplink0 interface at some point, for example.
This commit is contained in:
Michael Stapelberg
2022-06-15 23:19:43 +02:00
parent fb08bb280c
commit ce66287189
2 changed files with 12 additions and 1 deletions

View File

@ -46,7 +46,8 @@ const goldenInterfaces = `
"hardware_addr": "02:73:53:00:b0:0c",
"spoof_hardware_addr": "02:73:53:00:b0:aa",
"name": "lan0",
"addr": "192.168.42.1/24"
"addr": "192.168.42.1/24",
"mtu": 1492
},
{
"name": "wg0",
@ -393,6 +394,9 @@ func TestNetconfig(t *testing.T) {
if !strings.Contains(string(link), "link/ether 02:73:53:00:b0:aa") {
t.Errorf("lan0 MAC address is not 02:73:53:00:b0:aa")
}
if !strings.Contains(string(link), " mtu 1492 ") {
t.Errorf("lan0 MTU is not 1492 (link: %q)", string(link))
}
addrs, err := exec.Command("ip", "-netns", ns, "address", "show", "dev", "uplink0").Output()
if err != nil {

View File

@ -268,6 +268,7 @@ type InterfaceDetails struct {
Addr string `json:"addr"` // e.g. 192.168.42.1/24
ExtraAddrs []string `json:"extra_addrs"` // e.g. ["192.168.23.1/24"]
ExtraRoutes []Route `json:"extra_routes"`
MTU int `json:"mtu"` // e.g. 1492 for PPPoE connections
}
type BridgeDetails struct {
@ -422,6 +423,12 @@ func applyInterfaces(dir, root string, cfg InterfaceConfig) error {
attr.Name = details.Name
}
if details.MTU != 0 {
if err := netlink.LinkSetMTU(l, details.MTU); err != nil {
return fmt.Errorf("LinkSetMTU(%d): %v", details.MTU, err)
}
}
if spoof := details.SpoofHardwareAddr; spoof != "" {
hwaddr, err := net.ParseMAC(spoof)
if err != nil {