Don't assume we always run in in host pid space
Pass the path to the proc filesystem down
This commit is contained in:
1 parent
c8e0c12d34
commit
f05bb6c4e0
7 files changed
+29
-22
No files matched your search
+7
-6
@@ -1,5 +1,6 @@
|
||||
package net
|
||||
|
||||
import "path/filepath"
|
||||
import "fmt"
|
||||
import "io"
|
||||
import "os"
|
||||
@@ -7,21 +8,21 @@ import "os"
|
||||
// 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(name string) error {
|
||||
if err := sysctl(fmt.Sprintf("net/ipv4/neigh/%s/base_reachable_time", name), "5"); err != nil {
|
||||
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(fmt.Sprintf("net/ipv4/neigh/%s/delay_first_probe_time", name), "2"); err != nil {
|
||||
if err := sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/delay_first_probe_time", name), "2"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := sysctl(fmt.Sprintf("net/ipv4/neigh/%s/ucast_solicit", name), "1"); err != nil {
|
||||
if err := sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/ucast_solicit", name), "1"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func sysctl(variable, value string) error {
|
||||
f, err := os.OpenFile(fmt.Sprintf("/proc/sys/%s", variable), os.O_WRONLY, 0)
|
||||
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
|
||||
}
|
||||
|
||||
+6
-5
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/coreos/go-iptables/iptables"
|
||||
@@ -71,7 +72,7 @@ func DetectBridgeType(weaveBridgeName, datapathName string) BridgeType {
|
||||
var ErrSetBridgeMac = errors.New("Setting $DOCKER_BRIDGE MAC (mitigate https://github.com/docker/docker/issues/14908)")
|
||||
|
||||
func EnforceAddrAssignType(bridgeName string) error {
|
||||
sysctlFilename := fmt.Sprintf("/sys/class/net/%s/addr_assign_type", bridgeName)
|
||||
sysctlFilename := filepath.Join("/sys/class/net/", bridgeName, "/addr_assign_type")
|
||||
addrAssignType, err := ioutil.ReadFile(sysctlFilename)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "reading %q", sysctlFilename)
|
||||
@@ -186,7 +187,7 @@ type BridgeConfig struct {
|
||||
Port int
|
||||
}
|
||||
|
||||
func CreateBridge(config *BridgeConfig) (BridgeType, error) {
|
||||
func CreateBridge(procPath string, config *BridgeConfig) (BridgeType, error) {
|
||||
bridgeType := DetectBridgeType(config.WeaveBridgeName, config.DatapathName)
|
||||
|
||||
if bridgeType == None {
|
||||
@@ -231,13 +232,13 @@ func CreateBridge(config *BridgeConfig) (BridgeType, error) {
|
||||
// Set proxy_arp on the bridge, so that it could accept packets destined
|
||||
// to containers within the same subnet but running on remote hosts.
|
||||
// Without it, exact routes on each container are required.
|
||||
if err := sysctl("net/ipv4/conf/"+config.WeaveBridgeName+"/proxy_arp", "1"); err != nil {
|
||||
if err := sysctl(procPath, "net/ipv4/conf/"+config.WeaveBridgeName+"/proxy_arp", "1"); err != nil {
|
||||
return bridgeType, errors.Wrap(err, "setting proxy_arp")
|
||||
}
|
||||
// Avoid delaying the first ARP request. Also, setting it to 0 avoids
|
||||
// placing the request into a bounded queue as it can be seen:
|
||||
// https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/net/ipv4/arp.c?id=refs/tags/v4.6.1#n819
|
||||
if err := sysctl("net/ipv4/neigh/"+config.WeaveBridgeName+"/proxy_delay", "0"); err != nil {
|
||||
if err := sysctl(procPath, "net/ipv4/neigh/"+config.WeaveBridgeName+"/proxy_delay", "0"); err != nil {
|
||||
return bridgeType, errors.Wrap(err, "setting proxy_arp")
|
||||
}
|
||||
}
|
||||
@@ -252,7 +253,7 @@ func CreateBridge(config *BridgeConfig) (BridgeType, error) {
|
||||
return bridgeType, err
|
||||
}
|
||||
|
||||
if err := ConfigureARPCache(config.WeaveBridgeName); err != nil {
|
||||
if err := ConfigureARPCache(procPath, config.WeaveBridgeName); err != nil {
|
||||
return bridgeType, errors.Wrapf(err, "configuring ARP cache on bridge %q", config.WeaveBridgeName)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user