base-files: rework _ucidef_set_interface to be more generic
This is a rework of previously submitted patch reworking ucidef_set_interface_raw [1]. Here, keep the idea but instead make _ucidef_set_interface more generic and use it instead of ucidef_set_interface_raw. Also change the users like ucidef_set_interface_lan and others. [1] https://patchwork.ozlabs.org/patch/844961/ Signed-off-by: Roman Yeryomin <roman@advem.lv>
This commit is contained in:
		 Roman Yeryomin
					Roman Yeryomin
				
			
				
					committed by
					
						 John Crispin
						John Crispin
					
				
			
			
				
	
			
			
			 John Crispin
						John Crispin
					
				
			
						parent
						
							467b07e00c
						
					
				
				
					commit
					85048a9c1f
				
			| @@ -27,29 +27,26 @@ json_select_object() { | |||||||
| 	json_select "$1" | 	json_select "$1" | ||||||
| } | } | ||||||
|  |  | ||||||
| _ucidef_set_interface() { | ucidef_set_interface() { | ||||||
| 	local name="$1" | 	local network=$1 | ||||||
| 	local iface="$2" |  | ||||||
| 	local proto="$3" |  | ||||||
|  |  | ||||||
| 	json_select_object "$name" | 	[ -z "$network" ] && return | ||||||
| 	json_add_string ifname "$iface" |  | ||||||
|  |  | ||||||
| 	if ! json_is_a protocol string || [ -n "$proto" ]; then | 	json_select_object network | ||||||
| 		case "$proto" in | 	json_select_object "$network" | ||||||
| 			static|dhcp|none|pppoe) : ;; | 	shift | ||||||
| 			*) |  | ||||||
| 				case "$name" in |  | ||||||
| 					lan) proto="static" ;; |  | ||||||
| 					wan) proto="dhcp" ;; |  | ||||||
| 					*) proto="none" ;; |  | ||||||
| 				esac |  | ||||||
| 			;; |  | ||||||
| 		esac |  | ||||||
|  |  | ||||||
| 		json_add_string protocol "$proto" | 	while [ -n "$1" ]; do | ||||||
| 	fi | 		local opt="$1" | ||||||
|  | 		local val="$2" | ||||||
|  | 		shift; shift; | ||||||
|  |  | ||||||
|  | 		[ -n "$opt" -a -n "$val" ] || break | ||||||
|  |  | ||||||
|  | 		json_add_string "$opt" "$val" | ||||||
|  | 	done | ||||||
|  |  | ||||||
|  | 	json_select .. | ||||||
| 	json_select .. | 	json_select .. | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -66,31 +63,19 @@ ucidef_set_model_name() { | |||||||
| } | } | ||||||
|  |  | ||||||
| ucidef_set_interface_lan() { | ucidef_set_interface_lan() { | ||||||
| 	json_select_object network | 	ucidef_set_interface "lan" ifname "$1" protocol "${2:-static}" | ||||||
| 	_ucidef_set_interface lan "$@" |  | ||||||
| 	json_select .. |  | ||||||
| } | } | ||||||
|  |  | ||||||
| ucidef_set_interface_wan() { | ucidef_set_interface_wan() { | ||||||
| 	json_select_object network | 	ucidef_set_interface "wan" ifname "$1" protocol "${2:-dhcp}" | ||||||
| 	_ucidef_set_interface wan "$@" |  | ||||||
| 	json_select .. |  | ||||||
| } | } | ||||||
|  |  | ||||||
| ucidef_set_interfaces_lan_wan() { | ucidef_set_interfaces_lan_wan() { | ||||||
| 	local lan_if="$1" | 	local lan_if="$1" | ||||||
| 	local wan_if="$2" | 	local wan_if="$2" | ||||||
|  |  | ||||||
| 	json_select_object network | 	ucidef_set_interface_lan "$lan_if" | ||||||
| 	_ucidef_set_interface lan "$lan_if" | 	ucidef_set_interface_wan "$wan_if" | ||||||
| 	_ucidef_set_interface wan "$wan_if" |  | ||||||
| 	json_select .. |  | ||||||
| } |  | ||||||
|  |  | ||||||
| ucidef_set_interface_raw() { |  | ||||||
| 	json_select_object network |  | ||||||
| 	_ucidef_set_interface "$@" |  | ||||||
| 	json_select .. |  | ||||||
| } | } | ||||||
|  |  | ||||||
| _ucidef_add_switch_port() { | _ucidef_add_switch_port() { | ||||||
| @@ -185,9 +170,9 @@ _ucidef_finish_switch_roles() { | |||||||
| 					devices="${devices:+$devices }$device" | 					devices="${devices:+$devices }$device" | ||||||
| 				fi | 				fi | ||||||
| 			json_select .. | 			json_select .. | ||||||
|  |  | ||||||
| 			_ucidef_set_interface "$role" "$devices" |  | ||||||
| 		json_select .. | 		json_select .. | ||||||
|  |  | ||||||
|  | 		ucidef_set_interface "$role" ifname "$devices" | ||||||
| 	done | 	done | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -300,18 +285,7 @@ ucidef_set_interface_macaddr() { | |||||||
| 	local network="$1" | 	local network="$1" | ||||||
| 	local macaddr="$2" | 	local macaddr="$2" | ||||||
|  |  | ||||||
| 	json_select_object network | 	ucidef_set_interface "$network" macaddr "$macaddr" | ||||||
|  |  | ||||||
| 	json_select "$network" |  | ||||||
| 	[ $? -eq 0 ] || { |  | ||||||
| 		json_select .. |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	json_add_string macaddr "$macaddr" |  | ||||||
| 	json_select .. |  | ||||||
|  |  | ||||||
| 	json_select .. |  | ||||||
| } | } | ||||||
|  |  | ||||||
| ucidef_add_atm_bridge() { | ucidef_add_atm_bridge() { | ||||||
|   | |||||||
| @@ -402,7 +402,7 @@ ar71xx_setup_interfaces() | |||||||
| 			"0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" | 			"0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" | ||||||
| 		;; | 		;; | ||||||
| 	ew-balin) | 	ew-balin) | ||||||
| 		ucidef_set_interface_raw "usb2" "usb0" "static" | 		ucidef_set_interface "usb2" ifname "usb0" proto "static" | ||||||
| 		ucidef_add_switch "switch0" \ | 		ucidef_add_switch "switch0" \ | ||||||
| 			"0@eth0" "5:lan:4" "4:lan:5" "3:wan" | 			"0@eth0" "5:lan:4" "4:lan:5" "3:wan" | ||||||
| 		;; | 		;; | ||||||
| @@ -469,7 +469,7 @@ ar71xx_setup_interfaces() | |||||||
| 		;; | 		;; | ||||||
| 	tellstick-znet-lite) | 	tellstick-znet-lite) | ||||||
| 		ucidef_set_interface_wan "eth0" | 		ucidef_set_interface_wan "eth0" | ||||||
| 		ucidef_set_interface_raw "wlan" "wlan0" "dhcp" | 		ucidef_set_interface "wlan" ifname "wlan0" proto "dhcp" | ||||||
| 		;; | 		;; | ||||||
| 	tl-mr3420-v2|\ | 	tl-mr3420-v2|\ | ||||||
| 	tl-wr841n-v8|\ | 	tl-wr841n-v8|\ | ||||||
| @@ -500,7 +500,7 @@ ar71xx_setup_interfaces() | |||||||
| 		;; | 		;; | ||||||
| 	tl-wr841n-v1|\ | 	tl-wr841n-v1|\ | ||||||
| 	tl-wr941nd) | 	tl-wr941nd) | ||||||
| 		ucidef_set_interface_raw "eth" "eth0" | 		ucidef_set_interface "eth" ifname "eth0" | ||||||
| 		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan" | 		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan" | ||||||
| 		;; | 		;; | ||||||
| 	tl-wr741nd|\ | 	tl-wr741nd|\ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user