| 1 | // Copyright 2018 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/ |
| 15 | |
| 16 | import ( |
| 17 | "bytesscip-go gomod github.com/golang/go/src go1.24.2 bytes/" |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 19 | "ioscip-go gomod github.com/golang/go/src go1.24.2 io/" |
| 20 | "netscip-go gomod github.com/golang/go/src go1.24.2 net/" |
| 21 | "os/execscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/" |
| 22 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/" |
| 23 | "strconvscip-go gomod github.com/golang/go/src go1.24.2 strconv/" |
| 24 | "stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/" |
| 25 | "testingscip-go gomod github.com/golang/go/src go1.24.2 testing/" |
| 26 | |
| 27 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 28 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 29 | "github.com/onsi/gomega/gbytesscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gbytes`/" |
| 30 | "github.com/onsi/gomega/gexecscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/" |
| 31 | "github.com/vishvananda/netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/" |
| 32 | |
| 33 | "github.com/containernetworking/plugins/pkg/netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/" |
| 34 | "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/" |
| 35 | ) |
| 36 | |
| 37 | func TestTBFscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/TestTBF().(t *testingscip-go gomod github.com/golang/go/src go1.24.2 testing/.Tscip-go gomod github.com/golang/go/src go1.24.2 testing/T#) { |
| 38 | RegisterFailHandlerscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/RegisterFailHandler().(Failscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Fail().) |
| 39 | RunSpecsscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/RunSpecs().(t, "plugins/meta/bandwidth") |
| 40 | } |
| 41 | |
| 42 | var echoServerBinaryPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/echoServerBinaryPath., echoClientBinaryPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/echoClientBinaryPath. string |
| 43 | |
| 44 | var _ = SynchronizedBeforeSuitescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/SynchronizedBeforeSuite().(func() []byte { |
| 45 | serverBinaryPath, err := gexecscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/.Buildscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Build().("github.com/containernetworking/plugins/pkg/testutils/echo/server") |
| 46 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 47 | clientBinaryPath, err := gexecscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/.Buildscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Build().("github.com/containernetworking/plugins/pkg/testutils/echo/client") |
| 48 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 49 | return []byte(stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.2 strings/Join().([]string{serverBinaryPath, clientBinaryPath}, ",")) |
| 50 | }, func(datascip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/_:data. []byte) { |
| 51 | binaries := stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Splitscip-go gomod github.com/golang/go/src go1.24.2 strings/Split().(string(datascip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/_:data.), ",") |
| 52 | echoServerBinaryPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/echoServerBinaryPath. = binaries[0] |
| 53 | echoClientBinaryPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/echoClientBinaryPath. = binaries[1] |
| 54 | }) |
| 55 | |
| 56 | var _ = SynchronizedAfterSuitescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/SynchronizedAfterSuite().(func() {}, func() { |
| 57 | gexecscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/.CleanupBuildArtifactsscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/CleanupBuildArtifacts().() |
| 58 | }) |
| 59 | |
| 60 | func startInNetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/startInNetNS().(binPath string, netNS nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) (*gexecscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/.Sessionscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Session#, error) { |
| 61 | baseName := filepathscip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/Base().(netNS.Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.()) |
| 62 | // we are relying on the netNS path living in /var/run/netns |
| 63 | // where `ip netns exec` can find it |
| 64 | cmd := execscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/Command().("ip", "netns", "exec", baseName, binPath) |
| 65 | |
| 66 | session, err := gexecscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/.Startscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Start().(cmd, GinkgoWriterscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoWriter., GinkgoWriterscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoWriter.) |
| 67 | return session, err |
| 68 | } |
| 69 | |
| 70 | func startEchoServerInNamespacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/startEchoServerInNamespace().(netNS nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) (int, *gexecscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/.Sessionscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Session#) { |
| 71 | session, err := startInNetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/startInNetNS().(echoServerBinaryPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/echoServerBinaryPath., netNS) |
| 72 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 73 | |
| 74 | // wait for it to print it's address on stdout |
| 75 | Eventuallyscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Eventually().(session.Outscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Session#Out.).Shouldscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/AsyncAssertion#Should().(gbytesscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gbytes`/.Sayscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gbytes`/Say().("\n")) |
| 76 | _, portString, err := netscip-go gomod github.com/golang/go/src go1.24.2 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.24.2 net/SplitHostPort().(stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.2 strings/TrimSpace().(string(session.Outscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Session#Out..Contentsscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gbytes`/Buffer#Contents().()))) |
| 77 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 78 | |
| 79 | port, err := strconvscip-go gomod github.com/golang/go/src go1.24.2 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.24.2 strconv/Atoi().(portString) |
| 80 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 81 | |
| 82 | go func() { |
| 83 | // print out echoserver output to ginkgo to capture any errors that might be occurring. |
| 84 | ioscip-go gomod github.com/golang/go/src go1.24.2 io/.Copyscip-go gomod github.com/golang/go/src go1.24.2 io/Copy().(GinkgoWriterscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoWriter., ioscip-go gomod github.com/golang/go/src go1.24.2 io/.MultiReaderscip-go gomod github.com/golang/go/src go1.24.2 io/MultiReader().(session.Outscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Session#Out., session.Errscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/gexec`/Session#Err.)) |
| 85 | }() |
| 86 | |
| 87 | return port, session |
| 88 | } |
| 89 | |
| 90 | func makeTCPClientInNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/makeTCPClientInNS().(netns string, address string, port int, numBytes int) { |
| 91 | payload := bytesscip-go gomod github.com/golang/go/src go1.24.2 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.24.2 bytes/Repeat().([]byte{'a'}, numBytes) |
| 92 | message := string(payload) |
| 93 | |
| 94 | var cmd *execscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/.Cmdscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/Cmd# |
| 95 | if netns != "" { |
| 96 | netns = filepathscip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.2 `path/filepath`/Base().(netns) |
| 97 | cmd = execscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/Command().("ip", "netns", "exec", netns, echoClientBinaryPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/echoClientBinaryPath., "--target", fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("%s:%d", address, port), "--message", message) |
| 98 | } else { |
| 99 | cmd = execscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/Command().(echoClientBinaryPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/echoClientBinaryPath., "--target", fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("%s:%d", address, port), "--message", message) |
| 100 | } |
| 101 | cmd.Stdinscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/Cmd#Stdin. = bytesscip-go gomod github.com/golang/go/src go1.24.2 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24.2 bytes/NewBuffer().([]byte(message)) |
| 102 | cmd.Stderrscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/Cmd#Stderr. = GinkgoWriterscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoWriter. |
| 103 | out, err := cmd.Outputscip-go gomod github.com/golang/go/src go1.24.2 `os/exec`/Cmd#Output().() |
| 104 | |
| 105 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 106 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(string(out)).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(message)) |
| 107 | } |
| 108 | |
| 109 | func createVethscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/createVeth().(hostNs nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#, hostVethIfName string, containerNs nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#, containerVethIfName string, hostIP []byte, containerIP []byte, hostIfaceMTU int) { |
| 110 | linkAttrs := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NewLinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NewLinkAttrs().() |
| 111 | linkAttrs.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. = hostVethIfName |
| 112 | linkAttrs.Flagsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Flags. = netscip-go gomod github.com/golang/go/src go1.24.2 net/.FlagUpscip-go gomod github.com/golang/go/src go1.24.2 net/FlagUp. |
| 113 | linkAttrs.MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU. = hostIfaceMTU |
| 114 | vethDeviceRequest := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Vethscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Veth#{ |
| 115 | LinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Veth#LinkAttrs.: linkAttrs, |
| 116 | PeerNamescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Veth#PeerName.: containerVethIfName, |
| 117 | } |
| 118 | |
| 119 | err := hostNs.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 120 | if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAdd().(vethDeviceRequest); err != nil { |
| 121 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("creating veth pair: %s", err) |
| 122 | } |
| 123 | |
| 124 | containerVeth, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(containerVethIfName) |
| 125 | if err != nil { |
| 126 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to find newly-created veth device %q: %v", containerVethIfName, err) |
| 127 | } |
| 128 | |
| 129 | err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetNsFdscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetNsFd().(containerVeth, int(containerNs.Fdscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Fd.())) |
| 130 | if err != nil { |
| 131 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to move veth to container namespace: %s", err) |
| 132 | } |
| 133 | |
| 134 | localAddr := &netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPNetscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#{ |
| 135 | IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: hostIP, |
| 136 | Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: []byte{255, 255, 255, 255}, |
| 137 | } |
| 138 | peerAddr := &netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPNetscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#{ |
| 139 | IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: containerIP, |
| 140 | Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: []byte{255, 255, 255, 255}, |
| 141 | } |
| 142 | addr, err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.ParseAddrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/ParseAddr().(localAddr.Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().()) |
| 143 | if err != nil { |
| 144 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("parsing address %s: %s", localAddr, err) |
| 145 | } |
| 146 | |
| 147 | addr.Peerscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#Peer. = peerAddr |
| 148 | |
| 149 | addr.Scopescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#Scope. = int(netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.SCOPE_LINKscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/SCOPE_LINK.) |
| 150 | hostVeth, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(hostVethIfName) |
| 151 | if err != nil { |
| 152 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to find newly-created veth device %q: %v", containerVethIfName, err) |
| 153 | } |
| 154 | |
| 155 | err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.AddrAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/AddrAdd().(hostVeth, addr) |
| 156 | if err != nil { |
| 157 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("adding IP address %s: %s", localAddr, err) |
| 158 | } |
| 159 | |
| 160 | return nil |
| 161 | }) |
| 162 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 163 | |
| 164 | err = containerNs.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 165 | peerAddr := &netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPNetscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#{ |
| 166 | IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: hostIP, |
| 167 | Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: []byte{255, 255, 255, 255}, |
| 168 | } |
| 169 | localAddr := &netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPNetscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#{ |
| 170 | IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: containerIP, |
| 171 | Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: []byte{255, 255, 255, 255}, |
| 172 | } |
| 173 | addr, err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.ParseAddrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/ParseAddr().(localAddr.Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().()) |
| 174 | if err != nil { |
| 175 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("parsing address %s: %s", localAddr, err) |
| 176 | } |
| 177 | |
| 178 | addr.Peerscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#Peer. = peerAddr |
| 179 | |
| 180 | addr.Scopescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#Scope. = int(netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.SCOPE_LINKscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/SCOPE_LINK.) |
| 181 | containerVeth, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(containerVethIfName) |
| 182 | if err != nil { |
| 183 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to find newly-created veth device %q: %v", containerVethIfName, err) |
| 184 | } |
| 185 | err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.AddrAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/AddrAdd().(containerVeth, addr) |
| 186 | if err != nil { |
| 187 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("adding IP address %s: %s", localAddr, err) |
| 188 | } |
| 189 | |
| 190 | return nil |
| 191 | }) |
| 192 | |
| 193 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 194 | } |
| 195 | |
| 196 | func createVethInOneNsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/createVethInOneNs().(netNS nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#, vethName, peerName string) { |
| 197 | linkAttrs := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NewLinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NewLinkAttrs().() |
| 198 | linkAttrs.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. = vethName |
| 199 | linkAttrs.Flagsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Flags. = netscip-go gomod github.com/golang/go/src go1.24.2 net/.FlagUpscip-go gomod github.com/golang/go/src go1.24.2 net/FlagUp. |
| 200 | vethDeviceRequest := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Vethscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Veth#{ |
| 201 | LinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Veth#LinkAttrs.: linkAttrs, |
| 202 | PeerNamescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Veth#PeerName.: peerName, |
| 203 | } |
| 204 | |
| 205 | err := netNS.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 206 | if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAdd().(vethDeviceRequest); err != nil { |
| 207 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to create veth pair: %v", err) |
| 208 | } |
| 209 | |
| 210 | _, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(peerName) |
| 211 | if err != nil { |
| 212 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to find newly-created veth device %q: %v", peerName, err) |
| 213 | } |
| 214 | return nil |
| 215 | }) |
| 216 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 217 | } |
| 218 | |
| 219 | func createMacvlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/createMacvlan().(netNS nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#, master, macvlanName string) { |
| 220 | err := netNS.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(_ nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 221 | m, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(master) |
| 222 | if err != nil { |
| 223 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to lookup master %q: %v", master, err) |
| 224 | } |
| 225 | |
| 226 | linkAttrs := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NewLinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NewLinkAttrs().() |
| 227 | linkAttrs.MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU. = m.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU. |
| 228 | linkAttrs.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. = macvlanName |
| 229 | linkAttrs.ParentIndexscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#ParentIndex. = m.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().Indexscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Index. |
| 230 | macvlanDeviceRequest := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Macvlanscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Macvlan#{ |
| 231 | LinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Macvlan#LinkAttrs.: linkAttrs, |
| 232 | Modescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Macvlan#Mode.: netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.MACVLAN_MODE_BRIDGEscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/MACVLAN_MODE_BRIDGE., |
| 233 | } |
| 234 | |
| 235 | if err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAdd().(macvlanDeviceRequest); err != nil { |
| 236 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to create macvlan device: %s", err) |
| 237 | } |
| 238 | |
| 239 | _, err = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(macvlanName) |
| 240 | if err != nil { |
| 241 | return fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("failed to find newly-created macvlan device %q: %v", macvlanName, err) |
| 242 | } |
| 243 | return nil |
| 244 | }) |
| 245 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 246 | } |