]>
git.ipfire.org Git - people/arne_f/network.git/blob - functions.util
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 # Print a pretty error message
24 echo -e " ${FAIL}ERROR${NORMAL} : $@" >&2
27 # Print a pretty warn message
29 echo -e " ${WARN}WARNING${NORMAL}: $@" >&2
36 done |
sort |
tr "\n" " "
39 function config_read
() {
40 local config_file
=${1}
42 if [ -e "${config_file}" ]; then
48 function config_write
() {
49 local config_file
=${1}
52 # Check if all values to be written are sane
58 for param
in $
(listsort $@
); do
59 echo "${param}=\"${!param}\"" >> ${config_file}
63 function config_print() {
66 for param in $(listsort $@); do
67 printf "%-16s = %s
\n" "${param}" "${!param}"
71 function config_check() {
72 # If there is a function defined that is called __check
73 # we call that function
74 [ -n "$
(type -t _check
)" ] && _check
77 function network_config_set() {
78 while [ $# -gt 0 ]; do
84 warning "Invalid parameter given
: ${1}"
90 # Write configuration to disk
94 function network_config_read() {
95 config_read ${CONFIG_FILE}
98 function network_config_write() {
99 config_write ${CONFIG_FILE} ${CONFIG_FILE_PARAMS}
102 function network_config_print() {
103 config_print ${CONFIG_FILE_PARAMS}
106 # Speedup function to avoid a call of the basename binary
107 function basename() {
114 [ "${!param}" = "yes" ] || [ "${!param}" = "on" ] || [ "${!param}" = "1" ]
117 function mac_generate() {
119 for i in $(seq 0 5); do
120 mac[i]="0x$
(uuid | cut
-c 1-2)"
123 # Remove multicast bit
124 # and set address is software assigned
125 # XXX must doublecheck if this works
126 mac[0]=$((mac[0] & 0xfe))
127 mac[0]=$((mac[0] | 0x02))
130 for i in ${mac[*]}; do
131 if [ -n "${output}" ]; then
135 output="${output}$
(printf "%02x" ${i})"
138 # Check if output is valid
139 assert mac_is_valid ${output}
144 function mac_is_valid() {
147 [[ ${mac} =~ ^([0-9a-f]{2}\:){5}[0-9a-f]{2}$ ]]
151 cat /proc/sys/kernel/random/uuid
165 [ "${var}" = "${i}" ] && return ${EXIT_OK}
174 isoneof
${var} 0 1 no
yes on off
177 function isinteger
() {
180 [[ ${var} =~ ^
[0-9]+$
]]
192 if ! ${assertion}; then
193 error
"Assertion '${assertion}' failed."