func CreateAndAttachVeth(name, peerName, bridgeName string, mtu int, keepTXOn bool, init func(peer netlink.Link) error) (*netlink.Veth, error) {
	bridge, err := netlink.LinkByName(bridgeName)
	if err != nil {
		return nil, fmt.Errorf(`bridge "%s" not present; did you launch weave?`, bridgeName)
	}

	if mtu == 0 {
		mtu = bridge.Attrs().MTU
	}
	veth := &netlink.Veth{
		LinkAttrs: netlink.LinkAttrs{
			Name: name,
			MTU:  mtu},
		PeerName: peerName,
	}
	if err := netlink.LinkAdd(veth); err != nil {
		return nil, fmt.Errorf(`could not create veth pair %s-%s: %s`, name, peerName, err)
	}

	cleanup := func(format string, a ...interface{}) (*netlink.Veth, error) {
		netlink.LinkDel(veth)
		return nil, fmt.Errorf(format, a...)
	}

	bridgeType, err := ExistingBridgeType(bridgeName, DatapathName)
	if err != nil {
		return cleanup("detect bridge type: %s", err)
	}
	if err := bridgeType.attach(veth); err != nil {
		return cleanup("attaching veth %q to %q: %s", name, bridgeName, err)
	}
	if !bridgeType.IsFastdp() && !keepTXOn {
		if err := EthtoolTXOff(veth.PeerName); err != nil {
			return cleanup(`unable to set tx off on %q: %s`, peerName, err)
		}
	}

	if init != nil {
		peer, err := netlink.LinkByName(peerName)
		if err != nil {
			return cleanup("unable to find peer veth %s: %s", peerName, err)
		}
		if err := init(peer); err != nil {
			return cleanup("initializing veth: %s", err)
		}
	}

	if err := netlink.LinkSetUp(veth); err != nil {
		return cleanup("unable to bring veth up: %s", err)
	}

	return veth, nil
}
// create and attach a veth to the Weave bridge
create and attach a veth to the Weave bridge
// create and attach a veth to the Weave bridge
func CreateAndAttachVeth(name, peerName, bridgeName string, mtu int, keepTXOn bool, init func(peer netlink.Link) error) (*netlink.Veth, error) {
	bridge, err := netlink.LinkByName(bridgeName)
	if err != nil {
		return nil, fmt.Errorf(`bridge "%s" not present; did you launch weave?`, bridgeName)
	}
	if mtu == 0 {
		mtu = bridge.Attrs().MTU
	}
	veth := &netlink.Veth{
		LinkAttrs: netlink.LinkAttrs{
			Name: name,
			MTU:  mtu},
		PeerName: peerName,
	}
	if err := netlink.LinkAdd(veth); err != nil {
		return nil, fmt.Errorf(`could not create veth pair %s-%s: %s`, name, peerName, err)
	}
	cleanup := func(format string, a ...interface{}) (*netlink.Veth, error) {
		netlink.LinkDel(veth)
		return nil, fmt.Errorf(format, a...)
	}
	bridgeType, err := ExistingBridgeType(bridgeName, DatapathName)
	if err != nil {
		return cleanup("detect bridge type: %s", err)
	}
	if err := bridgeType.attach(veth); err != nil {
		return cleanup("attaching veth %q to %q: %s", name, bridgeName, err)
	}
	if !bridgeType.IsFastdp() && !keepTXOn {
		if err := EthtoolTXOff(veth.PeerName); err != nil {
			return cleanup(`unable to set tx off on %q: %s`, peerName, err)
		}
	}
	if init != nil {
		peer, err := netlink.LinkByName(peerName)
		if err != nil {
			return cleanup("unable to find peer veth %s: %s", peerName, err)
		}
		if err := init(peer); err != nil {
			return cleanup("initializing veth: %s", err)
		}
	}
	if err := netlink.LinkSetUp(veth); err != nil {
		return cleanup("unable to bring veth up: %s", err)
	}
	return veth, nil
}
func CreateAndAttachVeth ( name , peerName , bridgeName string , mtu int , keepTXOn bool , init func ( peer netlink . Link ) error ) ( * netlink . Veth , error ) { bridge , err := netlink . LinkByName ( bridgeName ) if err != nil { return nil , fmt . Errorf ( `bridge "%s" not present; did you launch weave?` , bridgeName ) } if mtu == 0 { mtu = bridge . Attrs ( ) . MTU } veth := & netlink . Veth { LinkAttrs : netlink . LinkAttrs { Name : name , MTU : mtu } , PeerName : peerName , } if err := netlink . LinkAdd ( veth ) ; err != nil { return nil , fmt . Errorf ( `could not create veth pair %s-%s: %s` , name , peerName , err ) } cleanup := func ( format string , a ... interface { } ) ( * netlink . Veth , error ) { netlink . LinkDel ( veth ) return nil , fmt . Errorf ( format , a ... ) } bridgeType , err := ExistingBridgeType ( bridgeName , DatapathName ) if err != nil { return cleanup ( " " , err ) } if err := bridgeType . attach ( veth ) ; err != nil { return cleanup ( " " , name , bridgeName , err ) } if ! bridgeType . IsFastdp ( ) && ! keepTXOn { if err := EthtoolTXOff ( veth . PeerName ) ; err != nil { return cleanup ( `unable to set tx off on %q: %s` , peerName , err ) } } if init != nil { peer , err := netlink . LinkByName ( peerName ) if err != nil { return cleanup ( " " , peerName , err ) } if err := init ( peer ) ; err != nil { return cleanup ( " " , err ) } } if err := netlink . LinkSetUp ( veth ) ; err != nil { return cleanup ( " " , err ) } return veth , nil }
create and attach a veth to the Weave bridge
create and attach a veth to the Weave bridge