Skip to main content

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 as ipSubnet("1.2.3.4/24").
  • ipSubnet(ipAddress, number): Construct a subnet from an IP address and length, such as ipSubnet(ipAddress("1.2.3.4"), 24).
  • ipSubnet(ipAddress, netmask): Construct a subnet from an IP address and a net mask, such as ipSubnet(ipAddress("1.2.3.4"), ipAddress("255.255.128.0")) which is equivalent to ipSubnet("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")) is 24.

  • address(subnet): returns the IP address for the subnet. For example, address(ipSubnet("1.2.3.4/24")) is ipAddress("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")) is ipAddress("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")) is ipAddress("1.2.3.255").

  • ip in subnet and ip 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 be true and ipAddress("1.2.3.4") not in ipSubnet("1.2.3.4/24") would be false.

  • isIPv4(ipSubnet): Tests whether ipSubnet is an IPv4 subnet. For example, isIPv4(ipSubnet("192.168.1.0/24")) returns true and isIPv4(ipSubnet("2001:0db8:abcd:0000::/56")) returns false.

  • isIPv6(ipSubnet): Tests whether ipSubnet is an IPv6 subnet. For example, isIPv6(ipSubnet("2001:0db8:abcd:0000::/56")) returns true and isIPv6(ipSubnet("192.168.1.0/24")) returns false.

Functions