func (endpoint *PhysicalEndpoint) Name() string {
	return endpoint.IfaceName
}
Name returns name of the physical interface.
package virtcontainers
import (
	"encoding/hex"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"math/rand"
	"net"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"time"
	"github.com/containernetworking/plugins/pkg/ns"
	"github.com/containers/virtcontainers/pkg/ethtool"
	"github.com/containers/virtcontainers/pkg/uuid"
	"github.com/sirupsen/logrus"
	"github.com/vishvananda/netlink"
	"github.com/vishvananda/netns"
	"golang.org/x/sys/unix"
)
type NetInterworkingModel int
const (
	NetXConnectDefaultModel NetInterworkingModel = iota
	NetXConnectBridgedModel
	NetXConnectMacVtapModel
	NetXConnectEnlightenedModel
	NetXConnectInvalidModel
)
func (n NetInterworkingModel) IsValid() bool {
	return 0 <= int(n) && int(n) < int(NetXConnectInvalidModel)
}
func (n *NetInterworkingModel) SetModel(modelName string) error {
	switch modelName {
	case "default":
		*n = DefaultNetInterworkingModel
		return nil
	case "bridged":
		*n = NetXConnectBridgedModel
		return nil
	case "macvtap":
		*n = NetXConnectMacVtapModel
		return nil
	case "enlightened":
		*n = NetXConnectEnlightenedModel
		return nil
	}
	return fmt.Errorf("Unknown type %s", modelName)
}
var DefaultNetInterworkingModel = NetXConnectMacVtapModel
const (
	defaultRouteDest  = "0.0.0.0/0"
	defaultRouteLabel = "default"
	defaultFilePerms  = 0600
	defaultQlen       = 1500
	defaultQueues     = 8
)
type DNSInfo struct {
	Servers  []string
	Domain   string
	Searches []string
	Options  []string
}
type NetlinkIface struct {
	netlink.LinkAttrs
	Type string
}
type NetworkInfo struct {
	Iface  NetlinkIface
	Addrs  []netlink.Addr
	Routes []netlink.Route
	DNS    DNSInfo
}
type NetworkInterface struct {
	Name     string
	HardAddr string
	Addrs    []netlink.Addr
}
type NetworkInterfacePair struct {
	ID        string
	Name      string
	VirtIface NetworkInterface
	TAPIface  NetworkInterface
	NetInterworkingModel
	VMFds    []*os.File
	VhostFds []*os.File
}
type NetworkConfig struct {
	NetNSPath         string
	NumInterfaces     int
	InterworkingModel NetInterworkingModel
}
type Endpoint interface {
	Properties() NetworkInfo
	Name() string
	HardwareAddr() string
	Type() EndpointType
	SetProperties(NetworkInfo)
	Attach(hypervisor) error
	Detach() error
}
type VirtualEndpoint struct {
	NetPair            NetworkInterfacePair
	EndpointProperties NetworkInfo
	Physical           bool
	EndpointType       EndpointType
}
type PhysicalEndpoint struct {
	IfaceName          string
	HardAddr           string
	EndpointProperties NetworkInfo
	EndpointType       EndpointType
	BDF                string
	Driver             string
	VendorDeviceID     string
}
type VhostUserEndpoint struct {
	SocketPath string
	HardAddr           string
	IfaceName          string
	EndpointProperties NetworkInfo
	EndpointType       EndpointType
}
func (endpoint *VirtualEndpoint) Properties() NetworkInfo {
	return endpoint.EndpointProperties
}
func (endpoint *VirtualEndpoint) Name() string {
	return endpoint.NetPair.VirtIface.Name
}
func (endpoint *VirtualEndpoint) HardwareAddr() string {
	return endpoint.NetPair.TAPIface.HardAddr
}
func (endpoint *VirtualEndpoint) Type() EndpointType {
	return endpoint.EndpointType
}
func (endpoint *VirtualEndpoint) SetProperties(properties NetworkInfo) {
	endpoint.EndpointProperties = properties
}
func networkLogger() *logrus.Entry {
	return virtLog.WithField("subsystem", "network")
}
func (endpoint *VirtualEndpoint) Attach(h hypervisor) error {
	networkLogger().Info("Attaching virtual endpoint")
	if err := xconnectVMNetwork(&(endpoint.NetPair), true); err != nil {
		networkLogger().WithError(err).Error("Error bridging virtual ep")
		return err
	}
	return h.addDevice(endpoint, netDev)
}
func (endpoint *VirtualEndpoint) Detach() error {
	networkLogger().Info("Detaching virtual endpoint")
	return xconnectVMNetwork(&(endpoint.NetPair), false)
}
func (endpoint *VhostUserEndpoint) Properties() NetworkInfo {
	return endpoint.EndpointProperties
}
func (endpoint *VhostUserEndpoint) Name() string {
	return endpoint.IfaceName
}
func (endpoint *VhostUserEndpoint) HardwareAddr() string {
	return endpoint.HardAddr
}
func (endpoint *VhostUserEndpoint) Type() EndpointType {
	return endpoint.EndpointType
}
func (endpoint *VhostUserEndpoint) SetProperties(properties NetworkInfo) {
	endpoint.EndpointProperties = properties
}
func (endpoint *VhostUserEndpoint) Attach(h hypervisor) error {
	networkLogger().Info("Attaching vhostuser based endpoint")
	randBytes, err := generateRandomBytes(8)
	if err != nil {
		return err
	}
	id := hex.EncodeToString(randBytes)
	d := VhostUserNetDevice{
		MacAddress: endpoint.HardAddr,
	}
	d.SocketPath = endpoint.SocketPath
	d.ID = id
	return h.addDevice(d, vhostuserDev)
}
func (endpoint *VhostUserEndpoint) Detach() error {
	networkLogger().Info("Detaching vhostuser based endpoint")
	return nil
}
func createVhostUserEndpoint(netInfo NetworkInfo, socket string) (*VhostUserEndpoint, error) {
	vhostUserEndpoint := &VhostUserEndpoint{
		SocketPath:   socket,
		HardAddr:     netInfo.Iface.HardwareAddr.String(),
		IfaceName:    netInfo.Iface.Name,
		EndpointType: VhostUserEndpointType,
	}
	return vhostUserEndpoint, nil
}
func (endpoint *PhysicalEndpoint) Properties() NetworkInfo {
	return endpoint.EndpointProperties
}
func (endpoint *PhysicalEndpoint) HardwareAddr() string {
	return endpoint.HardAddr
}