mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Allow sane defaults on setTunTap
This commit is contained in:
		
							parent
							
								
									fdd32b9571
								
							
						
					
					
						commit
						ebc4eacee4
					
				
					 1 changed files with 4 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -64,21 +64,19 @@ func (a *admin) init(c *Core, listenaddr string) {
 | 
			
		|||
		}
 | 
			
		||||
	})
 | 
			
		||||
	a.addHandler("setTunTap", []string{"<ifname|auto|none>", "[<tun|tap>]", "[<mtu>]"}, func(out *[]byte, ifparams ...string) {
 | 
			
		||||
		// Check parameters
 | 
			
		||||
		if (ifparams[0] != "none" && len(ifparams) != 3) ||
 | 
			
		||||
			(ifparams[0] == "none" && len(ifparams) != 1) {
 | 
			
		||||
			*out = []byte("Invalid number of parameters given\n")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		// Set sane defaults
 | 
			
		||||
		iftapmode := false
 | 
			
		||||
		ifmtu := 1280
 | 
			
		||||
		var err error
 | 
			
		||||
		// Check we have enough params for TAP mode
 | 
			
		||||
		if len(ifparams) > 1 {
 | 
			
		||||
			// Is it a TAP adapter?
 | 
			
		||||
			if ifparams[1] == "tap" {
 | 
			
		||||
				iftapmode = true
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		// Check we have enough params for MTU
 | 
			
		||||
		if len(ifparams) > 2 {
 | 
			
		||||
			// Make sure the MTU is sane
 | 
			
		||||
			ifmtu, err = strconv.Atoi(ifparams[2])
 | 
			
		||||
			if err != nil || ifmtu < 1280 || ifmtu > 65535 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue