mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	test adding BindToDevice to linux. if it works then we'll want to rethink slightly how we get the tcpContext on every platform, to make this compile everywhere and look a little cleaner
This commit is contained in:
		
							parent
							
								
									1fbab17b37
								
							
						
					
					
						commit
						bcacfb0638
					
				
					 2 changed files with 15 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -299,6 +299,7 @@ func (t *tcp) call(saddr string, options interface{}, sintf string, upgrade *Tcp
 | 
			
		|||
				Timeout: time.Second * 5,
 | 
			
		||||
			}
 | 
			
		||||
			if sintf != "" {
 | 
			
		||||
				dialer.Control = t.getContextWithBindToDevice(sintf)
 | 
			
		||||
				ief, err := net.InterfaceByName(sintf)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,3 +29,17 @@ func (t *tcp) tcpContext(network, address string, c syscall.RawConn) error {
 | 
			
		|||
	// Return nil because errors here are not considered fatal for the connection, it just means congestion control is suboptimal
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t *tcp) getContextWithBindToDevice(sintf string) func(string, string, syscall.RawConn) error {
 | 
			
		||||
	return func(network, address string, c syscall.RawConn) error {
 | 
			
		||||
		var err error
 | 
			
		||||
		btd := func(fd uintptr) {
 | 
			
		||||
			err = unix.BindToDevice(int(fd), sintf)
 | 
			
		||||
		}
 | 
			
		||||
		c.Control(btd)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.link.core.log.Debugln("Failed to set SO_BINDTODEVICE:", sintf)
 | 
			
		||||
		}
 | 
			
		||||
		return t.tcpContext(network, address, c)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue