mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Allow setting IfName to 'none' to run without TUN/TAP
This commit is contained in:
		
							parent
							
								
									120ce8bd2f
								
							
						
					
					
						commit
						02473158d4
					
				
					 3 changed files with 17 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -212,11 +212,13 @@ func (c *Core) DEBUG_startTun(ifname string, iftapmode bool) {
 | 
			
		|||
func (c *Core) DEBUG_startTunWithMTU(ifname string, iftapmode bool, mtu int) {
 | 
			
		||||
	addr := c.DEBUG_getAddr()
 | 
			
		||||
	straddr := fmt.Sprintf("%s/%v", net.IP(addr[:]).String(), 8*len(address_prefix))
 | 
			
		||||
	err := c.tun.setup(ifname, iftapmode, straddr, mtu)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	if ifname != "none" {
 | 
			
		||||
		err := c.tun.setup(ifname, iftapmode, straddr, mtu)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
		go c.tun.read()
 | 
			
		||||
	}
 | 
			
		||||
	go c.tun.read()
 | 
			
		||||
	go c.tun.write()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,6 +33,9 @@ func (tun *tunDevice) init(core *Core) {
 | 
			
		|||
func (tun *tunDevice) write() error {
 | 
			
		||||
	for {
 | 
			
		||||
		data := <-tun.recv
 | 
			
		||||
		if tun.iface == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if tun.iface.IsTAP() {
 | 
			
		||||
			var frame ethernet.Frame
 | 
			
		||||
			frame.Prepare(
 | 
			
		||||
| 
						 | 
				
			
			@ -88,5 +91,8 @@ func (tun *tunDevice) read() error {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (tun *tunDevice) close() error {
 | 
			
		||||
	if tun.iface == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return tun.iface.Close()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue