From 2e65184ccaa50b2fb24f8380631d24723499902b Mon Sep 17 00:00:00 2001 From: jow Date: Sun, 16 Dec 2012 18:22:02 +0000 Subject: base-files: various enhancements to network.sh - support reading inactive gateways and DNS information in network_get_gateway(), network_get_dnsserver() and network_get_dnssearch() by passing "true" as optional last argument - internally cache fetched values to speed up subsequent accesses to the same data, introduce network_flush_cache() to clear them - add some inline function documentation git-svn-id: svn://svn.openwrt.org/openwrt/trunk@34722 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 183 ++++++++++++++++++---- 1 file changed, 153 insertions(+), 30 deletions(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index a4652569b..9366e5937 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -1,11 +1,40 @@ . /usr/share/libubox/jshn.sh +__network_switch_inactive() +{ + local __tmp + + if [ "$1" = 0 ] || [ "$1" = false ]; then + return 1 + fi + + json_get_type __tmp "inactive" + + if [ "$__tmp" = object ]; then + json_select "inactive" + fi +} + +__network_set_cache() +{ + __NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1" + eval "__NETWORK_CV_$1='\$$2'" +} + +__network_get_cache() +{ + eval "[ -n \"\${__NETWORK_CV_$1+x}\" ] && export -- \"$2=\$__NETWORK_CV_$1\"" +} + __network_ipaddr() { local __var="$1" local __iface="$2" local __family="$3" - local __prefix="${4:-0}" + local __prefix="$4" + local __key="ipaddr_${2}_${3}_${4}" + + __network_get_cache "$__key" "$__var" && return 0 local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" @@ -27,6 +56,7 @@ __network_ipaddr() eval "export -- \"$__var=\${$__var}/$__tmp\"" } + __network_set_cache "$__key" "$__var" return 0 fi fi @@ -34,10 +64,24 @@ __network_ipaddr() return 1 } +# determine IPv4 address of given logical interface +# 1: destination variable +# 2: interface network_get_ipaddr() { __network_ipaddr "$1" "$2" 4 0; } + +# determine IPv6 address of given logical interface +# 1: destination variable +# 2: interface network_get_ipaddr6() { __network_ipaddr "$1" "$2" 6 0; } +# determine IPv4 subnet of given logical interface +# 1: destination variable +# 2: interface network_get_subnet() { __network_ipaddr "$1" "$2" 4 1; } + +# determine IPv6 subnet of given logical interface +# 1: destination variable +# 2: interface network_get_subnet6() { __network_ipaddr "$1" "$2" 6 1; } @@ -46,79 +90,127 @@ __network_gateway() local __var="$1" local __iface="$2" local __family="$3" + local __key="gateway_${2}_${3}" + + __network_get_cache "$__key" "$__var" && return 0 local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" - local __idx=1 json_load "${__tmp:-{}}" - if json_get_type __tmp route && [ "$__tmp" = array ]; then + for __tmp in 0 1; do - json_select route + if json_get_type __tmp route && [ "$__tmp" = array ]; then - while json_get_type __tmp "$__idx" && [ "$__tmp" = object ]; do + json_select route - json_select "$((__idx++))" - json_get_var __tmp target + local __idx=1 + while json_get_type __tmp "$__idx" && [ "$__tmp" = object ]; do - case "${__family}/${__tmp}" in - 4/0.0.0.0|6/::) - json_get_var "$__var" nexthop - return $? - ;; - esac + json_select "$((__idx++))" + json_get_var __tmp target + + case "${__family}/${__tmp}" in + 4/0.0.0.0|6/::) + json_get_var "$__var" nexthop + __network_set_cache "$__key" "$__var" + return $? + ;; + esac + + json_select ".." + + done json_select ".." - done - fi + fi + + __network_switch_inactive "$4" || break + + done return 1 } -network_get_gateway() { __network_gateway "$1" "$2" 4; } -network_get_gateway6() { __network_gateway "$1" "$2" 6; } +# determine IPv4 gateway of given logical interface +# 1: destination variable +# 2: interface +# 3: consider inactive gateway if "true" (optional) +network_get_gateway() { __network_gateway "$1" "$2" 4 "${3:-0}"; } + +# determine IPv6 gateway of given logical interface +# 1: destination variable +# 2: interface +# 3: consider inactive gateway if "true" (optional) +network_get_gateway6() { __network_gateway "$1" "$2" 6 "${3:-0}"; } __network_dns() { local __var="$1" local __iface="$2" local __field="$3" + local __key="dns_${2}_${3}" + + __network_get_cache "$__key" "$__var" && return 0 local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" local __dns="" - local __idx=1 json_load "${__tmp:-{}}" - if json_get_type __tmp "$__field" && [ "$__tmp" = array ]; then + for __tmp in 0 1; do - json_select "$__field" + if json_get_type __tmp "$__field" && [ "$__tmp" = array ]; then - while json_get_type __tmp "$__idx" && [ "$__tmp" = string ]; do + json_select "$__field" - json_get_var __tmp "$((__idx++))" - __dns="${__dns:+$__dns }$__tmp" + local __idx=1 + while json_get_type __tmp "$__idx" && [ "$__tmp" = string ]; do - done - fi + json_get_var __tmp "$((__idx++))" + __dns="${__dns:+$__dns }$__tmp" + + done + + json_select ".." + fi + + __network_switch_inactive "$4" || break + + done - eval "export -- \"$__var=$__dns\"" - [ -n "$__dns" ] + if [ -n "$__dns" ]; then + eval "export -- \"$__var=$__dns\"" + __network_set_cache "$__key" "$__var" + fi } -network_get_dnsserver() { __network_dns "$1" "$2" dns_server; } -network_get_dnssearch() { __network_dns "$1" "$2" dns_search; } +# determine the DNS servers of the given logical interface +# 1: destination variable +# 2: interface +# 3: consider inactive servers if "true" (optional) +network_get_dnsserver() { __network_dns "$1" "$2" dns_server "${3:-0}"; } + +# determine the domains of the given logical interface +# 1: destination variable +# 2: interface +# 3: consider inactive servers if "true" (optional) +network_get_dnssearch() { __network_dns "$1" "$2" dns_search "${3:-0}"; } __network_wan() { local __var="$1" local __family="$2" + local __key="wan_${2}" local __iface + __network_get_cache "$__key" "$__var" && return 0 + for __iface in $(ubus list | sed -ne 's/^network\.interface\.//p'); do if __network_gateway "$__var" "$__iface" "$__family"; then eval "export -- \"$__var=$__iface\"" + __network_set_cache "$__key" "$__var" return 0 fi done @@ -127,7 +219,12 @@ __network_wan() { return 1 } +# find the logical interface which holds the current IPv4 default route +# 1: destination variable network_find_wan() { __network_wan "$1" 4; } + +# find the logical interface which holds the current IPv6 default route +# 1: destination variable network_find_wan6() { __network_wan "$1" 6; } @@ -136,21 +233,33 @@ __network_device() local __var="$1" local __iface="$2" local __field="$3" + local __key="device_${2}_${3}" + + __network_get_cache "$__key" "$__var" && return 0 local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" [ -n "$__tmp" ] || return 1 json_load "$__tmp" - json_get_var "$__var" "$__field" + json_get_var "$__var" "$__field" && __network_set_cache "$__key" "$__var" } +# test whether the given logical interface is running +# 1: interface network_is_up() { local __up __network_device __up "$1" up && [ $__up -eq 1 ] } +# determine the layer 3 linux network device of the given logical interface +# 1: destination variable +# 2: interface network_get_device() { __network_device "$1" "$2" l3_device; } + +# determine the layer 2 linux network device of the given logical interface +# 1: destination variable +# 2: interface network_get_physdev() { __network_device "$1" "$2" device; } @@ -166,5 +275,19 @@ __network_defer() ubus call network.device set_state "$(json_dump)" 2>/dev/null } +# defer netifd actions on the given linux network device +# 1: device name network_defer_device() { __network_defer "$1" 1; } + +# continue netifd actions on the given linux network device +# 1: device name network_ready_device() { __network_defer "$1" 0; } + +# flush the internal value cache to force re-reading values from ubus +network_flush_cache() +{ + local __tmp + for __tmp in $__NETWORK_CACHE __NETWORK_CACHE; do + unset "$__tmp" + done +} -- cgit v1.2.3 From a06be29d4e91a4c00c0bd737e5da7c888edebdcc Mon Sep 17 00:00:00 2001 From: jow Date: Sun, 16 Dec 2012 20:17:18 +0000 Subject: base-files: rework cache handling in network.sh to keep the entire parsed ifstatus, use jshn namespaces to support using it concurrently with other jshn users git-svn-id: svn://svn.openwrt.org/openwrt/trunk@34725 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 288 ++++++++++++---------- 1 file changed, 159 insertions(+), 129 deletions(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index 9366e5937..d242abbe6 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -1,67 +1,153 @@ . /usr/share/libubox/jshn.sh -__network_switch_inactive() +__network_set_cache() { - local __tmp - - if [ "$1" = 0 ] || [ "$1" = false ]; then - return 1 - fi - - json_get_type __tmp "inactive" - - if [ "$__tmp" = object ]; then - json_select "inactive" + if [ -n "$3" ]; then + eval "export -- __NETWORK_CV_$1='$3'" + __NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1" + elif json_get_var "__NETWORK_CV_$1" "$2"; then + __NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1" fi } -__network_set_cache() +__network_export() { - __NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1" - eval "__NETWORK_CV_$1='\$$2'" + local __v="__NETWORK_CV_$2" + eval "export -- \"$1=\${$__v:+\$$__v$3}\"; [ -n \"\${$__v+x}\" ]" } -__network_get_cache() +__network_parse_ifstatus() { - eval "[ -n \"\${__NETWORK_CV_$1+x}\" ] && export -- \"$2=\$__NETWORK_CV_$1\"" -} + local __iface="$1" + local __key="${__iface}" + local __tmp + local __old_ns -__network_ipaddr() -{ - local __var="$1" - local __iface="$2" - local __family="$3" - local __prefix="$4" - local __key="ipaddr_${2}_${3}_${4}" + __network_export __tmp "${__key}__parsed" && return 0 + __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" + [ -n "$__tmp" ] || return 1 - __network_get_cache "$__key" "$__var" && return 0 + json_set_namespace "network" __old_ns + json_load "$__tmp" - local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" + __network_set_cache "${__key}__parsed" "" "1" - json_load "${__tmp:-{}}" - json_get_type __tmp "ipv${__family}_address" + for __tmp in "" "_inactive"; do - if [ "$__tmp" = array ]; then + __key="${__key}${__tmp}" - json_select "ipv${__family}_address" - json_get_type __tmp 1 + # parse addresses + local __family + for __family in 4 6; do + if json_get_type __tmp "ipv${__family}_address" && [ "$__tmp" = array ]; then - if [ "$__tmp" = object ]; then + json_select "ipv${__family}_address" - json_select 1 - json_get_var $__var address + if json_get_type __tmp 1 && [ "$__tmp" = object ]; then - [ $__prefix -gt 0 ] && { - json_get_var __tmp mask - eval "export -- \"$__var=\${$__var}/$__tmp\"" - } + json_select 1 + __network_set_cache "${__key}_address${__family}" address + __network_set_cache "${__key}_mask${__family}" mask + json_select ".." + + fi + + json_select ".." + + fi + done + + # parse routes + if json_get_type __tmp route && [ "$__tmp" = array ]; then + + json_select "route" + + local __idx=1 + while json_get_type __tmp "$__idx" && [ "$__tmp" = object ]; do + + json_select "$((__idx++))" + json_get_var __tmp target + + case "${__tmp}" in + 0.0.0.0) + __network_set_cache "${__key}_gateway4" nexthop + ;; + ::) + __network_set_cache "${__key}_gateway6" nexthop + ;; + esac + + json_select ".." + + done + + json_select ".." - __network_set_cache "$__key" "$__var" - return 0 fi + + # parse dns info + local __field + for __field in "dns_server" "dns_search"; do + if json_get_type __tmp "$__field" && [ "$__tmp" = array ]; then + + json_select "$__field" + + local __idx=1 + local __dns="" + + while json_get_type __tmp "$__idx" && [ "$__tmp" = string ]; do + + json_get_var __tmp "$((__idx++))" + __dns="${__dns:+$__dns }$__tmp" + + done + + json_select ".." + + if [ -n "$__dns" ]; then + __network_set_cache "${__key}_${__field}" "" "$__dns" + fi + fi + done + + # parse up state, device and physdev + for __field in "up" "l3_device" "device"; do + if json_get_type __tmp "$__field"; then + __network_set_cache "${__key}_${__field}" "$__field" + fi + done + + # descend into inactive table + json_get_type __tmp "inactive" && [ "$__tmp" = object ] && json_select "inactive" + + done + + json_cleanup + json_set_namespace "$__old_ns" + + return 0 +} + + +__network_ipaddr() +{ + local __var="$1" + local __iface="$2" + local __family="$3" + local __prefix="$4" + local __tmp + + __network_parse_ifstatus "$__iface" || return 1 + + if [ $__prefix -eq 1 ]; then + __network_export __tmp "${__iface}_mask${__family}" && \ + __network_export "$__var" "${__iface}_address${__family}" "/$__tmp" + return $? fi - return 1 + __network_export "$__var" "${__iface}_address${__family}" + return $? + } # determine IPv4 address of given logical interface @@ -90,47 +176,17 @@ __network_gateway() local __var="$1" local __iface="$2" local __family="$3" - local __key="gateway_${2}_${3}" - - __network_get_cache "$__key" "$__var" && return 0 - - local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" - - json_load "${__tmp:-{}}" - - for __tmp in 0 1; do - - if json_get_type __tmp route && [ "$__tmp" = array ]; then - - json_select route - - local __idx=1 - while json_get_type __tmp "$__idx" && [ "$__tmp" = object ]; do - - json_select "$((__idx++))" - json_get_var __tmp target - - case "${__family}/${__tmp}" in - 4/0.0.0.0|6/::) - json_get_var "$__var" nexthop - __network_set_cache "$__key" "$__var" - return $? - ;; - esac - - json_select ".." - - done - - json_select ".." - - fi + local __inactive="$4" - __network_switch_inactive "$4" || break + __network_parse_ifstatus "$__iface" || return 1 - done + if [ "$__inactive" = 1 -o "$__inactive" = "true" ]; then + __network_export "$__var" "${__iface}_inactive_gateway${__family}" && \ + return 0 + fi - return 1 + __network_export "$__var" "${__iface}_gateway${__family}" + return $? } # determine IPv4 gateway of given logical interface @@ -150,40 +206,17 @@ __network_dns() { local __var="$1" local __iface="$2" local __field="$3" - local __key="dns_${2}_${3}" - - __network_get_cache "$__key" "$__var" && return 0 - - local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" - local __dns="" - - json_load "${__tmp:-{}}" + local __inactive="$4" - for __tmp in 0 1; do + __network_parse_ifstatus "$__iface" || return 1 - if json_get_type __tmp "$__field" && [ "$__tmp" = array ]; then - - json_select "$__field" - - local __idx=1 - while json_get_type __tmp "$__idx" && [ "$__tmp" = string ]; do - - json_get_var __tmp "$((__idx++))" - __dns="${__dns:+$__dns }$__tmp" - - done - - json_select ".." - fi - - __network_switch_inactive "$4" || break - - done - - if [ -n "$__dns" ]; then - eval "export -- \"$__var=$__dns\"" - __network_set_cache "$__key" "$__var" + if [ "$__inactive" = 1 -o "$__inactive" = "true" ]; then + __network_export "$__var" "${__iface}_inactive_${__field}" && \ + return 0 fi + + __network_export "$__var" "${__iface}_${__field}" + return $? } # determine the DNS servers of the given logical interface @@ -195,23 +228,23 @@ network_get_dnsserver() { __network_dns "$1" "$2" dns_server "${3:-0}"; } # determine the domains of the given logical interface # 1: destination variable # 2: interface -# 3: consider inactive servers if "true" (optional) +# 3: consider inactive domains if "true" (optional) network_get_dnssearch() { __network_dns "$1" "$2" dns_search "${3:-0}"; } -__network_wan() { +__network_wan() +{ local __var="$1" local __family="$2" - local __key="wan_${2}" + local __inactive="$3" local __iface - __network_get_cache "$__key" "$__var" && return 0 - for __iface in $(ubus list | sed -ne 's/^network\.interface\.//p'); do - if __network_gateway "$__var" "$__iface" "$__family"; then - eval "export -- \"$__var=$__iface\"" - __network_set_cache "$__key" "$__var" - return 0 + if [ "$__iface" != loopback ]; then + if __network_gateway "$__var" "$__iface" "$__family" "$__inactive"; then + eval "export -- \"$__var=$__iface\"" + return 0 + fi fi done @@ -221,11 +254,13 @@ __network_wan() { # find the logical interface which holds the current IPv4 default route # 1: destination variable -network_find_wan() { __network_wan "$1" 4; } +# 2: consider inactive default routes if "true" (optional) +network_find_wan() { __network_wan "$1" 4 "${2:-0}"; } # find the logical interface which holds the current IPv6 default route # 1: destination variable -network_find_wan6() { __network_wan "$1" 6; } +# 2: consider inactive dafault routes if "true" (optional) +network_find_wan6() { __network_wan "$1" 6 "${2:-0}"; } __network_device() @@ -233,15 +268,10 @@ __network_device() local __var="$1" local __iface="$2" local __field="$3" - local __key="device_${2}_${3}" - - __network_get_cache "$__key" "$__var" && return 0 - local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)" - [ -n "$__tmp" ] || return 1 - - json_load "$__tmp" - json_get_var "$__var" "$__field" && __network_set_cache "$__key" "$__var" + __network_parse_ifstatus "$__iface" || return 1 + __network_export "$__var" "${__iface}_${__field}" + return $? } # test whether the given logical interface is running -- cgit v1.2.3 From 0cc78c202013a13896d42e9ed3264a3fe84bd1a3 Mon Sep 17 00:00:00 2001 From: jow Date: Mon, 17 Dec 2012 13:07:42 +0000 Subject: base-files: use json_is_a() in network.sh git-svn-id: svn://svn.openwrt.org/openwrt/trunk@34733 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index d242abbe6..424965acb 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -39,11 +39,11 @@ __network_parse_ifstatus() # parse addresses local __family for __family in 4 6; do - if json_get_type __tmp "ipv${__family}_address" && [ "$__tmp" = array ]; then + if json_is_a "ipv${__family}_address" array; then json_select "ipv${__family}_address" - if json_get_type __tmp 1 && [ "$__tmp" = object ]; then + if json_is_a 1 object; then json_select 1 __network_set_cache "${__key}_address${__family}" address @@ -58,12 +58,12 @@ __network_parse_ifstatus() done # parse routes - if json_get_type __tmp route && [ "$__tmp" = array ]; then + if json_is_a route array; then json_select "route" local __idx=1 - while json_get_type __tmp "$__idx" && [ "$__tmp" = object ]; do + while json_is_a "$__idx" object; do json_select "$((__idx++))" json_get_var __tmp target @@ -88,14 +88,14 @@ __network_parse_ifstatus() # parse dns info local __field for __field in "dns_server" "dns_search"; do - if json_get_type __tmp "$__field" && [ "$__tmp" = array ]; then + if json_is_a "$__field" array; then json_select "$__field" local __idx=1 local __dns="" - while json_get_type __tmp "$__idx" && [ "$__tmp" = string ]; do + while json_is_a "$__idx" string; do json_get_var __tmp "$((__idx++))" __dns="${__dns:+$__dns }$__tmp" @@ -118,7 +118,7 @@ __network_parse_ifstatus() done # descend into inactive table - json_get_type __tmp "inactive" && [ "$__tmp" = object ] && json_select "inactive" + json_is_a "inactive" object && json_select "inactive" done -- cgit v1.2.3 From 53edda1e3668752d18b2bbf4c3d6edc7e3ab1b6e Mon Sep 17 00:00:00 2001 From: mirko Date: Wed, 19 Dec 2012 16:07:46 +0000 Subject: Do not overload mount-call - trying to reduce confusion The behaviour of calling 'mount' differed depending on whether it called the busybox-mount, the mount of util-linux, the mount defined in /lib/functions.sh and /lib/functions/boot.sh /etc/preinit even included /lib/functions.sh and /lib/functions/boot.sh, both re-defining 'mount'. git-svn-id: svn://svn.openwrt.org/openwrt/trunk@34792 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/boot.sh | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/boot.sh b/package/base-files/files/lib/functions/boot.sh index 8c3f27ba4..137c3bf47 100644 --- a/package/base-files/files/lib/functions/boot.sh +++ b/package/base-files/files/lib/functions/boot.sh @@ -2,10 +2,6 @@ # Copyright (C) 2006-2010 OpenWrt.org # Copyright (C) 2010 Vertical Communications -mount() { - /bin/busybox mount -o noatime "$@" -} - boot_hook_splice_start() { export -n PI_HOOK_SPLICE=1 } @@ -112,12 +108,12 @@ dupe() { # } pivot() { # - mount -o move /proc $1/proc && \ + mount -o noatime,move /proc $1/proc && \ pivot_root $1 $1$2 && { - mount -o move $2/dev /dev - mount -o move $2/tmp /tmp - mount -o move $2/sys /sys 2>&- - mount -o move $2/overlay /overlay 2>&- + mount -o noatime,move $2/dev /dev + mount -o noatime,move $2/tmp /tmp + mount -o noatime,move $2/sys /sys 2>&- + mount -o noatime,move $2/overlay /overlay 2>&- return 0 } } @@ -126,16 +122,16 @@ fopivot() { # root=$1 { if grep -q overlay /proc/filesystems; then - mount -t overlayfs -olowerdir=/,upperdir=$1 "overlayfs:$1" /mnt && root=/mnt + mount -o noatime,lowerdir=/,upperdir=$1 -t overlayfs "overlayfs:$1" /mnt && root=/mnt elif grep -q mini_fo /proc/filesystems; then - mount -t mini_fo -o base=/,sto=$1 "mini_fo:$1" /mnt 2>&- && root=/mnt + mount -t mini_fo -o noatime,base=/,sto=$1 "mini_fo:$1" /mnt 2>&- && root=/mnt else - mount --bind / /mnt - mount --bind -o union "$1" /mnt && root=/mnt + mount --bind -o noatime / /mnt + mount --bind -o noatime,union "$1" /mnt && root=/mnt fi } || { [ "$3" = "1" ] && { - mount | grep "on $1 type" 2>&- 1>&- || mount -o bind $1 $1 + mount | grep "on $1 type" 2>&- 1>&- || mount -o noatime,bind $1 $1 dupe $1 $rom } } @@ -144,7 +140,7 @@ fopivot() { # ramoverlay() { mkdir -p /tmp/root - mount -t tmpfs -o mode=0755 root /tmp/root + mount -t tmpfs -o noatime,mode=0755 root /tmp/root fopivot /tmp/root /rom 1 } -- cgit v1.2.3 From c8e772f18ff31566e342cd44fbd7a6b2bc11efb2 Mon Sep 17 00:00:00 2001 From: mirko Date: Wed, 19 Dec 2012 16:07:53 +0000 Subject: merge /lib/functions/boot.sh and /lib/functions.sh git-svn-id: svn://svn.openwrt.org/openwrt/trunk@34794 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/boot.sh | 146 ------------------------- 1 file changed, 146 deletions(-) delete mode 100644 package/base-files/files/lib/functions/boot.sh (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/boot.sh b/package/base-files/files/lib/functions/boot.sh deleted file mode 100644 index 137c3bf47..000000000 --- a/package/base-files/files/lib/functions/boot.sh +++ /dev/null @@ -1,146 +0,0 @@ -#!/bin/sh -# Copyright (C) 2006-2010 OpenWrt.org -# Copyright (C) 2010 Vertical Communications - -boot_hook_splice_start() { - export -n PI_HOOK_SPLICE=1 -} - -boot_hook_splice_finish() { - local hook - for hook in $PI_STACK_LIST; do - local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook" - export -n "${hook}=${v% }" - export -n "${hook}_splice=" - done - export -n PI_HOOK_SPLICE= -} - -boot_hook_init() { - local hook="${1}_hook" - export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook" - export -n "$hook=" -} - -boot_hook_add() { - local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}" - local func="${2}" - - [ -n "$func" ] && { - local v; eval "v=\$$hook" - export -n "$hook=${v:+$v }$func" - } -} - -boot_hook_shift() { - local hook="${1}_hook" - local rvar="${2}" - - local v; eval "v=\$$hook" - [ -n "$v" ] && { - local first="${v%% *}" - - [ "$v" != "${v#* }" ] && \ - export -n "$hook=${v#* }" || \ - export -n "$hook=" - - export -n "$rvar=$first" - return 0 - } - - return 1 -} - -boot_run_hook() { - local hook="$1" - local func - - while boot_hook_shift "$hook" func; do - local ran; eval "ran=\$PI_RAN_$func" - [ -n "$ran" ] || { - export -n "PI_RAN_$func=1" - $func "$1" "$2" - } - done -} - -find_mtd_part() { - local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')" - local PREFIX=/dev/mtdblock - - PART="${PART##mtd}" - [ -d /dev/mtdblock ] && PREFIX=/dev/mtdblock/ - echo "${PART:+$PREFIX$PART}" -} - -jffs2_ready () { - mtdpart="$(find_mtd_part rootfs_data)" - [ -z "$mtdpart" ] && return 1 - magic=$(hexdump $mtdpart -n 4 -e '4/1 "%02x"') - [ "$magic" != "deadc0de" ] -} - -dupe() { # - cd $1 - echo -n "creating directories... " - { - cd $2 - find . -xdev -type d - echo "./dev ./overlay ./mnt ./proc ./tmp" - # xdev skips mounted directories - cd $1 - } | xargs mkdir -p - echo "done" - - echo -n "setting up symlinks... " - for file in $(cd $2; find . -xdev -type f;); do - case "$file" in - ./rom/note) ;; #nothing - ./etc/config*|\ - ./usr/lib/opkg/info/*) cp -af $2/$file $file;; - *) ln -sf /rom/${file#./*} $file;; - esac - done - for file in $(cd $2; find . -xdev -type l;); do - cp -af $2/${file#./*} $file - done - echo "done" -} - -pivot() { # - mount -o noatime,move /proc $1/proc && \ - pivot_root $1 $1$2 && { - mount -o noatime,move $2/dev /dev - mount -o noatime,move $2/tmp /tmp - mount -o noatime,move $2/sys /sys 2>&- - mount -o noatime,move $2/overlay /overlay 2>&- - return 0 - } -} - -fopivot() { # - root=$1 - { - if grep -q overlay /proc/filesystems; then - mount -o noatime,lowerdir=/,upperdir=$1 -t overlayfs "overlayfs:$1" /mnt && root=/mnt - elif grep -q mini_fo /proc/filesystems; then - mount -t mini_fo -o noatime,base=/,sto=$1 "mini_fo:$1" /mnt 2>&- && root=/mnt - else - mount --bind -o noatime / /mnt - mount --bind -o noatime,union "$1" /mnt && root=/mnt - fi - } || { - [ "$3" = "1" ] && { - mount | grep "on $1 type" 2>&- 1>&- || mount -o noatime,bind $1 $1 - dupe $1 $rom - } - } - pivot $root $2 -} - -ramoverlay() { - mkdir -p /tmp/root - mount -t tmpfs -o noatime,mode=0755 root /tmp/root - fopivot /tmp/root /rom 1 -} - -- cgit v1.2.3 From a9e848f1b73ec05528ca7c01603a80ff87faad97 Mon Sep 17 00:00:00 2001 From: cyrus Date: Tue, 15 Jan 2013 13:07:51 +0000 Subject: base-files: add support for ipv6-prefixes in connection with netifd git-svn-id: svn://svn.openwrt.org/openwrt/trunk@35168 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index 424965acb..8f87d1d0b 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -57,6 +57,20 @@ __network_parse_ifstatus() fi done + # parse prefixes + if json_is_a "ipv6_prefix" array; then + json_select "ipv6_prefix" + + if json_is_a 1 object; then + json_select 1 + __network_set_cache "${__key}_prefix6_address" address + __network_set_cache "${__key}_prefix6_mask" mask + json_select ".." + fi + + json_select ".." + fi + # parse routes if json_is_a route array; then @@ -170,6 +184,22 @@ network_get_subnet() { __network_ipaddr "$1" "$2" 4 1; } # 2: interface network_get_subnet6() { __network_ipaddr "$1" "$2" 6 1; } +# determine IPv6 prefix +network_get_prefix6() { + local __prefix="$1" + local __iface="$2" + local __address + local __mask + + __network_parse_ifstatus "$__iface" || return 1 + __network_export __address "${__iface}_prefix6_address" + local return="$?" + [ "$return" -eq 0 ] || return $? + __network_export __mask "${__iface}_prefix6_mask" + eval "$__prefix=$__address/$__mask" + return 0 +} + __network_gateway() { -- cgit v1.2.3 From af83088d4355ae96152c9260844d7a9a6f28d58a Mon Sep 17 00:00:00 2001 From: jow Date: Mon, 21 Jan 2013 18:54:58 +0000 Subject: base-files: network.sh: simplify network_get_prefix6() git-svn-id: svn://svn.openwrt.org/openwrt/trunk@35286 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index 8f87d1d0b..86b6fc569 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -186,18 +186,15 @@ network_get_subnet6() { __network_ipaddr "$1" "$2" 6 1; } # determine IPv6 prefix network_get_prefix6() { - local __prefix="$1" + local __var="$1" local __iface="$2" local __address local __mask __network_parse_ifstatus "$__iface" || return 1 - __network_export __address "${__iface}_prefix6_address" - local return="$?" - [ "$return" -eq 0 ] || return $? - __network_export __mask "${__iface}_prefix6_mask" - eval "$__prefix=$__address/$__mask" - return 0 + __network_export __mask "${__iface}_prefix6_mask" || return 1 + __network_export __var "${__iface}_prefix6_address" "$__mask" + return $? } -- cgit v1.2.3 From 19cb7485b1725013ba6a1e941ac5e8b250de2faf Mon Sep 17 00:00:00 2001 From: jow Date: Mon, 21 Jan 2013 19:02:38 +0000 Subject: base-files: network.sh: fix typo in previous commit git-svn-id: svn://svn.openwrt.org/openwrt/trunk@35287 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index 86b6fc569..ff153c6c9 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -193,7 +193,7 @@ network_get_prefix6() { __network_parse_ifstatus "$__iface" || return 1 __network_export __mask "${__iface}_prefix6_mask" || return 1 - __network_export __var "${__iface}_prefix6_address" "$__mask" + __network_export __var "${__iface}_prefix6_address" "/$__mask" return $? } -- cgit v1.2.3 From a95f83769f0d3a51bae6d2597a015cbcf76d7ae4 Mon Sep 17 00:00:00 2001 From: cyrus Date: Tue, 22 Jan 2013 16:47:16 +0000 Subject: base-files: fix network_get_prefix6 git-svn-id: svn://svn.openwrt.org/openwrt/trunk@35300 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index ff153c6c9..369fa3dbd 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -193,7 +193,7 @@ network_get_prefix6() { __network_parse_ifstatus "$__iface" || return 1 __network_export __mask "${__iface}_prefix6_mask" || return 1 - __network_export __var "${__iface}_prefix6_address" "/$__mask" + __network_export "$__var" "${__iface}_prefix6_address" "/$__mask" return $? } -- cgit v1.2.3 From fb1862c487ba175fb3222d3cb0d233e2cf07c597 Mon Sep 17 00:00:00 2001 From: juhosg Date: Mon, 18 Feb 2013 09:56:23 +0000 Subject: base-files: introduce commonly used helper functions for setting leds Currently, most platforms define such helpers in their own diag.sh implementation with almost identical code. By factoring out the common ground it's possible to simplify maintainability and homogenize the haptics over multiple platforms (so far as is reasonably practicable, in a next step). [juhosg: - fix led_set_attr parameters in led_timer - add led_morse and status_led_set_morse helpers - add status_led_blink_{preinit,failsafe} helpers] Signed-off-by: Michael Heimpold Signed-off-by: Gabor Juhos git-svn-id: svn://svn.openwrt.org/openwrt/trunk@35648 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/leds.sh | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 package/base-files/files/lib/functions/leds.sh (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/leds.sh b/package/base-files/files/lib/functions/leds.sh new file mode 100644 index 000000000..743c7da78 --- /dev/null +++ b/package/base-files/files/lib/functions/leds.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# Copyright (C) 2013 OpenWrt.org + +led_set_attr() { + [ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2" +} + +led_timer() { + led_set_attr $1 "trigger" "timer" + led_set_attr $1 "delay_on" "$2" + led_set_attr $1 "delay_off" "$3" +} + +led_on() { + led_set_attr $1 "trigger" "none" + led_set_attr $1 "brightness" 255 +} + +led_off() { + led_set_attr $1 "trigger" "none" + led_set_attr $1 "brightness" 0 +} + +led_morse() { + led_set_attr $1 "trigger" "morse" + led_set_attr $1 "delay" "$2" + led_set_attr $1 "message" "$3" +} + +status_led_set_timer() { + led_timer $status_led "$1" "$2" + [ -n "$status_led2" ] && led_timer $status_led2 "$1" "$2" +} + +status_led_set_heartbeat() { + led_set_attr $status_led "trigger" "heartbeat" +} + +status_led_set_morse() { + led_morse $status_led "$1" "$2" + [ -n "$status_led2" ] && led_morse $status_led2 "$1" "$2" +} + +status_led_on() { + led_on $status_led + [ -n "$status_led2" ] && led_on $status_led2 +} + +status_led_off() { + led_off $status_led + [ -n "$status_led2" ] && led_off $status_led2 +} + +status_led_blink_slow() { + led_timer $status_led 1000 1000 +} + +status_led_blink_fast() { + led_timer $status_led 100 100 +} + +status_led_blink_preinit() { + led_timer $status_led 200 200 +} + +status_led_blink_failsafe() { + led_timer $status_led 50 50 +} -- cgit v1.2.3 From 7b026cdf8a8da5c160105cae06813c956766b65c Mon Sep 17 00:00:00 2001 From: cyrus Date: Tue, 9 Apr 2013 08:03:08 +0000 Subject: Adapt default network configuration for IPv6 git-svn-id: svn://svn.openwrt.org/openwrt/trunk@36278 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/uci-defaults.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh index 477c00cfd..959ae5eba 100644 --- a/package/base-files/files/lib/functions/uci-defaults.sh +++ b/package/base-files/files/lib/functions/uci-defaults.sh @@ -150,6 +150,8 @@ set network.loopback.ifname='lo' set network.loopback.proto='static' set network.loopback.ipaddr='127.0.0.1' set network.loopback.netmask='255.0.0.0' +set network.globals='globals' +set network.globals.ula_prefix='auto' EOF } @@ -174,6 +176,7 @@ set network.lan.type='bridge' set network.lan.proto='static' set network.lan.ipaddr='192.168.1.1' set network.lan.netmask='255.255.255.0' +set network.lan.ip6assign='64' EOF } @@ -184,6 +187,9 @@ ucidef_set_interface_wan() { set network.wan='interface' set network.wan.ifname='$ifname' set network.wan.proto='dhcp' +set network.wan6='interface' +set network.wan6.ifname='@wan' +set network.wan6.proto='dhcpv6' EOF } -- cgit v1.2.3 From c37a21d752af2af20e31fde9235c85161a8c5e8a Mon Sep 17 00:00:00 2001 From: cyrus Date: Mon, 22 Apr 2013 19:40:16 +0000 Subject: Change default IPv6 config to enable DHCPv6-PD git-svn-id: svn://svn.openwrt.org/openwrt/trunk@36384 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/uci-defaults.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh index 959ae5eba..bf6fe1e30 100644 --- a/package/base-files/files/lib/functions/uci-defaults.sh +++ b/package/base-files/files/lib/functions/uci-defaults.sh @@ -176,7 +176,7 @@ set network.lan.type='bridge' set network.lan.proto='static' set network.lan.ipaddr='192.168.1.1' set network.lan.netmask='255.255.255.0' -set network.lan.ip6assign='64' +set network.lan.ip6assign='60' EOF } -- cgit v1.2.3 From bd4ec4d567494ce433865557e7896a2072f16707 Mon Sep 17 00:00:00 2001 From: jow Date: Mon, 6 May 2013 09:33:56 +0000 Subject: base-files: change network_find_wan() procedure to ignore default gateways in different routing tables git-svn-id: svn://svn.openwrt.org/openwrt/trunk@36553 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/lib/functions/network.sh | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'package/base-files/files/lib/functions') diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index 369fa3dbd..d86a504bf 100644 --- a/package/base-files/files/lib/functions/network.sh +++ b/package/base-files/files/lib/functions/network.sh @@ -80,16 +80,20 @@ __network_parse_ifstatus() while json_is_a "$__idx" object; do json_select "$((__idx++))" - json_get_var __tmp target - - case "${__tmp}" in - 0.0.0.0) - __network_set_cache "${__key}_gateway4" nexthop - ;; - ::) - __network_set_cache "${__key}_gateway6" nexthop - ;; - esac + json_get_var __tmp table + + if [ -z "$__tmp" ]; then + json_get_var __tmp target + + case "${__tmp}" in + 0.0.0.0) + __network_set_cache "${__key}_gateway4" nexthop + ;; + ::) + __network_set_cache "${__key}_gateway6" nexthop + ;; + esac + fi json_select ".." -- cgit v1.2.3