Files
weave/net/arp.go
Bryan Boreham 7174738d9d Don't exit if machine has no ipv6 installed
We are trying to turn off `accept_ra`, so if we get an error that the
option doesn't exist we can just ignore it.
2020-06-04 16:12:38 +00:00

52 lines
1.2 KiB
Go

package net
import (
"fmt"
"io"
"os"
"path/filepath"
)
// Configure the ARP cache parameters for the given interface. This
// makes containers react more quickly to a change in the MAC address
// associated with an IP address.
func configureARPCache(procPath, name string) error {
if err := sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/base_reachable_time", name), "5"); err != nil {
return err
}
if err := sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/delay_first_probe_time", name), "2"); err != nil {
return err
}
return sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/ucast_solicit", name), "1")
}
func sysctl(procPath, variable, value string) error {
f, err := os.OpenFile(filepath.Join(procPath, "/sys/", variable), os.O_WRONLY, 0)
if err != nil {
return err
}
n, err := io.WriteString(f, value)
if err != nil {
return err
}
if n < len(value) {
return io.ErrShortWrite
}
err = f.Close()
if err != nil {
return err
}
return nil
}
func sysctlIfExists(procPath, variable, value string) error {
err := sysctl(procPath, variable, value)
if err != nil && os.IsNotExist(err) {
err = nil // ignore 'not found' errors
}
return err
}