meshwizard: add option addchannelbefore
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / check-range-in-range.sh
1 #!/bin/sh
2 # Checks whether a netrange is inside another netrange, returns 1 if true
3 # Takes two arguments: $1: net from which we want to know if it is inside $2
4 # nets need to be given in CIDR notation
5
6 dir=$(dirname $0)
7
8 awk -f $dir/common.awk -f - $* <<EOF
9 BEGIN {
10
11         slpos=index(ARGV[1],"/")
12         ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
13         netmask=compl(2**(32-int(substr(ARGV[1],slpos+1)))-1)
14         network=and(ipaddr,netmask)
15         broadcast=or(network,compl(netmask))
16
17         slpos2=index(ARGV[2],"/")
18         ipaddr2=ip2int(substr(ARGV[2],0,slpos2-1))
19         netmask2=compl(2**(32-int(substr(ARGV[2],slpos2+1)))-1)
20         network2=and(ipaddr2,netmask2)
21         broadcast2=or(network2,compl(netmask2))
22
23         if (network >= network2) {
24                 if (network <= broadcast2) {
25                         if (broadcast <= broadcast2) {
26                                 print "1"
27                         }
28                 }
29         }
30 }
31 EOF