| 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 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 19 | "logscip-go gomod github.com/golang/go/src go1.24.2 log/" |
| 20 | "netscip-go gomod github.com/golang/go/src go1.24.2 net/" |
| 21 | "osscip-go gomod github.com/golang/go/src go1.24.2 os/" |
| 22 | "strconvscip-go gomod github.com/golang/go/src go1.24.2 strconv/" |
| 23 | |
| 24 | 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`/" |
| 25 | "github.com/containernetworking/plugins/pkg/ipscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ip`/" |
| 26 | "github.com/containernetworking/plugins/plugins/ipam/host-local/backendscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/" |
| 27 | ) |
| 28 | |
| 29 | type IPAllocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator# struct { |
| 30 | rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset. *RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet# |
| 31 | storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store. backendscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/.Storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store# |
| 32 | rangeIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeID. string // Used for tracking last reserved ip |
| 33 | } |
| 34 | |
| 35 | func NewIPAllocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/NewIPAllocator().(s *RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#, store backendscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/.Storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#, id int) *IPAllocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator# { |
| 36 | return &IPAllocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#{ |
| 37 | rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset.: s, |
| 38 | storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store.: store, |
| 39 | rangeIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeID.: strconvscip-go gomod github.com/golang/go/src go1.24.2 strconv/.Itoascip-go gomod github.com/golang/go/src go1.24.2 strconv/Itoa().(id), |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Get allocates an IP |
| 44 | func (a *IPAllocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#) Getscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#Get().(id string, ifname string, requestedIP 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#) (*currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.IPConfigscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#, error) { |
| 45 | a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..Lockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#Lock.() |
| 46 | defer a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..Unlockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#Unlock.() |
| 47 | |
| 48 | var reservedIP *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# |
| 49 | var gw 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# |
| 50 | |
| 51 | if requestedIP != nil { |
| 52 | if err := canonicalizeIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/canonicalizeIP().(&requestedIP); err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | |
| 56 | r, err := a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset..RangeForscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#RangeFor().(requestedIP) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | |
| 61 | if requestedIP.Equalscip-go gomod github.com/golang/go/src go1.24.2 net/IP#Equal().(r.Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Gateway.) { |
| 62 | 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().("requested ip %s is subnet's gateway", requestedIP.Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IP#String().()) |
| 63 | } |
| 64 | |
| 65 | reserved, err := a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..Reservescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#Reserve.(id, ifname, requestedIP, a.rangeIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeID.) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | if !reserved { |
| 70 | 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().("requested IP address %s is not available in range set %s", requestedIP, a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset..Stringscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#String().()) |
| 71 | } |
| 72 | reservedIP = &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#{IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: requestedIP, Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: r.Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet..Mask} |
| 73 | gw = r.Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Gateway. |
| 74 | |
| 75 | } else { |
| 76 | // try to get allocated IPs for this given id, if exists, just return error |
| 77 | // because duplicate allocation is not allowed in SPEC |
| 78 | // https://github.com/containernetworking/cni/blob/master/SPEC.md |
| 79 | allocatedIPs := a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..GetByIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#GetByID.(id, ifname) |
| 80 | for _, allocatedIP := range allocatedIPs { |
| 81 | // check whether the existing IP belong to this range set |
| 82 | if _, err := a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset..RangeForscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#RangeFor().(allocatedIP); err == 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().("%s has been allocated to %s, duplicate allocation is not allowed", allocatedIP.Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IP#String().(), id) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | iter, err := a.GetIterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#GetIter().() |
| 88 | if err != nil { |
| 89 | return nil, err |
| 90 | } |
| 91 | for { |
| 92 | reservedIP, gw = iter.Nextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#Next().() |
| 93 | if reservedIP == nil { |
| 94 | break |
| 95 | } |
| 96 | |
| 97 | reserved, err := a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..Reservescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#Reserve.(id, ifname, reservedIP.IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP., a.rangeIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeID.) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | if reserved { |
| 103 | break |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if reservedIP == nil { |
| 109 | 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 addresses available in range set: %s", a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset..Stringscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#String().()) |
| 110 | } |
| 111 | |
| 112 | return ¤tscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.IPConfigscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#{ |
| 113 | Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address.: *reservedIP, |
| 114 | Gatewayscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Gateway.: gw, |
| 115 | }, nil |
| 116 | } |
| 117 | |
| 118 | // Release clears all IPs allocated for the container with given ID |
| 119 | func (a *IPAllocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#) Releasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#Release().(id string, ifname string) error { |
| 120 | a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..Lockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#Lock.() |
| 121 | defer a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..Unlockscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#Unlock.() |
| 122 | |
| 123 | return a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..ReleaseByIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#ReleaseByID.(id, ifname) |
| 124 | } |
| 125 | |
| 126 | type RangeIterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter# struct { |
| 127 | rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeset. *RangeSetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet# |
| 128 | |
| 129 | // The current range id |
| 130 | rangeIdxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeIdx. int |
| 131 | |
| 132 | // Our current position |
| 133 | curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. 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# |
| 134 | |
| 135 | // The IP where we started iterating; if we hit this again, we're done. |
| 136 | startIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#startIP. 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# |
| 137 | } |
| 138 | |
| 139 | // GetIter encapsulates the strategy for this allocator. |
| 140 | // We use a round-robin strategy, attempting to evenly use the whole set. |
| 141 | // More specifically, a crash-looping container will not see the same IP until |
| 142 | // the entire range has been run through. |
| 143 | // We may wish to consider avoiding recently-released IPs in the future. |
| 144 | func (a *IPAllocatorscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#) GetIterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#GetIter().() (*RangeIterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#, error) { |
| 145 | iter := RangeIterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#{ |
| 146 | rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeset.: a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset., |
| 147 | } |
| 148 | |
| 149 | // Round-robin by trying to allocate from the last reserved IP + 1 |
| 150 | startFromLastReservedIP := false |
| 151 | |
| 152 | // We might get a last reserved IP that is wrong if the range indexes changed. |
| 153 | // This is not critical, we just lose round-robin this one time. |
| 154 | lastReservedIP, err := a.storescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#store..LastReservedIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend`/Store#LastReservedIP.(a.rangeIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeID.) |
| 155 | if err != nil && !osscip-go gomod github.com/golang/go/src go1.24.2 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.24.2 os/IsNotExist().(err) { |
| 156 | logscip-go gomod github.com/golang/go/src go1.24.2 log/.Printfscip-go gomod github.com/golang/go/src go1.24.2 log/Printf().("Error retrieving last reserved ip: %v", err) |
| 157 | } else if lastReservedIP != nil { |
| 158 | startFromLastReservedIP = a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset..Containsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeSet#Contains().(lastReservedIP) |
| 159 | } |
| 160 | |
| 161 | // Find the range in the set with this IP |
| 162 | if startFromLastReservedIP { |
| 163 | for i, r := range *a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset. { |
| 164 | if r.Containsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Contains().(lastReservedIP) { |
| 165 | iter.rangeIdxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeIdx. = i |
| 166 | |
| 167 | // We advance the cursor on every Next(), so the first call |
| 168 | // to next() will return lastReservedIP + 1 |
| 169 | iter.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. = lastReservedIP |
| 170 | break |
| 171 | } |
| 172 | } |
| 173 | } else { |
| 174 | iter.rangeIdxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeIdx. = 0 |
| 175 | iter.startIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#startIP. = (*a.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/IPAllocator#rangeset.)[0].RangeStartscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#RangeStart. |
| 176 | } |
| 177 | return &iter, nil |
| 178 | } |
| 179 | |
| 180 | // Next returns the next IP, its mask, and its gateway. Returns nil |
| 181 | // if the iterator has been exhausted |
| 182 | func (i *RangeIterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#) Nextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#Next().() (*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#) { |
| 183 | r := (*i.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeset.)[i.rangeIdxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeIdx.] |
| 184 | |
| 185 | // If this is the first time iterating and we're not starting in the middle |
| 186 | // of the range, then start at rangeStart, which is inclusive |
| 187 | if i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. == nil { |
| 188 | i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. = r.RangeStartscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#RangeStart. |
| 189 | i.startIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#startIP. = i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. |
| 190 | if i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur..Equalscip-go gomod github.com/golang/go/src go1.24.2 net/IP#Equal().(r.Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Gateway.) { |
| 191 | return i.Nextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#Next().() |
| 192 | } |
| 193 | return &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#{IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur., Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: r.Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet..Mask}, r.Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Gateway. |
| 194 | } |
| 195 | |
| 196 | // If we've reached the end of this range, we need to advance the range |
| 197 | // RangeEnd is inclusive as well |
| 198 | if i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur..Equalscip-go gomod github.com/golang/go/src go1.24.2 net/IP#Equal().(r.RangeEndscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#RangeEnd.) { |
| 199 | i.rangeIdxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeIdx.++ |
| 200 | i.rangeIdxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeIdx. %= len(*i.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeset.) |
| 201 | r = (*i.rangesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeset.)[i.rangeIdxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#rangeIdx.] |
| 202 | |
| 203 | i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. = r.RangeStartscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#RangeStart. |
| 204 | } else { |
| 205 | i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. = 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().(i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur.) |
| 206 | } |
| 207 | |
| 208 | if i.startIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#startIP. == nil { |
| 209 | i.startIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#startIP. = i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur. |
| 210 | } else if i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur..Equalscip-go gomod github.com/golang/go/src go1.24.2 net/IP#Equal().(i.startIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#startIP.) { |
| 211 | // IF we've looped back to where we started, give up |
| 212 | return nil, nil |
| 213 | } |
| 214 | |
| 215 | if i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur..Equalscip-go gomod github.com/golang/go/src go1.24.2 net/IP#Equal().(r.Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Gateway.) { |
| 216 | return i.Nextscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#Next().() |
| 217 | } |
| 218 | |
| 219 | return &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#{IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: i.curscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/RangeIter#cur., Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: r.Subnetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Subnet..Mask}, r.Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator`/Range#Gateway. |
| 220 | } |