Skip to content
Snippets Groups Projects
Commit 269fe6a1 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

move network config functionality, effiency improvements

parent fd077ff3
Branches
Tags
No related merge requests found
...@@ -94,3 +94,92 @@ wifi_generate_ifname() { ...@@ -94,3 +94,92 @@ wifi_generate_ifname() {
} }
done done
} }
remove_from_networks() {
local iface=$1
local ifname=""
for net in $(uci show network | grep network.*.interface | awk -F'[.,=]' '{print$2}' | tr '\n' ' '); do
ifname=""
for ifc in $(uci -q get network.$net.ifname); do
if [ "$ifc" != "$iface" ]; then
ifname="$ifname $ifc"
fi
done
uci -q set network.$net.ifname="$(echo $ifname | sed 's/[ \t]*$//')"
uci commit network
done
}
remove_disabled_vifs() {
local cfg=$1
local vif=$2
config_get is_lan $cfg is_lan "0"
config_get type $cfg type
[ "$is_lan" == "0" -o "$type" != "bridge" ] && return
ifname=$(uci -q get network.$cfg.ifname)
for ifc in $ifname; do
[ -n "${ifc/wlan*/}" ] && continue
vif_cfg=$(uci show wireless | grep @wifi-iface | grep "ifname=\'$ifc\'" | awk -F '.' '{print $2}')
device=$(uci -q get wireless.$vif_cfg.device)
radio_disabled=$(uci -q get wireless.$device.disabled)
disabled=$(uci -q get wireless.$vif_cfg.disabled)
net=$(uci -q get wireless.$vif_cfg.network)
[ "$disabled" == "1" -o "$net" != "$cfg" -o "$radio_disabled" == "1" -o -z "$vif_cfg" ] || continue
remove_from_networks $ifc
done
}
network_remove_disabled_vifs() {
config_load network
config_foreach remove_disabled_vifs interface
}
add_to_network() {
local cfg=$1
local nets=$2
local iface=""
local ifname=""
config_get network $cfg network
config_get iface $cfg ifname
config_get disabled $cfg disabled "0"
[ -n "$iface" ] || return
[ "$disabled" == "1" ] && return
config_get device $cfg device
radio_disabled=$(uci -q get wireless.$device.disabled)
[ "$radio_disabled" == "1" ] && return
for net in $nets; do
is_lan="$(uci -q get network.$net.is_lan)"
is_lan=${is_lan:-0}
type="$(uci -q get network.$net.type)"
[ "$is_lan" == "1" -a "$type" == "bridge" ] || continue
ifname="$(uci -q get network.$net.ifname)"
if [ "$net" == "$network" ]; then
ifname="$ifname $iface"
fi
uci -q set network.$net.ifname="$(echo $ifname | tr ' ' '\n' | sort -u | tr '\n' ' ' | sed 's/[ \t]*$//')"
done
uci commit network
}
network_add_vifs() {
nets=$(uci show network | grep network.*.interface | awk -F'[.,=]' '{print$2}')
config_load wireless
config_foreach add_to_network wifi-iface "$nets"
}
\ No newline at end of file
...@@ -188,17 +188,4 @@ EOF ...@@ -188,17 +188,4 @@ EOF
detect_intel_interfaces $dev $radioname $ifidx detect_intel_interfaces $dev $radioname $ifidx
devidx=$(($devidx + 1)) devidx=$(($devidx + 1))
done done
} }
\ No newline at end of file
config_load network
for radio in wlan0 wlan2; do
config_foreach remove_disabled_vifs interface $radio
for idx in 1 2 3 4; do
vif="$radio.$idx"
config_foreach remove_disabled_vifs interface $vif
done
done
config_load wireless
config_foreach add_to_network wifi-iface
\ No newline at end of file
#!/bin/sh #!/bin/sh
remove_from_networks() {
local iface=$1
local ifname=""
for net in $(uci show network | grep network.*.interface | awk -F'[.,=]' '{print$2}' | tr '\n' ' '); do
ifname=""
for ifc in $(uci -q get network.$net.ifname); do
if [ "$ifc" != "$iface" ]; then
ifname="$ifname $ifc"
fi
done
uci -q set network.$net.ifname="$(echo $ifname | sed 's/[ \t]*$//')"
uci commit network
done
}
remove_disabled_vifs() {
local cfg=$1
local vif=$2
config_load network
config_get is_lan $cfg is_lan "0"
config_get type $cfg type
[ "$is_lan" == "0" -o "$type" != "bridge" ] && return
ifname=$(uci -q get network.$cfg.ifname)
for ifc in $ifname; do
vif_cfg=$(uci show wireless | grep @wifi-iface | grep "ifname=\'$ifc\'" | awk -F '.' '{print $2}')
device=$(uci -q get wireless.$vif_cfg.device)
radio_disabled=$(uci -q get wireless.$device.disabled)
disabled=$(uci -q get wireless.$vif_cfg.disabled)
net=$(uci -q get wireless.$vif_cfg.network)
[ "$disabled" == "1" -o "$net" != "$cfg" -o "$radio_disabled" == "1" ] || continue
if [ $ifc == $vif ]; then
#echo "wifi: remove $ifc from $interface" >/dev/console
remove_from_networks $interface $ifc
break
fi
done
}
add_to_network() {
local cfg=$1
local iface=""
local ifname=""
config_get network $cfg network
config_get iface $cfg ifname
config_get disabled $cfg disabled "0"
[ "$disabled" == "1" ] && return
config_get device $cfg device
radio_disabled=$(uci -q get wireless.$device.disabled)
[ "$radio_disabled" == "1" ] && return
for net in $(uci show network | grep network.*.interface | awk -F'[.,=]' '{print$2}'); do
is_lan="$(uci -q get network.$net.is_lan)"
is_lan=${is_lan:-0}
type="$(uci -q get network.$net.type)"
[ "$is_lan" == "1" -a "$type" == "bridge" ] || continue
ifname="$(uci -q get network.$net.ifname)"
if [ "$net" == "$network" ]; then
ifname="$ifname $iface"
fi
uci -q set network.$net.ifname="$(echo $ifname | tr ' ' '\n' | sort -u | tr '\n' ' ' | sed 's/[ \t]*$//')"
done
uci commit network
}
wifi_add_section_status() { wifi_add_section_status() {
if ! uci -q get wireless.status >/dev/null; then if ! uci -q get wireless.status >/dev/null; then
[ -f /etc/config/wireless ] || touch /etc/config/wireless [ -f /etc/config/wireless ] || touch /etc/config/wireless
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment