mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Try to fix CKR setup deadlock, fix some Windows output formatting
This commit is contained in:
		
							parent
							
								
									a10c141896
								
							
						
					
					
						commit
						30c03369cd
					
				
					 3 changed files with 19 additions and 21 deletions
				
			
		| 
						 | 
				
			
			@ -59,11 +59,10 @@ func (c *cryptokey) init(tun *TunAdapter) {
 | 
			
		|||
// Configure the CKR routes - this must only ever be called from the router
 | 
			
		||||
// goroutine, e.g. through router.doAdmin
 | 
			
		||||
func (c *cryptokey) configure() error {
 | 
			
		||||
	c.tun.config.Mutex.RLock()
 | 
			
		||||
	defer c.tun.config.Mutex.RUnlock()
 | 
			
		||||
	current, _ := c.tun.config.Get()
 | 
			
		||||
 | 
			
		||||
	// Set enabled/disabled state
 | 
			
		||||
	c.setEnabled(c.tun.config.Current.TunnelRouting.Enable)
 | 
			
		||||
	c.setEnabled(current.TunnelRouting.Enable)
 | 
			
		||||
 | 
			
		||||
	// Clear out existing routes
 | 
			
		||||
	c.mutexroutes.Lock()
 | 
			
		||||
| 
						 | 
				
			
			@ -72,14 +71,14 @@ func (c *cryptokey) configure() error {
 | 
			
		|||
	c.mutexroutes.Unlock()
 | 
			
		||||
 | 
			
		||||
	// Add IPv6 routes
 | 
			
		||||
	for ipv6, pubkey := range c.tun.config.Current.TunnelRouting.IPv6Destinations {
 | 
			
		||||
	for ipv6, pubkey := range current.TunnelRouting.IPv6Destinations {
 | 
			
		||||
		if err := c.addRoute(ipv6, pubkey); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Add IPv4 routes
 | 
			
		||||
	for ipv4, pubkey := range c.tun.config.Current.TunnelRouting.IPv4Destinations {
 | 
			
		||||
	for ipv4, pubkey := range current.TunnelRouting.IPv4Destinations {
 | 
			
		||||
		if err := c.addRoute(ipv4, pubkey); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +92,7 @@ func (c *cryptokey) configure() error {
 | 
			
		|||
 | 
			
		||||
	// Add IPv6 sources
 | 
			
		||||
	c.ipv6sources = make([]net.IPNet, 0)
 | 
			
		||||
	for _, source := range c.tun.config.Current.TunnelRouting.IPv6Sources {
 | 
			
		||||
	for _, source := range current.TunnelRouting.IPv6Sources {
 | 
			
		||||
		if err := c.addSourceSubnet(source); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +100,7 @@ func (c *cryptokey) configure() error {
 | 
			
		|||
 | 
			
		||||
	// Add IPv4 sources
 | 
			
		||||
	c.ipv4sources = make([]net.IPNet, 0)
 | 
			
		||||
	for _, source := range c.tun.config.Current.TunnelRouting.IPv4Sources {
 | 
			
		||||
	for _, source := range current.TunnelRouting.IPv4Sources {
 | 
			
		||||
		if err := c.addSourceSubnet(source); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -119,13 +119,12 @@ func (tun *TunAdapter) Init(config *config.NodeState, log *log.Logger, listener
 | 
			
		|||
// Start the setup process for the TUN/TAP adapter. If successful, starts the
 | 
			
		||||
// read/write goroutines to handle packets on that interface.
 | 
			
		||||
func (tun *TunAdapter) Start() error {
 | 
			
		||||
	tun.config.Mutex.RLock()
 | 
			
		||||
	defer tun.config.Mutex.RUnlock()
 | 
			
		||||
	current, _ := tun.config.Get()
 | 
			
		||||
	if tun.config == nil || tun.listener == nil || tun.dialer == nil {
 | 
			
		||||
		return errors.New("No configuration available to TUN/TAP")
 | 
			
		||||
	}
 | 
			
		||||
	var boxPub crypto.BoxPubKey
 | 
			
		||||
	boxPubHex, err := hex.DecodeString(tun.config.Current.EncryptionPublicKey)
 | 
			
		||||
	boxPubHex, err := hex.DecodeString(current.EncryptionPublicKey)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -133,9 +132,9 @@ func (tun *TunAdapter) Start() error {
 | 
			
		|||
	nodeID := crypto.GetNodeID(&boxPub)
 | 
			
		||||
	tun.addr = *address.AddrForNodeID(nodeID)
 | 
			
		||||
	tun.subnet = *address.SubnetForNodeID(nodeID)
 | 
			
		||||
	tun.mtu = tun.config.Current.IfMTU
 | 
			
		||||
	ifname := tun.config.Current.IfName
 | 
			
		||||
	iftapmode := tun.config.Current.IfTAPMode
 | 
			
		||||
	tun.mtu = current.IfMTU
 | 
			
		||||
	ifname := current.IfName
 | 
			
		||||
	iftapmode := current.IfTAPMode
 | 
			
		||||
	addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1)
 | 
			
		||||
	if ifname != "none" {
 | 
			
		||||
		if err := tun.setup(ifname, iftapmode, addr, tun.mtu); err != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,18 +31,18 @@ func (tun *TunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int
 | 
			
		|||
	}
 | 
			
		||||
	// Disable/enable the interface to resets its configuration (invalidating iface)
 | 
			
		||||
	cmd := exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=DISABLED")
 | 
			
		||||
	tun.log.Printf("netsh command: %v", strings.Join(cmd.Args, " "))
 | 
			
		||||
	tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " "))
 | 
			
		||||
	output, err := cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		tun.log.Errorf("Windows netsh failed: %v.", err)
 | 
			
		||||
		tun.log.Errorln("Windows netsh failed:", err)
 | 
			
		||||
		tun.log.Traceln(string(output))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	cmd = exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=ENABLED")
 | 
			
		||||
	tun.log.Printf("netsh command: %v", strings.Join(cmd.Args, " "))
 | 
			
		||||
	tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " "))
 | 
			
		||||
	output, err = cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		tun.log.Errorf("Windows netsh failed: %v.", err)
 | 
			
		||||
		tun.log.Errorln("Windows netsh failed:", err)
 | 
			
		||||
		tun.log.Traceln(string(output))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -71,10 +71,10 @@ func (tun *TunAdapter) setupMTU(mtu int) error {
 | 
			
		|||
		fmt.Sprintf("interface=%s", tun.iface.Name()),
 | 
			
		||||
		fmt.Sprintf("mtu=%d", mtu),
 | 
			
		||||
		"store=active")
 | 
			
		||||
	tun.log.Debugln("netsh command: %v", strings.Join(cmd.Args, " "))
 | 
			
		||||
	tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " "))
 | 
			
		||||
	output, err := cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		tun.log.Errorf("Windows netsh failed: %v.", err)
 | 
			
		||||
		tun.log.Errorln("Windows netsh failed:", err)
 | 
			
		||||
		tun.log.Traceln(string(output))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -88,10 +88,10 @@ func (tun *TunAdapter) setupAddress(addr string) error {
 | 
			
		|||
		fmt.Sprintf("interface=%s", tun.iface.Name()),
 | 
			
		||||
		fmt.Sprintf("addr=%s", addr),
 | 
			
		||||
		"store=active")
 | 
			
		||||
	tun.log.Debugln("netsh command: %v", strings.Join(cmd.Args, " "))
 | 
			
		||||
	tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " "))
 | 
			
		||||
	output, err := cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		tun.log.Errorf("Windows netsh failed: %v.", err)
 | 
			
		||||
		tun.log.Errorln("Windows netsh failed:", err)
 | 
			
		||||
		tun.log.Traceln(string(output))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue