Debian Codegraph @

plugins/main/bridge/bridge.go

raw symbols SCIP
1 // Copyright 2014 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/main/bridge`/
16
17 import (
18 "encoding/jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/"
19 "errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/"
20 "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/"
21 "netscip-go gomod github.com/golang/go/src go1.24.2 net/"
22 "osscip-go gomod github.com/golang/go/src go1.24.2 os/"
23 "runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/"
24 "sortscip-go gomod github.com/golang/go/src go1.24.2 sort/"
25 "syscallscip-go gomod github.com/golang/go/src go1.24.2 syscall/"
26 "timescip-go gomod github.com/golang/go/src go1.24.2 time/"
27
28 "github.com/vishvananda/netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/"
29
30 "github.com/containernetworking/cni/pkg/skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/"
31 "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/"
32 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`/"
33 "github.com/containernetworking/cni/pkg/versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/"
34 "github.com/containernetworking/plugins/pkg/ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/"
35 "github.com/containernetworking/plugins/pkg/ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/"
36 "github.com/containernetworking/plugins/pkg/linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/"
37 "github.com/containernetworking/plugins/pkg/netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/"
38 "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/"
39 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`/"
40 "github.com/containernetworking/plugins/pkg/utils/sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/"
41 )
42
43 // For testcases to force an error after IPAM has been performed
44 var debugPostIPAMErrorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/debugPostIPAMError. error
45
46 const defaultBrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/defaultBrName. = "cni0"
47
48 type NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf# struct {
49 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/main/bridge`/NetConf#NetConf.
50 BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName. string `json:"bridge"`
51 IsGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsGW. bool `json:"isGateway"`
52 IsDefaultGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsDefaultGW. bool `json:"isDefaultGateway"`
53 ForceAddressscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#ForceAddress. bool `json:"forceAddress"`
54 IPMasqscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IPMasq. bool `json:"ipMasq"`
55 IPMasqBackendscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IPMasqBackend. *string `json:"ipMasqBackend,omitempty"`
56 MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#MTU. int `json:"mtu"`
57 HairpinModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#HairpinMode. bool `json:"hairpinMode"`
58 PromiscModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PromiscMode. bool `json:"promiscMode"`
59 Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan. int `json:"vlan"`
60 VlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#VlanTrunk. []*VlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk# `json:"vlanTrunk,omitempty"`
61 PreserveDefaultVlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PreserveDefaultVlan. bool `json:"preserveDefaultVlan"`
62 MacSpoofChkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#MacSpoofChk. bool `json:"macspoofchk,omitempty"`
63 EnableDadscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#EnableDad. bool `json:"enabledad,omitempty"`
64 DisableContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#DisableContainerInterface. bool `json:"disableContainerInterface,omitempty"`
65 PortIsolationscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PortIsolation. bool `json:"portIsolation,omitempty"`
66
67 Argsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Args. struct {
68 Cniscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#$anon_234645cb7b436ede#Cni. BridgeArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/BridgeArgs# `json:"cni,omitempty"`
69 } `json:"args,omitempty"`
70 RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#RuntimeConfig. struct {
71 Macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#$anon_1fa12328be2dcae1#Mac. string `json:"mac,omitempty"`
72 } `json:"runtimeConfig,omitempty"`
73
74 macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#mac. string
75 vlansscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#vlans. []int
76 }
77
78 type VlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk# struct {
79 MinIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MinID. *int `json:"minID,omitempty"`
80 MaxIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MaxID. *int `json:"maxID,omitempty"`
81 IDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#ID. *int `json:"id,omitempty"`
82 }
83
84 type BridgeArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/BridgeArgs# struct {
85 Macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/BridgeArgs#Mac. string `json:"mac,omitempty"`
86 }
87
88 // MacEnvArgs represents CNI_ARGS
89 type MacEnvArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/MacEnvArgs# struct {
90 typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.CommonArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/MacEnvArgs#CommonArgs.
91 MACscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/MacEnvArgs#MAC. typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.UnmarshallableStringscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/UnmarshallableString# `json:"mac,omitempty"`
92 }
93
94 type gwInfoscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo# struct {
95 gwsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#gws. []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#
96 familyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#family. int
97 defaultRouteFoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#defaultRouteFound. bool
98 }
99
100 func initscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/init().() {
101 // this ensures that main runs only on main thread (thread group leader).
102 // since namespace ops (unshare, setns) are done for a single thread, we
103 // must ensure that the goroutine does not jump from OS thread to thread
104 runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/.LockOSThreadscip-go gomod github.com/golang/go/src go1.24.2 runtime/LockOSThread().()
105 }
106
107 func loadNetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/loadNetConf().(bytes []byte, envArgs string) (*NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#, string, error) {
108 n := &NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#{
109 BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName.: defaultBrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/defaultBrName.,
110 }
111 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().(bytes, n); err != nil {
112 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 load netconf: %v", err)
113 }
114 if n.Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan. < 0 || n.Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan. > 4094 {
115 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().("invalid VLAN ID %d (must be between 0 and 4094)", n.Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan.)
116 }
117 var err error
118 n.vlansscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#vlans., err = collectVlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/collectVlanTrunk().(n.VlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#VlanTrunk.)
119 if err != nil {
120 // fail to parsing
121 return nil, "", err
122 }
123
124 if envArgs != "" {
125 e := MacEnvArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/MacEnvArgs#{}
126 if err := typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.LoadArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/LoadArgs().(envArgs, &e); err != nil {
127 return nil, "", err
128 }
129
130 if e.MACscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/MacEnvArgs#MAC. != "" {
131 n.macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#mac. = string(e.MACscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/MacEnvArgs#MAC.)
132 }
133 }
134
135 if mac := n.Argsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Args..Cniscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#$anon_234645cb7b436ede#Cni..Macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/BridgeArgs#Mac.; mac != "" {
136 n.macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#mac. = mac
137 }
138
139 if mac := n.RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#RuntimeConfig..Macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#$anon_1fa12328be2dcae1#Mac.; mac != "" {
140 n.macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#mac. = mac
141 }
142
143 return n, n.CNIVersionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#CNIVersion., nil
144 }
145
146 // This method is copied from https://github.com/k8snetworkplumbingwg/ovs-cni/blob/v0.27.2/pkg/plugin/plugin.go
147 func collectVlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/collectVlanTrunk().(vlanTrunk []*VlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#) ([]int, error) {
148 if vlanTrunk == nil {
149 return nil, nil
150 }
151
152 vlanMap := make(map[int]struct{})
153 for _, item := range vlanTrunk {
154 var minID int
155 var maxID int
156 var ID int
157
158 switch {
159 case item.MinIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MinID. != nil && item.MaxIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MaxID. != nil:
160 minID = *item.MinIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MinID.
161 if minID <= 0 || minID > 4094 {
162 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("incorrect trunk minID parameter")
163 }
164 maxID = *item.MaxIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MaxID.
165 if maxID <= 0 || maxID > 4094 {
166 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("incorrect trunk maxID parameter")
167 }
168 if maxID < minID {
169 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("minID is greater than maxID in trunk parameter")
170 }
171 for v := minID; v <= maxID; v++ {
172 vlanMap[v] = struct{}{}
173 }
174 case item.MinIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MinID. == nil && item.MaxIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MaxID. != nil:
175 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("minID and maxID should be configured simultaneously, minID is missing")
176 case item.MinIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MinID. != nil && item.MaxIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#MaxID. == nil:
177 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("minID and maxID should be configured simultaneously, maxID is missing")
178 }
179
180 // single vid
181 if item.IDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#ID. != nil {
182 ID = *item.IDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/VlanTrunk#ID.
183 if ID <= 0 || ID > 4094 {
184 return nil, errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("incorrect trunk id parameter")
185 }
186 vlanMap[ID] = struct{}{}
187 }
188 }
189
190 if len(vlanMap) == 0 {
191 return nil, nil
192 }
193 vlans := make([]int, 0, len(vlanMap))
194 for k := range vlanMap {
195 vlans = append(vlans, k)
196 }
197 sortscip-go gomod github.com/golang/go/src go1.24.2 sort/.Slicescip-go gomod github.com/golang/go/src go1.24.2 sort/Slice().(vlans, func(i int, j int) bool { return vlans[i] < vlans[j] })
198 return vlans, nil
199 }
200
201 // calcGateways processes the results from the IPAM plugin and does the
202 // following for each IP family:
203 // - Calculates and compiles a list of gateway addresses
204 // - Adds a default route if needed
205 func calcGatewaysscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/calcGateways().(result *currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Resultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#, n *NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#) (*gwInfoscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#, *gwInfoscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#, error) {
206 gwsV4 := &gwInfoscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#{}
207 gwsV6 := &gwInfoscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#{}
208
209 for _, ipc := range result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs. {
210
211 // Determine if this config is IPv4 or IPv6
212 var gws *gwInfoscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#
213 defaultNet := &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#{}
214 switch {
215 case ipc.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address..IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP..To4scip-go gomod github.com/golang/go/src go1.24.2 net/IP#To4().() != nil:
216 gws = gwsV4
217 gws.familyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#family. = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.FAMILY_V4scip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/FAMILY_V4.
218 defaultNet.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP. = netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPv4zeroscip-go gomod github.com/golang/go/src go1.24.2 net/IPv4zero.
219 case len(ipc.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address..IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.) == netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPv6lenscip-go gomod github.com/golang/go/src go1.24.2 net/IPv6len.:
220 gws = gwsV6
221 gws.familyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#family. = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.FAMILY_V6scip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/FAMILY_V6.
222 defaultNet.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP. = netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPv6zeroscip-go gomod github.com/golang/go/src go1.24.2 net/IPv6zero.
223 default:
224 return nil, 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().("Unknown IP object: %v", ipc)
225 }
226 defaultNet.Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask. = netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPMaskscip-go gomod github.com/golang/go/src go1.24.2 net/IPMask#(defaultNet.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.)
227
228 // All IPs currently refer to the container interface
229 ipc.Interfacescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Interface. = currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Intscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Int().(2)
230
231 // If not provided, calculate the gateway address corresponding
232 // to the selected IP address
233 if ipc.Gatewayscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Gateway. == nil && n.IsGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsGW. {
234 ipc.Gatewayscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Gateway. = calcGatewayIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/calcGatewayIP().(&ipc.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address.)
235 }
236
237 // Add a default route for this family using the current
238 // gateway address if necessary.
239 if n.IsDefaultGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsDefaultGW. && !gws.defaultRouteFoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#defaultRouteFound. {
240 for _, route := range result.Routesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Routes. {
241 if route.GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW. != nil && defaultNet.Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().() == route.Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().() {
242 gws.defaultRouteFoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#defaultRouteFound. = true
243 break
244 }
245 }
246 if !gws.defaultRouteFoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#defaultRouteFound. {
247 result.Routesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Routes. = append(
248 result.Routesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Routes.,
249 &typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.Routescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#{Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst.: *defaultNet, GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW.: ipc.Gatewayscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Gateway.},
250 )
251 gws.defaultRouteFoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#defaultRouteFound. = true
252 }
253 }
254
255 // Append this gateway address to the list of gateways
256 if n.IsGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsGW. {
257 gw := 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#{
258 IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: ipc.Gatewayscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Gateway.,
259 Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: ipc.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address..Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.,
260 }
261 gws.gwsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#gws. = append(gws.gwsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#gws., gw)
262 }
263 }
264 return gwsV4, gwsV6, nil
265 }
266
267 func ensureAddrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/ensureAddr().(br 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#, family int, ipn *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#, forceAddress bool) error {
268 addrs, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.AddrListscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/AddrList().(br, family)
269 if err != nil && err != syscallscip-go gomod github.com/golang/go/src go1.24.2 syscall/.ENOENTscip-go gomod github.com/golang/go/src go1.24.2 syscall/ENOENT. {
270 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 get list of IP addresses: %v", err)
271 }
272
273 ipnStr := ipn.Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().()
274 for _, a := range addrs {
275
276 // string comp is actually easiest for doing IPNet comps
277 if a.IPNetscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#IPNet..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().() == ipnStr {
278 return nil
279 }
280
281 // Multiple IPv6 addresses are allowed on the bridge if the
282 // corresponding subnets do not overlap. For IPv4 or for
283 // overlapping IPv6 subnets, reconfigure the IP address if
284 // forceAddress is true, otherwise throw an error.
285 if family == netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.FAMILY_V4scip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/FAMILY_V4. || a.IPNetscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#IPNet..Containsscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Contains().(ipn.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.) || ipn.Containsscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Contains().(a.IPNetscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#IPNet..IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.) {
286 if forceAddress {
287 if err = deleteAddrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/deleteAddr().(br, a.IPNetscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#IPNet.); err != nil {
288 return err
289 }
290 } else {
291 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().("%q already has an IP address different from %v", br.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., ipnStr)
292 }
293 }
294 }
295
296 addr := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Addrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#{IPNetscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#IPNet.: ipn, Labelscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#Label.: ""}
297 if 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().(br, addr); err != nil && err != syscallscip-go gomod github.com/golang/go/src go1.24.2 syscall/.EEXISTscip-go gomod github.com/golang/go/src go1.24.2 syscall/EEXIST. {
298 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 add IP address %s to %q: %v", ipnStr, br.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., err)
299 }
300
301 // Set the bridge's MAC to itself. Otherwise, the bridge will take the
302 // lowest-numbered mac on the bridge, and will change as ifs churn
303 if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetHardwareAddrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetHardwareAddr().(br, br.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.); err != nil {
304 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 set bridge's mac: %v", err)
305 }
306
307 return nil
308 }
309
310 func deleteAddrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/deleteAddr().(br 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#, ipn *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#) error {
311 addr := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Addrscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#{IPNetscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#IPNet.: ipn, Labelscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Addr#Label.: ""}
312
313 if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.AddrDelscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/AddrDel().(br, addr); err != nil {
314 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 remove IP address from %q: %v", br.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., err)
315 }
316
317 return nil
318 }
319
320 func bridgeByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/bridgeByName().(name string) (*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#, error) {
321 l, 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().(name)
322 if err != nil {
323 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 lookup %q: %v", name, err)
324 }
325 br, ok := l.(*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#)
326 if !ok {
327 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().("%q already exists but is not a bridge", name)
328 }
329 return br, nil
330 }
331
332 func ensureBridgescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/ensureBridge().(brName string, mtu int, promiscMode, vlanFiltering bool) (*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#, error) {
333 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().()
334 linkAttrs.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. = brName
335 linkAttrs.MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU. = mtu
336 br := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#{
337 LinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#LinkAttrs.: linkAttrs,
338 }
339 if vlanFiltering {
340 br.VlanFilteringscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#VlanFiltering. = &vlanFiltering
341 }
342
343 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().(br)
344 if err != nil && err != syscallscip-go gomod github.com/golang/go/src go1.24.2 syscall/.EEXISTscip-go gomod github.com/golang/go/src go1.24.2 syscall/EEXIST. {
345 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 add %q: %v", brName, err)
346 }
347
348 if promiscMode {
349 if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.SetPromiscOnscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/SetPromiscOn().(br); err != nil {
350 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 set promiscuous mode on %q: %v", brName, err)
351 }
352 }
353
354 // Re-fetch link to read all attributes and if it already existed,
355 // ensure it's really a bridge with similar configuration
356 br, err = bridgeByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/bridgeByName().(brName)
357 if err != nil {
358 return nil, err
359 }
360
361 // we want to own the routes for this interface
362 _, _ = sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(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().("net/ipv6/conf/%s/accept_ra", brName), "0")
363
364 if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetUpscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetUp().(br); err != nil {
365 return nil, err
366 }
367
368 return br, nil
369 }
370
371 func ensureVlanInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/ensureVlanInterface().(br *netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#, vlanID int, preserveDefaultVlan bool) (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#, error) {
372 name := 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", br.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name., vlanID)
373
374 brGatewayVeth, 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().(name)
375 if err != nil {
376 if err.Error() != "Link not found" {
377 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 find interface %q: %v", name, err)
378 }
379
380 hostNS, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetCurrentNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetCurrentNS().()
381 if err != nil {
382 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().("faild to find host namespace: %v", err)
383 }
384
385 _, brGatewayIface, err := setupVethscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/setupVeth().(hostNS, br, name, br.MTUscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MTU., false, vlanID, nil, preserveDefaultVlan, "", false)
386 if err != nil {
387 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().("faild to create vlan gateway %q: %v", name, err)
388 }
389
390 brGatewayVeth, 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().(brGatewayIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
391 if err != nil {
392 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 lookup %q: %v", brGatewayIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err)
393 }
394
395 err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetUpscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetUp().(brGatewayVeth)
396 if err != nil {
397 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 up %q: %v", brGatewayIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err)
398 }
399 }
400
401 return brGatewayVeth, nil
402 }
403
404 func setupVethscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/setupVeth().(
405 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#,
406 br *netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#,
407 ifName string,
408 mtu int,
409 hairpinMode bool,
410 vlanID int,
411 vlans []int,
412 preserveDefaultVlan bool,
413 mac string,
414 portIsolation bool,
415 ) (*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#, *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) {
416 contIface := &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#{}
417 hostIface := &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#{}
418
419 err := netns.Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(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#) error {
420 // create the veth pair in the container and move host end into host netns
421 hostVeth, containerVeth, err := ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.SetupVethscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/SetupVeth().(ifName, mtu, mac, hostNS)
422 if err != nil {
423 return err
424 }
425 contIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. = containerVeth.Namescip-go gomod github.com/golang/go/src go1.24.2 net/Interface#Name.
426 contIface.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. = containerVeth.HardwareAddrscip-go gomod github.com/golang/go/src go1.24.2 net/Interface#HardwareAddr..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/HardwareAddr#String().()
427 contIface.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. = netns.Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.()
428 hostIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. = hostVeth.Namescip-go gomod github.com/golang/go/src go1.24.2 net/Interface#Name.
429 return nil
430 })
431 if err != nil {
432 return nil, nil, err
433 }
434
435 // need to lookup hostVeth again as its index has changed during ns move
436 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().(hostIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
437 if err != nil {
438 return nil, 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 lookup %q: %v", hostIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err)
439 }
440 hostIface.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. = hostVeth.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().()
441
442 // connect host veth end to the bridge
443 if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetMasterscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetMaster().(hostVeth, br); err != nil {
444 return nil, 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 connect %q to bridge %v: %v", hostVeth.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., br.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#Attrs().().Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name., err)
445 }
446
447 // set hairpin mode
448 if err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetHairpinscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetHairpin().(hostVeth, hairpinMode); err != nil {
449 return nil, 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 setup hairpin mode for %v: %v", hostVeth.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., err)
450 }
451
452 // set isolation mode
453 if err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetIsolatedscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetIsolated().(hostVeth, portIsolation); err != nil {
454 return nil, 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 set isolated on for %v: %v", hostVeth.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., err)
455 }
456
457 if (vlanID != 0 || len(vlans) > 0) && !preserveDefaultVlan {
458 err = removeDefaultVlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/removeDefaultVlan().(hostVeth)
459 if err != nil {
460 return nil, 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 remove default vlan on interface %q: %v", hostIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err)
461 }
462 }
463
464 if vlanID != 0 {
465 err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.BridgeVlanAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/BridgeVlanAdd().(hostVeth, uint16(vlanID), true, true, false, true)
466 if err != nil {
467 return nil, 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 setup vlan tag on interface %q: %v", hostIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err)
468 }
469 }
470
471 for _, v := range vlans {
472 err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.BridgeVlanAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/BridgeVlanAdd().(hostVeth, uint16(v), false, false, false, true)
473 if err != nil {
474 return nil, 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 setup vlan tag on interface %q: %w", hostIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err)
475 }
476 }
477
478 // Backwards compatibility with users that did not specify a vlanID
479 if vlanID == 0 && len(vlans) > 0 {
480 // If no vlan is specified, we set the native vlan on the trunk equal to 1
481 err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.BridgeVlanAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/BridgeVlanAdd().(hostVeth, 1, true, true, false, true)
482 if err != nil {
483 return nil, 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 setup default native vlan tag on interface %q: %v", hostIface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., err)
484 }
485 }
486
487 return hostIface, contIface, nil
488 }
489
490 func removeDefaultVlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/removeDefaultVlan().(hostVeth 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#) error {
491 vlanInfo, err := netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.BridgeVlanListscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/BridgeVlanList().()
492 if err != nil {
493 return err
494 }
495
496 brVlanInfo, ok := vlanInfo[int32(hostVeth.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.)]
497 if ok {
498 for _, info := range brVlanInfo {
499 err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.BridgeVlanDelscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/BridgeVlanDel().(hostVeth, info.Vidscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink/nl`/BridgeVlanInfo#Vid., false, false, false, true)
500 if err != nil {
501 return err
502 }
503 }
504 }
505
506 return nil
507 }
508
509 func calcGatewayIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/calcGatewayIP().(ipn *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#) netscip-go gomod github.com/golang/go/src go1.24.2 net/.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IP# {
510 nid := ipn.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP..Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IP#Mask().(ipn.Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.)
511 return ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.NextIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/NextIP().(nid)
512 }
513
514 func setupBridgescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/setupBridge().(n *NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#) (*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#, *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) {
515 vlanFiltering := n.Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan. != 0 || n.VlanTrunkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#VlanTrunk. != nil
516 // create bridge if necessary
517 br, err := ensureBridgescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/ensureBridge().(n.BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName., n.MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#MTU., n.PromiscModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PromiscMode., vlanFiltering)
518 if err != nil {
519 return nil, 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 create bridge %q: %v", n.BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName., err)
520 }
521
522 return br, &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#{
523 Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.: br.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#Attrs().().Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name.,
524 Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac.: br.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#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().(),
525 }, nil
526 }
527
528 func enableIPForwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/enableIPForward().(family int) error {
529 if family == netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.FAMILY_V4scip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/FAMILY_V4. {
530 return ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.EnableIP4Forwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/EnableIP4Forward().()
531 }
532 return ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.EnableIP6Forwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/EnableIP6Forward().()
533 }
534
535 func cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/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 {
536 success := false
537
538 n, cniVersion, err := loadNetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/loadNetConf().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData., args.Argsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Args.)
539 if err != nil {
540 return err
541 }
542
543 isLayer3 := n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type. != ""
544
545 if isLayer3 && n.DisableContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#DisableContainerInterface. {
546 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().("cannot use IPAM when DisableContainerInterface flag is set")
547 }
548
549 if n.IsDefaultGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsDefaultGW. {
550 n.IsGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsGW. = true
551 }
552
553 if n.HairpinModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#HairpinMode. && n.PromiscModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PromiscMode. {
554 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().("cannot set hairpin mode and promiscuous mode at the same time")
555 }
556
557 br, brInterface, err := setupBridgescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/setupBridge().(n)
558 if err != nil {
559 return err
560 }
561
562 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.)
563 if err != nil {
564 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", args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns., err)
565 }
566 defer netns.Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.()
567
568 hostInterface, containerInterface, err := setupVethscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/setupVeth().(netns, br, args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., n.MTUscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#MTU., n.HairpinModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#HairpinMode., n.Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan., n.vlansscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#vlans., n.PreserveDefaultVlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PreserveDefaultVlan., n.macscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#mac., n.PortIsolationscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PortIsolation.)
569 if err != nil {
570 return err
571 }
572
573 // Assume L2 interface only
574 result := &currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Resultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#{
575 CNIVersionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#CNIVersion.: currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.ImplementedSpecVersionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/ImplementedSpecVersion.,
576 Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#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#{
577 brInterface,
578 hostInterface,
579 containerInterface,
580 },
581 }
582
583 if n.MacSpoofChkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#MacSpoofChk. {
584 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofChecker().(hostInterface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., containerInterface.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac., uniqueIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/uniqueID().(args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID., args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.))
585 if err := sc.Setupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Setup().(); err != nil {
586 return err
587 }
588 defer func() {
589 if !success {
590 if err := sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().(); err != nil {
591 fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24.2 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.2 os/Stderr., "%v", err)
592 }
593 }
594 }()
595 }
596
597 if isLayer3 {
598 // run the IPAM plugin and get back the config to apply
599 r, err := ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecAdd().(n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.)
600 if err != nil {
601 return err
602 }
603
604 // release IP in case of failure
605 defer func() {
606 if !success {
607 ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecDel().(n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.)
608 }
609 }()
610
611 // Convert whatever the IPAM result was into the current Result type
612 ipamResult, 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().(r)
613 if err != nil {
614 return err
615 }
616
617 result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs. = ipamResult.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.
618 result.Routesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Routes. = ipamResult.Routesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Routes.
619 result.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#DNS. = ipamResult.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#DNS.
620
621 if len(result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.) == 0 {
622 return errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Newscip-go gomod github.com/golang/go/src go1.24.2 errors/New().("IPAM plugin returned missing IP config")
623 }
624
625 // Gather gateway information for each IP family
626 gwsV4, gwsV6, err := calcGatewaysscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/calcGateways().(result, n)
627 if err != nil {
628 return err
629 }
630
631 // Configure the container hardware address and IP address(es)
632 if 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 {
633 if n.EnableDadscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#EnableDad. {
634 _, _ = sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(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().("/net/ipv6/conf/%s/enhanced_dad", args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.), "1")
635 _, _ = sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(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().("net/ipv6/conf/%s/accept_dad", args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.), "1")
636 } else {
637 _, _ = sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(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().("net/ipv6/conf/%s/accept_dad", args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.), "0")
638 }
639 _, _ = sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(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().("net/ipv4/conf/%s/arp_notify", args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.), "1")
640
641 // Add the IP to the interface
642 return ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ConfigureIfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ConfigureIface().(args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., result)
643 }); err != nil {
644 return err
645 }
646
647 if n.IsGWscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IsGW. {
648 var vlanInterface *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#
649 // Set the IP address(es) on the bridge and enable forwarding
650 for _, gws := range []*gwInfoscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#{gwsV4, gwsV6} {
651 for _, gw := range gws.gwsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#gws. {
652 if n.Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan. != 0 {
653 vlanIface, err := ensureVlanInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/ensureVlanInterface().(br, n.Vlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#Vlan., n.PreserveDefaultVlanscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PreserveDefaultVlan.)
654 if err != nil {
655 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 vlan interface: %v", err)
656 }
657
658 if vlanInterface == nil {
659 vlanInterface = &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#{
660 Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.: vlanIface.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.,
661 Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac.: vlanIface.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().(),
662 }
663 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., vlanInterface)
664 }
665
666 err = ensureAddrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/ensureAddr().(vlanIface, gws.familyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#family., &gw, n.ForceAddressscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#ForceAddress.)
667 if err != nil {
668 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 set vlan interface for bridge with addr: %v", err)
669 }
670 } else {
671 err = ensureAddrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/ensureAddr().(br, gws.familyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#family., &gw, n.ForceAddressscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#ForceAddress.)
672 if err != nil {
673 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 set bridge addr: %v", err)
674 }
675 }
676 }
677
678 if gws.gwsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#gws. != nil {
679 if err = enableIPForwardscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/enableIPForward().(gws.familyscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/gwInfo#family.); err != nil {
680 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 enable forwarding: %v", err)
681 }
682 }
683 }
684 }
685
686 if n.IPMasqscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IPMasq. {
687 ipns := []*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#{}
688 for _, ipc := range result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs. {
689 ipns = append(ipns, &ipc.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address.)
690 }
691 if err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.SetupIPMasqForNetworksscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/SetupIPMasqForNetworks().(n.IPMasqBackendscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IPMasqBackend., ipns, n.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#Name., args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.); err != nil {
692 return err
693 }
694 }
695 } else if !n.DisableContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#DisableContainerInterface. {
696 if 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 {
697 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().(args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.)
698 if err != nil {
699 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 retrieve link: %v", err)
700 }
701
702 // If layer 2 we still need to set the container veth to up
703 if err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetUpscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetUp().(link); err != nil {
704 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 set %q up: %v", args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., err)
705 }
706 return nil
707 }); err != nil {
708 return err
709 }
710 }
711
712 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().(hostInterface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
713 if err != nil {
714 return err
715 }
716
717 if !n.DisableContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#DisableContainerInterface. {
718 // check bridge port state
719 retries := []int{0, 50, 500, 1000, 1000}
720 for idx, sleep := range retries {
721 timescip-go gomod github.com/golang/go/src go1.24.2 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.2 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.24.2 time/.Durationscip-go gomod github.com/golang/go/src go1.24.2 time/Duration#(sleep) * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.2 time/Millisecond.)
722
723 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().(hostInterface.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
724 if err != nil {
725 return err
726 }
727 if hostVeth.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().OperStatescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#OperState. == netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.OperUpscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/OperUp. {
728 break
729 }
730
731 if idx == len(retries)-1 {
732 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().("bridge port in error state: %s", hostVeth.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().OperStatescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#OperState.)
733 }
734 }
735 }
736
737 // In certain circumstances, the host-side of the veth may change addrs
738 hostInterface.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. = hostVeth.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().()
739
740 // Refetch the bridge since its MAC address may change when the first
741 // veth is added or after its IP address is set
742 br, err = bridgeByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/bridgeByName().(n.BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName.)
743 if err != nil {
744 return err
745 }
746 brInterface.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. = br.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#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().()
747
748 // Return an error requested by testcases, if any
749 if debugPostIPAMErrorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/debugPostIPAMError. != nil {
750 return debugPostIPAMErrorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/debugPostIPAMError.
751 }
752
753 // Use incoming DNS settings if provided, otherwise use the
754 // settings that were already configured by the IPAM plugin
755 if dnsConfSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/dnsConfSet().(n.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#DNS.) {
756 result.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#DNS. = n.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#DNS.
757 }
758
759 success = true
760
761 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, cniVersion)
762 }
763
764 func dnsConfSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/dnsConfSet().(dnsConf typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.DNSscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#) bool {
765 return dnsConf.Nameserversscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Nameservers. != nil ||
766 dnsConf.Searchscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Search. != nil ||
767 dnsConf.Optionsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Options. != nil ||
768 dnsConf.Domainscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/DNS#Domain. != ""
769 }
770
771 func cmdDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/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 {
772 n, _, err := loadNetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/loadNetConf().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData., args.Argsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Args.)
773 if err != nil {
774 return err
775 }
776
777 isLayer3 := n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type. != ""
778
779 ipamDel := func() error {
780 if isLayer3 {
781 if err := ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecDel().(n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.); err != nil {
782 return err
783 }
784 }
785 return nil
786 }
787
788 if args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns. == "" {
789 return ipamDel()
790 }
791
792 // There is a netns so try to clean up. Delete can be called multiple times
793 // so don't return an error if the device is already removed.
794 // If the device isn't there then don't try to clean up IP masq either.
795 var ipnets []*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#
796 err = nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.WithNetNSPathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/WithNetNSPath().(args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns., 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 {
797 var err error
798 ipnets, err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.DelLinkByNameAddrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/DelLinkByNameAddr().(args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.)
799 if err != nil && err == ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.ErrLinkNotFoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/ErrLinkNotFound. {
800 return nil
801 }
802 return err
803 })
804 if err != nil {
805 // if NetNs is passed down by the Cloud Orchestration Engine, or if it called multiple times
806 // so don't return an error if the device is already removed.
807 // https://github.com/kubernetes/kubernetes/issues/43014#issuecomment-287164444
808 _, ok := err.(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NSPathNotExistErrscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NSPathNotExistErr#)
809 if ok {
810 return ipamDel()
811 }
812 return err
813 }
814
815 // call ipam.ExecDel after clean up device in netns
816 if err := ipamDel(); err != nil {
817 return err
818 }
819
820 if n.MacSpoofChkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#MacSpoofChk. {
821 sc := linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/.NewSpoofCheckerscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/NewSpoofChecker().("", "", uniqueIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/uniqueID().(args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID., args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.))
822 if err := sc.Teardownscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/link`/SpoofChecker#Teardown().(); err != nil {
823 fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.24.2 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.2 os/Stderr., "%v", err)
824 }
825 }
826
827 if isLayer3 && n.IPMasqscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#IPMasq. {
828 if err := ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.TeardownIPMasqForNetworksscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/TeardownIPMasqForNetworks().(ipnets, n.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#Name., args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.); err != nil {
829 return err
830 }
831 }
832
833 return err
834 }
835
836 func mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/main().() {
837 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#{
838 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/main/bridge`/cmdAdd().,
839 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/main/bridge`/cmdCheck().,
840 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/main/bridge`/cmdDel().,
841 Statusscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CNIFuncs#Status.: cmdStatusscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cmdStatus().,
842 /* FIXME GC */
843 }, versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/.Allscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/All., 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().("bridge"))
844 }
845
846 type cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf# struct {
847 Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#Name. string
848 ifIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#ifIndex. int
849 peerIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#peerIndex. int
850 masterIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#masterIndex. int
851 foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. bool
852 }
853
854 func validateInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateInterface().(intf 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#, expectInSb bool) (cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#, 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#, error) {
855 ifFound := cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#{foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found.: false}
856 if intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. == "" {
857 return ifFound, 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().("Interface name missing ")
858 }
859
860 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().(intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
861 if err != nil {
862 return ifFound, 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().("Interface name %s not found", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
863 }
864
865 if expectInSb {
866 if intf.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. == "" {
867 return ifFound, 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().("Interface %s is expected to be in a sandbox", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
868 }
869 } else {
870 if intf.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. != "" {
871 return ifFound, 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().("Interface %s should not be in sandbox", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
872 }
873 }
874
875 return ifFound, link, err
876 }
877
878 func validateCniBrInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateCniBrInterface().(intf 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#, n *NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#) (cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#, error) {
879 brFound, link, err := validateInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateInterface().(intf, false)
880 if err != nil {
881 return brFound, err
882 }
883
884 _, isBridge := link.(*netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Bridgescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Bridge#)
885 if !isBridge {
886 return brFound, 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().("Interface %s does not have link type of bridge", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.)
887 }
888
889 if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != "" {
890 if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != link.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().() {
891 return brFound, 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().("Bridge interface %s Mac doesn't match: %s", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac.)
892 }
893 }
894
895 linkPromisc := link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().Promiscscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Promisc. != 0
896 if linkPromisc != n.PromiscModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PromiscMode. {
897 return brFound, 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().("Bridge interface %s configured Promisc Mode %v doesn't match current state: %v ",
898 intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., n.PromiscModescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#PromiscMode., linkPromisc)
899 }
900
901 brFound.foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. = true
902 brFound.Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#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.
903 brFound.ifIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#ifIndex. = link.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.
904 brFound.masterIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#masterIndex. = link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().MasterIndexscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MasterIndex.
905
906 return brFound, nil
907 }
908
909 func validateCniVethInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateCniVethInterface().(intf *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#, brIf cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#, contIf cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#) (cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#, error) {
910 vethFound, link, err := validateInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateInterface().(*intf, false)
911 if err != nil {
912 return vethFound, err
913 }
914
915 _, isVeth := link.(*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#)
916 if !isVeth {
917 // just skip it, it's not what CNI created
918 return vethFound, nil
919 }
920
921 _, vethFound.peerIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#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().(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.)
922 if err != nil {
923 return vethFound, 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().("Unable to obtain veth peer index for veth %s", 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.)
924 }
925 vethFound.ifIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#ifIndex. = link.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.
926 vethFound.masterIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#masterIndex. = link.Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().MasterIndexscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#MasterIndex.
927
928 if vethFound.ifIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#ifIndex. != contIf.peerIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#peerIndex. {
929 return vethFound, nil
930 }
931
932 if contIf.ifIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#ifIndex. != vethFound.peerIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#peerIndex. {
933 return vethFound, nil
934 }
935
936 if vethFound.masterIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#masterIndex. != brIf.ifIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#ifIndex. {
937 return vethFound, nil
938 }
939
940 if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != "" {
941 if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != link.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().() {
942 return vethFound, 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().("Interface %s Mac doesn't match: %s not found", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac.)
943 }
944 }
945
946 vethFound.foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. = true
947 vethFound.Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#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.
948
949 return vethFound, nil
950 }
951
952 func validateCniContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateCniContainerInterface().(intf 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#) (cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#, error) {
953 vethFound, link, err := validateInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateInterface().(intf, true)
954 if err != nil {
955 return vethFound, err
956 }
957
958 _, isVeth := link.(*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#)
959 if !isVeth {
960 return vethFound, 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().("Error: Container interface %s not of type veth", 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.)
961 }
962 _, vethFound.peerIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#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().(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.)
963 if err != nil {
964 return vethFound, 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().("Unable to obtain veth peer index for veth %s", 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.)
965 }
966 vethFound.ifIndexscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#ifIndex. = link.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.
967
968 if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != "" {
969 if intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac. != link.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().() {
970 return vethFound, 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().("Interface %s Mac %s doesn't match container Mac: %s", intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name., intf.Macscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Mac., link.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.)
971 }
972 }
973
974 vethFound.foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. = true
975 vethFound.Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#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.
976
977 return vethFound, nil
978 }
979
980 func cmdCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/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 {
981 n, _, err := loadNetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/loadNetConf().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData., args.Argsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Args.)
982 if err != nil {
983 return err
984 }
985 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.)
986 if err != nil {
987 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", args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns., err)
988 }
989 defer netns.Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.()
990
991 // run the IPAM plugin and get back the config to apply
992 err = ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecCheck().(n.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.)
993 if err != nil {
994 return err
995 }
996
997 // Parse previous result.
998 if n.NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#NetConf..RawPrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#RawPrevResult. == nil {
999 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().("Required prevResult missing")
1000 }
1001
1002 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().(&n.NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#NetConf.); err != nil {
1003 return err
1004 }
1005
1006 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().(n.PrevResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#PrevResult.)
1007 if err != nil {
1008 return err
1009 }
1010
1011 var errLink error
1012 var contCNI, vethCNI cniBridgeIfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#
1013 var brMap, contMap 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#
1014
1015 // Find interfaces for names whe know, CNI Bridge and container
1016 for _, intf := range result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces. {
1017 if n.BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName. == intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. {
1018 brMap = *intf
1019 continue
1020 } else if args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName. == intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. {
1021 if args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns. == intf.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. {
1022 contMap = *intf
1023 continue
1024 }
1025 }
1026 }
1027
1028 brCNI, err := validateCniBrInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateCniBrInterface().(brMap, n)
1029 if err != nil {
1030 return err
1031 }
1032
1033 // The namespace must be the same as what was configured
1034 if args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns. != contMap.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox. {
1035 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().("Sandbox in prevResult %s doesn't match configured netns: %s",
1036 contMap.Sandboxscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Sandbox., args.Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.)
1037 }
1038
1039 // Check interface against values found in the container
1040 if 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 {
1041 contCNI, errLink = validateCniContainerInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateCniContainerInterface().(contMap)
1042 if errLink != nil {
1043 return errLink
1044 }
1045 return nil
1046 }); err != nil {
1047 return err
1048 }
1049
1050 // Now look for veth that is peer with container interface.
1051 // Anything else wasn't created by CNI, skip it
1052 for _, intf := range result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces. {
1053 // Skip this result if name is the same as cni bridge
1054 // It's either the cni bridge we dealt with above, or something with the
1055 // same name in a different namespace. We just skip since it's not ours
1056 if brMap.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. == intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. {
1057 continue
1058 }
1059
1060 // same here for container name
1061 if contMap.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. == intf.Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name. {
1062 continue
1063 }
1064
1065 vethCNI, errLink = validateCniVethInterfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/validateCniVethInterface().(intf, brCNI, contCNI)
1066 if errLink != nil {
1067 return errLink
1068 }
1069
1070 if vethCNI.foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. {
1071 // veth with container interface as peer and bridge as master found
1072 break
1073 }
1074 }
1075
1076 if !brCNI.foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. {
1077 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().("CNI created bridge %s in host namespace was not found", n.BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName.)
1078 }
1079 if !contCNI.foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. {
1080 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().("CNI created interface in container %s not found", args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.)
1081 }
1082 if !vethCNI.foundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cniBridgeIf#found. {
1083 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().("CNI veth created for bridge %s was not found", n.BrNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#BrName.)
1084 }
1085
1086 // Check prevResults for ips, routes and dns against values found in the container
1087 return 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 {
1088 err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.ValidateExpectedInterfaceIPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/ValidateExpectedInterfaceIPs().(args.IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName., result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.)
1089 if err != nil {
1090 return err
1091 }
1092
1093 err = ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.ValidateExpectedRoutescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/ValidateExpectedRoute().(result.Routesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Routes.)
1094 if err != nil {
1095 return err
1096 }
1097 return nil
1098 })
1099 }
1100
1101 func uniqueIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/uniqueID().(containerID, cniIface string) string {
1102 return containerID + "-" + cniIface
1103 }
1104
1105 func cmdStatusscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/cmdStatus().(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 {
1106 conf := NetConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/main/bridge`/NetConf#{}
1107 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().(args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData., &conf); err != nil {
1108 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 load netconf: %w", err)
1109 }
1110
1111 if conf.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type. != "" {
1112 if err := ipamscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/.ExecStatusscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ipam`/ExecStatus().(conf.IPAMscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#IPAM..Typescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPAM#Type., args.StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.); err != nil {
1113 return err
1114 }
1115 }
1116
1117 return nil
1118 }