aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Prindeville <philipp@redfish-solutions.com>2023-11-19 12:26:15 -0700
committerKevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>2023-11-19 20:36:40 +0000
commit1481d5cb0b70d15edea607ed7cfc718c85166e98 (patch)
tree3cd56a17755bea91b7c5bdf4f90d4fd1c8fea9e2
parente9ac1b19e0f3d383ab83373c261bfb5527a29521 (diff)
downloadupstream-1481d5cb0b70d15edea607ed7cfc718c85166e98.tar.gz
upstream-1481d5cb0b70d15edea607ed7cfc718c85166e98.tar.bz2
upstream-1481d5cb0b70d15edea607ed7cfc718c85166e98.zip
base-files: ipcalc.sh: Should take netmask or prefix after slash
dnmasq.init now invokes ipcalc.sh as either: ipcalc.sh address/netmask ... or: ipcalc.sh address/prefix but the existing version doesn't accept the 2nd notation. We're trying to rationalize the usage of ipcalc.sh, and here we add support for the 2nd format. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
-rwxr-xr-xpackage/base-files/files/bin/ipcalc.sh20
1 files changed, 10 insertions, 10 deletions
diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh
index 827cb5dc2ea..9b5e5accdca 100755
--- a/package/base-files/files/bin/ipcalc.sh
+++ b/package/base-files/files/bin/ipcalc.sh
@@ -34,19 +34,19 @@ function compl32(v) {
BEGIN {
slpos=index(ARGV[1],"/")
- if (slpos == 0) {
- ipaddr=ip2int(ARGV[1])
- dotpos=index(ARGV[2],".")
- if (dotpos == 0)
- netmask=compl32(2**(32-int(ARGV[2]))-1)
- else
- netmask=ip2int(ARGV[2])
- } else {
- ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
- netmask=compl32(2**(32-int(substr(ARGV[1],slpos+1)))-1)
+ if (slpos != 0) {
+ # rearrange arguments to not use compound notation
ARGV[4]=ARGV[3]
ARGV[3]=ARGV[2]
+ ARGV[2]=substr(ARGV[1],slpos+1)
+ ARGV[1]=substr(ARGV[1],0,slpos-1)
}
+ ipaddr=ip2int(ARGV[1])
+ dotpos=index(ARGV[2],".")
+ if (dotpos == 0)
+ netmask=compl32(2**(32-int(ARGV[2]))-1)
+ else
+ netmask=ip2int(ARGV[2])
network=and(ipaddr,netmask)
prefix=32-bitcount(compl32(netmask))