| 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 mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ |
| 16 | |
| 17 | import ( |
| 18 | "contextscip-go gomod github.com/golang/go/src go1.24.2 context/" |
| 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 | "logscip-go gomod github.com/golang/go/src go1.24.2 log/" |
| 22 | "math/randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/" |
| 23 | "netscip-go gomod github.com/golang/go/src go1.24.2 net/" |
| 24 | "stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/" |
| 25 | "syncscip-go gomod github.com/golang/go/src go1.24.2 sync/" |
| 26 | "sync/atomicscip-go gomod github.com/golang/go/src go1.24.2 `sync/atomic`/" |
| 27 | "timescip-go gomod github.com/golang/go/src go1.24.2 time/" |
| 28 | |
| 29 | dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/ "github.com/insomniacslk/dhcp/dhcpv4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/" |
| 30 | "github.com/insomniacslk/dhcp/dhcpv4/nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/" |
| 31 | "github.com/vishvananda/netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/" |
| 32 | |
| 33 | "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/" |
| 34 | "github.com/containernetworking/plugins/pkg/netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/" |
| 35 | "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/" |
| 36 | ) |
| 37 | |
| 38 | // RFC 2131 suggests using exponential backoff, starting with 4sec |
| 39 | // and randomized to +/- 1sec |
| 40 | const ( |
| 41 | resendDelay0scip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/resendDelay0. = 4 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second. |
| 42 | resendDelayMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/resendDelayMax. = 62 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second. |
| 43 | defaultLeaseTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/defaultLeaseTime. = 60 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Minutescip-go gomod github.com/golang/go/src go1.24.2 time/Minute. |
| 44 | defaultResendTimeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/defaultResendTimeout. = 208 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second. // fast resend + backoff resend |
| 45 | ) |
| 46 | |
| 47 | // To speed up the retry for first few failures, we retry without |
| 48 | // backoff for a few times |
| 49 | const ( |
| 50 | resendFastDelayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/resendFastDelay. = 2 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second. |
| 51 | resendFastMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/resendFastMax. = 4 |
| 52 | ) |
| 53 | |
| 54 | const ( |
| 55 | leaseStateBoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateBound. = iota |
| 56 | leaseStateRenewingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateRenewing. |
| 57 | leaseStateRebindingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateRebinding. |
| 58 | ) |
| 59 | |
| 60 | // Timing for retrying link existence check |
| 61 | const ( |
| 62 | linkCheckDelay0scip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/linkCheckDelay0. = 1 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second. |
| 63 | linkCheckRetryMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/linkCheckRetryMax. = 10 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second. |
| 64 | linkCheckTotalTimeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/linkCheckTotalTimeout. = 30 * timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second. |
| 65 | ) |
| 66 | |
| 67 | // This implementation uses 1 OS thread per lease. This is because |
| 68 | // all the network operations have to be done in network namespace |
| 69 | // of the interface. This can be improved by switching to the proper |
| 70 | // namespace for network ops and using fewer threads. However, this |
| 71 | // needs to be done carefully as dhcp4client ops are blocking. |
| 72 | |
| 73 | type DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease# struct { |
| 74 | clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID. string |
| 75 | latestLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#latestLease. *nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Leasescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease# |
| 76 | linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link. netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Linkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link# |
| 77 | linkNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#linkName. string |
| 78 | renewalTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#renewalTime. timescip-go gomod github.com/golang/go/src go1.24.2 time/.Timescip-go gomod github.com/golang/go/src go1.24.2 time/Time# |
| 79 | rebindingTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#rebindingTime. timescip-go gomod github.com/golang/go/src go1.24.2 time/.Timescip-go gomod github.com/golang/go/src go1.24.2 time/Time# |
| 80 | expireTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#expireTime. timescip-go gomod github.com/golang/go/src go1.24.2 time/.Timescip-go gomod github.com/golang/go/src go1.24.2 time/Time# |
| 81 | timeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#timeout. 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# |
| 82 | resendMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendMax. 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# |
| 83 | resendTimeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendTimeout. 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# |
| 84 | broadcastscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#broadcast. bool |
| 85 | stoppingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#stopping. uint32 |
| 86 | stopscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#stop. chan struct{} |
| 87 | checkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#check. chan struct{} |
| 88 | wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#wg. syncscip-go gomod github.com/golang/go/src go1.24.2 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup# |
| 89 | cancelFuncscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#cancelFunc. contextscip-go gomod github.com/golang/go/src go1.24.2 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.24.2 context/CancelFunc# |
| 90 | ctxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#ctx. contextscip-go gomod github.com/golang/go/src go1.24.2 context/.Contextscip-go gomod github.com/golang/go/src go1.24.2 context/Context# |
| 91 | // list of requesting and providing options and if they are necessary / their value |
| 92 | optsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#opts. []dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Optionscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option# |
| 93 | } |
| 94 | |
| 95 | var requestOptionsDefaultscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/requestOptionsDefault. = []dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionCodescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionCode#{ |
| 96 | dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionRouterscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionRouter., |
| 97 | dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionSubnetMaskscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionSubnetMask., |
| 98 | } |
| 99 | |
| 100 | func prepareOptionsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/prepareOptions().(cniArgs string, provideOptions []ProvideOptionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#, requestOptions []RequestOptionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/RequestOption#) ( |
| 101 | []dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Optionscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#, error, |
| 102 | ) { |
| 103 | var opts []dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Optionscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option# |
| 104 | |
| 105 | var err error |
| 106 | // parse CNI args |
| 107 | cniArgsParsed := map[string]string{} |
| 108 | for _, argPair := range stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Splitscip-go gomod github.com/golang/go/src go1.24.2 strings/Split().(cniArgs, ";") { |
| 109 | args := stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.SplitNscip-go gomod github.com/golang/go/src go1.24.2 strings/SplitN().(argPair, "=", 2) |
| 110 | if len(args) > 1 { |
| 111 | cniArgsParsed[args[0]] = args[1] |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // parse providing options map |
| 116 | var optParsed dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionCodescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionCode# |
| 117 | for _, opt := range provideOptions { |
| 118 | optParsed, err = parseOptionNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/parseOptionName().(string(opt.Optionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Option.)) |
| 119 | if err != nil { |
| 120 | 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().("Can not parse option %q: %w", opt.Optionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Option., err) |
| 121 | } |
| 122 | if len(opt.Valuescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Value.) > 0 { |
| 123 | if len(opt.Valuescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Value.) > 255 { |
| 124 | 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().("value too long for option %q: %q", opt.Optionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Option., opt.Valuescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Value.) |
| 125 | } |
| 126 | opts = append(opts, dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Optionscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#{Codescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#Code.: optParsed, Valuescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#Value.: dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Stringscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/String#(opt.Valuescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Value.)}) |
| 127 | } |
| 128 | if value, ok := cniArgsParsed[opt.ValueFromCNIArgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#ValueFromCNIArg.]; ok { |
| 129 | if len(value) > 255 { |
| 130 | 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().("value too long for option %q from CNI_ARGS %q: %q", opt.Optionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Option., opt.ValueFromCNIArgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#ValueFromCNIArg., opt.Valuescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/ProvideOption#Value.) |
| 131 | } |
| 132 | opts = append(opts, dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Optionscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#{Codescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#Code.: optParsed, Valuescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#Value.: dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Stringscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/String#(value)}) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // parse necessary options map |
| 137 | var optsRequesting dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionCodeListscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionCodeList# |
| 138 | skipRequireDefault := false |
| 139 | for _, opt := range requestOptions { |
| 140 | if opt.SkipDefaultscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/RequestOption#SkipDefault. { |
| 141 | skipRequireDefault = true |
| 142 | } |
| 143 | if opt.Optionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/RequestOption#Option. == "" { |
| 144 | continue |
| 145 | } |
| 146 | optParsed, err = parseOptionNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/parseOptionName().(string(opt.Optionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/RequestOption#Option.)) |
| 147 | if err != nil { |
| 148 | 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().("Can not parse option %q: %w", opt.Optionscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/RequestOption#Option., err) |
| 149 | } |
| 150 | optsRequesting.Addscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionCodeList#Add().(optParsed) |
| 151 | } |
| 152 | if !skipRequireDefault { |
| 153 | for _, opt := range requestOptionsDefaultscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/requestOptionsDefault. { |
| 154 | optsRequesting.Addscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionCodeList#Add().(opt) |
| 155 | } |
| 156 | } |
| 157 | if len(optsRequesting) > 0 { |
| 158 | opts = append(opts, dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Optionscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#{Codescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#Code.: dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionParameterRequestListscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionParameterRequestList., Valuescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#Value.: optsRequesting}) |
| 159 | } |
| 160 | |
| 161 | return opts, err |
| 162 | } |
| 163 | |
| 164 | // AcquireLease gets an DHCP lease and then maintains it in the background |
| 165 | // by periodically renewing it. The acquired lease can be released by |
| 166 | // calling DHCPLease.Stop() |
| 167 | func AcquireLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/AcquireLease().( |
| 168 | clientID, netns, ifName string, |
| 169 | opts []dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Optionscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Option#, |
| 170 | timeout, resendMax 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#, resendTimeout 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#, broadcast bool, |
| 171 | ) (*DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#, error) { |
| 172 | errCh := make(chan error, 1) |
| 173 | |
| 174 | ctx := contextscip-go gomod github.com/golang/go/src go1.24.2 context/.Backgroundscip-go gomod github.com/golang/go/src go1.24.2 context/Background().() |
| 175 | ctx, cancel := contextscip-go gomod github.com/golang/go/src go1.24.2 context/.WithCancelscip-go gomod github.com/golang/go/src go1.24.2 context/WithCancel().(ctx) |
| 176 | |
| 177 | l := &DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#{ |
| 178 | clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.: clientID, |
| 179 | stopscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#stop.: make(chan struct{}), |
| 180 | checkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#check.: make(chan struct{}), |
| 181 | timeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#timeout.: timeout, |
| 182 | resendMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendMax.: resendMax, |
| 183 | resendTimeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendTimeout.: resendTimeout, |
| 184 | broadcastscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#broadcast.: broadcast, |
| 185 | optsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#opts.: opts, |
| 186 | cancelFuncscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#cancelFunc.: cancel, |
| 187 | ctxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#ctx.: ctx, |
| 188 | } |
| 189 | |
| 190 | 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().("%v: acquiring lease", clientID) |
| 191 | |
| 192 | l.wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#wg..Addscip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup#Add().(1) |
| 193 | go func() { |
| 194 | errCh <- 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().(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 { |
| 195 | defer l.wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#wg..Donescip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup#Done().() |
| 196 | |
| 197 | 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().(ifName) |
| 198 | if err != nil { |
| 199 | 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().("error looking up %q: %v", ifName, err) |
| 200 | } |
| 201 | |
| 202 | l.linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link. = link |
| 203 | l.linkNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#linkName. = 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. |
| 204 | |
| 205 | if err = l.acquirescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#acquire().(); err != nil { |
| 206 | return err |
| 207 | } |
| 208 | |
| 209 | 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().("%v: lease acquired, expiration is %v", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., l.expireTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#expireTime.) |
| 210 | |
| 211 | errCh <- nil |
| 212 | |
| 213 | l.maintainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#maintain().() |
| 214 | return nil |
| 215 | }) |
| 216 | }() |
| 217 | |
| 218 | if err := <-errCh; err != nil { |
| 219 | return nil, err |
| 220 | } |
| 221 | |
| 222 | return l, nil |
| 223 | } |
| 224 | |
| 225 | // Stop terminates the background task that maintains the lease |
| 226 | // and issues a DHCP Release |
| 227 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) Stopscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#Stop().() { |
| 228 | if atomicscip-go gomod github.com/golang/go/src go1.24.2 `sync/atomic`/.CompareAndSwapUint32scip-go gomod github.com/golang/go/src go1.24.2 `sync/atomic`/CompareAndSwapUint32().(&l.stoppingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#stopping., 0, 1) { |
| 229 | close(l.stopscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#stop.) |
| 230 | l.cancelFuncscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#cancelFunc.() |
| 231 | } |
| 232 | l.wgscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#wg..Waitscip-go gomod github.com/golang/go/src go1.24.2 sync/WaitGroup#Wait().() |
| 233 | } |
| 234 | |
| 235 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) Checkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#Check().() { |
| 236 | l.checkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#check. <- struct{}{} |
| 237 | } |
| 238 | |
| 239 | func withClientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/withClientID().(clientID string) dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Modifierscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Modifier# { |
| 240 | return func(d *dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.DHCPv4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#) { |
| 241 | optClientID := []byte{0} |
| 242 | optClientID = append(optClientID, []byte(clientID)...) |
| 243 | d.Optionsscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#Options..Updatescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Options#Update().(dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptClientIdentifierscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptClientIdentifier().(optClientID)) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | func withAllOptionsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/withAllOptions().(l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.Modifierscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Modifier# { |
| 248 | return func(d *dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.DHCPv4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#) { |
| 249 | for _, opt := range l.optsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#opts. { |
| 250 | d.Optionsscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#Options..Updatescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Options#Update().(opt) |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) acquirescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#acquire().() error { |
| 256 | if (l.linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link..Attrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#Attrs().().Flagsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Flags. & netscip-go gomod github.com/golang/go/src go1.24.2 net/.FlagUpscip-go gomod github.com/golang/go/src go1.24.2 net/FlagUp.) != netscip-go gomod github.com/golang/go/src go1.24.2 net/.FlagUpscip-go gomod github.com/golang/go/src go1.24.2 net/FlagUp. { |
| 257 | 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().("Link %q down. Attempting to set up", l.linkNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#linkName.) |
| 258 | 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().(l.linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link.); err != nil { |
| 259 | return err |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | c, err := newDHCPClientscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/newDHCPClient().(l.linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link., l.timeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#timeout.) |
| 264 | if err != nil { |
| 265 | return err |
| 266 | } |
| 267 | defer c.Closescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Client#Close().() |
| 268 | |
| 269 | timeoutCtx, cancel := contextscip-go gomod github.com/golang/go/src go1.24.2 context/.WithTimeoutCausescip-go gomod github.com/golang/go/src go1.24.2 context/WithTimeoutCause().(l.ctxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#ctx., l.resendTimeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendTimeout., errNoMoreTriesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/errNoMoreTries.) |
| 270 | defer cancel() |
| 271 | pkt, err := backoffRetryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/backoffRetry().(timeoutCtx, l.resendMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendMax., func() (*nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Leasescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#, error) { |
| 272 | return c.Requestscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Client#Request().( |
| 273 | timeoutCtx, |
| 274 | withClientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/withClientID().(l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.), |
| 275 | withAllOptionsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/withAllOptions().(l), |
| 276 | ) |
| 277 | }) |
| 278 | if err != nil { |
| 279 | return err |
| 280 | } |
| 281 | |
| 282 | l.commitscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#commit().(pkt) |
| 283 | return nil |
| 284 | } |
| 285 | |
| 286 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) commitscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#commit().(lease *nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Leasescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#) { |
| 287 | l.latestLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#latestLease. = lease |
| 288 | ack := lease.ACKscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#ACK. |
| 289 | |
| 290 | leaseTime := ack.IPAddressLeaseTimescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#IPAddressLeaseTime().(defaultLeaseTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/defaultLeaseTime.) |
| 291 | rebindingTime := ack.IPAddressRebindingTimescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#IPAddressRebindingTime().(leaseTime * 85 / 100) |
| 292 | renewalTime := ack.IPAddressRenewalTimescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#IPAddressRenewalTime().(leaseTime / 2) |
| 293 | |
| 294 | now := timescip-go gomod github.com/golang/go/src go1.24.2 time/.Nowscip-go gomod github.com/golang/go/src go1.24.2 time/Now().() |
| 295 | l.expireTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#expireTime. = now.Addscip-go gomod github.com/golang/go/src go1.24.2 time/Time#Add().(leaseTime) |
| 296 | l.renewalTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#renewalTime. = now.Addscip-go gomod github.com/golang/go/src go1.24.2 time/Time#Add().(renewalTime) |
| 297 | l.rebindingTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#rebindingTime. = now.Addscip-go gomod github.com/golang/go/src go1.24.2 time/Time#Add().(rebindingTime) |
| 298 | } |
| 299 | |
| 300 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) maintainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#maintain().() { |
| 301 | state := leaseStateBoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateBound. |
| 302 | |
| 303 | for { |
| 304 | var sleepDur 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# |
| 305 | |
| 306 | linkCheckCtx, cancel := contextscip-go gomod github.com/golang/go/src go1.24.2 context/.WithTimeoutCausescip-go gomod github.com/golang/go/src go1.24.2 context/WithTimeoutCause().(l.ctxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#ctx., l.resendTimeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendTimeout., errNoMoreTriesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/errNoMoreTries.) |
| 307 | defer cancel() |
| 308 | linkExists, _ := checkLinkExistsWithBackoffscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/checkLinkExistsWithBackoff().(linkCheckCtx, l.linkNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#linkName.) |
| 309 | if !linkExists { |
| 310 | 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().("%v: interface %s no longer exists or link check failed, terminating lease maintenance", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., l.linkNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#linkName.) |
| 311 | return |
| 312 | } |
| 313 | |
| 314 | switch state { |
| 315 | case leaseStateBoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateBound.: |
| 316 | sleepDur = timescip-go gomod github.com/golang/go/src go1.24.2 time/.Untilscip-go gomod github.com/golang/go/src go1.24.2 time/Until().(l.renewalTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#renewalTime.) |
| 317 | if sleepDur <= 0 { |
| 318 | 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().("%v: renewing lease", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.) |
| 319 | state = leaseStateRenewingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateRenewing. |
| 320 | continue |
| 321 | } |
| 322 | |
| 323 | case leaseStateRenewingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateRenewing.: |
| 324 | if err := l.renewscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#renew().(); err != nil { |
| 325 | 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().("%v: %v", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., err) |
| 326 | |
| 327 | if timescip-go gomod github.com/golang/go/src go1.24.2 time/.Nowscip-go gomod github.com/golang/go/src go1.24.2 time/Now().().Afterscip-go gomod github.com/golang/go/src go1.24.2 time/Time#After().(l.rebindingTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#rebindingTime.) { |
| 328 | 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().("%v: renewal time expired, rebinding", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.) |
| 329 | state = leaseStateRebindingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateRebinding. |
| 330 | } |
| 331 | } else { |
| 332 | 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().("%v: lease renewed, expiration is %v", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., l.expireTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#expireTime.) |
| 333 | state = leaseStateBoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateBound. |
| 334 | } |
| 335 | |
| 336 | case leaseStateRebindingscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateRebinding.: |
| 337 | if err := l.acquirescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#acquire().(); err != nil { |
| 338 | 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().("%v: %v", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., err) |
| 339 | |
| 340 | if timescip-go gomod github.com/golang/go/src go1.24.2 time/.Nowscip-go gomod github.com/golang/go/src go1.24.2 time/Now().().Afterscip-go gomod github.com/golang/go/src go1.24.2 time/Time#After().(l.expireTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#expireTime.) { |
| 341 | 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().("%v: lease expired, bringing interface DOWN", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.) |
| 342 | l.downIfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#downIface().() |
| 343 | return |
| 344 | } |
| 345 | } else { |
| 346 | 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().("%v: lease rebound, expiration is %v", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., l.expireTimescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#expireTime.) |
| 347 | state = leaseStateBoundscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/leaseStateBound. |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | select { |
| 352 | case <-timescip-go gomod github.com/golang/go/src go1.24.2 time/.Afterscip-go gomod github.com/golang/go/src go1.24.2 time/After().(sleepDur): |
| 353 | |
| 354 | case <-l.checkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#check.: |
| 355 | 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().("%v: Checking lease", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.) |
| 356 | |
| 357 | case <-l.stopscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#stop.: |
| 358 | if err := l.releasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#release().(); err != nil { |
| 359 | 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().("%v: failed to release DHCP lease: %v", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., err) |
| 360 | } |
| 361 | return |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | func checkLinkExistsWithBackoffscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/checkLinkExistsWithBackoff().(ctx contextscip-go gomod github.com/golang/go/src go1.24.2 context/.Contextscip-go gomod github.com/golang/go/src go1.24.2 context/Context#, linkName string) (bool, error) { |
| 367 | baseDelay := linkCheckDelay0scip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/linkCheckDelay0. |
| 368 | for { |
| 369 | exists, err := checkLinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/checkLinkByName().(linkName) |
| 370 | if err == nil { |
| 371 | return exists, nil |
| 372 | } |
| 373 | |
| 374 | select { |
| 375 | case <-ctx.Donescip-go gomod github.com/golang/go/src go1.24.2 context/Context#Done().(): |
| 376 | return false, ctx.Errscip-go gomod github.com/golang/go/src go1.24.2 context/Context#Err().() // Context's done, return with its error |
| 377 | case <-timescip-go gomod github.com/golang/go/src go1.24.2 time/.Afterscip-go gomod github.com/golang/go/src go1.24.2 time/After().(baseDelay): |
| 378 | if baseDelay < linkCheckRetryMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/linkCheckRetryMax. { |
| 379 | baseDelay *= 2 |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | func checkLinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/checkLinkByName().(linkName string) (bool, error) { |
| 386 | _, 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().(linkName) |
| 387 | if err != nil { |
| 388 | linkNotFoundErr := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkNotFoundErrorscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkNotFoundError#{} |
| 389 | if errorsscip-go gomod github.com/golang/go/src go1.24.2 errors/.Asscip-go gomod github.com/golang/go/src go1.24.2 errors/As().(err, linkNotFoundErr) { |
| 390 | return false, nil |
| 391 | } |
| 392 | return false, err |
| 393 | } |
| 394 | return true, nil |
| 395 | } |
| 396 | |
| 397 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) downIfacescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#downIface().() { |
| 398 | if err := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkSetDownscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkSetDown().(l.linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link.); err != nil { |
| 399 | 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().("%v: failed to bring %v interface DOWN: %v", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID., l.linkNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#linkName., err) |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) renewscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#renew().() error { |
| 404 | c, err := newDHCPClientscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/newDHCPClient().(l.linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link., l.timeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#timeout.) |
| 405 | if err != nil { |
| 406 | return err |
| 407 | } |
| 408 | defer c.Closescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Client#Close().() |
| 409 | |
| 410 | timeoutCtx, cancel := contextscip-go gomod github.com/golang/go/src go1.24.2 context/.WithTimeoutCausescip-go gomod github.com/golang/go/src go1.24.2 context/WithTimeoutCause().(l.ctxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#ctx., l.resendTimeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendTimeout., errNoMoreTriesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/errNoMoreTries.) |
| 411 | defer cancel() |
| 412 | lease, err := backoffRetryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/backoffRetry().(timeoutCtx, l.resendMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#resendMax., func() (*nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Leasescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#, error) { |
| 413 | return c.Renewscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Client#Renew().( |
| 414 | timeoutCtx, |
| 415 | l.latestLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#latestLease., |
| 416 | withClientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/withClientID().(l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.), |
| 417 | withAllOptionsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/withAllOptions().(l), |
| 418 | ) |
| 419 | }) |
| 420 | if err != nil { |
| 421 | return err |
| 422 | } |
| 423 | |
| 424 | l.commitscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#commit().(lease) |
| 425 | return nil |
| 426 | } |
| 427 | |
| 428 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) releasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#release().() error { |
| 429 | 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().("%v: releasing lease", l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.) |
| 430 | |
| 431 | c, err := newDHCPClientscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/newDHCPClient().(l.linkscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#link., l.timeoutscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#timeout.) |
| 432 | if err != nil { |
| 433 | return err |
| 434 | } |
| 435 | defer c.Closescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Client#Close().() |
| 436 | |
| 437 | if err = c.Releasescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Client#Release().(l.latestLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#latestLease., withClientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/withClientID().(l.clientIDscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#clientID.)); err != nil { |
| 438 | 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 send DHCPRELEASE") |
| 439 | } |
| 440 | |
| 441 | return nil |
| 442 | } |
| 443 | |
| 444 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) IPNetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#IPNet().() (*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) { |
| 445 | ack := l.latestLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#latestLease..ACKscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#ACK. |
| 446 | |
| 447 | mask := ack.SubnetMaskscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#SubnetMask().() |
| 448 | if mask == nil { |
| 449 | 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().("DHCP option Subnet Mask not found in DHCPACK") |
| 450 | } |
| 451 | |
| 452 | 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#{ |
| 453 | IPscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#IP.: ack.YourIPAddrscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#YourIPAddr., |
| 454 | Maskscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#Mask.: mask, |
| 455 | }, nil |
| 456 | } |
| 457 | |
| 458 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#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# { |
| 459 | ack := l.latestLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#latestLease..ACKscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#ACK. |
| 460 | gws := ack.Routerscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#Router().() |
| 461 | if len(gws) > 0 { |
| 462 | return gws[0] |
| 463 | } |
| 464 | return nil |
| 465 | } |
| 466 | |
| 467 | func (l *DHCPLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#) Routesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#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# { |
| 468 | 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#{} |
| 469 | |
| 470 | ack := l.latestLeasescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#latestLease..ACKscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#ACK. |
| 471 | |
| 472 | // RFC 3442 states that if Classless Static Routes (option 121) |
| 473 | // exist, we ignore Static Routes (option 33) and the Router/Gateway. |
| 474 | opt121Routes := ack.ClasslessStaticRoutescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#ClasslessStaticRoute().() |
| 475 | if len(opt121Routes) > 0 { |
| 476 | for _, r := range opt121Routes { |
| 477 | route := &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.: *r.Destscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Route#Dest., GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW.: r.Routerscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Route#Router.} |
| 478 | // if router is not specified, add SCOPE_LINK so routes are installed |
| 479 | if r.Routerscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Route#Router..IsUnspecifiedscip-go gomod github.com/golang/go/src go1.24.2 net/IP#IsUnspecified().() { |
| 480 | scopeLinkValue := int(netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.SCOPE_LINKscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/SCOPE_LINK.) |
| 481 | route.Scopescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Scope. = &scopeLinkValue |
| 482 | } |
| 483 | routes = append(routes, route) |
| 484 | } |
| 485 | return routes |
| 486 | } |
| 487 | |
| 488 | // Append Static Routes |
| 489 | if ack.Optionsscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#Options..Hasscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Options#Has().(dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionStaticRoutingTablescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionStaticRoutingTable.) { |
| 490 | routes = append(routes, parseRoutesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/parseRoutes().(ack.Optionsscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/DHCPv4#Options..Getscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/Options#Get().(dhcp4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/.OptionStaticRoutingTablescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4`/OptionStaticRoutingTable.))...) |
| 491 | } |
| 492 | |
| 493 | // The CNI spec says even if there is a gateway specified, we must |
| 494 | // add a default route in the routes section. |
| 495 | if gw := l.Gatewayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/DHCPLease#Gateway().(); gw != nil { |
| 496 | _, defaultRoute, _ := netscip-go gomod github.com/golang/go/src go1.24.2 net/.ParseCIDRscip-go gomod github.com/golang/go/src go1.24.2 net/ParseCIDR().("0.0.0.0/0") |
| 497 | routes = append(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#{Dstscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#Dst.: *defaultRoute, GWscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/Route#GW.: gw}) |
| 498 | } |
| 499 | |
| 500 | return routes |
| 501 | } |
| 502 | |
| 503 | // jitter returns a random value within [-span, span) range |
| 504 | func jitterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/jitter().(span 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#) 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# { |
| 505 | return 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#(float64(span) * (2.0*randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/.Float64scip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/Float64().() - 1.0)) |
| 506 | } |
| 507 | |
| 508 | func backoffRetryscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/backoffRetry().(ctx contextscip-go gomod github.com/golang/go/src go1.24.2 context/.Contextscip-go gomod github.com/golang/go/src go1.24.2 context/Context#, resendMax 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#, f func() (*nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Leasescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#, error)) (*nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Leasescip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Lease#, error) { |
| 509 | baseDelay := resendDelay0scip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/resendDelay0. |
| 510 | var sleepTime 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# |
| 511 | fastRetryLimit := resendFastMaxscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/resendFastMax. |
| 512 | for { |
| 513 | pkt, err := f() |
| 514 | if err == nil { |
| 515 | return pkt, nil |
| 516 | } |
| 517 | |
| 518 | logscip-go gomod github.com/golang/go/src go1.24.2 log/.Printscip-go gomod github.com/golang/go/src go1.24.2 log/Print().(err) |
| 519 | |
| 520 | if fastRetryLimit == 0 { |
| 521 | sleepTime = baseDelay + jitterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/jitter().(timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second.) |
| 522 | } else { |
| 523 | sleepTime = resendFastDelayscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/resendFastDelay. + jitterscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/jitter().(timescip-go gomod github.com/golang/go/src go1.24.2 time/.Secondscip-go gomod github.com/golang/go/src go1.24.2 time/Second.) |
| 524 | fastRetryLimit-- |
| 525 | } |
| 526 | |
| 527 | 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().("retrying in %f seconds", sleepTime.Secondsscip-go gomod github.com/golang/go/src go1.24.2 time/Duration#Seconds().()) |
| 528 | |
| 529 | select { |
| 530 | case <-ctx.Donescip-go gomod github.com/golang/go/src go1.24.2 context/Context#Done().(): |
| 531 | return nil, contextscip-go gomod github.com/golang/go/src go1.24.2 context/.Causescip-go gomod github.com/golang/go/src go1.24.2 context/Cause().(ctx) |
| 532 | case <-timescip-go gomod github.com/golang/go/src go1.24.2 time/.Afterscip-go gomod github.com/golang/go/src go1.24.2 time/After().(sleepTime): |
| 533 | // only adjust delay time if we are in normal backoff stage |
| 534 | if baseDelay < resendMax && fastRetryLimit == 0 { |
| 535 | baseDelay *= 2 |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | func newDHCPClientscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/ipam/dhcp`/newDHCPClient().( |
| 542 | link netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Linkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Link#, |
| 543 | timeout 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#, |
| 544 | clientOpts ...nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.ClientOptscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/ClientOpt#, |
| 545 | ) (*nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Clientscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/Client#, error) { |
| 546 | clientOpts = append(clientOpts, nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.WithTimeoutscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/WithTimeout().(timeout)) |
| 547 | return nclient4scip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/.Newscip-go gomod github.com/insomniacslk/dhcp a3a4c1f04475 `github.com/insomniacslk/dhcp/dhcpv4/nclient4`/New().(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., clientOpts...) |
| 548 | } |