summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2022-03-31 18:29:20 -0400
committerDave Henderson <dhenderson@gmail.com>2022-05-06 22:58:04 -0400
commit254de4e4e97fe1550d7092bbf25a8a6c31f0fd74 (patch)
tree43130543e5ddb045db63a8b90d689c44ceb17e6d /docs
parent2f294d7884667800579e3ac3a16241e2df8698bb (diff)
Rename to CIDR*, generate docs
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/content/functions/net.md139
1 files changed, 139 insertions, 0 deletions
diff --git a/docs/content/functions/net.md b/docs/content/functions/net.md
index bbea71e0..ca0d8da1 100644
--- a/docs/content/functions/net.md
+++ b/docs/content/functions/net.md
@@ -13,6 +13,7 @@ calculations.
[RFC 4632]: http://tools.ietf.org/html/rfc4632
[RFC 4291]: http://tools.ietf.org/html/rfc4291
[`inet.af/netaddr`]: https://pkg.go.dev/inet.af/netaddr
+[`net`]: https://pkg.go.dev/net
## `net.LookupIP`
@@ -320,3 +321,141 @@ $ gomplate -i '{{ $range := net.ParseIPRange "1.2.3.0-1.2.3.233" -}}
{{ $range.Prefixes }}'
[1.2.3.0/25 1.2.3.128/26 1.2.3.192/27]
```
+
+## `net.CIDRHost` _(experimental)_
+**Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
+
+[experimental]: ../config/#experimental
+
+Calculates a full host IP address for a given host number within a given IP network address prefix.
+
+The IP network can be in the form `"192.168.1.0/24"` or `"2001::db8::/32"`,
+the CIDR notations defined in [RFC 4632][] and [RFC 4291][].
+
+Any of `netip.Addr`'s methods may be called on the resulting value. See
+[the docs](https://pkg.go.dev/net/netip#Addr) for details.
+
+### Usage
+
+```go
+net.CIDRHost hostnum prefix
+```
+```go
+prefix | net.CIDRHost hostnum
+```
+
+### Arguments
+
+| name | description |
+|------|-------------|
+| `hostnum` | _(required)_ Is a whole number that can be represented as a binary integer with no more than the number of digits remaining in the address after the given prefix. |
+| `prefix` | _(required)_ Must be given in CIDR notation. It must represent either an IPv4 or IPv6 prefix, containing a `/`. String or [`net.IPNet`](https://pkg.go.dev/net#IPNet) object returned from `net.ParseIPPrefix` can by used. |
+
+### Examples
+
+```console
+$ gomplate -i '{{ "10.12.127.0/20" | net.CIDRHost 268 }}'
+10.12.113.12
+```
+
+## `net.CIDRNetmask` _(experimental)_
+**Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
+
+[experimental]: ../config/#experimental
+
+The result is a subnet address formatted in the conventional dotted-decimal IPv4 address syntax or hexadecimal IPv6 address syntax, as expected by some software.
+
+Any of `netip.Addr`'s methods may be called on the resulting value. See
+[the docs](https://pkg.go.dev/net/netip#Addr) for details.
+
+### Usage
+
+```go
+net.CIDRNetmask prefix
+```
+```go
+prefix | net.CIDRNetmask
+```
+
+### Arguments
+
+| name | description |
+|------|-------------|
+| `prefix` | _(required)_ Must be given in CIDR notation. It must represent either an IPv4 or IPv6 prefix, containing a `/`. String or [`net.IPNet`](https://pkg.go.dev/net#IPNet) object returned from `net.ParseIPPrefix` can by used. |
+
+### Examples
+
+```console
+$ gomplate -i '{{ net.CIDRNetmask "10.12.127.0/20" }}'
+255.255.240.0
+$ gomplate -i '{{ net.CIDRNetmask "fd00:fd12:3456:7890:00a2::/72" }}'
+ffff:ffff:ffff:ffff:ff00::
+```
+
+## `net.CIDRSubnets` _(experimental)_
+**Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
+
+[experimental]: ../config/#experimental
+
+Calculates a subnet address within given IP network address prefix.
+
+Any of `netip.Prefix`'s methods may be called on the resulting values. See
+[the docs](https://pkg.go.dev/net/netip#Prefix) for details.
+
+### Usage
+
+```go
+net.CIDRSubnets newbits prefix
+```
+```go
+prefix | net.CIDRSubnets newbits
+```
+
+### Arguments
+
+| name | description |
+|------|-------------|
+| `newbits` | _(required)_ Is the number of additional bits with which to extend the prefix. For example, if given a prefix ending in `/16` and a `newbits` value of `4`, the resulting subnet address will have length `/20`. |
+| `prefix` | _(required)_ Must be given in CIDR notation. It must represent either an IPv4 or IPv6 prefix, containing a `/`. String or [`net.IPNet`](https://pkg.go.dev/net#IPNet) object returned from `net.ParseIPPrefix` can by used. |
+
+### Examples
+
+```console
+$ gomplate -i '{{ index ("10.0.0.0/16" | net.CIDRSubnets 2) 1 }}'
+10.0.64.0/18
+$ gomplate -i '{{ net.CIDRSubnets 2 "10.0.0.0/16" -}}'
+[10.0.0.0/18 10.0.64.0/18 10.0.128.0/18 10.0.192.0/18]
+```
+
+## `net.CIDRSubnetSizes` _(experimental)_
+**Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
+
+[experimental]: ../config/#experimental
+
+Calculates a sequence of consecutive IP address ranges within a particular CIDR prefix.
+
+Any of `netip.Prefix`'s methods may be called on the resulting values. See
+[the docs](https://pkg.go.dev/net/netip#Prefix) for details.
+
+### Usage
+
+```go
+net.CIDRSubnetSizes newbits... prefix
+```
+```go
+prefix | net.CIDRSubnetSizes newbits...
+```
+
+### Arguments
+
+| name | description |
+|------|-------------|
+| `newbits...` | _(required)_ Numbers of additional network prefix bits for returned address range. |
+| `prefix` | _(required)_ Must be given in CIDR notation. It must represent either an IPv4 or IPv6 prefix, containing a `/`. String or [`net.IPNet`](https://pkg.go.dev/net#IPNet) object returned from `net.ParseIPPrefix` can by used. |
+
+### Examples
+
+```console
+$ gomplate -i '{{ net.CIDRSubnetSizes 4 4 8 4 "10.1.0.0/16" -}}'
+[10.1.0.0/20 10.1.16.0/20 10.1.32.0/24 10.1.48.0/20]
+```