Skip to content

fix: copy route MTU when creating interfaces and routes from net namespace #11857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions runsc/boot/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,29 @@ import (
"gvisor.dev/gvisor/runsc/config"
)

var (
// DefaultLoopbackLink contains IP addresses and routes of "127.0.0.1/8" and
// "::1/8" on "lo" interface.
DefaultLoopbackLink = LoopbackLink{
Name: "lo",
Addresses: []IPWithPrefix{
{Address: net.IP("\x7f\x00\x00\x01"), PrefixLen: 8},
{Address: net.IPv6loopback, PrefixLen: 128},
},
Routes: []Route{
{
Destination: net.IPNet{
IP: net.IPv4(0x7f, 0, 0, 0),
Mask: net.IPv4Mask(0xff, 0, 0, 0),
},
// DefaultLoopbackLink contains IP addresses and routes of "127.0.0.1/8" and
// "::1/8" on "lo" interface.
var DefaultLoopbackLink = LoopbackLink{
Name: "lo",
Addresses: []IPWithPrefix{
{Address: net.IP("\x7f\x00\x00\x01"), PrefixLen: 8},
{Address: net.IPv6loopback, PrefixLen: 128},
},
Routes: []Route{
{
Destination: net.IPNet{
IP: net.IPv4(0x7f, 0, 0, 0),
Mask: net.IPv4Mask(0xff, 0, 0, 0),
},
{
Destination: net.IPNet{
IP: net.IPv6loopback,
Mask: net.IPMask(strings.Repeat("\xff", net.IPv6len)),
},
},
{
Destination: net.IPNet{
IP: net.IPv6loopback,
Mask: net.IPMask(strings.Repeat("\xff", net.IPv6len)),
},
},
}
)
},
}

// Network exposes methods that can be used to configure a network stack.
type Network struct {
Expand All @@ -83,6 +81,7 @@ type Network struct {
type Route struct {
Destination net.IPNet
Gateway net.IP
MTU uint32
}

// DefaultRoute represents a catch all route to the default gateway.
Expand Down Expand Up @@ -224,6 +223,7 @@ func (r *Route) toTcpipRoute(id tcpip.NICID) (tcpip.Route, error) {
Destination: subnet,
Gateway: ipToAddress(r.Gateway),
NIC: id,
MTU: r.MTU,
}, nil
}

Expand Down
5 changes: 5 additions & 0 deletions runsc/sandbox/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ func routesForIface(iface net.Interface, disableIPv6 bool) ([]boot.Route, *boot.
var defv4, defv6 *boot.Route
var routes []boot.Route
for _, r := range rs {
mtu := uint32(r.MTU)

// Is it a default route?
if r.Dst == nil {
if r.Gw == nil {
Expand All @@ -526,6 +528,7 @@ func routesForIface(iface net.Interface, disableIPv6 bool) ([]boot.Route, *boot.
Mask: net.IPMask(net.IPv4zero),
},
Gateway: r.Gw,
MTU: mtu,
}
case header.IPv6AddressSize:
if defv6 != nil {
Expand All @@ -539,6 +542,7 @@ func routesForIface(iface net.Interface, disableIPv6 bool) ([]boot.Route, *boot.
Mask: net.IPMask(net.IPv6zero),
},
Gateway: r.Gw,
MTU: mtu,
}
}
default:
Expand All @@ -555,6 +559,7 @@ func routesForIface(iface net.Interface, disableIPv6 bool) ([]boot.Route, *boot.
routes = append(routes, boot.Route{
Destination: dst,
Gateway: r.Gw,
MTU: mtu,
})
}
return routes, defv4, defv6, nil
Expand Down