IP subnets can be obtained from the data model or via pattern matching against configuration text (see Section Details on Patterns for how to match subnets). In addition, there are three ways to construct IP subnets from other values:
ipSubnet(string): Construct a subnet from a string, such asipSubnet("1.2.3.4/24").ipSubnet(ipAddress, number): Construct a subnet from an IP address and length, such asipSubnet(ipAddress("1.2.3.4"), 24).ipSubnet(ipAddress, netmask): Construct a subnet from an IP address and a net mask, such asipSubnet(ipAddress("1.2.3.4"), ipAddress("255.255.128.0"))which is equivalent toipSubnet("1.2.3.4/17").
In addition, the following functions work on subnets:
-
length(subnet): the length of the subnet. For example,length(ipSubnet("1.2.3.4/24"))is24. -
address(subnet): returns the IP address for the subnet. For example,address(ipSubnet("1.2.3.4/24"))isipAddress("1.2.3.4"). -
networkAddress(subnet): returns the network IP address for the subnet, that is the IP address for the subnet, with all host bits set to 0. For example,networkAddress(ipSubnet("1.2.3.4/24"))isipAddress("1.2.3.0"). -
broadcastAddress(subnet): returns the broadcast IP address for the subnet, that is, the IP address for the subnet, with all host bits set to 1. For example,broadcastAddress(ipSubnet("1.2.3.4/24"))isipAddress("1.2.3.255"). -
ip in subnetandip not in subnet: returns a boolean value indicating whether the given IP address (the first argument) is a member of the given IP subnet (the second argument). For example,ipAddress("1.2.3.4") in ipSubnet("1.2.3.4/24")would betrueandipAddress("1.2.3.4") not in ipSubnet("1.2.3.4/24")would befalse. -
isIPv4(ipSubnet): Tests whetheripSubnetis an IPv4 subnet. For example,isIPv4(ipSubnet("192.168.1.0/24"))returnstrueandisIPv4(ipSubnet("2001:0db8:abcd:0000::/56"))returnsfalse. -
isIPv6(ipSubnet): Tests whetheripSubnetis an IPv6 subnet. For example,isIPv6(ipSubnet("2001:0db8:abcd:0000::/56"))returnstrueandisIPv6(ipSubnet("192.168.1.0/24"))returnsfalse.