refactor static-ip to match babel settings
This commit is contained in:
		
							parent
							
								
									b8fb5f1766
								
							
						
					
					
						commit
						3eabe5eb52
					
				| @ -1,6 +1,8 @@ | ||||
| -- TODO: conditional range required when tmp set | ||||
| if need_string({'node_prefix4'}, false) then -- optional | ||||
|   need_number({'node_prefix4_range'}, true) | ||||
|   need_boolean({'node_prefix4_temporary'}, false) | ||||
| end | ||||
| 
 | ||||
| need_string({'tmpIp4'}, false) | ||||
| need_number({'tmpIp4Range'}, false) | ||||
| need_string({'tmpIp6'}, false) | ||||
| need_number({'tmpIp6Range'}, false) | ||||
| need_string({'node_prefix6'}, true) -- always required | ||||
| need_number({'node_prefix6_range'}, false) | ||||
| need_boolean({'node_prefix6_temporary'}, false) | ||||
|  | ||||
| @ -64,11 +64,11 @@ local function static_ip(name, ifname, macaddr, actually_use) | ||||
| 	local static6 = uci:get('gluon-static-ip', name, 'ip6') | ||||
| 
 | ||||
|   if site.prefix4() then | ||||
|     if not static4 and site.tmpIp4() and name ~= 'loopback' then | ||||
|       local tmp4 = ip.new(site.tmpIp4()) | ||||
|     if not static4 and site.node_prefix4() and name ~= 'loopback' then | ||||
|       local tmp4 = ip.new(site.node_prefix4()) | ||||
| 
 | ||||
|   		-- magic that turns mac into random number | ||||
|   		local ipnum = ipnum(macaddr, IPV4_PREFIX_MAX - site.tmpIp4Range()) | ||||
|   		local ipnum = ipnum(macaddr, IPV4_PREFIX_MAX - site.node_prefix4_range()) | ||||
| 
 | ||||
|   		-- the rare case where we get 0 or 1 as our mac based number | ||||
|   		if ipnum < 2 then | ||||
| @ -80,11 +80,11 @@ local function static_ip(name, ifname, macaddr, actually_use) | ||||
|   end | ||||
| 
 | ||||
|   if site.prefix6() then | ||||
|     if not static6 and site.tmpIp6() and (site.tmpIp6Everywhere() or name == 'loopback') then | ||||
|       local tmp6 = ip.new(site.tmpIp6()) | ||||
|     if not static6 and site.node_prefix6() and (site.tmpIp6Everywhere() or name == 'loopback') then | ||||
|       local tmp6 = ip.new(site.node_prefix6()) | ||||
| 
 | ||||
|   		-- magic that turns mac into random number | ||||
|   		local ipnum = ipnum(macaddr, IPV6_PREFIX_MAX - site.tmpIp6Range(), true) | ||||
|   		local ipnum = ipnum(macaddr, IPV6_PREFIX_MAX - site.node_prefix6_range(64), true) | ||||
| 
 | ||||
|   		-- the rare case where we get 0 or 1 as our mac based number | ||||
|   		if tonumber(ipnum:gsub(':', ''), 16) < 2 then | ||||
|  | ||||
| @ -38,8 +38,8 @@ local function intf_setting(intf, desc, enabled) | ||||
| 	if site.prefix4() and intf ~= 'loopback' then | ||||
| 		local v4addr = uci:get('gluon-static-ip', intf, 'ip4') | ||||
| 
 | ||||
| 		if site.tmpIp4() and v4addr then | ||||
| 			local tmp = ip.new(site.tmpIp4(), site.tmpIp4Range()) | ||||
| 		if site.node_prefix4() and v4addr and site.node_prefix4_temporary() then | ||||
| 			local tmp = ip.new(site.node_prefix4(), site.node_prefix4()) | ||||
| 			local isTmp = tmp:contains(ip.new(v4addr):host()) | ||||
| 
 | ||||
| 			if isTmp then | ||||
| @ -59,11 +59,11 @@ local function intf_setting(intf, desc, enabled) | ||||
| 		-- TODO: datatype = "ip4cidr" | ||||
| 		v4.datatype = "maxlength(32)" | ||||
| 		v4.default = v4addr | ||||
| 		v4.required = site.tmpIp4() | ||||
| 		v4.required = site.node_prefix4() | ||||
| 
 | ||||
| 		function v4:write(data) | ||||
| 			-- TODO: validate via datatype | ||||
| 			if data == '' and not site.tmpIp4() then | ||||
| 			if data == '' and not site.node_prefix4() then | ||||
| 				data = null | ||||
| 			end | ||||
| 
 | ||||
| @ -78,8 +78,8 @@ local function intf_setting(intf, desc, enabled) | ||||
| 	if site.prefix6() then | ||||
| 		local v6addr = uci:get('gluon-static-ip', intf, 'ip6') | ||||
| 
 | ||||
| 		if site.tmpIp6() and v6addr then | ||||
| 			local tmp = ip.new(site.tmpIp6(), site.tmpIp6Range()) | ||||
| 		if site.node_prefix6() and v6addr and site.node_prefix6_temporary() then | ||||
| 			local tmp = ip.new(site.node_prefix6(), site.node_prefix6_range(64)) | ||||
| 			local isTmp = tmp:contains(ip.new(v6addr):host()) | ||||
| 
 | ||||
| 			if isTmp then | ||||
| @ -102,7 +102,7 @@ local function intf_setting(intf, desc, enabled) | ||||
| 
 | ||||
| 		function v6:write(data) | ||||
| 			-- TODO: validate via datatype | ||||
| 			if data == '' and (not site.tmpIp6() or (not site.tmpIp6Everywhere() or intf ~= 'loopback')) then | ||||
| 			if data == '' and (not site.node_prefix6() or (not site.tmpIp6Everywhere() or intf ~= 'loopback')) then | ||||
| 				data = null | ||||
| 			end | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user