base-files: board.d: support specifiying the protocol of lan and wan
Some boards, e.g. the Sheeva Plug, require the lan interface to be set to DHCP instead of a static address, therfore support that. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org> SVN-Revision: 47732
This commit is contained in:
		| @@ -20,12 +20,13 @@ generate_static_network() { | |||||||
| 	EOF | 	EOF | ||||||
| } | } | ||||||
|  |  | ||||||
|  | addr_offset=2 | ||||||
| generate_network() { | generate_network() { | ||||||
| 	local ifname macaddr type | 	local ifname macaddr protocol type | ||||||
|  |  | ||||||
| 	json_select network | 	json_select network | ||||||
| 		json_select "$1" | 		json_select "$1" | ||||||
| 			json_get_vars ifname macaddr | 			json_get_vars ifname macaddr protocol | ||||||
| 		json_select .. | 		json_select .. | ||||||
| 	json_select .. | 	json_select .. | ||||||
|  |  | ||||||
| @@ -45,23 +46,32 @@ generate_network() { | |||||||
| 		set network.$1.macaddr='$macaddr' | 		set network.$1.macaddr='$macaddr' | ||||||
| 	EOF | 	EOF | ||||||
|  |  | ||||||
|  | 	case "$protocol" in | ||||||
|  | 		static) | ||||||
|  | 			local ipaddr | ||||||
| 			case "$1" in | 			case "$1" in | ||||||
| 		lan) | 				lan) ipaddr="192.168.1.1" ;; | ||||||
|  | 				*) ipaddr="192.168.$((addr_offset++)).1" ;; | ||||||
|  | 			esac | ||||||
|  |  | ||||||
| 			uci -q batch <<-EOF | 			uci -q batch <<-EOF | ||||||
| 				set network.$1.proto='static' | 				set network.$1.proto='static' | ||||||
| 				set network.$1.ipaddr='192.168.1.1' | 				set network.$1.ipaddr='$ipaddr' | ||||||
| 				set network.$1.netmask='255.255.255.0' | 				set network.$1.netmask='255.255.255.0' | ||||||
| 				set network.$1.ip6assign='60' | 				set network.$1.ip6assign='60' | ||||||
| 			EOF | 			EOF | ||||||
| 		;; | 		;; | ||||||
| 		wan) |  | ||||||
|  | 		dhcp) | ||||||
|  | 			# fixup IPv6 slave interface if parent is a bridge | ||||||
|  | 			[ "$type" = "bridge" ] && ifname="br-$1" | ||||||
|  |  | ||||||
| 			uci -q batch <<-EOF | 			uci -q batch <<-EOF | ||||||
| 				set network.$1.proto='dhcp' | 				set network.$1.proto='dhcp' | ||||||
| 				delete network.wan6 | 				delete network.${1}6 | ||||||
| 				set network.wan6='interface' | 				set network.${1}6='interface' | ||||||
| 				set network.wan6.type='$type' | 				set network.${1}6.ifname='$ifname' | ||||||
| 				set network.wan6.ifname='$ifname' | 				set network.${1}6.proto='dhcpv6' | ||||||
| 				set network.wan6.proto='dhcpv6' |  | ||||||
| 			EOF | 			EOF | ||||||
| 		;; | 		;; | ||||||
| 	esac | 	esac | ||||||
|   | |||||||
| @@ -32,9 +32,26 @@ json_select_object() { | |||||||
| _ucidef_set_interface() { | _ucidef_set_interface() { | ||||||
| 	local name="$1" | 	local name="$1" | ||||||
| 	local iface="$2" | 	local iface="$2" | ||||||
|  | 	local proto="$3" | ||||||
|  |  | ||||||
| 	json_select_object "$name" | 	json_select_object "$name" | ||||||
| 	json_add_string ifname "$iface" | 	json_add_string ifname "$iface" | ||||||
|  |  | ||||||
|  | 	if ! json_is_a protocol string; then | ||||||
|  | 		case "$proto" in | ||||||
|  | 			static|dhcp|none) : ;; | ||||||
|  | 			*) | ||||||
|  | 				case "$name" in | ||||||
|  | 					lan) proto="static" ;; | ||||||
|  | 					wan) proto="dhcp" ;; | ||||||
|  | 					*) proto="none" ;; | ||||||
|  | 				esac | ||||||
|  | 			;; | ||||||
|  | 		esac | ||||||
|  |  | ||||||
|  | 		json_add_string protocol "$proto" | ||||||
|  | 	fi | ||||||
|  |  | ||||||
| 	json_select .. | 	json_select .. | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -57,18 +74,14 @@ ucidef_set_interface_loopback() | |||||||
| } | } | ||||||
|  |  | ||||||
| ucidef_set_interface_lan() { | ucidef_set_interface_lan() { | ||||||
| 	local lan_if="$1" |  | ||||||
|  |  | ||||||
| 	json_select_object network | 	json_select_object network | ||||||
| 	_ucidef_set_interface lan "$lan_if" | 	_ucidef_set_interface lan "$@" | ||||||
| 	json_select .. | 	json_select .. | ||||||
| } | } | ||||||
|  |  | ||||||
| ucidef_set_interface_wan() { | ucidef_set_interface_wan() { | ||||||
|         local wan_if="$1" |  | ||||||
|  |  | ||||||
| 	json_select_object network | 	json_select_object network | ||||||
|         _ucidef_set_interface wan "$wan_if" | 	_ucidef_set_interface wan "$@" | ||||||
| 	json_select .. | 	json_select .. | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -164,14 +177,17 @@ _ucidef_finish_switch_roles() { | |||||||
| 		json_select .. | 		json_select .. | ||||||
|  |  | ||||||
| 		json_select_object network | 		json_select_object network | ||||||
|  | 			local devices | ||||||
|  |  | ||||||
| 			json_select_object "$role" | 			json_select_object "$role" | ||||||
| 				# attach previous interfaces (for multi-switch devices) | 				# attach previous interfaces (for multi-switch devices) | ||||||
| 				local devices; json_get_var devices ifname | 				json_get_var devices ifname | ||||||
| 				if ! list_contains devices "$device"; then | 				if ! list_contains devices "$device"; then | ||||||
| 					devices="${devices:+$devices }$device" | 					devices="${devices:+$devices }$device" | ||||||
| 				fi | 				fi | ||||||
| 				json_add_string ifname "$devices" |  | ||||||
| 			json_select .. | 			json_select .. | ||||||
|  |  | ||||||
|  | 			_ucidef_set_interface "$role" "$devices" | ||||||
| 		json_select .. | 		json_select .. | ||||||
| 	done | 	done | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jo-Philipp Wich
					Jo-Philipp Wich