blob: a9dece418d6817a6ded7f2e743dbe648ece68a91 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001. /lib/functions.sh
2
3migrate_ports() {
4 local config="$1"
5 local type ports ifname
6
7 config_get type "$config" type
8 [ "$type" != "bridge" ] && return
9
10 config_get ports "$config" ports
11 [ -n "$ports" ] && return
12
13 config_get ifname "$config" ifname
14 [ -z "$ifname" ] && return
15
16 for port in $ifname; do
17 uci add_list network.$config.ports="$port"
18 done
19 uci delete network.$config.ifname
20}
21
22migrate_bridge() {
23 local config="$1"
24 local type ifname
25
26 config_get type "$config" type
27 [ "$type" != "bridge" ] && return
28
29 config_get ifname "$config" ifname
30
31 uci -q batch <<-EOF
32 add network device
33 set network.@device[-1].name='br-$config'
34 set network.@device[-1].type='bridge'
35 EOF
36 for port in $ifname; do
37 uci add_list network.@device[-1].ports="$port"
38 done
39
40 uci -q batch <<-EOF
41 delete network.$config.type
42 delete network.$config.ifname
43 set network.$config.device='br-$config'
44 EOF
45}
46
47config_load network
48config_foreach migrate_ports device
49config_foreach migrate_bridge interface