dhcp service example: rewrite "private network to mask" as case statement
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 8 Feb 2019 09:37:05 +0000 (10:37 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 8 Feb 2019 09:37:05 +0000 (10:37 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
examples/var_service/dhcp_if/convert2ipconf

index 038b1f7f1cfb9c95e53f89cdecdb8263e6888f7f..31e3c7fde159e2bf1e41c83bf0fbbc5c36ee3eb9 100755 (executable)
@@ -29,14 +29,19 @@ test "$ip" || exit 1
 # some servers do not return subnet option.
 # guess it for standard private networks.
 if ! test "$mask"; then
-       if test "$ip" != "${ip#192.168.}"; then
-               mask=16
-       elif test "$ip" != "${ip#172.16.}"; then
-               mask=12
-               # repeat for each in 172.17. - 172.31. range?
-       elif test "$ip" != "${ip#10.}"; then
-               mask=8
-       fi
+       case "$ip" in
+       10.*)
+               mask=8;;
+       192.168.*)
+               mask=16;;
+       #172.16-31.x.x
+       172.1[6789].*)
+               mask=12;;
+       172.2[0123456789].*)
+               mask=12;;
+       172.3[01].*)
+               mask=12;;
+       esac
 fi
 
 # some servers do not return router option.