opentofu/internal/ipaddr
Martin Atkins 9d9c1486fa ipaddr: Exempt from all lint rules
The code in this package is all snapshot from the Go codebase in older
versions, inlined here to allow OpenTofu's cidr-calculation-related
functions to preserve their original behavior despite upstream changing
the parsing rules in a breaking way.

This code is intentionally modified as little as possible from the upstream
code it was derived from. We are imposing on ourselves considerably
stricter style conventions than the Go project follows and so we need
to disable various linters for this package to allow this code to remain
written in the Go idiomatic style, rather than in OpenTofu's stricter
local style.

In particular, we've chosen to prohibit ourselves from using named return
values or package-global variables, despite those both being typical in the
standard library and in other codebases.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-06 08:36:42 -08:00
..
doc.go Update copyright notice (#1232) 2024-02-08 09:48:59 +00:00
ip_test.go ipaddr: Exempt from all lint rules 2025-01-06 08:36:42 -08:00
ip.go ipaddr: Exempt from all lint rules 2025-01-06 08:36:42 -08:00
LICENSE lang/funcs: Preserve IP address leading zero behavior from Go 1.16 2021-08-17 15:20:05 -07:00
parse.go ipaddr: Exempt from all lint rules 2025-01-06 08:36:42 -08:00
PATENTS lang/funcs: Preserve IP address leading zero behavior from Go 1.16 2021-08-17 15:20:05 -07:00
README.md Remove Terraform mentions in docs in the codebase (#713) 2023-10-12 12:11:01 +01:00

Forked IP address parsing functions

This directory contains a subset of code from the Go project's net package as of Go 1.16, used under the Go project license which we've included here in LICENSE and PATENTS, which are also copied from the Go project.

OpenTofu has its own fork of these functions because Go 1.17 included a breaking change to reject IPv4 address octets written with leading zeros.

The Go project rationale for that change was that Go historically interpreted leading-zero octets inconsistently with many other implementations, trimming off the zeros and still treating the rest as decimal rather than treating the octet as octal.

The Go team made the reasonable observation that having a function that interprets a non-normalized form in a manner inconsistent with other implementations may cause naive validation or policy checks to produce incorrect results, and thus it's a potential security concern. For more information, see Go issue #30999.

After careful consideration, it was concluded that OpenTofu's use of these functions as part of the implementation of the cidrhost, cidrsubnet, cidrsubnets, and cidrnetmask functions has a more limited impact than the general availability of these functions in the Go standard library, and so we can't justify a similar exception to our compatibility promises as the Go team made to their Go 1.0 compatibility promises.

If you're considering using this package for new functionality other than the built-in functions mentioned above, please do so only if consistency with the behavior of those functions is important. Otherwise, new features are not burdened by the same compatibility constraints and so should typically prefer to use the stricter interpretation of the upstream parsing functions.