diff --git a/src/runtime/virtcontainers/endpoint.go b/src/runtime/virtcontainers/endpoint.go index 173df85997..7786bb3e1f 100644 --- a/src/runtime/virtcontainers/endpoint.go +++ b/src/runtime/virtcontainers/endpoint.go @@ -51,8 +51,8 @@ const ( // VhostUserEndpointType is the vhostuser network interface. VhostUserEndpointType EndpointType = "vhost-user" - // BridgedMacvlanEndpointType is macvlan network interface. - BridgedMacvlanEndpointType EndpointType = "macvlan" + // MacvlanEndpointType is macvlan network interface. + MacvlanEndpointType EndpointType = "macvlan" // MacvtapEndpointType is macvtap network interface. MacvtapEndpointType EndpointType = "macvtap" @@ -80,7 +80,7 @@ func (endpointType *EndpointType) Set(value string) error { *endpointType = VhostUserEndpointType return nil case "macvlan": - *endpointType = BridgedMacvlanEndpointType + *endpointType = MacvlanEndpointType return nil case "macvtap": *endpointType = MacvtapEndpointType @@ -108,8 +108,8 @@ func (endpointType *EndpointType) String() string { return string(VethEndpointType) case VhostUserEndpointType: return string(VhostUserEndpointType) - case BridgedMacvlanEndpointType: - return string(BridgedMacvlanEndpointType) + case MacvlanEndpointType: + return string(MacvlanEndpointType) case MacvtapEndpointType: return string(MacvtapEndpointType) case TapEndpointType: diff --git a/src/runtime/virtcontainers/endpoint_test.go b/src/runtime/virtcontainers/endpoint_test.go index 4cf615d078..48d5f7ff3a 100644 --- a/src/runtime/virtcontainers/endpoint_test.go +++ b/src/runtime/virtcontainers/endpoint_test.go @@ -35,8 +35,8 @@ func TestVhostUserEndpointTypeSet(t *testing.T) { testEndpointTypeSet(t, "vhost-user", VhostUserEndpointType) } -func TestBridgedMacvlanEndpointTypeSet(t *testing.T) { - testEndpointTypeSet(t, "macvlan", BridgedMacvlanEndpointType) +func TestMacvlanEndpointTypeSet(t *testing.T) { + testEndpointTypeSet(t, "macvlan", MacvlanEndpointType) } func TestMacvtapEndpointTypeSet(t *testing.T) { @@ -69,9 +69,9 @@ func TestVhostUserEndpointTypeString(t *testing.T) { testEndpointTypeString(t, &endpointType, string(VhostUserEndpointType)) } -func TestBridgedMacvlanEndpointTypeString(t *testing.T) { - endpointType := BridgedMacvlanEndpointType - testEndpointTypeString(t, &endpointType, string(BridgedMacvlanEndpointType)) +func TestMacvlanEndpointTypeString(t *testing.T) { + endpointType := MacvlanEndpointType + testEndpointTypeString(t, &endpointType, string(MacvlanEndpointType)) } func TestMacvtapEndpointTypeString(t *testing.T) { diff --git a/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go b/src/runtime/virtcontainers/macvlan_endpoint.go similarity index 56% rename from src/runtime/virtcontainers/bridgedmacvlan_endpoint.go rename to src/runtime/virtcontainers/macvlan_endpoint.go index be1cd8abea..4b86ede16f 100644 --- a/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go +++ b/src/runtime/virtcontainers/macvlan_endpoint.go @@ -14,10 +14,10 @@ import ( vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types" ) -var macvlanTrace = getNetworkTrace(BridgedMacvlanEndpointType) +var macvlanTrace = getNetworkTrace(MacvlanEndpointType) -// BridgedMacvlanEndpoint represents a macvlan endpoint that is bridged to the VM -type BridgedMacvlanEndpoint struct { +// MacvlanEndpoint represents a macvlan endpoint that is bridged to the VM +type MacvlanEndpoint struct { EndpointType EndpointType PCIPath vcTypes.PciPath EndpointProperties NetworkInfo @@ -26,9 +26,9 @@ type BridgedMacvlanEndpoint struct { TxRateLimiter bool } -func createBridgedMacvlanNetworkEndpoint(idx int, ifName string, interworkingModel NetInterworkingModel) (*BridgedMacvlanEndpoint, error) { +func createMacvlanNetworkEndpoint(idx int, ifName string, interworkingModel NetInterworkingModel) (*MacvlanEndpoint, error) { if idx < 0 { - return &BridgedMacvlanEndpoint{}, fmt.Errorf("invalid network endpoint index: %d", idx) + return &MacvlanEndpoint{}, fmt.Errorf("invalid network endpoint index: %d", idx) } netPair, err := createNetworkInterfacePair(idx, ifName, interworkingModel) @@ -36,9 +36,9 @@ func createBridgedMacvlanNetworkEndpoint(idx int, ifName string, interworkingMod return nil, err } - endpoint := &BridgedMacvlanEndpoint{ + endpoint := &MacvlanEndpoint{ NetPair: netPair, - EndpointType: BridgedMacvlanEndpointType, + EndpointType: MacvlanEndpointType, } if ifName != "" { endpoint.NetPair.VirtIface.Name = ifName @@ -48,49 +48,49 @@ func createBridgedMacvlanNetworkEndpoint(idx int, ifName string, interworkingMod } // Properties returns properties of the interface. -func (endpoint *BridgedMacvlanEndpoint) Properties() NetworkInfo { +func (endpoint *MacvlanEndpoint) Properties() NetworkInfo { return endpoint.EndpointProperties } // Name returns name of the veth interface in the network pair. -func (endpoint *BridgedMacvlanEndpoint) Name() string { +func (endpoint *MacvlanEndpoint) Name() string { return endpoint.NetPair.VirtIface.Name } // HardwareAddr returns the mac address that is assigned to the tap interface // in th network pair. -func (endpoint *BridgedMacvlanEndpoint) HardwareAddr() string { +func (endpoint *MacvlanEndpoint) HardwareAddr() string { return endpoint.NetPair.TAPIface.HardAddr } // Type identifies the endpoint as a bridged macvlan endpoint. -func (endpoint *BridgedMacvlanEndpoint) Type() EndpointType { +func (endpoint *MacvlanEndpoint) Type() EndpointType { return endpoint.EndpointType } // SetProperties sets the properties for the endpoint. -func (endpoint *BridgedMacvlanEndpoint) SetProperties(properties NetworkInfo) { +func (endpoint *MacvlanEndpoint) SetProperties(properties NetworkInfo) { endpoint.EndpointProperties = properties } // PciPath returns the PCI path of the endpoint. -func (endpoint *BridgedMacvlanEndpoint) PciPath() vcTypes.PciPath { +func (endpoint *MacvlanEndpoint) PciPath() vcTypes.PciPath { return endpoint.PCIPath } // SetPciPath sets the PCI path of the endpoint. -func (endpoint *BridgedMacvlanEndpoint) SetPciPath(pciPath vcTypes.PciPath) { +func (endpoint *MacvlanEndpoint) SetPciPath(pciPath vcTypes.PciPath) { endpoint.PCIPath = pciPath } // NetworkPair returns the network pair of the endpoint. -func (endpoint *BridgedMacvlanEndpoint) NetworkPair() *NetworkInterfacePair { +func (endpoint *MacvlanEndpoint) NetworkPair() *NetworkInterfacePair { return &endpoint.NetPair } // Attach for virtual endpoint bridges the network pair and adds the // tap interface of the network pair to the hypervisor. -func (endpoint *BridgedMacvlanEndpoint) Attach(ctx context.Context, s *Sandbox) error { +func (endpoint *MacvlanEndpoint) Attach(ctx context.Context, s *Sandbox) error { span, ctx := macvlanTrace(ctx, "Attach", endpoint) defer span.End() @@ -105,7 +105,7 @@ func (endpoint *BridgedMacvlanEndpoint) Attach(ctx context.Context, s *Sandbox) // Detach for the virtual endpoint tears down the tap and bridge // created for the veth interface. -func (endpoint *BridgedMacvlanEndpoint) Detach(ctx context.Context, netNsCreated bool, netNsPath string) error { +func (endpoint *MacvlanEndpoint) Detach(ctx context.Context, netNsCreated bool, netNsPath string) error { // The network namespace would have been deleted at this point // if it has not been created by virtcontainers. if !netNsCreated { @@ -121,49 +121,49 @@ func (endpoint *BridgedMacvlanEndpoint) Detach(ctx context.Context, netNsCreated } // HotAttach for bridged macvlan endpoint not supported yet -func (endpoint *BridgedMacvlanEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { - return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot attach") +func (endpoint *MacvlanEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { + return fmt.Errorf("MacvlanEndpoint does not support Hot attach") } // HotDetach for bridged macvlan endpoint not supported yet -func (endpoint *BridgedMacvlanEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { - return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot detach") +func (endpoint *MacvlanEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { + return fmt.Errorf("MacvlanEndpoint does not support Hot detach") } -func (endpoint *BridgedMacvlanEndpoint) save() persistapi.NetworkEndpoint { +func (endpoint *MacvlanEndpoint) save() persistapi.NetworkEndpoint { netpair := saveNetIfPair(&endpoint.NetPair) return persistapi.NetworkEndpoint{ Type: string(endpoint.Type()), - BridgedMacvlan: &persistapi.BridgedMacvlanEndpoint{ + Macvlan: &persistapi.MacvlanEndpoint{ NetPair: *netpair, }, } } -func (endpoint *BridgedMacvlanEndpoint) load(s persistapi.NetworkEndpoint) { - endpoint.EndpointType = BridgedMacvlanEndpointType +func (endpoint *MacvlanEndpoint) load(s persistapi.NetworkEndpoint) { + endpoint.EndpointType = MacvlanEndpointType - if s.BridgedMacvlan != nil { - netpair := loadNetIfPair(&s.BridgedMacvlan.NetPair) + if s.Macvlan != nil { + netpair := loadNetIfPair(&s.Macvlan.NetPair) endpoint.NetPair = *netpair } } -func (endpoint *BridgedMacvlanEndpoint) GetRxRateLimiter() bool { +func (endpoint *MacvlanEndpoint) GetRxRateLimiter() bool { return endpoint.RxRateLimiter } -func (endpoint *BridgedMacvlanEndpoint) SetRxRateLimiter() error { +func (endpoint *MacvlanEndpoint) SetRxRateLimiter() error { endpoint.RxRateLimiter = true return nil } -func (endpoint *BridgedMacvlanEndpoint) GetTxRateLimiter() bool { +func (endpoint *MacvlanEndpoint) GetTxRateLimiter() bool { return endpoint.TxRateLimiter } -func (endpoint *BridgedMacvlanEndpoint) SetTxRateLimiter() error { +func (endpoint *MacvlanEndpoint) SetTxRateLimiter() error { endpoint.TxRateLimiter = true return nil } diff --git a/src/runtime/virtcontainers/bridgedmacvlan_endpoint_test.go b/src/runtime/virtcontainers/macvlan_endpoint_test.go similarity index 80% rename from src/runtime/virtcontainers/bridgedmacvlan_endpoint_test.go rename to src/runtime/virtcontainers/macvlan_endpoint_test.go index 702bab707f..f490aff47e 100644 --- a/src/runtime/virtcontainers/bridgedmacvlan_endpoint_test.go +++ b/src/runtime/virtcontainers/macvlan_endpoint_test.go @@ -12,10 +12,10 @@ import ( "github.com/stretchr/testify/assert" ) -func TestCreateBridgedMacvlanEndpoint(t *testing.T) { +func TestCreateMacvlanEndpoint(t *testing.T) { macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04} - expected := &BridgedMacvlanEndpoint{ + expected := &MacvlanEndpoint{ NetPair: NetworkInterfacePair{ TapInterface: TapInterface{ ID: "uniqueTestID-4", @@ -30,10 +30,10 @@ func TestCreateBridgedMacvlanEndpoint(t *testing.T) { }, NetInterworkingModel: DefaultNetInterworkingModel, }, - EndpointType: BridgedMacvlanEndpointType, + EndpointType: MacvlanEndpointType, } - result, err := createBridgedMacvlanNetworkEndpoint(4, "", DefaultNetInterworkingModel) + result, err := createMacvlanNetworkEndpoint(4, "", DefaultNetInterworkingModel) assert.NoError(t, err) // the resulting ID will be random - so let's overwrite to test the rest of the flow diff --git a/src/runtime/virtcontainers/network.go b/src/runtime/virtcontainers/network.go index bf2b09a3ae..062a70d6ad 100644 --- a/src/runtime/virtcontainers/network.go +++ b/src/runtime/virtcontainers/network.go @@ -256,8 +256,8 @@ func generateEndpoints(typedEndpoints []TypedJSONEndpoint) ([]Endpoint, error) { var endpoint VhostUserEndpoint endpointInf = &endpoint - case BridgedMacvlanEndpointType: - var endpoint BridgedMacvlanEndpoint + case MacvlanEndpointType: + var endpoint MacvlanEndpoint endpointInf = &endpoint case MacvtapEndpointType: @@ -378,7 +378,7 @@ func getLinkForEndpoint(endpoint Endpoint, netHandle *netlink.Handle) (netlink.L switch ep := endpoint.(type) { case *VethEndpoint: link = &netlink.Veth{} - case *BridgedMacvlanEndpoint: + case *MacvlanEndpoint: link = &netlink.Macvlan{} case *IPVlanEndpoint: link = &netlink.IPVlan{} @@ -1254,7 +1254,7 @@ func createEndpoint(netInfo NetworkInfo, idx int, model NetInterworkingModel, li endpoint, err = createVhostUserEndpoint(netInfo, socketPath) } else if netInfo.Iface.Type == "macvlan" { networkLogger().Infof("macvlan interface found") - endpoint, err = createBridgedMacvlanNetworkEndpoint(idx, netInfo.Iface.Name, model) + endpoint, err = createMacvlanNetworkEndpoint(idx, netInfo.Iface.Name, model) } else if netInfo.Iface.Type == "macvtap" { networkLogger().Infof("macvtap interface found") endpoint, err = createMacvtapNetworkEndpoint(netInfo) @@ -1456,7 +1456,7 @@ func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor H func addRxRateLimiter(endpoint Endpoint, maxRate uint64) error { var linkName string switch ep := endpoint.(type) { - case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *BridgedMacvlanEndpoint: + case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *MacvlanEndpoint: netPair := endpoint.NetworkPair() linkName = netPair.TapInterface.TAPIface.Name case *MacvtapEndpoint, *TapEndpoint: @@ -1612,7 +1612,7 @@ func addTxRateLimiter(endpoint Endpoint, maxRate uint64) error { var netPair *NetworkInterfacePair var linkName string switch ep := endpoint.(type) { - case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *BridgedMacvlanEndpoint: + case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *MacvlanEndpoint: netPair = endpoint.NetworkPair() switch netPair.NetInterworkingModel { // For those endpoints we've already used tcfilter as their inter-networking model, @@ -1685,7 +1685,7 @@ func removeHTBQdisc(linkName string) error { func removeRxRateLimiter(endpoint Endpoint, networkNSPath string) error { var linkName string switch ep := endpoint.(type) { - case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *BridgedMacvlanEndpoint: + case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *MacvlanEndpoint: netPair := endpoint.NetworkPair() linkName = netPair.TapInterface.TAPIface.Name case *MacvtapEndpoint, *TapEndpoint: @@ -1706,7 +1706,7 @@ func removeRxRateLimiter(endpoint Endpoint, networkNSPath string) error { func removeTxRateLimiter(endpoint Endpoint, networkNSPath string) error { var linkName string switch ep := endpoint.(type) { - case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *BridgedMacvlanEndpoint: + case *VethEndpoint, *IPVlanEndpoint, *TuntapEndpoint, *MacvlanEndpoint: netPair := endpoint.NetworkPair() switch netPair.NetInterworkingModel { case NetXConnectTCFilterModel: diff --git a/src/runtime/virtcontainers/persist.go b/src/runtime/virtcontainers/persist.go index 3f51b8c4e0..b8fc2c8abb 100644 --- a/src/runtime/virtcontainers/persist.go +++ b/src/runtime/virtcontainers/persist.go @@ -380,8 +380,8 @@ func (s *Sandbox) loadNetwork(netInfo persistapi.NetworkInfo) { ep = &VethEndpoint{} case VhostUserEndpointType: ep = &VhostUserEndpoint{} - case BridgedMacvlanEndpointType: - ep = &BridgedMacvlanEndpoint{} + case MacvlanEndpointType: + ep = &MacvlanEndpoint{} case MacvtapEndpointType: ep = &MacvtapEndpoint{} case TapEndpointType: diff --git a/src/runtime/virtcontainers/persist/api/network.go b/src/runtime/virtcontainers/persist/api/network.go index 7283aba3cb..f1c1cc2f86 100644 --- a/src/runtime/virtcontainers/persist/api/network.go +++ b/src/runtime/virtcontainers/persist/api/network.go @@ -60,7 +60,7 @@ type TuntapEndpoint struct { TuntapInterface TuntapInterface } -type BridgedMacvlanEndpoint struct { +type MacvlanEndpoint struct { NetPair NetworkInterfacePair } @@ -82,14 +82,14 @@ type VhostUserEndpoint struct { // NetworkEndpoint contains network interface information type NetworkEndpoint struct { // One and only one of these below are not nil according to Type. - Physical *PhysicalEndpoint `json:",omitempty"` - Veth *VethEndpoint `json:",omitempty"` - VhostUser *VhostUserEndpoint `json:",omitempty"` - BridgedMacvlan *BridgedMacvlanEndpoint `json:",omitempty"` - Macvtap *MacvtapEndpoint `json:",omitempty"` - Tap *TapEndpoint `json:",omitempty"` - IPVlan *IPVlanEndpoint `json:",omitempty"` - Tuntap *TuntapEndpoint `json:",omitempty"` + Physical *PhysicalEndpoint `json:",omitempty"` + Veth *VethEndpoint `json:",omitempty"` + VhostUser *VhostUserEndpoint `json:",omitempty"` + Macvlan *MacvlanEndpoint `json:",omitempty"` + Macvtap *MacvtapEndpoint `json:",omitempty"` + Tap *TapEndpoint `json:",omitempty"` + IPVlan *IPVlanEndpoint `json:",omitempty"` + Tuntap *TuntapEndpoint `json:",omitempty"` Type string } diff --git a/src/runtime/virtcontainers/qemu_arch_base.go b/src/runtime/virtcontainers/qemu_arch_base.go index deec2b8176..426da6bac6 100644 --- a/src/runtime/virtcontainers/qemu_arch_base.go +++ b/src/runtime/virtcontainers/qemu_arch_base.go @@ -571,7 +571,7 @@ func networkModelToQemuType(model NetInterworkingModel) govmmQemu.NetDeviceType func genericNetwork(endpoint Endpoint, vhost, nestedRun bool, index int) (govmmQemu.NetDevice, error) { var d govmmQemu.NetDevice switch ep := endpoint.(type) { - case *VethEndpoint, *BridgedMacvlanEndpoint, *IPVlanEndpoint: + case *VethEndpoint, *MacvlanEndpoint, *IPVlanEndpoint: netPair := ep.NetworkPair() d = govmmQemu.NetDevice{ Type: networkModelToQemuType(netPair.NetInterworkingModel), diff --git a/src/runtime/virtcontainers/qemu_arch_base_test.go b/src/runtime/virtcontainers/qemu_arch_base_test.go index 4b495f73d9..1989e643a0 100644 --- a/src/runtime/virtcontainers/qemu_arch_base_test.go +++ b/src/runtime/virtcontainers/qemu_arch_base_test.go @@ -490,7 +490,7 @@ func TestQemuArchBaseAppendNetwork(t *testing.T) { macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04} - macvlanEp := &BridgedMacvlanEndpoint{ + macvlanEp := &MacvlanEndpoint{ NetPair: NetworkInterfacePair{ TapInterface: TapInterface{ ID: "uniqueTestID-4", @@ -505,7 +505,7 @@ func TestQemuArchBaseAppendNetwork(t *testing.T) { }, NetInterworkingModel: DefaultNetInterworkingModel, }, - EndpointType: BridgedMacvlanEndpointType, + EndpointType: MacvlanEndpointType, } macvtapEp := &MacvtapEndpoint{