| 1 | // Copyright 2015 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 allocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/ |
| 16 | |
| 17 | import ( |
| 18 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 20 | "netscip-go gomod github.com/golang/go/src go1.24.2 net/" |
| 21 | |
| 22 | "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/" |
| 23 | "github.com/containernetworking/cni/pkg/versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/" |
| 24 | "github.com/containernetworking/plugins/pkg/ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/" |
| 25 | ) |
| 26 | |
| 27 | // The top-level network config - IPAM plugins are passed the full configuration |
| 28 | // of the calling plugin, not just the IPAM section. |
| 29 | type Netscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net# struct { |
| 30 | Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#Name. string `json:"name"` |
| 31 | CNIVersionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#CNIVersion. string `json:"cniVersion"` |
| 32 | IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM. *IPAMConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig# `json:"ipam"` |
| 33 | RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#RuntimeConfig. struct { |
| 34 | // The capability arg |
| 35 | IPRangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_f769a5c462e39e27#IPRanges. []RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet# `json:"ipRanges,omitempty"` |
| 36 | IPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_f769a5c462e39e27#IPs. []*ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.IPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/IP# `json:"ips,omitempty"` |
| 37 | } `json:"runtimeConfig,omitempty"` |
| 38 | Argsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#Args. *struct { |
| 39 | Ascip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_1b75945a9f10cfa5#A. *IPAMArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMArgs# `json:"cni"` |
| 40 | } `json:"args"` |
| 41 | } |
| 42 | |
| 43 | // IPAMConfig represents the IP related network configuration. |
| 44 | // This nests Range because we initially only supported a single |
| 45 | // range directly, and wish to preserve backwards compatibility |
| 46 | type IPAMConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig# struct { |
| 47 | *Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Range. |
| 48 | Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Name. string |
| 49 | Typescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Type. string `json:"type"` |
| 50 | Routesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Routes. []*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# `json:"routes"` |
| 51 | DataDirscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#DataDir. string `json:"dataDir"` |
| 52 | ResolvConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#ResolvConf. string `json:"resolvConf"` |
| 53 | Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges. []RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet# `json:"ranges"` |
| 54 | IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs. []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# `json:"-"` // Requested IPs from CNI_ARGS, args and capabilities |
| 55 | } |
| 56 | |
| 57 | type IPAMEnvArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMEnvArgs# struct { |
| 58 | 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/ipam/host-local/backend/allocator`/IPAMEnvArgs#CommonArgs. |
| 59 | IPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMEnvArgs#IP. ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.IPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/IP# `json:"ip,omitempty"` |
| 60 | } |
| 61 | |
| 62 | type IPAMArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMArgs# struct { |
| 63 | IPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMArgs#IPs. []*ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/.IPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/IP# `json:"ips"` |
| 64 | } |
| 65 | |
| 66 | type RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet# []Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range# |
| 67 | |
| 68 | type Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range# struct { |
| 69 | RangeStartscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#RangeStart. 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# `json:"rangeStart,omitempty"` // The first ip, inclusive |
| 70 | RangeEndscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#RangeEnd. 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# `json:"rangeEnd,omitempty"` // The last ip, inclusive |
| 71 | Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet. typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.IPNetscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/IPNet# `json:"subnet"` |
| 72 | Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Gateway. 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# `json:"gateway,omitempty"` |
| 73 | } |
| 74 | |
| 75 | // NewIPAMConfig creates a NetworkConfig from the given network name. |
| 76 | func LoadIPAMConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/LoadIPAMConfig().(bytes []byte, envArgs string) (*IPAMConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#, string, error) { |
| 77 | n := Netscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#{} |
| 78 | 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 { |
| 79 | return nil, "", err |
| 80 | } |
| 81 | |
| 82 | if n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM. == nil { |
| 83 | 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().("IPAM config missing 'ipam' key") |
| 84 | } |
| 85 | |
| 86 | // parse custom IP from env args |
| 87 | if envArgs != "" { |
| 88 | e := IPAMEnvArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMEnvArgs#{} |
| 89 | 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) |
| 90 | if err != nil { |
| 91 | return nil, "", err |
| 92 | } |
| 93 | |
| 94 | if e.IPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMEnvArgs#IP..ToIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/IP#ToIP().() != nil { |
| 95 | n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs. = []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#{e.IPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMEnvArgs#IP..ToIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/IP#ToIP().()} |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // parse custom IPs from CNI args in network config |
| 100 | if n.Argsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#Args. != nil && n.Argsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#Args..Ascip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_1b75945a9f10cfa5#A. != nil && len(n.Argsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#Args..Ascip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_1b75945a9f10cfa5#A..IPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMArgs#IPs.) != 0 { |
| 101 | for _, i := range n.Argsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#Args..Ascip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_1b75945a9f10cfa5#A..IPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMArgs#IPs. { |
| 102 | n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs. = append(n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs., i.ToIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/IP#ToIP().()) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // parse custom IPs from runtime configuration |
| 107 | if len(n.RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#RuntimeConfig..IPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_f769a5c462e39e27#IPs.) > 0 { |
| 108 | for _, i := range n.RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#RuntimeConfig..IPsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_f769a5c462e39e27#IPs. { |
| 109 | n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs. = append(n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs., i.ToIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/IP#ToIP().()) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | for idx := range n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs. { |
| 114 | if err := canonicalizeIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/canonicalizeIP().(&n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..IPArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#IPArgs.[idx]); err != nil { |
| 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().("cannot understand ip: %v", err) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // If a single range (old-style config) is specified, prepend it to |
| 120 | // the Ranges array |
| 121 | if n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Range. != nil && n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Range..Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet..IP != nil { |
| 122 | n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges. = append([]RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#{{*n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Range.}}, n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges....) |
| 123 | } |
| 124 | n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Range. = nil |
| 125 | |
| 126 | // If a range is supplied as a runtime config, prepend it to the Ranges |
| 127 | if len(n.RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#RuntimeConfig..IPRangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_f769a5c462e39e27#IPRanges.) > 0 { |
| 128 | n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges. = append(n.RuntimeConfigscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#RuntimeConfig..IPRangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#$anon_f769a5c462e39e27#IPRanges., n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges....) |
| 129 | } |
| 130 | |
| 131 | if len(n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges.) == 0 { |
| 132 | return nil, "", fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Errorf().("no IP ranges specified") |
| 133 | } |
| 134 | |
| 135 | // Validate all ranges |
| 136 | numV4 := 0 |
| 137 | numV6 := 0 |
| 138 | for i := range n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges. { |
| 139 | if err := n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges.[i].Canonicalizescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Canonicalize().(); err != nil { |
| 140 | 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 range set %d: %s", i, err) |
| 141 | } |
| 142 | |
| 143 | if n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges.[i][0].RangeStartscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#RangeStart..To4scip-go gomod github.com/golang/go/src go1.24.2 net/IP#To4().() != nil { |
| 144 | numV4++ |
| 145 | } else { |
| 146 | numV6++ |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // CNI spec 0.2.0 and below supported only one v4 and v6 address |
| 151 | if numV4 > 1 || numV6 > 1 { |
| 152 | if ok, _ := versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/.GreaterThanOrEqualToscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/GreaterThanOrEqualTo().(n.CNIVersionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#CNIVersion., "0.3.0"); !ok { |
| 153 | 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().("CNI version %v does not support more than 1 address per family", n.CNIVersionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#CNIVersion.) |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Check for overlaps |
| 158 | l := len(n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges.) |
| 159 | for i, p1 := range n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges.[:l-1] { |
| 160 | for j, p2 := range n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Rangesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Ranges.[i+1:] { |
| 161 | if p1.Overlapsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Overlaps().(&p2) { |
| 162 | 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().("range set %d overlaps with %d", i, (i + j + 1)) |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Copy net name into IPAM so not to drag Net struct around |
| 168 | n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM..Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAMConfig#Name. = n.Namescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#Name. |
| 169 | |
| 170 | return n.IPAMscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#IPAM., n.CNIVersionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Net#CNIVersion., nil |
| 171 | } |