Skip to content
Snippets Groups Projects
Commit 84b47e5d authored by kaiyou's avatar kaiyou
Browse files

Improve router advertisement configuration

parent 84dfac3d
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ import (
"github.com/vishvananda/netlink"
)
const ACCEPT_RA = "net.ipv6.conf.eth0.accept_ra_pinfo"
const ACCEPT_PINFO = "net.ipv6.conf.eth0.accept_ra_pinfo"
const ACCEPT_DFTRTR = "net.ipv6.conf.eth0.accept_ra_defrtr"
......@@ -44,6 +45,10 @@ func (c *Container) SetupNetworking(etc string) error {
return fmt.Errorf("could not set the interface up: %w", err)
}
// Setup addresses and routes
err = setupRA(iface)
if err != nil {
return fmt.Errorf("could not enable RA: %w", err)
}
err = setupAddress(iface, c.config.IP)
if err != nil {
return fmt.Errorf("could not set the address: %w", err)
......@@ -104,12 +109,20 @@ func (c *Container) setupIPVlan(master string, mtu int) (string, error) {
return tmpName, nil
}
func setupRA(iface netlink.Link) error {
// Accept router advertisement, even when forwarding is
// enabled, this is further specified by setupAddress
// and setupGw
_, err := sysctl.Sysctl(ACCEPT_RA, "2")
return err
}
func setupAddress(iface netlink.Link, ip net.IPNet) error {
// Accept router advertisement for addresses if required,
// otherwise use provided IP
accept_ra := "1"
accept_pinfo := "1"
if len(ip.IP) > 0 {
accept_ra = "0"
accept_pinfo = "0"
addr := &netlink.Addr{
IPNet: &ip,
}
......@@ -118,14 +131,14 @@ func setupAddress(iface netlink.Link, ip net.IPNet) error {
return err
}
}
_, err := sysctl.Sysctl(ACCEPT_PINFO, accept_ra)
_, err := sysctl.Sysctl(ACCEPT_PINFO, accept_pinfo)
return err
}
func setupGw(iface netlink.Link, gw net.IP) error {
// Accept router advertisement for default routes if required,
// otherwise use provided gateway
accept_ra := "1"
accept_defrtr := "1"
if len(gw) > 0 {
// First add a link-local route to the gateway, so that
// out-of-lan default routes are handled properly
......@@ -151,7 +164,7 @@ func setupGw(iface netlink.Link, gw net.IP) error {
return err
}
}
_, err := sysctl.Sysctl(ACCEPT_DFTRTR, accept_ra)
_, err := sysctl.Sysctl(ACCEPT_DFTRTR, accept_defrtr)
return err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment