Skip to content

Commit 1f2bb9f

Browse files
Merge pull request #175 from bpickard22/ds-merge-3/7/25
OCPBUGS-45272: Ds merge 3/7/25
2 parents b93f264 + eab2098 commit 1f2bb9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+648
-132
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ require (
1616
github.com/onsi/ginkgo/v2 v2.22.2
1717
github.com/onsi/gomega v1.36.2
1818
github.com/opencontainers/selinux v1.11.1
19-
github.com/safchain/ethtool v0.5.9
19+
github.com/safchain/ethtool v0.5.10
2020
github.com/vishvananda/netlink v1.3.0
21-
golang.org/x/sys v0.29.0
21+
golang.org/x/sys v0.30.0
2222
sigs.k8s.io/knftables v0.0.18
2323
)
2424

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
9797
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9898
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9999
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
100-
github.com/safchain/ethtool v0.5.9 h1://6RvaOKFf3nQ0rl5+8zBbE4/72455VC9Jq61pfq67E=
101-
github.com/safchain/ethtool v0.5.9/go.mod h1:w8oSsZeowyRaM7xJJBAbubzzrOkwO8TBgPSEqPP/5mg=
100+
github.com/safchain/ethtool v0.5.10 h1:Im294gZtuf4pSGJRAOGKaASNi3wMeFaGaWuSaomedpc=
101+
github.com/safchain/ethtool v0.5.10/go.mod h1:w9jh2Lx7YBR4UwzLkzCmWl85UY0W2uZdd7/DckVE5+c=
102102
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
103103
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
104104
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -164,9 +164,9 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
164164
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
165165
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
166166
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
167-
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
168-
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
169167
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
168+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
169+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
170170
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
171171
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
172172
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

plugins/ipam/dhcp/lease.go

+51-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package main
1616

1717
import (
1818
"context"
19+
"errors"
1920
"fmt"
2021
"log"
2122
"math/rand"
@@ -55,6 +56,13 @@ const (
5556
leaseStateRebinding
5657
)
5758

59+
// Timing for retrying link existence check
60+
const (
61+
linkCheckDelay0 = 1 * time.Second
62+
linkCheckRetryMax = 10 * time.Second
63+
linkCheckTotalTimeout = 30 * time.Second
64+
)
65+
5866
// This implementation uses 1 OS thread per lease. This is because
5967
// all the network operations have to be done in network namespace
6068
// of the interface. This can be improved by switching to the proper
@@ -65,6 +73,7 @@ type DHCPLease struct {
6573
clientID string
6674
latestLease *nclient4.Lease
6775
link netlink.Link
76+
linkName string
6877
renewalTime time.Time
6978
rebindingTime time.Time
7079
expireTime time.Time
@@ -190,6 +199,7 @@ func AcquireLease(
190199
}
191200

192201
l.link = link
202+
l.linkName = link.Attrs().Name
193203

194204
if err = l.acquire(); err != nil {
195205
return err
@@ -243,7 +253,7 @@ func withAllOptions(l *DHCPLease) dhcp4.Modifier {
243253

244254
func (l *DHCPLease) acquire() error {
245255
if (l.link.Attrs().Flags & net.FlagUp) != net.FlagUp {
246-
log.Printf("Link %q down. Attempting to set up", l.link.Attrs().Name)
256+
log.Printf("Link %q down. Attempting to set up", l.linkName)
247257
if err := netlink.LinkSetUp(l.link); err != nil {
248258
return err
249259
}
@@ -292,6 +302,14 @@ func (l *DHCPLease) maintain() {
292302
for {
293303
var sleepDur time.Duration
294304

305+
linkCheckCtx, cancel := context.WithTimeoutCause(l.ctx, l.resendTimeout, errNoMoreTries)
306+
defer cancel()
307+
linkExists, _ := checkLinkExistsWithBackoff(linkCheckCtx, l.linkName)
308+
if !linkExists {
309+
log.Printf("%v: interface %s no longer exists or link check failed, terminating lease maintenance", l.clientID, l.linkName)
310+
return
311+
}
312+
295313
switch state {
296314
case leaseStateBound:
297315
sleepDur = time.Until(l.renewalTime)
@@ -344,9 +362,40 @@ func (l *DHCPLease) maintain() {
344362
}
345363
}
346364

365+
func checkLinkExistsWithBackoff(ctx context.Context, linkName string) (bool, error) {
366+
baseDelay := linkCheckDelay0
367+
for {
368+
exists, err := checkLinkByName(linkName)
369+
if err == nil {
370+
return exists, nil
371+
}
372+
373+
select {
374+
case <-ctx.Done():
375+
return false, ctx.Err() // Context's done, return with its error
376+
case <-time.After(baseDelay):
377+
if baseDelay < linkCheckRetryMax {
378+
baseDelay *= 2
379+
}
380+
}
381+
}
382+
}
383+
384+
func checkLinkByName(linkName string) (bool, error) {
385+
_, err := netlink.LinkByName(linkName)
386+
if err != nil {
387+
var linkNotFoundErr *netlink.LinkNotFoundError = &netlink.LinkNotFoundError{}
388+
if errors.As(err, linkNotFoundErr) {
389+
return false, nil
390+
}
391+
return false, err
392+
}
393+
return true, nil
394+
}
395+
347396
func (l *DHCPLease) downIface() {
348397
if err := netlink.LinkSetDown(l.link); err != nil {
349-
log.Printf("%v: failed to bring %v interface DOWN: %v", l.clientID, l.link.Attrs().Name, err)
398+
log.Printf("%v: failed to bring %v interface DOWN: %v", l.clientID, l.linkName, err)
350399
}
351400
}
352401

plugins/main/host-device/host-device.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func cmdAdd(args *skel.CmdArgs) error {
131131
defer containerNs.Close()
132132

133133
result := &current.Result{}
134+
result.Interfaces = []*current.Interface{{
135+
Name: args.IfName,
136+
Sandbox: containerNs.Path(),
137+
}}
138+
134139
var contDev netlink.Link
135140
if !cfg.DPDKMode {
136141
hostDev, err := getLink(cfg.Device, cfg.HWAddr, cfg.KernelPath, cfg.PCIAddr, cfg.auxDevice)
@@ -143,11 +148,10 @@ func cmdAdd(args *skel.CmdArgs) error {
143148
return fmt.Errorf("failed to move link %v", err)
144149
}
145150

146-
result.Interfaces = []*current.Interface{{
147-
Name: contDev.Attrs().Name,
148-
Mac: contDev.Attrs().HardwareAddr.String(),
149-
Sandbox: containerNs.Path(),
150-
}}
151+
// Override the device name with the name in the container namespace
152+
result.Interfaces[0].Name = contDev.Attrs().Name
153+
// Set the MAC address of the interface
154+
result.Interfaces[0].Mac = contDev.Attrs().HardwareAddr.String()
151155
}
152156

153157
if cfg.IPAM.Type == "" {

plugins/main/host-device/host-device_test.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func buildOneConfig(name, cniVersion string, orig *Net, prevResult types.Result)
218218

219219
type tester interface {
220220
expectInterfaces(result types.Result, name, mac, sandbox string)
221-
expectDpdkInterfaceIP(result types.Result, ipAddress string)
221+
expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string)
222222
}
223223

224224
type testerBase struct{}
@@ -256,11 +256,16 @@ func (t *testerV10x) expectInterfaces(result types.Result, name, mac, sandbox st
256256
}))
257257
}
258258

259-
func (t *testerV10x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
259+
func (t *testerV10x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
260260
// check that the result was sane
261261
res, err := types100.NewResultFromResult(result)
262262
Expect(err).NotTo(HaveOccurred())
263-
Expect(res.Interfaces).To(BeEmpty())
263+
Expect(res.Interfaces).To(Equal([]*types100.Interface{
264+
{
265+
Name: name,
266+
Sandbox: sandbox,
267+
},
268+
}))
264269
Expect(res.IPs).To(HaveLen(1))
265270
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
266271
}
@@ -278,11 +283,16 @@ func (t *testerV04x) expectInterfaces(result types.Result, name, mac, sandbox st
278283
}))
279284
}
280285

281-
func (t *testerV04x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
286+
func (t *testerV04x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
282287
// check that the result was sane
283288
res, err := types040.NewResultFromResult(result)
284289
Expect(err).NotTo(HaveOccurred())
285-
Expect(res.Interfaces).To(BeEmpty())
290+
Expect(res.Interfaces).To(Equal([]*types040.Interface{
291+
{
292+
Name: name,
293+
Sandbox: sandbox,
294+
},
295+
}))
286296
Expect(res.IPs).To(HaveLen(1))
287297
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
288298
}
@@ -300,11 +310,16 @@ func (t *testerV03x) expectInterfaces(result types.Result, name, mac, sandbox st
300310
}))
301311
}
302312

303-
func (t *testerV03x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
313+
func (t *testerV03x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
304314
// check that the result was sane
305315
res, err := types040.NewResultFromResult(result)
306316
Expect(err).NotTo(HaveOccurred())
307-
Expect(res.Interfaces).To(BeEmpty())
317+
Expect(res.Interfaces).To(Equal([]*types040.Interface{
318+
{
319+
Name: name,
320+
Sandbox: sandbox,
321+
},
322+
}))
308323
Expect(res.IPs).To(HaveLen(1))
309324
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
310325
}
@@ -598,7 +613,7 @@ var _ = Describe("base functionality", func() {
598613

599614
// check that the result was sane
600615
t := newTesterByVersion(ver)
601-
t.expectDpdkInterfaceIP(resI, targetIP)
616+
t.expectDpdkInterfaceIP(resI, cniName, targetNS.Path(), targetIP)
602617

603618
// call CmdDel
604619
_ = originalNS.Do(func(ns.NetNS) error {
@@ -870,7 +885,7 @@ var _ = Describe("base functionality", func() {
870885

871886
// check that the result was sane
872887
t := newTesterByVersion(ver)
873-
t.expectDpdkInterfaceIP(resI, targetIP)
888+
t.expectDpdkInterfaceIP(resI, cniName, targetNS.Path(), targetIP)
874889

875890
// call CmdCheck
876891
n := &Net{}

plugins/meta/firewall/firewall.go

+7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ const (
6464
// IngressPolicySameBridge executes `iptables` regardless to the value of `Backend`.
6565
// IngressPolicySameBridge may not work as expected for non-bridge networks.
6666
IngressPolicySameBridge IngressPolicy = "same-bridge"
67+
68+
// IngressPolicyIsolated ("isolated"): similar to ingress policy "same-bridge" with the exception
69+
// that connections from the same bridge are also blocked.
70+
// This is equivalent to Docker network option "enable_icc" when set to false.
71+
// IngressPolicyIsolated executes `iptables` regardless to the value of `Backend`.
72+
// IngressPolicyIsolated may not work as expected for non-bridge networks.
73+
IngressPolicyIsolated IngressPolicy = "isolated"
6774
)
6875

6976
type FirewallBackend interface {

0 commit comments

Comments
 (0)