func (ipsec *IPSec) Destroy(localPeer, remotePeer mesh.PeerName, connUID uint64, localIP, remoteIP net.IP, udpPort int) error {
	outSPIID := getSPIId(localPeer, remotePeer, connUID)
	inSPIID := getSPIId(remotePeer, localPeer, connUID)

	ipsec.Lock()
	defer ipsec.Unlock()

	// Destroy inbound

	if inSPIInfo, ok := ipsec.spiInfo[inSPIID]; ok {
		ipsec.log.Infof("ipsec: destroy: in %s -> %s 0x%x", remoteIP, localIP, inSPIInfo.spi)

		inSPI := inSPIInfo.spi

		inSA := &netlink.XfrmState{
			Src:   remoteIP,
			Dst:   localIP,
			Proto: netlink.XFRM_PROTO_ESP,
			Spi:   int(inSPI),
		}
		if err := netlink.XfrmStateDel(inSA); err != nil {
			ipsec.log.Warnf("ipsec: xfrm state del (in, %s, %s, 0x%x) failed: %s", inSA.Src, inSA.Dst, inSA.Spi, err)
		}

		if err := ipsec.removeDropNonEncrypted(localIP, remoteIP, udpPort, inSPI); err != nil {
			ipsec.log.Warnf("ipsec: remove protecting rules (%s, %s, %d, 0x%x) failed: %s", localIP, remoteIP, udpPort, inSPI, err)
		}

		delete(ipsec.spiInfo, inSPIID)
		delete(ipsec.spis, inSPI)
	}

	// Destroy outbound

	if outSPIInfo, ok := ipsec.spiInfo[outSPIID]; ok {
		ipsec.log.Infof("ipsec: destroy: out %s -> %s 0x%x", localIP, remoteIP, outSPIInfo.spi)

		if err := netlink.XfrmPolicyDel(xfrmPolicy(localIP, remoteIP, outSPIInfo.spi)); err != nil {
			ipsec.log.Warnf("ipsec: xfrm policy del (%s, %s, 0x%x) failed: %s", localIP, remoteIP, outSPIInfo.spi, err)
		}

		outSA := &netlink.XfrmState{
			Src:   localIP,
			Dst:   remoteIP,
			Proto: netlink.XFRM_PROTO_ESP,
			Spi:   int(outSPIInfo.spi),
		}
		if err := netlink.XfrmStateDel(outSA); err != nil {
			ipsec.log.Warnf("ipsec: xfrm state del (out, %s, %s, 0x%x) failed: %s", outSA.Src, outSA.Dst, outSA.Spi, err)
		}

		delete(ipsec.spiInfo, outSPIID)
		delete(ipsec.spis, outSPIInfo.spi)
	}

	return nil
}
// Destroy destroys any (inbound / outbound) ipsec establishment between the peers.
Destroy destroys any (inbound / outbound) ipsec establishment between the peers.
// Destroy destroys any ( inbound / outbound ) ipsec establishment between the peers .
func (ipsec *IPSec) Destroy(localPeer, remotePeer mesh.PeerName, connUID uint64, localIP, remoteIP net.IP, udpPort int) error {
	outSPIID := getSPIId(localPeer, remotePeer, connUID)
	inSPIID := getSPIId(remotePeer, localPeer, connUID)
	ipsec.Lock()
	defer ipsec.Unlock()
	if inSPIInfo, ok := ipsec.spiInfo[inSPIID]; ok {
		ipsec.log.Infof("ipsec: destroy: in %s -> %s 0x%x", remoteIP, localIP, inSPIInfo.spi)
		inSPI := inSPIInfo.spi
		inSA := &netlink.XfrmState{
			Src:   remoteIP,
			Dst:   localIP,
			Proto: netlink.XFRM_PROTO_ESP,
			Spi:   int(inSPI),
		}
		if err := netlink.XfrmStateDel(inSA); err != nil {
			ipsec.log.Warnf("ipsec: xfrm state del (in, %s, %s, 0x%x) failed: %s", inSA.Src, inSA.Dst, inSA.Spi, err)
		}
		if err := ipsec.removeDropNonEncrypted(localIP, remoteIP, udpPort, inSPI); err != nil {
			ipsec.log.Warnf("ipsec: remove protecting rules (%s, %s, %d, 0x%x) failed: %s", localIP, remoteIP, udpPort, inSPI, err)
		}
		delete(ipsec.spiInfo, inSPIID)
		delete(ipsec.spis, inSPI)
	}
	if outSPIInfo, ok := ipsec.spiInfo[outSPIID]; ok {
		ipsec.log.Infof("ipsec: destroy: out %s -> %s 0x%x", localIP, remoteIP, outSPIInfo.spi)
		if err := netlink.XfrmPolicyDel(xfrmPolicy(localIP, remoteIP, outSPIInfo.spi)); err != nil {
			ipsec.log.Warnf("ipsec: xfrm policy del (%s, %s, 0x%x) failed: %s", localIP, remoteIP, outSPIInfo.spi, err)
		}
		outSA := &netlink.XfrmState{
			Src:   localIP,
			Dst:   remoteIP,
			Proto: netlink.XFRM_PROTO_ESP,
			Spi:   int(outSPIInfo.spi),
		}
		if err := netlink.XfrmStateDel(outSA); err != nil {
			ipsec.log.Warnf("ipsec: xfrm state del (out, %s, %s, 0x%x) failed: %s", outSA.Src, outSA.Dst, outSA.Spi, err)
		}
		delete(ipsec.spiInfo, outSPIID)
		delete(ipsec.spis, outSPIInfo.spi)
	}
	return nil
}
func ( ipsec * IPSec ) Destroy ( localPeer , remotePeer mesh . PeerName , connUID uint64 , localIP , remoteIP net . IP , udpPort int ) error { outSPIID := getSPIId ( localPeer , remotePeer , connUID ) inSPIID := getSPIId ( remotePeer , localPeer , connUID ) ipsec . Lock ( ) defer ipsec . Unlock ( ) if inSPIInfo , ok := ipsec . spiInfo [ inSPIID ] ; ok { ipsec . log . Infof ( " " , remoteIP , localIP , inSPIInfo . spi ) inSPI := inSPIInfo . spi inSA := & netlink . XfrmState { Src : remoteIP , Dst : localIP , Proto : netlink . XFRM_PROTO_ESP , Spi : int ( inSPI ) , } if err := netlink . XfrmStateDel ( inSA ) ; err != nil { ipsec . log . Warnf ( " " , inSA . Src , inSA . Dst , inSA . Spi , err ) } if err := ipsec . removeDropNonEncrypted ( localIP , remoteIP , udpPort , inSPI ) ; err != nil { ipsec . log . Warnf ( " " , localIP , remoteIP , udpPort , inSPI , err ) } delete ( ipsec . spiInfo , inSPIID ) delete ( ipsec . spis , inSPI ) } if outSPIInfo , ok := ipsec . spiInfo [ outSPIID ] ; ok { ipsec . log . Infof ( " " , localIP , remoteIP , outSPIInfo . spi ) if err := netlink . XfrmPolicyDel ( xfrmPolicy ( localIP , remoteIP , outSPIInfo . spi ) ) ; err != nil { ipsec . log . Warnf ( " " , localIP , remoteIP , outSPIInfo . spi , err ) } outSA := & netlink . XfrmState { Src : localIP , Dst : remoteIP , Proto : netlink . XFRM_PROTO_ESP , Spi : int ( outSPIInfo . spi ) , } if err := netlink . XfrmStateDel ( outSA ) ; err != nil { ipsec . log . Warnf ( " " , outSA . Src , outSA . Dst , outSA . Spi , err ) } delete ( ipsec . spiInfo , outSPIID ) delete ( ipsec . spis , outSPIInfo . spi ) } return nil }
Destroy destroys any (inbound / outbound) ipsec establishment between the peers.
Destroy destroys any ( inbound / outbound ) ipsec establishment between the peers .
// Destroy inbound // Destroy outbound