mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	disable/enable the tap device at startup to clear any old settings, e.g. old addresses
This commit is contained in:
		
							parent
							
								
									06e3c8c997
								
							
						
					
					
						commit
						d52fab8af6
					
				
					 1 changed files with 25 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -15,6 +15,28 @@ func (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
 | 
			
		|||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	// Disable/enable the interface to resets its configuration (invalidating iface)
 | 
			
		||||
	cmd := exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=DISABLED")
 | 
			
		||||
	tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " "))
 | 
			
		||||
	output, err := cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		tun.core.log.Printf("Windows netsh failed: %v.", err)
 | 
			
		||||
		tun.core.log.Println(string(output))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	cmd = exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=ENABLED")
 | 
			
		||||
	tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " "))
 | 
			
		||||
	output, err = cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		tun.core.log.Printf("Windows netsh failed: %v.", err)
 | 
			
		||||
		tun.core.log.Println(string(output))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	// Get a new iface
 | 
			
		||||
	iface, err = water.New(config)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	tun.iface = iface
 | 
			
		||||
	tun.mtu = mtu
 | 
			
		||||
	return tun.setupAddress(addr)
 | 
			
		||||
| 
						 | 
				
			
			@ -23,9 +45,10 @@ func (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
 | 
			
		|||
func (tun *tunDevice) setupAddress(addr string) error {
 | 
			
		||||
	// Set address
 | 
			
		||||
	// addr = strings.TrimRight(addr, "/8")
 | 
			
		||||
	cmd := exec.Command("netsh", "interface", "ipv6", "set", "address",
 | 
			
		||||
	cmd := exec.Command("netsh", "interface", "ipv6", "add", "address",
 | 
			
		||||
		fmt.Sprintf("interface=%s", tun.iface.Name()),
 | 
			
		||||
		fmt.Sprintf("addr=%s", addr))
 | 
			
		||||
		fmt.Sprintf("addr=%s", addr),
 | 
			
		||||
		"store=active")
 | 
			
		||||
	tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " "))
 | 
			
		||||
	output, err := cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue