aboutsummaryrefslogtreecommitdiff
path: root/package/base-files/files/bin/ipcalc.sh
Commit message (Collapse)AuthorAge
* base-files: ipcalc.sh: Add netmask2prefix functionPhilip Prindeville2023-12-12
| | | | | | Also add is_contiguous to check if it's a valid netmask. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: ipcalc.sh: Add prefix-to-netmask conversionPhilip Prindeville2023-12-12
| | | | | | | Seems like it might be used in other places, so factor it into the library. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: ipcalc.sh: Add some commentary, etc.Philip Prindeville2023-12-12
| | | | | | | | Explain some of the more obscure logic, or where we deviate from what the original awk code did. Also, give a count of the usable addresses on the subnet. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: ipcalc.sh: Add support for decimal outputPhilip Prindeville2023-12-12
| | | | | | | | This is useful if you later need to perform numeric range-checking on addresses, i.e. to see if an address falls inside a CIDR range, etc. and what interface it corresponds to. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: ipcalc.sh: Rewrite in pure shellPhilip Prindeville2023-12-12
| | | | | | Also add better error checking on input. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: ipcalc.sh: Should take netmask or prefix after slashPhilip Prindeville2023-11-19
| | | | | | | | | | | | | | | | 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>
* base-files: ipcalc.sh: make check slightly more future-proofLeon M. Busch-George2023-09-25
| | | | | | | The previous code handling the equal-condition might be removed or altered in the future and the case might be overlooked. Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
* base-files: ipcalc.sh: turn error into warningLeon M. Busch-George2023-09-25
| | | | | | | | | | | | | | Some users have their routers configured to supply a DHCP range that includes the local interface address. That worked with dnsmasq because it automatically skips the local address. Re-enable those existing configurations for the release and hint at possible future problems. Signed-off-by: Leon M. Busch-George <leon@georgemail.eu> [ wrap commit description and remove unecessary text ] Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* base-files: ipcalc.sh clarify range parameters in commentLeon M. Busch-George2023-09-25
| | | | | | | | To avoid confusion when working with ipcalc.sh, clarify that the last two parameters belong to the range calculation and rename 'num' to the slightly less ambiguous 'size'. Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
* base-files: ipcalc.sh: don't print broadcast addr for prefix > 30Leon M. Busch-George2023-09-25
| | | | | | | | | | Printing a broadcast address doesn't make any sense for /31 and /32 prefixes. Strictly speaking, the same goes for the network address but it is useful to get the first address in the prefix, e.g. to create a canonical CIDR notation "$NETWORK/$PREFIX". Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
* base-files: ipcalc.sh: correctly set limit for prefix > 30Leon M. Busch-George2023-09-25
| | | | | | | | For /31 and /32 prefixes, there are only host addresses - no network and broadcast address with all-zero and all-one bits. Reflect this when setting the limit. Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
* base-files: ipcalc.sh: correctly interpret num parameterLeon M. Busch-George2023-09-25
| | | | | | | | The start and end addresses are inclusive. Thus, adding num without substracting one results in num + 1 addresses. Add the substraction and to implement the documented behaviour. Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
* base-files: ipcalc.sh: fix awk regex syntaxLeon M. George2023-02-07
| | | | | | It worked fine before but gawk warns about it. Signed-off-by: Leon M. George <leon@georgemail.eu>
* base-files: ipcalc.sh: trim for statementLeon M. George2023-02-07
| | | | | | For gawk compatibility. Signed-off-by: Leon M. George <leon@georgemail.eu>
* base-files: ipcalc.sh: use shebang to invoke awkLeon M. George2023-02-07
| | | | | | | | | | | There's hardly an shell logic in ipcalc.sh and a $* that would garble parameter positions. Move the awk invokation to the shebang. A rename from "ipcalc.sh" to "ipcalc" is desirable but could prove tricky with packages in other repositories depending on the filename. Signed-off-by: Leon M. George <leon@georgemail.eu>
* base-files: ipcalc.sh: fail when network is too smallLeon M. George2023-02-07
| | | | | | | | It's possible to move range boundaries in a way that the start address lies behind the end address. Detect this condition and exit with an error message. Signed-off-by: Leon M. George <leon@georgemail.eu>
* base-files: ipcalc.sh: don't include own address in rangeLeon M. George2023-02-07
| | | | | | Make sure our own address doesn't lie in the calculated range. Signed-off-by: Leon M. George <leon@georgemail.eu>
* base-files: ipcalc.sh: check for params before calculating start/endLeon M. George2023-02-07
| | | | | | | With this patch, ipcalc only calculates range boundaries if the corresponding parameters are supplied. Signed-off-by: Leon M. George <leon@georgemail.eu>
* base-files: ipcalc.sh: support bit length as netmask parameterJo-Philipp Wich2013-12-16
| | | | SVN-Revision: 39100
* base-files: fix whitespacesLuka Perkov2013-12-09
| | | | | | Signed-off-by: Luka Perkov <luka@openwrt.org> SVN-Revision: 39006
* base-files: ipcalc.sh: fix broken calculations on 64bit systemsJo-Philipp Wich2012-12-23
| | | | | | | | Calculate complements by using awk's xor() function with a mask of 0xffffffff instead of relying on the compl() function which appears to produce broken results on certain 64bit architectures. SVN-Revision: 34875
* ipcalc.sh CIDR notation Hi,Jo-Philipp Wich2011-05-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the attached patch makes ipcalc.sh accept IP/Netmask combinations in CIDR notation. Before you could only do: # sh ipcalc.sh 192.168.0.0 255.255.255.0 1 10 IP=192.168.0.0 NETMASK=255.255.255.0 BROADCAST=192.168.0.255 NETWORK=192.168.0.0 PREFIX=24 START=192.168.0.1 END=192.168.0.11 with this patch you can also execute it with: sh ipcalc.sh 192.168.0.0/24 1 10 IP=192.168.0.0 NETMASK=255.255.255.0 BROADCAST=192.168.0.255 NETWORK=192.168.0.0 PREFIX=24 START=192.168.0.1 END=192.168.0.11 The patch is based on #1260 [1], i just changed one line to calculate the START end END ips right. I wonder why that never got included. If there is no reason not to do i would like to ask you to commit that patch, because its a functionality i (and probably others) miss quite often. Btw, i also fixed 4 useless tabs, that might look a bit strange in the patch. Regards, Manuel SVN-Revision: 26930
* base-files: remove a stale reference to /usr/lib/common.awk (thx, swalker)Felix Fietkau2011-02-13
| | | | SVN-Revision: 25528
* base-files: /usr/lib/common.awk is only used by /bin/ipcalc.sh, move the ↵Felix Fietkau2011-02-13
| | | | | | code there SVN-Revision: 25495
* base-files: ipcalc.sh: fix off-by-one in range-calculationJo-Philipp Wich2009-06-29
| | | | SVN-Revision: 16619
* upgrade dnsmasq to latest version, rewrite dnsmasq init script for uci, ↵Felix Fietkau2007-03-17
rename /bin/ipcalc to /bin/ipcalc.sh (fixes #1452) SVN-Revision: 6595