calculate_switch_vlans() {
local switch=$1
- local ports port
+ local ports port attr val
local prev_role
local num device role index
local n_cpu=0 cpu0 cpu1 cpu2 cpu3
json_select "$port"
json_get_vars num device role
+ if json_is_a attr object; then
+ json_get_keys attr attr
+ json_select attr
+
+ uci -q batch <<-EOF
+ add network switch_port
+ set network.@switch_port[-1].device='$switch'
+ set network.@switch_port[-1].port=$num
+ EOF
+
+ for attr in $attr; do
+ json_get_var val "$attr"
+ uci -q set network.@switch_port[-1].$attr="$val"
+ done
+
+ json_select ..
+ fi
+
+ json_select ..
+
if [ -n "$num" ] && [ -n "$device" ]; then
export "cpu$n_cpu=$num"
export "dev$n_cpu=$device"
n_vlan=$((n_vlan + 1))
prev_role="$role"
fi
-
- json_select ..
done
unset prev_role
# autogenerate vlans
for port in $ports ""; do
- json_select "$port"
-
if [ -n "$port" ]; then
+ json_select "$port"
json_get_vars num device role
+ json_select ..
else
num="-"; role="-"
fi
fi
fi
-
- json_select ..
done
json_select ..
eval device="\$dev$((vlan_off++ % n_cpu))"
[ $n_vlan -gt $n_cpu ] && device="$device.$vlan_off"
+ # quirk: append ifnames for subsequent switches
+ case "$switch" in switch[1-9])
+ local prev_devs="$(uci -q get "network.$role.ifname")"
+ if echo "$prev_devs" | grep -wq "$device"; then
+ device="$prev_devs"
+ else
+ device="$prev_devs $device"
+ fi
+ ;; esac
+
uci -q batch <<-EOF
- delete network.$role
set network.$role='interface'
set network.$role.ifname='$device'
EOF
;;
wan) uci -q batch <<-EOF
set network.wan.proto='dhcp'
- delete network.wan6
set network.wan6='interface'
set network.wan6.ifname='$device'
set network.wan6.proto='dhcpv6'