Skip to content

Commit a406af4

Browse files
PoC code to fix the SWIFT v2 issues in Kata
1 parent 07fd3ff commit a406af4

6 files changed

Lines changed: 244 additions & 146 deletions

File tree

src/runtime/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ require (
4949
github.com/sirupsen/logrus v1.9.3
5050
github.com/stretchr/testify v1.9.0
5151
github.com/urfave/cli v1.22.14
52-
github.com/vishvananda/netlink v1.2.1-beta.2
53-
github.com/vishvananda/netns v0.0.4
52+
github.com/vishvananda/netlink v1.3.1
53+
github.com/vishvananda/netns v0.0.5
5454
gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20220601114329-47893b162965
5555
go.opentelemetry.io/otel v1.23.1
5656
go.opentelemetry.io/otel/exporters/jaeger v1.0.0

src/runtime/go.sum

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,10 @@ github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG
333333
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
334334
github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk=
335335
github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA=
336-
github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs=
337-
github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
338-
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
339-
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
340-
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
336+
github.com/vishvananda/netlink v1.3.1 h1:3AEMt62VKqz90r0tmNhog0r/PpWKmrEShJU0wJW6bV0=
337+
github.com/vishvananda/netlink v1.3.1/go.mod h1:ARtKouGSTGchR8aMwmkzC0qiNPrrWO5JS/XMVl45+b4=
338+
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
339+
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
341340
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
342341
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
343342
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
@@ -430,9 +429,7 @@ golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7w
430429
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
431430
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
432431
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
433-
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
434432
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
435-
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
436433
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
437434
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
438435
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -445,7 +442,9 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
445442
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
446443
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
447444
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
445+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
448446
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
447+
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
449448
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
450449
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
451450
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

src/runtime/virtcontainers/network_linux.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,34 @@ func (n *LinuxNetwork) addSingleEndpoint(ctx context.Context, s *Sandbox, netInf
123123

124124
// Check if interface is a physical interface. Do not create
125125
// tap interface/bridge if it is.
126-
isPhysical, err := isPhysicalIface(netInfo.Iface.Name)
127-
if err != nil {
128-
return nil, err
126+
isPhysical := isPhysicalIface(netInfo.Link)
127+
var err error
128+
idx := len(n.eps)
129+
130+
// Avoid endpoint naming conflicts
131+
// When creating a new endpoint, we check existing endpoint names and automatically adjust the naming of the new endpoint to ensure uniqueness.
132+
lastIdx := -1
133+
if len(n.eps) > 0 {
134+
lastEndpoint := n.eps[len(n.eps)-1]
135+
re := regexp.MustCompile("[0-9]+")
136+
matchStr := re.FindString(lastEndpoint.Name())
137+
n, err := strconv.ParseInt(matchStr, 10, 64)
138+
if err != nil {
139+
return nil, err
140+
}
141+
lastIdx = int(n)
142+
}
143+
if idx <= lastIdx {
144+
idx = lastIdx + 1
129145
}
130146

131147
if isPhysical {
132-
if s.config.HypervisorConfig.ColdPlugVFIO == config.NoPort {
133-
// When `cold_plug_vfio` is set to "no-port", the PhysicalEndpoint's VFIO device cannot be attached to the guest VM.
134-
// Fail early to prevent the VF interface from being unbound and rebound to the VFIO driver.
135-
return nil, fmt.Errorf("unable to add PhysicalEndpoint %s because cold_plug_vfio is disabled", netInfo.Iface.Name)
136-
}
137148
networkLogger().WithField("interface", netInfo.Iface.Name).Info("Physical network interface found")
138-
endpoint, err = createPhysicalEndpoint(netInfo)
149+
isFVIODisabled := (s.config.HypervisorConfig.ColdPlugVFIO == config.NoPort)
150+
endpoint, err = createPhysicalEndpoint(idx, netInfo, isFVIODisabled, n.interworkingModel)
139151
} else {
140152
var socketPath string
141-
idx := len(n.eps)
142-
143-
// Avoid endpoint naming conflicts
144-
// When creating a new endpoint, we check existing endpoint names and automatically adjust the naming of the new endpoint to ensure uniqueness.
145-
lastIdx := -1
146-
if len(n.eps) > 0 {
147-
lastEndpoint := n.eps[len(n.eps)-1]
148-
re := regexp.MustCompile("[0-9]+")
149-
matchStr := re.FindString(lastEndpoint.Name())
150-
n, err := strconv.ParseInt(matchStr, 10, 64)
151-
if err != nil {
152-
return nil, err
153-
}
154-
lastIdx = int(n)
155-
}
156-
if idx <= lastIdx {
157-
idx = lastIdx + 1
158-
}
153+
159154
// Check if this is a dummy interface which has a vhost-user socket associated with it
160155
socketPath, err = vhostUserSocketPath(netInfo)
161156
if err != nil {
@@ -654,6 +649,8 @@ func getLinkForEndpoint(endpoint Endpoint, netHandle *netlink.Handle) (netlink.L
654649
var link netlink.Link
655650

656651
switch ep := endpoint.(type) {
652+
case *PhysicalEndpoint:
653+
link = &netlink.Device{}
657654
case *VethEndpoint:
658655
link = &netlink.Veth{}
659656
case *MacvlanEndpoint:
@@ -676,6 +673,10 @@ func getLinkByName(netHandle *netlink.Handle, name string, expectedLink netlink.
676673
}
677674

678675
switch expectedLink.Type() {
676+
case (&netlink.Device{}).Type():
677+
if l, ok := link.(*netlink.Device); ok {
678+
return l, nil
679+
}
679680
case (&netlink.Tuntap{}).Type():
680681
if l, ok := link.(*netlink.Tuntap); ok {
681682
return l, nil

src/runtime/virtcontainers/persist/api/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type PhysicalEndpoint struct {
4444
BDF string
4545
Driver string
4646
VendorDeviceID string
47+
NetPair NetworkInterfacePair
4748
}
4849

4950
type MacvtapEndpoint struct {

0 commit comments

Comments
 (0)