Sfoglia il codice sorgente

init/functions: better not use ipcalc which is not present on minimal distro

Frédéric Pierret (fepitre) 4 anni fa
parent
commit
3f5dc53d75
1 ha cambiato i file con 5 aggiunte e 1 eliminazioni
  1. 5 1
      init/functions

+ 5 - 1
init/functions

@@ -158,9 +158,13 @@ get_qubes_managed_iface() {
     fi
 }
 
+# Based on: https://forums.gentoo.org/viewtopic-t-888736-start-0.html
 get_prefix_from_subnet() {
     local subnet="$1"
-    prefix="$(ipcalc -p 0.0.0.0 "$subnet" | sed 's/PREFIX=//')"
+    local x=${subnet##*255.}
+    set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) "${x%%.*}"
+    x=${1%%$3*}
+    prefix=$(( $2 + (${#x}/4) ))
 
     if [ "x$prefix" != "x" ]; then
         echo "$prefix"