]> git.ipfire.org Git - people/ms/network.git/commitdiff
Some work on making things faster.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Jun 2012 14:51:54 +0000 (14:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Jun 2012 14:51:54 +0000 (14:51 +0000)
No functional changes.

functions.util

index 694c7a408672ad2770026a5c0c04b6e12a0dfb3a..0b646f7ddd610166845dcd30f1c589492c24a0ef 100644 (file)
@@ -75,6 +75,12 @@ function basename() {
        echo "${1##*/}"
 }
 
+function touch() {
+       local file=${1}
+
+       : > ${file}
+}
+
 function enabled() {
        local param=${1}
 
@@ -82,31 +88,38 @@ function enabled() {
 }
 
 function mac_generate() {
-       local mac=()
+       # Get a bunch of random hex digits
+       # and remove all dashes from the input.
+       local random=$(</proc/sys/kernel/random/uuid)
+       random=${random//-/}
+       assert isset random
+
+       local output
+
+       local i o
        for i in $(seq 0 5); do
-               mac[i]="$(uuid)"
-               mac[i]="0x${mac[i]:0:2}"
-       done
+               o="0x${random:0:2}"
+               random="${random:2:${#random}}"
 
-       # Remove multicast bit
-       # and set address is software assigned
-       # XXX must doublecheck if this works
-       mac[0]=$((mac[0] & 0xfe))
-       mac[0]=$((mac[0] | 0x02))
+               case "${i}" in
+                       0)
+                               # Remove multicast bit
+                               # and set address is software assigned
+                               o=$(( ${o} & 0xfe ))
+                               o=$(( ${o} | 0x02 ))
 
-       local output
-       for i in ${mac[*]}; do
-               if [ -n "${output}" ]; then
-                       output="${output}:"
-               fi
-       
-               output="${output}$(printf "%02x" ${i})"
+                               printf -v output "%02x" "${o}"
+                               ;;
+                       *)
+                               printf -v output "%s:%02x" "${output}" "${o}"
+                               ;;
+               esac
        done
 
        # Check if output is valid
        assert mac_is_valid ${output}
 
-       echo ${output}
+       echo "${output}"
 }
 
 function mac_format() {