From c4f3575368c5aeef4134d82125df2814d688cc2a Mon Sep 17 00:00:00 2001 From: nbd Date: Sun, 30 Jul 2006 03:09:09 +0000 Subject: rewrite of the network scripts and configuration git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4323 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 147 +++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100755 package/base-files/default/lib/network/config.sh (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh new file mode 100755 index 000000000..59ec84aba --- /dev/null +++ b/package/base-files/default/lib/network/config.sh @@ -0,0 +1,147 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + +# DEBUG="echo" + +find_config() { + local type iface ifn + for ifn in $interfaces; do + config_get type "$ifn" type + config_get iface "$ifn" ifname + case "$type" in + bridge) + config_get iface "$ifn" ifnames + ;; + esac + for ifc in $iface; do + [ "$ifc" = "$1" ] && { + echo "$ifn" + return 0 + } + done + done + + return 1; +} + +scan_interfaces() { + local mode type iface + interfaces= + config_cb() { + config_get type "$CONFIG_SECTION" TYPE + case "$type" in + interface) + config_get type "$CONFIG_SECTION" type + config_get mode "$CONFIG_SECTION" proto + case "$type" in + bridge) + config_get iface "$CONFIG_SECTION" ifname + iface="${iface:-br-$CONFIG_SECTION}" + config_set "$CONFIG_SECTION" ifname "$iface" + ;; + esac + append interfaces "$CONFIG_SECTION" + ( type "scan_$mode" ) >/dev/null 2>/dev/null && eval "scan_$mode '$CONFIG_SECTION'" + ;; + esac + } + config_load network +} + +add_vlan() { + local vif="${1%\.*}" + + [ "$1" = "$vif" ] || ifconfig "$1" >/dev/null 2>/dev/null || { + ifconfig "$vif" up 2>/dev/null >/dev/null || add_vlan "$vif" + $DEBUG vconfig add "$vif" "${1##*\.}" + } +} + +setup_interface() { + local iface="$1" + local config="$2" + local proto="$3" + + [ -n "$config" ] || { + config=$(find_config "$iface") + [ "$?" = 0 ] || return 1 + } + + [ -n "$proto" ] || { + config_get proto "$config" proto + } + + config_get iftype "$config" type + + # Setup VLAN interfaces + add_vlan "$iface" + + # Setup bridging + case "$iftype" in + bridge) + config_get bridge_ifname "$config" ifname + ifconfig "$iface" up 2>/dev/null >/dev/null + ifconfig "$bridge_ifname" 2>/dev/null >/dev/null && { + $DEBUG brctl addif "$bridge_ifname" "$iface" + return 0 + } || { + $DEBUG brctl addbr "$bridge_ifname" + $DEBUG brctl setfd "$bridge_ifname" 0 + $DEBUG brctl addif "$bridge_ifname" "$iface" + iface="$bridge_ifname" + } + ;; + esac + + # Interface settings + config_get mtu "$config" mtu + $DEBUG ifconfig "$iface" ${mtu:+mtu $mtu} up + + pidfile="/var/run/$iface.pid" + case "$proto" in + static) + config_get ipaddr "$config" ipaddr + config_get netmask "$config" netmask + [ -z "$ipaddr" -o -z "$netmask" ] && return 1 + + config_get ip6addr "$config" ip6addr + config_get gateway "$config" gateway + config_get dns "$config" dns + + $DEBUG ifconfig "$iface" "$ipaddr" netmask "$netmask" + [ -z "$gateway" ] || route add default gw "$gateway" + [ -z "$dns" -o -f /tmp/resolv.conf ] || { + for ns in $dns; do + echo "nameserver $ns" >> /tmp/resolv.conf + done + } + + env -i ACTION="ifup" INTERFACE="config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" & + ;; + dhcp) + pid="$(cat "$pidfile" 2>/dev/null)" + [ -n "$pid" -a -d "/proc/$pid" ] && kill -9 "$pid" + + config_get ipaddr "$config" ipaddr + config_get netmask "$config" netmask + config_get hostname "$config" hostname + config_get proto1 "$config" proto + + [ -z "$ipaddr" ] || \ + $DEBUG ifconfig "$iface" "$ipaddr" ${netmask:+netmask "$netmask"} + + # don't stay running in background if dhcp is not the main proto on the interface (e.g. when using pptp) + [ "$proto1" != "$proto" ] && dhcpopts="-n -q" + $DEBUG udhcpc -i "$iface" ${ipaddr:+-r $ipaddr} ${hostname:+-H $hostname} -b -p "$pidfile" ${dhcpopts:- -R &} + ;; + *) + if ( eval "type setup_interface_$proto" ) >/dev/null 2>/dev/null; then + eval "setup_interface_$proto '$iface' '$config' '$proto'" + else + echo "Interface type $proto not supported." + return 1 + fi + ;; + esac +} + -- cgit v1.2.3 From fd40fb97f848901b4d3c197d0e83e95b01312f9a Mon Sep 17 00:00:00 2001 From: nbd Date: Sun, 30 Jul 2006 13:21:18 +0000 Subject: fix more instances of '' abuse git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4326 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 59ec84aba..76db09de1 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -4,11 +4,11 @@ # DEBUG="echo" find_config() { - local type iface ifn + local iftype iface ifn for ifn in $interfaces; do - config_get type "$ifn" type + config_get iftype "$ifn" type config_get iface "$ifn" ifname - case "$type" in + case "$iftype" in bridge) config_get iface "$ifn" ifnames ;; @@ -25,15 +25,15 @@ find_config() { } scan_interfaces() { - local mode type iface + local mode iftype iface interfaces= config_cb() { - config_get type "$CONFIG_SECTION" TYPE - case "$type" in + config_get iftype "$CONFIG_SECTION" TYPE + case "$iftype" in interface) - config_get type "$CONFIG_SECTION" type + config_get iftype "$CONFIG_SECTION" type config_get mode "$CONFIG_SECTION" proto - case "$type" in + case "$iftype" in bridge) config_get iface "$CONFIG_SECTION" ifname iface="${iface:-br-$CONFIG_SECTION}" -- cgit v1.2.3 From 3692c8f246d2c2e5b5e203d791c6a4ac07593d9f Mon Sep 17 00:00:00 2001 From: nbd Date: Fri, 4 Aug 2006 09:50:11 +0000 Subject: fix ppp related bug in the network scripts git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4437 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 76db09de1..163e42e80 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -13,7 +13,8 @@ find_config() { config_get iface "$ifn" ifnames ;; esac - for ifc in $iface; do + config_get device "$ifn" device + for ifc in ${device:-iface}; do [ "$ifc" = "$1" ] && { echo "$ifn" return 0 -- cgit v1.2.3 From 15651c68cfa3f423b1f45f25bc8d0107580eff35 Mon Sep 17 00:00:00 2001 From: nbd Date: Sat, 19 Aug 2006 14:45:14 +0000 Subject: fix typo git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4608 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 163e42e80..690d7996e 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -14,7 +14,7 @@ find_config() { ;; esac config_get device "$ifn" device - for ifc in ${device:-iface}; do + for ifc in ${device:-$iface}; do [ "$ifc" = "$1" ] && { echo "$ifn" return 0 -- cgit v1.2.3 From a8a833f845c7cf981ad46255271ef605098afd08 Mon Sep 17 00:00:00 2001 From: nbd Date: Wed, 23 Aug 2006 18:47:31 +0000 Subject: change 'ifnames' to 'ifname' in network config, fix #697 git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4638 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 30 +++++++----------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 690d7996e..0cd6cb889 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -8,11 +8,6 @@ find_config() { for ifn in $interfaces; do config_get iftype "$ifn" type config_get iface "$ifn" ifname - case "$iftype" in - bridge) - config_get iface "$ifn" ifnames - ;; - esac config_get device "$ifn" device for ifc in ${device:-$iface}; do [ "$ifc" = "$1" ] && { @@ -32,17 +27,9 @@ scan_interfaces() { config_get iftype "$CONFIG_SECTION" TYPE case "$iftype" in interface) - config_get iftype "$CONFIG_SECTION" type - config_get mode "$CONFIG_SECTION" proto - case "$iftype" in - bridge) - config_get iface "$CONFIG_SECTION" ifname - iface="${iface:-br-$CONFIG_SECTION}" - config_set "$CONFIG_SECTION" ifname "$iface" - ;; - esac + config_get proto "$CONFIG_SECTION" proto append interfaces "$CONFIG_SECTION" - ( type "scan_$mode" ) >/dev/null 2>/dev/null && eval "scan_$mode '$CONFIG_SECTION'" + ( type "scan_$proto" ) >/dev/null 2>/dev/null && eval "scan_$proto '$CONFIG_SECTION'" ;; esac } @@ -80,16 +67,15 @@ setup_interface() { # Setup bridging case "$iftype" in bridge) - config_get bridge_ifname "$config" ifname ifconfig "$iface" up 2>/dev/null >/dev/null - ifconfig "$bridge_ifname" 2>/dev/null >/dev/null && { - $DEBUG brctl addif "$bridge_ifname" "$iface" + ifconfig "br-$config" 2>/dev/null >/dev/null && { + $DEBUG brctl addif "br-$config" "$iface" return 0 } || { - $DEBUG brctl addbr "$bridge_ifname" - $DEBUG brctl setfd "$bridge_ifname" 0 - $DEBUG brctl addif "$bridge_ifname" "$iface" - iface="$bridge_ifname" + $DEBUG brctl addbr "br-$config" + $DEBUG brctl setfd "br-$config" 0 + $DEBUG brctl addif "br-$config" "$iface" + iface="br-$config" } ;; esac -- cgit v1.2.3 From 8aff78b0096b4c2f8ec34fdcf96e55ef8bb9a24a Mon Sep 17 00:00:00 2001 From: nbd Date: Thu, 24 Aug 2006 13:22:53 +0000 Subject: default value for *_device in scan_interfaces git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4652 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 0cd6cb889..d4864ae86 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -30,6 +30,9 @@ scan_interfaces() { config_get proto "$CONFIG_SECTION" proto append interfaces "$CONFIG_SECTION" ( type "scan_$proto" ) >/dev/null 2>/dev/null && eval "scan_$proto '$CONFIG_SECTION'" + config_get ifname "$CONFIG_SECTION" ifname + config_get device "$CONFIG_SECTION" device + config_set "$CONFIG_SECTION" device "${device:-$ifname}" ;; esac } -- cgit v1.2.3 From 00394c57717f28bb3b9860020729cd73036a8cf8 Mon Sep 17 00:00:00 2001 From: nbd Date: Thu, 24 Aug 2006 13:46:47 +0000 Subject: revert to using *_ifnames internally, too many problems with firewall, ppp, etc. otherwise git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4653 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index d4864ae86..5bc74d128 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -21,7 +21,7 @@ find_config() { } scan_interfaces() { - local mode iftype iface + local mode iftype iface ifname device interfaces= config_cb() { config_get iftype "$CONFIG_SECTION" TYPE @@ -29,10 +29,15 @@ scan_interfaces() { interface) config_get proto "$CONFIG_SECTION" proto append interfaces "$CONFIG_SECTION" + config_get iftype "$CONFIG_SECTION" iftype + case "$iftype" in + bridge) + config_get ifname "$CONFIG_SECTION" ifname + config_set "$CONFIG_SECTION" ifnames "$ifname" + config_set "$CONFIG_SECTION" ifname br-"$CONFIG_SECTION" + ;; + esac ( type "scan_$proto" ) >/dev/null 2>/dev/null && eval "scan_$proto '$CONFIG_SECTION'" - config_get ifname "$CONFIG_SECTION" ifname - config_get device "$CONFIG_SECTION" device - config_set "$CONFIG_SECTION" device "${device:-$ifname}" ;; esac } -- cgit v1.2.3 From f7d68e0a92d2978712aa6ebf610a300f5818948a Mon Sep 17 00:00:00 2001 From: nbd Date: Sun, 27 Aug 2006 10:05:58 +0000 Subject: fix find_config() in the network scripts git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4682 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 5bc74d128..ec05c3eb8 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -4,12 +4,15 @@ # DEBUG="echo" find_config() { - local iftype iface ifn + local iftype device iface ifaces ifn for ifn in $interfaces; do config_get iftype "$ifn" type config_get iface "$ifn" ifname + case "$iftype" in + bridge) config_get ifaces "$ifn" ifnames;; + esac config_get device "$ifn" device - for ifc in ${device:-$iface}; do + for ifc in $device $iface $ifaces; do [ "$ifc" = "$1" ] && { echo "$ifn" return 0 -- cgit v1.2.3 From 465de48141a686fc4915fa816a24b976fa00a5bd Mon Sep 17 00:00:00 2001 From: mbm Date: Sun, 27 Aug 2006 11:11:55 +0000 Subject: fix minor typo & move loopback to network config git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4683 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index ec05c3eb8..bb58a3e75 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -32,7 +32,7 @@ scan_interfaces() { interface) config_get proto "$CONFIG_SECTION" proto append interfaces "$CONFIG_SECTION" - config_get iftype "$CONFIG_SECTION" iftype + config_get iftype "$CONFIG_SECTION" type case "$iftype" in bridge) config_get ifname "$CONFIG_SECTION" ifname -- cgit v1.2.3 From cf496205a8d92c574137aad7266207c3e23563d7 Mon Sep 17 00:00:00 2001 From: nbd Date: Fri, 6 Oct 2006 20:24:05 +0000 Subject: minor cleanup git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4939 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index bb58a3e75..3e18db1b4 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -59,17 +59,14 @@ add_vlan() { setup_interface() { local iface="$1" local config="$2" - local proto="$3" + local proto [ -n "$config" ] || { config=$(find_config "$iface") [ "$?" = 0 ] || return 1 } - [ -n "$proto" ] || { - config_get proto "$config" proto - } - + proto="${3:-$(config_get "$config" proto)}" config_get iftype "$config" type # Setup VLAN interfaces -- cgit v1.2.3 From 2f1f57762eebd54951e731e6d34392c61f19a1be Mon Sep 17 00:00:00 2001 From: nbd Date: Mon, 9 Oct 2006 05:59:26 +0000 Subject: add new /bin/uci script and api for manipulating buildroot-ng config files git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4982 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../base-files/default/lib/config/uci-update.awk | 160 +++++++++++++++++++++ package/base-files/default/lib/config/uci.sh | 138 ++++++++++++++++++ 2 files changed, 298 insertions(+) create mode 100644 package/base-files/default/lib/config/uci-update.awk create mode 100755 package/base-files/default/lib/config/uci.sh (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/config/uci-update.awk b/package/base-files/default/lib/config/uci-update.awk new file mode 100644 index 000000000..efa875850 --- /dev/null +++ b/package/base-files/default/lib/config/uci-update.awk @@ -0,0 +1,160 @@ +# Configuration update functions +# +# Copyright (C) 2006 by Fokus Fraunhofer +# Copyright (C) 2006 by Felix Fietkau +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +function read_file(filename, result) { + while ((getline 1) { + l[i2] = substr(rest,1,RSTART-1) + i2++ + } + aidx=index(rest,"\"") + if (aidx>=RSTART && aidx<=RSTART+RLENGTH) { + rest=substr(rest,aidx+1) + # find the end of the string + match(rest,/\"/) + l[i2]=substr(rest,1,RSTART-1) + i2++ + } + rest=substr(rest,RSTART+RLENGTH) + } else { + l[i2] = rest + i2++ + rest = "" + } + } + line = lines[n] + + # when a command wants to set a config value for the current + # section and a blank line is encountered before an option with + # the same name, insert it here to maintain some coherency between + # manually and automatically created option lines + # if an option with the same name appears after this point, simply + # ignore it, because it is already set. + if ((section != "") && (l[1] != "option")) { + if (line ~ /^[ \t]*$/) { + if (update ~ "^" section "\\.") { + gsub("^" section ".", "", update) + cfg = cfg cmd2option(update) "\n" + gsub(/=.*$/, "", update) + update = "-" section "." update + } + } + } + + if (l[1] == "config") { + # look for all unset values + if (section != "") { + flag=0 + if (update ~ "^" section "\\.") { + flag=1 + gsub("^" section ".", "", update) + cfg = cfg cmd2option(update) "\n" + + update = "-" section "." update + } + if (flag!=0) cfg = cfg "\n" + } + + remove = "" + section = l[3] + if (!length(section)) { + section = "cfg" scnt + } + scnt++ + if (update == "-" section) { + remove = "section" + update = "" + } else if (update ~ "^@" section "=") { + update = "" + } else if (update ~ "^&" section "=") { + gsub("^&" section "=", "", update) + line = cmd2config(l[2],update) + update = "" + } + } + if (remove == "option") remove = "" + if (l[1] == "option") { + if (update ~ "^-" section "\\." l[2] "$") remove = "option" + # if a supplied config value already exists, replace the whole line + if (match(update, "^" section "." l[2] "=")) { + gsub("^" section ".", "", update) + line = cmd2option(update) + update = "" + } + } + if (remove == "") cfg = cfg line "\n" + } + + # any new options for the last section?? + if (section != "") { + if (update ~ "^" section "\\.") { + gsub("^" section ".", "", update) + cfg = cfg cmd2option(update) "\n" + + update = "-" section "." update + } + } + + if (update ~ "^@") { + # new section + section = stype = substr(update,2) + gsub(/=.*$/,"",section) + gsub(/^.*=/,"",stype) + cfg = cfg "\nconfig \"" stype "\" \"" section "\"\n" + } + + return cfg +} diff --git a/package/base-files/default/lib/config/uci.sh b/package/base-files/default/lib/config/uci.sh new file mode 100755 index 000000000..ccd6ee57b --- /dev/null +++ b/package/base-files/default/lib/config/uci.sh @@ -0,0 +1,138 @@ +#!/bin/sh +# Shell script defining macros for manipulating config files +# +# Copyright (C) 2006 by Fokus Fraunhofer +# Copyright (C) 2006 by Felix Fietkau +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +uci_load() { + config_load "$PACKAGE" + local PACKAGE_BASE="$(basename "$PACKAGE")" + [ -f "/tmp/.uci/${PACKAGE_BASE}" ] && { + . "/tmp/.uci/${PACKAGE_BASE}" + config_cb + } +} + +uci_do_update() { + local FILENAME="$1" + local UPDATE="$2" + awk -f /lib/config/uci-update.awk -f - <> "/tmp/.uci/${PACKAGE_BASE}" +} + +uci_set() { + local PACKAGE="$1" + local CONFIG="$2" + local OPTION="$3" + local VALUE="$4" + + ( # spawn a subshell so you don't mess up the current environment + uci_load "$PACKAGE" + config_get type "$CONFIG" TYPE + [ -z "$type" ] + ) || uci_add_update "$PACKAGE" "CONFIG_SECTION='$CONFIG'${N}option '$OPTION' '$VALUE'" +} + +uci_add() { + local PACKAGE="$1" + local TYPE="$2" + local CONFIG="$3" + + uci_add_update "$PACKAGE" "config '$TYPE' '$CONFIG'" +} + +uci_rename() { + local PACKAGE="$1" + local CONFIG="$2" + local VALUE="$3" + + uci_add_update "$PACKAGE" "config_rename '$CONFIG' '$VALUE'" +} + +uci_remove() { + local PACKAGE="$1" + local CONFIG="$2" + local OPTION="$3" + + if [ -z "$OPTION" ]; then + uci_add_update "$PACKAGE" "config_clear '$CONFIG'" + else + uci_add_update "$PACKAGE" "config_unset '$CONFIG' '$OPTION'" + fi +} + +uci_commit() { + local PACKAGE="$1" + local PACKAGE_BASE="$(basename "$PACKAGE")" + + mkdir -p /tmp/.uci + lock "/tmp/.uci/$PACKAGE_BASE.lock" + [ -f "/tmp/.uci/$PACKAGE_BASE" ] && ( + updatestr="" + + # replace handlers + config() { + append updatestr "config = update_config(config, \"@$2=$1\")" "$N" + } + option() { + append updatestr "config = update_config(config, \"$CONFIG_SECTION.$1=$2\")" "$N" + } + config_rename() { + append updatestr "config = update_config(config, \"&$1=$2\")" "$N" + } + config_unset() { + append updatestr "config = update_config(config, \"-$1.$2\")" "$N" + } + config_clear() { + append updatestr "config = update_config(config, \"-$1\")" "$N" + } + + . "/tmp/.uci/$PACKAGE_BASE" + + # completely disable handlers so that they don't get in the way + config() { + return 0 + } + option() { + return 0 + } + + config_load "$PACKAGE" || CONFIG_FILENAME="$ROOT/etc/config/$PACKAGE_BASE" + uci_do_update "$CONFIG_FILENAME" "$updatestr" > "/tmp/.uci/$PACKAGE_BASE.new" && { + mv -f "/tmp/.uci/$PACKAGE_BASE.new" "$CONFIG_FILENAME" && \ + rm -f "/tmp/.uci/$PACKAGE_BASE" + } + ) + lock -u "/tmp/.uci/$PACKAGE_BASE.lock" +} + + -- cgit v1.2.3 From 564ea3531fda823c933161fd0dc18c7b4d26bf99 Mon Sep 17 00:00:00 2001 From: nbd Date: Mon, 9 Oct 2006 12:35:31 +0000 Subject: save the real configured interface name in the 'device' variable when running scan_interfaces() - fixes pppoe problems git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4983 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/lib/network/config.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'package/base-files/default/lib') diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index 3e18db1b4..18f794a31 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -33,9 +33,10 @@ scan_interfaces() { config_get proto "$CONFIG_SECTION" proto append interfaces "$CONFIG_SECTION" config_get iftype "$CONFIG_SECTION" type + config_get ifname "$CONFIG_SECTION" ifname + config_set "$CONFIG_SECTION" device "$ifname" case "$iftype" in bridge) - config_get ifname "$CONFIG_SECTION" ifname config_set "$CONFIG_SECTION" ifnames "$ifname" config_set "$CONFIG_SECTION" ifname br-"$CONFIG_SECTION" ;; -- cgit v1.2.3