| 1 | // Copyright IBM Corp. 2020, 2025 |
| 2 | // SPDX-License-Identifier: MPL-2.0 |
| 3 | |
| 4 | package cidrscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/ |
| 5 | |
| 6 | import ( |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 8 | "netscip-go gomod github.com/golang/go/src go1.24.0 net/" |
| 9 | |
| 10 | "github.com/zclconf/go-cty/ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/" |
| 11 | "github.com/zclconf/go-cty/cty/functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/" |
| 12 | ) |
| 13 | |
| 14 | // NetmaskFunc is a function that converts an IPv4 address prefix given in CIDR |
| 15 | // notation into a subnet mask address. |
| 16 | var NetmaskFuncscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc. = functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.Newscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/New().(&functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.Specscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#{ |
| 17 | Paramsscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#Params.: []functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.Parameterscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#{ |
| 18 | { |
| 19 | Namescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#Name.: "prefix", |
| 20 | Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#Type.: ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Stringscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/String., |
| 21 | }, |
| 22 | }, |
| 23 | Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#Type.: functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.StaticReturnTypescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/StaticReturnType().(ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Stringscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/String.), |
| 24 | Implscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#Impl.: func(argsscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:args. []ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#, retTypescip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:retType. ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Type#) (retscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:ret. ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#, errscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:err. error) { |
| 25 | _, network, errscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:err. := netscip-go gomod github.com/golang/go/src go1.24.0 net/.ParseCIDRscip-go gomod github.com/golang/go/src go1.24.0 net/ParseCIDR().(argsscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:args.[0].AsStringscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#AsString().()) |
| 26 | if errscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:err. != nil { |
| 27 | return ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.UnknownValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/UnknownVal().(ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Stringscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/String.), fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("invalid CIDR expression: %s", errscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc:err.) |
| 28 | } |
| 29 | |
| 30 | return ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().(netscip-go gomod github.com/golang/go/src go1.24.0 net/.IPscip-go gomod github.com/golang/go/src go1.24.0 net/IP#(network.Maskscip-go gomod github.com/golang/go/src go1.24.0 net/IPNet#Mask.).Stringscip-go gomod github.com/golang/go/src go1.24.0 net/IP#String().()), nil |
| 31 | }, |
| 32 | }) |
| 33 | |
| 34 | // Netmask converts an IPv4 address prefix given in CIDR notation into a subnet mask address. |
| 35 | func Netmaskscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/Netmask().(prefix ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#) (ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#, error) { |
| 36 | return NetmaskFuncscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/cidr`/NetmaskFunc..Callscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Function#Call().([]ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#{prefix}) |
| 37 | } |