func CreateHostVeth(containerId string, k8sName string, k8sNamespace string) error {
	hostVethName := "cali" + containerId[:min(11, len(containerId))]
	if k8sName != "" {
		workload := fmt.Sprintf("%s.%s", k8sNamespace, k8sName)
		hostVethName = k8sbackend.VethNameForWorkload(workload)
	}

	peerVethName := "calipeer"

	// Clean up if peer Veth exists.
	if oldPeerVethName, err := netlink.LinkByName(peerVethName); err == nil {
		if err = netlink.LinkDel(oldPeerVethName); err != nil {
			return fmt.Errorf("failed to delete old peer Veth %v: %v", oldPeerVethName, err)
		}
	}

	veth := &netlink.Veth{
		LinkAttrs: netlink.LinkAttrs{
			Name:  hostVethName,
			Flags: net.FlagUp,
			MTU:   1500,
		},
		PeerName: peerVethName,
	}

	if err := netlink.LinkAdd(veth); err != nil {
		return err
	}

	return nil
}
// Create veth pair on host
Create veth pair on host
// Create veth pair on host
func CreateHostVeth(containerId string, k8sName string, k8sNamespace string) error {
	hostVethName := "cali" + containerId[:min(11, len(containerId))]
	if k8sName != "" {
		workload := fmt.Sprintf("%s.%s", k8sNamespace, k8sName)
		hostVethName = k8sbackend.VethNameForWorkload(workload)
	}
	peerVethName := "calipeer"
	if oldPeerVethName, err := netlink.LinkByName(peerVethName); err == nil {
		if err = netlink.LinkDel(oldPeerVethName); err != nil {
			return fmt.Errorf("failed to delete old peer Veth %v: %v", oldPeerVethName, err)
		}
	}
	veth := &netlink.Veth{
		LinkAttrs: netlink.LinkAttrs{
			Name:  hostVethName,
			Flags: net.FlagUp,
			MTU:   1500,
		},
		PeerName: peerVethName,
	}
	if err := netlink.LinkAdd(veth); err != nil {
		return err
	}
	return nil
}
func CreateHostVeth ( containerId string , k8sName string , k8sNamespace string ) error { hostVethName := " " + containerId [ : min ( 11 , len ( containerId ) ) ] if k8sName != " " { workload := fmt . Sprintf ( " " , k8sNamespace , k8sName ) hostVethName = k8sbackend . VethNameForWorkload ( workload ) } peerVethName := " " if oldPeerVethName , err := netlink . LinkByName ( peerVethName ) ; err == nil { if err = netlink . LinkDel ( oldPeerVethName ) ; err != nil { return fmt . Errorf ( " " , oldPeerVethName , err ) } } veth := & netlink . Veth { LinkAttrs : netlink . LinkAttrs { Name : hostVethName , Flags : net . FlagUp , MTU : 1500 , } , PeerName : peerVethName , } if err := netlink . LinkAdd ( veth ) ; err != nil { return err } return nil }
Create veth pair on host
Create veth pair on host
// Clean up if peer Veth exists.