| 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 | |
| 15 | package mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/ |
| 16 | |
| 17 | import ( |
| 18 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 20 | "mathscip-go gomod github.com/golang/go/src go1.24.2 math/" |
| 21 | |
| 22 | "github.com/vishvananda/netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/" |
| 23 | |
| 24 | "github.com/containernetworking/cni/pkg/skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/" |
| 25 | "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/" |
| 26 | currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/ "github.com/containernetworking/cni/pkg/types/100scip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/" |
| 27 | "github.com/containernetworking/cni/pkg/versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/" |
| 28 | "github.com/containernetworking/plugins/pkg/ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/" |
| 29 | "github.com/containernetworking/plugins/pkg/netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/" |
| 30 | "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/" |
| 31 | "github.com/containernetworking/plugins/pkg/utilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/" |
| 32 | bvscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/ "github.com/containernetworking/plugins/pkg/utils/buildversionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/" |
| 33 | ) |
| 34 | |
| 35 | const ( |
| 36 | maxIfbDeviceLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/maxIfbDeviceLength. = 15 |
| 37 | ifbDevicePrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/ifbDevicePrefix. = "bwp" |
| 38 | ) |
| 39 | |
| 40 | // BandwidthEntry corresponds to a single entry in the bandwidth argument, |
| 41 | // see CONVENTIONS.md |
| 42 | type BandwidthEntryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry# struct { |
| 43 | IngressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressRate. uint64 `json:"ingressRate"` // Bandwidth rate in bps for traffic through container. 0 for no limit. If ingressRate is set, ingressBurst must also be set |
| 44 | IngressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressBurst. uint64 `json:"ingressBurst"` // Bandwidth burst in bits for traffic through container. 0 for no limit. If ingressBurst is set, ingressRate must also be set |
| 45 | |
| 46 | EgressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressRate. uint64 `json:"egressRate"` // Bandwidth rate in bps for traffic through container. 0 for no limit. If egressRate is set, egressBurst must also be set |
| 47 | EgressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressBurst. uint64 `json:"egressBurst"` // Bandwidth burst in bits for traffic through container. 0 for no limit. If egressBurst is set, egressRate must also be set |
| 48 | } |
| 49 | |
| 50 | func (bw *BandwidthEntryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#) isZeroscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#isZero().() bool { |
| 51 | return bw.IngressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressBurst. == 0 && bw.IngressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressRate. == 0 && bw.EgressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressBurst. == 0 && bw.EgressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressRate. == 0 |
| 52 | } |
| 53 | |
| 54 | type PluginConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf# struct { |
| 55 | typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#NetConf. |
| 56 | |
| 57 | RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#RuntimeConfig. struct { |
| 58 | Bandwidthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#$anon_c15fe7d9e6186c79#Bandwidth. *BandwidthEntryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry# `json:"bandwidth,omitempty"` |
| 59 | } `json:"runtimeConfig,omitempty"` |
| 60 | |
| 61 | *BandwidthEntryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#BandwidthEntry. |
| 62 | } |
| 63 | |
| 64 | // parseConfig parses the supplied configuration (and prevResult) from stdin. |
| 65 | func parseConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/parseConfig().(stdin []byte) (*PluginConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#, error) { |
| 66 | conf := PluginConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#{} |
| 67 | |
| 68 | if err := jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/Unmarshal().(stdin, &conf); err != nil { |
| 69 | return nil, 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 parse network configuration: %v", err) |
| 70 | } |
| 71 | |
| 72 | bandwidth := getBandwidthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getBandwidth().(&conf) |
| 73 | if bandwidth != nil { |
| 74 | err := validateRateAndBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/validateRateAndBurst().(bandwidth.IngressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressRate., bandwidth.IngressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressBurst.) |
| 75 | if err != nil { |
| 76 | return nil, err |
| 77 | } |
| 78 | err = validateRateAndBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/validateRateAndBurst().(bandwidth.EgressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressRate., bandwidth.EgressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressBurst.) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if conf.RawPrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#RawPrevResult. != nil { |
| 85 | var err error |
| 86 | if err = versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/.ParsePrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/ParsePrevResult().(&conf.NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#NetConf.); err != nil { |
| 87 | return nil, 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().("could not parse prevResult: %v", err) |
| 88 | } |
| 89 | |
| 90 | _, err = currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.NewResultFromResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/NewResultFromResult().(conf.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult.) |
| 91 | if err != nil { |
| 92 | return nil, 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().("could not convert result to current version: %v", err) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return &conf, nil |
| 97 | } |
| 98 | |
| 99 | func getBandwidthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getBandwidth().(conf *PluginConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#) *BandwidthEntryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry# { |
| 100 | if conf.BandwidthEntryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#BandwidthEntry. == nil && conf.RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#RuntimeConfig..Bandwidthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#$anon_c15fe7d9e6186c79#Bandwidth. != nil { |
| 101 | return conf.RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#RuntimeConfig..Bandwidthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#$anon_c15fe7d9e6186c79#Bandwidth. |
| 102 | } |
| 103 | return conf.BandwidthEntryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/PluginConf#BandwidthEntry. |
| 104 | } |
| 105 | |
| 106 | func validateRateAndBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/validateRateAndBurst().(rate, burst uint64) error { |
| 107 | switch { |
| 108 | case burst == 0 && rate != 0: |
| 109 | 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().("if rate is set, burst must also be set") |
| 110 | case rate == 0 && burst != 0: |
| 111 | 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().("if burst is set, rate must also be set") |
| 112 | case burst/8 >= mathscip-go gomod github.com/golang/go/src go1.24.2 math/.MaxUint32scip-go gomod github.com/golang/go/src go1.24.2 math/MaxUint32.: |
| 113 | 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().("burst cannot be more than 4GB") |
| 114 | } |
| 115 | |
| 116 | return nil |
| 117 | } |
| 118 | |
| 119 | func getIfbDeviceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getIfbDeviceName().(networkName string, containerID string) string { |
| 120 | return utilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/.MustFormatHashWithPrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils`/MustFormatHashWithPrefix().(maxIfbDeviceLengthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/maxIfbDeviceLength., ifbDevicePrefixscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/ifbDevicePrefix., networkName+containerID) |
| 121 | } |
| 122 | |
| 123 | func getMTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getMTU().(deviceName string) (int, error) { |
| 124 | link, 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().(deviceName) |
| 125 | if err != nil { |
| 126 | return -1, err |
| 127 | } |
| 128 | |
| 129 | return link.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., nil |
| 130 | } |
| 131 | |
| 132 | // get the veth peer of container interface in host namespace |
| 133 | func getHostInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getHostInterface().(interfaces []*currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#, containerIfName 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#) (*currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#, error) { |
| 134 | if len(interfaces) == 0 { |
| 135 | return nil, 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().("no interfaces provided") |
| 136 | } |
| 137 | |
| 138 | // get veth peer index of container interface |
| 139 | var peerIndex int |
| 140 | var err error |
| 141 | _ = 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 { |
| 142 | _, peerIndex, err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.GetVethPeerIfindexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/GetVethPeerIfindex().(containerIfName) |
| 143 | return nil |
| 144 | }) |
| 145 | if peerIndex <= 0 { |
| 146 | return nil, 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().("container interface %s has no veth peer: %v", containerIfName, err) |
| 147 | } |
| 148 | |
| 149 | // find host interface by index |
| 150 | link, err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkByIndexscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkByIndex().(peerIndex) |
| 151 | if err != nil { |
| 152 | return nil, 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().("veth peer with index %d is not in host ns", peerIndex) |
| 153 | } |
| 154 | for _, iface := range interfaces { |
| 155 | if iface.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. == "" && iface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. == link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. { |
| 156 | return iface, nil |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return nil, 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().("no veth peer of container interface found in host ns") |
| 161 | } |
| 162 | |
| 163 | func cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/cmdAdd().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) error { |
| 164 | conf, err := parseConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/parseConfig().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.) |
| 165 | if err != nil { |
| 166 | return err |
| 167 | } |
| 168 | |
| 169 | bandwidth := getBandwidthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getBandwidth().(conf) |
| 170 | if bandwidth == nil || bandwidth.isZeroscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#isZero().() { |
| 171 | return typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.PrintResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PrintResult().(conf.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult., conf.CNIVersionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#CNIVersion.) |
| 172 | } |
| 173 | |
| 174 | if conf.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult. == 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().("must be called as chained plugin") |
| 176 | } |
| 177 | |
| 178 | result, err := currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.NewResultFromResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/NewResultFromResult().(conf.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult.) |
| 179 | if err != nil { |
| 180 | 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().("could not convert result to current version: %v", err) |
| 181 | } |
| 182 | |
| 183 | netns, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetNS().(args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.) |
| 184 | if err != nil { |
| 185 | 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 open netns %q: %v", netns, err) |
| 186 | } |
| 187 | defer netns.Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.() |
| 188 | |
| 189 | hostInterface, err := getHostInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getHostInterface().(result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces., args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., netns) |
| 190 | if err != nil { |
| 191 | return err |
| 192 | } |
| 193 | |
| 194 | if bandwidth.IngressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressRate. > 0 && bandwidth.IngressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressBurst. > 0 { |
| 195 | err = CreateIngressQdiscscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/CreateIngressQdisc().(bandwidth.IngressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressRate., bandwidth.IngressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressBurst., hostInterface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.) |
| 196 | if err != nil { |
| 197 | return err |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if bandwidth.EgressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressRate. > 0 && bandwidth.EgressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressBurst. > 0 { |
| 202 | mtu, err := getMTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getMTU().(hostInterface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.) |
| 203 | if err != nil { |
| 204 | return err |
| 205 | } |
| 206 | |
| 207 | ifbDeviceName := getIfbDeviceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getIfbDeviceName().(conf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#Name., args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.) |
| 208 | |
| 209 | err = CreateIfbscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/CreateIfb().(ifbDeviceName, mtu) |
| 210 | if err != nil { |
| 211 | return err |
| 212 | } |
| 213 | |
| 214 | ifbDevice, 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().(ifbDeviceName) |
| 215 | if err != nil { |
| 216 | return err |
| 217 | } |
| 218 | |
| 219 | result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces. = append(result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces., ¤tscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#{ |
| 220 | Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.: ifbDeviceName, |
| 221 | Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac.: ifbDevice.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().HardwareAddrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#HardwareAddr..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/HardwareAddr#String().(), |
| 222 | }) |
| 223 | err = CreateEgressQdiscscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/CreateEgressQdisc().(bandwidth.EgressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressRate., bandwidth.EgressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressBurst., hostInterface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., ifbDeviceName) |
| 224 | if err != nil { |
| 225 | return err |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.PrintResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PrintResult().(result, conf.CNIVersionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#CNIVersion.) |
| 230 | } |
| 231 | |
| 232 | func cmdDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/cmdDel().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) error { |
| 233 | conf, err := parseConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/parseConfig().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.) |
| 234 | if err != nil { |
| 235 | return err |
| 236 | } |
| 237 | |
| 238 | ifbDeviceName := getIfbDeviceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getIfbDeviceName().(conf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#Name., args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.) |
| 239 | |
| 240 | return TeardownIfbscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/TeardownIfb().(ifbDeviceName) |
| 241 | } |
| 242 | |
| 243 | func mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/main().() { |
| 244 | skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.PluginMainFuncsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/PluginMainFuncs().(skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CNIFuncsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#{ |
| 245 | Addscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Add.: cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/cmdAdd()., |
| 246 | Checkscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Check.: cmdCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/cmdCheck()., |
| 247 | Delscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Del.: cmdDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/cmdDel()., |
| 248 | /* FIXME GC */ |
| 249 | /* FIXME Status */ |
| 250 | }, versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/.VersionsStartingFromscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/VersionsStartingFrom().("0.3.0"), bvscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/.BuildStringscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/buildversion`/BuildString().("bandwidth")) |
| 251 | } |
| 252 | |
| 253 | func SafeQdiscListscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/SafeQdiscList().(link netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Linkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#) ([]netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Qdiscscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Qdisc#, error) { |
| 254 | qdiscs, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.QdiscListscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/QdiscList().(link) |
| 255 | if err != nil { |
| 256 | return nil, err |
| 257 | } |
| 258 | result := []netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Qdiscscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Qdisc#{} |
| 259 | for _, qdisc := range qdiscs { |
| 260 | // filter out pfifo_fast qdiscs because |
| 261 | // older kernels don't return them |
| 262 | _, pfifo := qdisc.(*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.PfifoFastscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/PfifoFast#) |
| 263 | if !pfifo { |
| 264 | result = append(result, qdisc) |
| 265 | } |
| 266 | } |
| 267 | return result, nil |
| 268 | } |
| 269 | |
| 270 | func cmdCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/cmdCheck().(args *skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#) error { |
| 271 | bwConf, err := parseConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/parseConfig().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.) |
| 272 | if err != nil { |
| 273 | return err |
| 274 | } |
| 275 | |
| 276 | if bwConf.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult. == nil { |
| 277 | 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().("must be called as a chained plugin") |
| 278 | } |
| 279 | |
| 280 | result, err := currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.NewResultFromResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/NewResultFromResult().(bwConf.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult.) |
| 281 | if err != nil { |
| 282 | 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().("could not convert result to current version: %v", err) |
| 283 | } |
| 284 | |
| 285 | netns, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetNS().(args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.) |
| 286 | if err != nil { |
| 287 | 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 open netns %q: %v", netns, err) |
| 288 | } |
| 289 | defer netns.Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.() |
| 290 | |
| 291 | hostInterface, err := getHostInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getHostInterface().(result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces., args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., netns) |
| 292 | if err != nil { |
| 293 | return err |
| 294 | } |
| 295 | link, 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().(hostInterface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.) |
| 296 | if err != nil { |
| 297 | return err |
| 298 | } |
| 299 | |
| 300 | bandwidth := getBandwidthscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getBandwidth().(bwConf) |
| 301 | |
| 302 | // No bandwidth config; nothing to do. |
| 303 | if bandwidth == nil || bandwidth.isZeroscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#isZero().() { |
| 304 | return nil |
| 305 | } |
| 306 | |
| 307 | if bandwidth.IngressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressRate. > 0 && bandwidth.IngressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressBurst. > 0 { |
| 308 | rateInBytes := bandwidth.IngressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressRate. / 8 |
| 309 | burstInBytes := bandwidth.IngressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#IngressBurst. / 8 |
| 310 | bufferInBytes := bufferscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/buffer().(rateInBytes, uint32(burstInBytes)) |
| 311 | latency := latencyInUsecscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/latencyInUsec().(latencyInMillisscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/latencyInMillis.) |
| 312 | limitInBytes := limitscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/limit().(rateInBytes, latency, uint32(burstInBytes)) |
| 313 | |
| 314 | qdiscs, err := SafeQdiscListscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/SafeQdiscList().(link) |
| 315 | if err != nil { |
| 316 | return err |
| 317 | } |
| 318 | if len(qdiscs) == 0 { |
| 319 | 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 qdisc") |
| 320 | } |
| 321 | |
| 322 | for _, qdisc := range qdiscs { |
| 323 | tbf, isTbf := qdisc.(*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Tbfscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#) |
| 324 | if !isTbf { |
| 325 | break |
| 326 | } |
| 327 | if tbf.Ratescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#Rate. != rateInBytes { |
| 328 | 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().("Rate doesn't match") |
| 329 | } |
| 330 | if tbf.Limitscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#Limit. != limitInBytes { |
| 331 | 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().("Limit doesn't match") |
| 332 | } |
| 333 | if tbf.Bufferscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#Buffer. != bufferInBytes { |
| 334 | 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().("Buffer doesn't match") |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if bandwidth.EgressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressRate. > 0 && bandwidth.EgressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressBurst. > 0 { |
| 340 | rateInBytes := bandwidth.EgressRatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressRate. / 8 |
| 341 | burstInBytes := bandwidth.EgressBurstscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/BandwidthEntry#EgressBurst. / 8 |
| 342 | bufferInBytes := bufferscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/buffer().(rateInBytes, uint32(burstInBytes)) |
| 343 | latency := latencyInUsecscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/latencyInUsec().(latencyInMillisscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/latencyInMillis.) |
| 344 | limitInBytes := limitscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/limit().(rateInBytes, latency, uint32(burstInBytes)) |
| 345 | |
| 346 | ifbDeviceName := getIfbDeviceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/getIfbDeviceName().(bwConf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#Name., args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.) |
| 347 | |
| 348 | ifbDevice, 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().(ifbDeviceName) |
| 349 | if err != nil { |
| 350 | 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().("get ifb device: %s", err) |
| 351 | } |
| 352 | |
| 353 | qdiscs, err := SafeQdiscListscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/bandwidth`/SafeQdiscList().(ifbDevice) |
| 354 | if err != nil { |
| 355 | return err |
| 356 | } |
| 357 | if len(qdiscs) == 0 { |
| 358 | 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 qdisc") |
| 359 | } |
| 360 | |
| 361 | for _, qdisc := range qdiscs { |
| 362 | tbf, isTbf := qdisc.(*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Tbfscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#) |
| 363 | if !isTbf { |
| 364 | break |
| 365 | } |
| 366 | if tbf.Ratescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#Rate. != rateInBytes { |
| 367 | 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().("Rate doesn't match") |
| 368 | } |
| 369 | if tbf.Limitscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#Limit. != limitInBytes { |
| 370 | 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().("Limit doesn't match") |
| 371 | } |
| 372 | if tbf.Bufferscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Tbf#Buffer. != bufferInBytes { |
| 373 | 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().("Buffer doesn't match") |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | return nil |
| 379 | } |