mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-26 17:01:14 +00:00
base-files: generate network config with "device" options
Replace "ifname" with "device" as netifd has been recently patches to used the later one. It's more clear and accurate. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
This commit is contained in:
parent
553cc47ec7
commit
4b9a67362d
@ -40,7 +40,7 @@ generate_static_network() {
|
|||||||
uci -q batch <<-EOF
|
uci -q batch <<-EOF
|
||||||
delete network.loopback
|
delete network.loopback
|
||||||
set network.loopback='interface'
|
set network.loopback='interface'
|
||||||
set network.loopback.ifname='lo'
|
set network.loopback.device='lo'
|
||||||
set network.loopback.proto='static'
|
set network.loopback.proto='static'
|
||||||
set network.loopback.ipaddr='127.0.0.1'
|
set network.loopback.ipaddr='127.0.0.1'
|
||||||
set network.loopback.netmask='255.0.0.0'
|
set network.loopback.netmask='255.0.0.0'
|
||||||
@ -91,22 +91,22 @@ generate_static_network() {
|
|||||||
|
|
||||||
addr_offset=2
|
addr_offset=2
|
||||||
generate_network() {
|
generate_network() {
|
||||||
local ports ifname macaddr protocol type ipaddr netmask vlan
|
local ports device macaddr protocol type ipaddr netmask vlan
|
||||||
local bridge=$2
|
local bridge=$2
|
||||||
|
|
||||||
json_select network
|
json_select network
|
||||||
json_select "$1"
|
json_select "$1"
|
||||||
|
json_get_vars device macaddr protocol ipaddr netmask vlan
|
||||||
json_get_values ports ports
|
json_get_values ports ports
|
||||||
json_get_vars ifname macaddr protocol ipaddr netmask vlan
|
|
||||||
json_select ..
|
json_select ..
|
||||||
json_select ..
|
json_select ..
|
||||||
|
|
||||||
[ -n "$ifname" -o -n "$ports" ] || return
|
[ -n "$device" -o -n "$ports" ] || return
|
||||||
|
|
||||||
# Force bridge for "lan" as it may have other devices (e.g. wireless)
|
# Force bridge for "lan" as it may have other devices (e.g. wireless)
|
||||||
# bridged
|
# bridged
|
||||||
[ "$1" = "lan" -a -z "$ports" ] && {
|
[ "$1" = "lan" -a -z "$ports" ] && {
|
||||||
ports="$ifname"
|
ports="$device"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -n "$ports" -a -z "$bridge" ] && {
|
[ -n "$ports" -a -z "$bridge" ] && {
|
||||||
@ -117,19 +117,19 @@ generate_network() {
|
|||||||
set network.@device[-1].macaddr='$macaddr'
|
set network.@device[-1].macaddr='$macaddr'
|
||||||
EOF
|
EOF
|
||||||
for port in $ports; do uci add_list network.@device[-1].ports="$port"; done
|
for port in $ports; do uci add_list network.@device[-1].ports="$port"; done
|
||||||
ifname=br-$1
|
device=br-$1
|
||||||
type=
|
type=
|
||||||
macaddr=""
|
macaddr=""
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -n "$bridge" ] && {
|
[ -n "$bridge" ] && {
|
||||||
[ -z "$ports" ] && ports="$ifname"
|
[ -z "$ports" ] && ports="$device"
|
||||||
if [ -z "$vlan" ]; then
|
if [ -z "$vlan" ]; then
|
||||||
bridge_vlan_id=$((bridge_vlan_id + 1))
|
bridge_vlan_id=$((bridge_vlan_id + 1))
|
||||||
vlan=$bridge_vlan_id
|
vlan=$bridge_vlan_id
|
||||||
fi
|
fi
|
||||||
generate_bridge_vlan $1 $bridge "$ports" $vlan
|
generate_bridge_vlan $1 $bridge "$ports" $vlan
|
||||||
ifname=$bridge.$vlan
|
device=$bridge.$vlan
|
||||||
type=""
|
type=""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,12 +137,12 @@ generate_network() {
|
|||||||
delete network.$1
|
delete network.$1
|
||||||
set network.$1='interface'
|
set network.$1='interface'
|
||||||
set network.$1.type='$type'
|
set network.$1.type='$type'
|
||||||
set network.$1.ifname='$ifname'
|
set network.$1.device='$device'
|
||||||
set network.$1.proto='none'
|
set network.$1.proto='none'
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ -n "$macaddr" ]; then
|
if [ -n "$macaddr" ]; then
|
||||||
for name in $ifname; do
|
for name in $device; do
|
||||||
uci -q batch <<-EOF
|
uci -q batch <<-EOF
|
||||||
delete network.$1_${name/./_}_dev
|
delete network.$1_${name/./_}_dev
|
||||||
set network.$1_${name/./_}_dev='device'
|
set network.$1_${name/./_}_dev='device'
|
||||||
@ -172,14 +172,14 @@ generate_network() {
|
|||||||
|
|
||||||
dhcp)
|
dhcp)
|
||||||
# fixup IPv6 slave interface if parent is a bridge
|
# fixup IPv6 slave interface if parent is a bridge
|
||||||
[ "$type" = "bridge" ] && ifname="br-$1"
|
[ "$type" = "bridge" ] && device="br-$1"
|
||||||
|
|
||||||
uci set network.$1.proto='dhcp'
|
uci set network.$1.proto='dhcp'
|
||||||
[ -e /proc/sys/net/ipv6 ] && {
|
[ -e /proc/sys/net/ipv6 ] && {
|
||||||
uci -q batch <<-EOF
|
uci -q batch <<-EOF
|
||||||
delete network.${1}6
|
delete network.${1}6
|
||||||
set network.${1}6='interface'
|
set network.${1}6='interface'
|
||||||
set network.${1}6.ifname='$ifname'
|
set network.${1}6.device='$device'
|
||||||
set network.${1}6.proto='dhcpv6'
|
set network.${1}6.proto='dhcpv6'
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ generate_network() {
|
|||||||
set network.$1.ipv6='1'
|
set network.$1.ipv6='1'
|
||||||
delete network.${1}6
|
delete network.${1}6
|
||||||
set network.${1}6='interface'
|
set network.${1}6='interface'
|
||||||
set network.${1}6.ifname='@${1}'
|
set network.${1}6.device='@${1}'
|
||||||
set network.${1}6.proto='dhcpv6'
|
set network.${1}6.proto='dhcpv6'
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ ucidef_set_interface() {
|
|||||||
|
|
||||||
[ -n "$opt" -a -n "$val" ] || break
|
[ -n "$opt" -a -n "$val" ] || break
|
||||||
|
|
||||||
[ "$opt" = "ifname" -a "$val" != "${val/ //}" ] && {
|
[ "$opt" = "device" -a "$val" != "${val/ //}" ] && {
|
||||||
json_select_array "ports"
|
json_select_array "ports"
|
||||||
for e in $val; do json_add_string "" "$e"; done
|
for e in $val; do json_add_string "" "$e"; done
|
||||||
json_close_array
|
json_close_array
|
||||||
@ -79,11 +79,11 @@ ucidef_set_compat_version() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ucidef_set_interface_lan() {
|
ucidef_set_interface_lan() {
|
||||||
ucidef_set_interface "lan" ifname "$1" protocol "${2:-static}"
|
ucidef_set_interface "lan" device "$1" protocol "${2:-static}"
|
||||||
}
|
}
|
||||||
|
|
||||||
ucidef_set_interface_wan() {
|
ucidef_set_interface_wan() {
|
||||||
ucidef_set_interface "wan" ifname "$1" protocol "${2:-dhcp}"
|
ucidef_set_interface "wan" device "$1" protocol "${2:-dhcp}"
|
||||||
}
|
}
|
||||||
|
|
||||||
ucidef_set_interfaces_lan_wan() {
|
ucidef_set_interfaces_lan_wan() {
|
||||||
@ -201,14 +201,14 @@ _ucidef_finish_switch_roles() {
|
|||||||
|
|
||||||
json_select_object "$role"
|
json_select_object "$role"
|
||||||
# attach previous interfaces (for multi-switch devices)
|
# attach previous interfaces (for multi-switch devices)
|
||||||
json_get_var devices ifname
|
json_get_var devices device
|
||||||
if ! list_contains devices "$device"; then
|
if ! list_contains devices "$device"; then
|
||||||
devices="${devices:+$devices }$device"
|
devices="${devices:+$devices }$device"
|
||||||
fi
|
fi
|
||||||
json_select ..
|
json_select ..
|
||||||
json_select ..
|
json_select ..
|
||||||
|
|
||||||
ucidef_set_interface "$role" ifname "$devices"
|
ucidef_set_interface "$role" device "$devices"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,17 +6,17 @@ board_config_update
|
|||||||
case "$(board_name)" in
|
case "$(board_name)" in
|
||||||
dlink,dir-685)
|
dlink,dir-685)
|
||||||
# These are all connected to eth0 thru RTL8366RB
|
# These are all connected to eth0 thru RTL8366RB
|
||||||
ucidef_set_interface "eth" ifname "eth0" protocol "none"
|
ucidef_set_interface "eth" device "eth0" protocol "none"
|
||||||
ucidef_set_interfaces_lan_wan "lan0 lan1 lan2 lan3" "wan"
|
ucidef_set_interfaces_lan_wan "lan0 lan1 lan2 lan3" "wan"
|
||||||
;;
|
;;
|
||||||
itian,sq201)
|
itian,sq201)
|
||||||
# These are all connected to eth1 thru VSC7395
|
# These are all connected to eth1 thru VSC7395
|
||||||
ucidef_set_interface "eth" ifname "eth1" protocol "none"
|
ucidef_set_interface "eth" device "eth1" protocol "none"
|
||||||
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "eth0"
|
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "eth0"
|
||||||
;;
|
;;
|
||||||
storlink,gemini324)
|
storlink,gemini324)
|
||||||
# These are all connected to eth1 thru VSC7385
|
# These are all connected to eth1 thru VSC7385
|
||||||
ucidef_set_interface "eth" ifname "eth1" protocol "none"
|
ucidef_set_interface "eth" device "eth1" protocol "none"
|
||||||
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "eth0"
|
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "eth0"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -23,7 +23,7 @@ for lan in /sys/class/net/lan*; do
|
|||||||
done
|
done
|
||||||
ucidef_set_bridge_device switch
|
ucidef_set_bridge_device switch
|
||||||
ucidef_set_interface_wan "$lan_list"
|
ucidef_set_interface_wan "$lan_list"
|
||||||
ucidef_set_interface "lan" ifname "lan1:t" protocol "static" vlan 100
|
ucidef_set_interface "lan" device "lan1:t" protocol "static" vlan 100
|
||||||
|
|
||||||
lan_mac=""
|
lan_mac=""
|
||||||
wan_mac=""
|
wan_mac=""
|
||||||
|
Loading…
Reference in New Issue
Block a user