diff --git a/libnetwork/drivers/bridge/bridge.go b/libnetwork/drivers/bridge/bridge.go index a58e11dd94..7332cdf24b 100644 --- a/libnetwork/drivers/bridge/bridge.go +++ b/libnetwork/drivers/bridge/bridge.go @@ -9,10 +9,8 @@ import ( "net" "os" "os/exec" - "path/filepath" "strconv" "sync" - "syscall" "github.com/docker/docker/libnetwork/datastore" "github.com/docker/docker/libnetwork/discoverapi" @@ -891,32 +889,10 @@ func addToBridge(nlh *netlink.Handle, ifaceName, bridgeName string) error { func setHairpinMode(nlh *netlink.Handle, link netlink.Link, enable bool) error { err := nlh.LinkSetHairpin(link, enable) - if err != nil && err != syscall.EINVAL { - // If error is not EINVAL something else went wrong, bail out right away + if err != nil { return fmt.Errorf("unable to set hairpin mode on %s via netlink: %v", link.Attrs().Name, err) } - - // Hairpin mode successfully set up - if err == nil { - return nil - } - - // The netlink method failed with EINVAL which is probably because of an older - // kernel. Try one more time via the sysfs method. - path := filepath.Join("/sys/class/net", link.Attrs().Name, "brport/hairpin_mode") - - var val []byte - if enable { - val = []byte{'1', '\n'} - } else { - val = []byte{'0', '\n'} - } - - if err := os.WriteFile(path, val, 0644); err != nil { - return fmt.Errorf("unable to set hairpin mode on %s via sysfs: %v", link.Attrs().Name, err) - } - return nil } diff --git a/libnetwork/drivers/overlay/ov_network.go b/libnetwork/drivers/overlay/ov_network.go index e3bdfa8d42..7b8c9dec63 100644 --- a/libnetwork/drivers/overlay/ov_network.go +++ b/libnetwork/drivers/overlay/ov_network.go @@ -124,6 +124,8 @@ func setDefaultVlan() { } brName := os.Args[2] + // IFLA_BR_VLAN_DEFAULT_PVID was added in Linux v4.4 (see torvalds/linux@0f963b7), so we can't use netlink for + // setting this until Docker drops support for CentOS/RHEL 7 (kernel 3.10, eol date: 2024-06-30). path := filepath.Join("/sys/class/net", brName, "bridge/default_pvid") data := []byte{'0', '\n'} diff --git a/libnetwork/osl/interface_linux.go b/libnetwork/osl/interface_linux.go index 1cfe83c57c..561e7fc7e0 100644 --- a/libnetwork/osl/interface_linux.go +++ b/libnetwork/osl/interface_linux.go @@ -3,7 +3,6 @@ package osl import ( "fmt" "net" - "regexp" "sync" "syscall" "time" @@ -418,30 +417,6 @@ func setInterfaceRoutes(nlh *netlink.Handle, iface netlink.Link, i *nwIface) err return nil } -// In older kernels (like the one in Centos 6.6 distro) sysctl does not have netns support. Therefore -// we cannot gather the statistics from /sys/class/net//statistics/ files. Per-netns stats -// are naturally found in /proc/net/dev in kernels which support netns (ifconfig relies on that). -const ( - base = "[ ]*%s:([ ]+[0-9]+){16}" -) - -func scanInterfaceStats(data, ifName string, i *types.InterfaceStatistics) error { - var ( - bktStr string - bkt uint64 - ) - - regex := fmt.Sprintf(base, ifName) - re := regexp.MustCompile(regex) - line := re.FindString(data) - - _, err := fmt.Sscanf(line, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", - &bktStr, &i.RxBytes, &i.RxPackets, &i.RxErrors, &i.RxDropped, &bkt, &bkt, &bkt, - &bkt, &i.TxBytes, &i.TxPackets, &i.TxErrors, &i.TxDropped, &bkt, &bkt, &bkt, &bkt) - - return err -} - func checkRouteConflict(nlh *netlink.Handle, address *net.IPNet, family int) error { routes, err := nlh.RouteList(nil, family) if err != nil { diff --git a/libnetwork/osl/sandbox_linux_test.go b/libnetwork/osl/sandbox_linux_test.go index 64e3ed8177..acda5eee9e 100644 --- a/libnetwork/osl/sandbox_linux_test.go +++ b/libnetwork/osl/sandbox_linux_test.go @@ -158,32 +158,6 @@ func verifyCleanup(t *testing.T, s Sandbox, wait bool) { } } -func TestScanStatistics(t *testing.T) { - data := - "Inter-| Receive | Transmit\n" + - " face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n" + - " eth0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + - " wlan0: 7787685 11141 0 0 0 0 0 0 1681390 7220 0 0 0 0 0 0\n" + - " lo: 783782 1853 0 0 0 0 0 0 783782 1853 0 0 0 0 0 0\n" + - "lxcbr0: 0 0 0 0 0 0 0 0 9006 61 0 0 0 0 0 0\n" - - i := &types.InterfaceStatistics{} - - if err := scanInterfaceStats(data, "wlan0", i); err != nil { - t.Fatal(err) - } - if i.TxBytes != 1681390 || i.TxPackets != 7220 || i.RxBytes != 7787685 || i.RxPackets != 11141 { - t.Fatalf("Error scanning the statistics") - } - - if err := scanInterfaceStats(data, "lxcbr0", i); err != nil { - t.Fatal(err) - } - if i.TxBytes != 9006 || i.TxPackets != 61 || i.RxBytes != 0 || i.RxPackets != 0 { - t.Fatalf("Error scanning the statistics") - } -} - func TestDisableIPv6DAD(t *testing.T) { defer testutils.SetupTestOSContext(t)()