generate_bridge() {
local name=$1
+ local macaddr=$2
uci -q batch <<-EOF
set network.$name=device
set network.$name.name=$name
set network.$name.type=bridge
EOF
+ if [ -n "$macaddr" ]; then
+ uci -q batch <<-EOF
+ set network.$name.macaddr=$macaddr
+ EOF
+ fi
}
bridge_vlan_id=0
local name=$1_vlan
local device=$2
local ports="$3"
- bridge_vlan_id=$((bridge_vlan_id + 1))
+ local vlan="$4"
uci -q batch <<-EOF
set network.$name=bridge-vlan
set network.$name.device='$device'
- set network.$name.vlan='$bridge_vlan_id'
+ set network.$name.vlan='$vlan'
set network.$name.ports='$ports'
EOF
}
addr_offset=2
generate_network() {
- local ifname macaddr protocol type ipaddr netmask
+ local ifname macaddr protocol type ipaddr netmask vlan
local bridge=$2
json_select network
json_select "$1"
- json_get_vars ifname macaddr protocol ipaddr netmask
+ json_get_vars ifname macaddr protocol ipaddr netmask vlan
json_select ..
json_select ..
esac
[ -n "$bridge" ] && {
- generate_bridge_vlan $1 $bridge "$ifname"
- ifname=$bridge.$bridge_vlan_id
+ if [ -z "$vlan" ]; then
+ bridge_vlan_id=$((bridge_vlan_id + 1))
+ vlan=$bridge_vlan_id
+ fi
+ generate_bridge_vlan $1 $bridge "$ifname" $vlan
+ ifname=$bridge.$vlan
type=""
}
umask 077
if [ ! -s /etc/config/network ]; then
+ bridge_name=""
touch /etc/config/network
generate_static_network
json_get_vars bridge
- [ -n "$bridge" ] && generate_bridge $bridge
+ [ -n "$bridge" ] && {
+ json_select bridge
+ json_get_vars name macaddr
+ generate_bridge "$name" "$macaddr"
+ json_select ..
+ bridge_name=$name
+ }
json_get_keys keys network
- for key in $keys; do generate_network $key $bridge; done
+ for key in $keys; do generate_network $key $bridge_name; done
json_get_keys keys switch
for key in $keys; do generate_switch $key; done
}
ucidef_set_bridge_device() {
- json_add_string bridge "${1:switch0}"
+ json_select_object bridge
+ json_add_string name "${1:switch0}"
+ json_select ..
+}
+
+ucidef_set_bridge_mac() {
+ json_select_object bridge
+ json_add_string macaddr "${1}"
+ json_select ..
+}
+
+ucidef_set_network_device_mac() {
+ json_select_object "network-device"
+ json_select_object "${1}"
+ json_add_string macaddr "${2}"
+ json_select ..
+ json_select ..
}
_ucidef_add_switch_port() {