Skip to content

Commit

Permalink
Change cidrhost() to get IP from end of the range when negative numbe…
Browse files Browse the repository at this point in the history
…r given

Ref: apparentlymart/go-cidr#2
  • Loading branch information
tmshn committed Apr 19, 2017
1 parent 4a78258 commit eabda4b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
15 changes: 15 additions & 0 deletions config/interpolate_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,26 @@ func TestInterpolateFuncCidrHost(t *testing.T) {
"192.168.1.5",
false,
},
{
`${cidrhost("192.168.1.0/24", -5)}`,
"192.168.1.251",
false,
},
{
`${cidrhost("192.168.1.0/24", -256)}`,
"192.168.1.0",
false,
},
{
`${cidrhost("192.168.1.0/30", 255)}`,
nil,
true, // 255 doesn't fit in two bits
},
{
`${cidrhost("192.168.1.0/30", -255)}`,
nil,
true, // 255 doesn't fit in two bits
},
{
`${cidrhost("not-a-cidr", 6)}`,
nil,
Expand Down
9 changes: 8 additions & 1 deletion vendor/github.com/apparentlymart/go-cidr/cidr/cidr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,10 @@
"revisionTime": "2016-08-22T23:00:20Z"
},
{
"checksumSHA1": "kn+zdUr5TNsoAX8BgjOaWYtMT5U=",
"checksumSHA1": "FIL83loX9V9APvGQIjJpbxq53F0=",
"path": "github.com/apparentlymart/go-cidr/cidr",
"revision": "a3ebdb999b831ecb6ab8a226e31b07b2b9061c47"
"revision": "7e4b007599d4e2076d9a81be723b3912852dda2c",
"revisionTime": "2017-04-18T07:21:50Z"
},
{
"checksumSHA1": "yicZ9OtLcy3iCgraWO015yeoO5E=",
Expand Down
6 changes: 4 additions & 2 deletions website/source/docs/configuration/interpolation.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ The supported built-in functions are:
* `chomp(string)` - Removes trailing newlines from the given string.

* `cidrhost(iprange, hostnum)` - Takes an IP address range in CIDR notation
and creates an IP address with the given host number. For example,
`cidrhost("10.0.0.0/8", 2)` returns `10.0.0.2`.
and creates an IP address with the given host number. If given host
number is negative, the count starts from the end of the range.
For example, `cidrhost("10.0.0.0/8", 2)` returns `10.0.0.2` and
`cidrhost("10.0.0.0/8", 2)` returns `10.255.255.254`.

* `cidrnetmask(iprange)` - Takes an IP address range in CIDR notation
and returns the address-formatted subnet mask format that some
Expand Down

0 comments on commit eabda4b

Please sign in to comment.