mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Add support for specifying tun device name
This commit is contained in:
		
							parent
							
								
									e5d526881d
								
							
						
					
					
						commit
						1c799b305d
					
				
					 3 changed files with 12 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -196,14 +196,14 @@ func (c *Core) DEBUG_getAddr() *address {
 | 
			
		|||
  return address_addrForNodeID(&c.dht.nodeID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Core) DEBUG_startTun() {
 | 
			
		||||
  c.DEBUG_startTunWithMTU(1280)
 | 
			
		||||
func (c *Core) DEBUG_startTun(ifname string) {
 | 
			
		||||
  c.DEBUG_startTunWithMTU(ifname, 1280)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Core) DEBUG_startTunWithMTU(mtu int) {
 | 
			
		||||
func (c *Core) DEBUG_startTunWithMTU(ifname string, mtu int) {
 | 
			
		||||
  addr := c.DEBUG_getAddr()
 | 
			
		||||
  straddr := fmt.Sprintf("%s/%v", net.IP(addr[:]).String(), 8*len(address_prefix))
 | 
			
		||||
  err := c.tun.setup(straddr, mtu)
 | 
			
		||||
  err := c.tun.setup(ifname, straddr, mtu)
 | 
			
		||||
  if err != nil { panic(err) }
 | 
			
		||||
  go c.tun.read()
 | 
			
		||||
  go c.tun.write()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,8 +18,10 @@ func (tun *tunDevice) init(core *Core) {
 | 
			
		|||
  tun.core = core
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (tun *tunDevice) setup(addr string, mtu int) error {
 | 
			
		||||
	iface, err := water.New(water.Config{ DeviceType: water.TUN })
 | 
			
		||||
func (tun *tunDevice) setup(ifname string, addr string, mtu int) error {
 | 
			
		||||
        config := water.Config{ DeviceType: water.TUN }
 | 
			
		||||
        if ifname != "" && ifname != "auto" { config.Name = ifname }
 | 
			
		||||
	iface, err := water.New(config)
 | 
			
		||||
	if err != nil { panic(err) }
 | 
			
		||||
  tun.iface = iface
 | 
			
		||||
  tun.mtu = mtu //1280 // Lets default to the smallest thing allowed for now
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue