12216583a1
* new config parser for agent This patch implements a new config parser for the consul agent which makes the following changes to the previous implementation: * add HCL support * all configuration fragments in tests and for default config are expressed as HCL fragments * HCL fragments can be provided on the command line so that they can eventually replace the command line flags. * HCL/JSON fragments are parsed into a temporary Config structure which can be merged using reflection (all values are pointers). The existing merge logic of overwrite for values and append for slices has been preserved. * A single builder process generates a typed runtime configuration for the agent. The new implementation is more strict and fails in the builder process if no valid runtime configuration can be generated. Therefore, additional validations in other parts of the code should be removed. The builder also pre-computes all required network addresses so that no address/port magic should be required where the configuration is used and should therefore be removed. * Upgrade github.com/hashicorp/hcl to support int64 * improve error messages * fix directory permission test * Fix rtt test * Fix ForceLeave test * Skip performance test for now until we know what to do * Update github.com/hashicorp/memberlist to update log prefix * Make memberlist use the default logger * improve config error handling * do not fail on non-existing data-dir * experiment with non-uniform timeouts to get a handle on stalled leader elections * Run tests for packages separately to eliminate the spurious port conflicts * refactor private address detection and unify approach for ipv4 and ipv6. Fixes #2825 * do not allow unix sockets for DNS * improve bind and advertise addr error handling * go through builder using test coverage * minimal update to the docs * more coverage tests fixed * more tests * fix makefile * cleanup * fix port conflicts with external port server 'porter' * stop test server on error * do not run api test that change global ENV concurrently with the other tests * Run remaining api tests concurrently * no need for retry with the port number service * monkey patch race condition in go-sockaddr until we understand why that fails * monkey patch hcl decoder race condidtion until we understand why that fails * monkey patch spurious errors in strings.EqualFold from here * add test for hcl decoder race condition. Run with go test -parallel 128 * Increase timeout again * cleanup * don't log port allocations by default * use base command arg parsing to format help output properly * handle -dc deprecation case in Build * switch autopilot.max_trailing_logs to int * remove duplicate test case * remove unused methods * remove comments about flag/config value inconsistencies * switch got and want around since the error message was misleading. * Removes a stray debug log. * Removes a stray newline in imports. * Fixes TestACL_Version8. * Runs go fmt. * Adds a default case for unknown address types. * Reoders and reformats some imports. * Adds some comments and fixes typos. * Reorders imports. * add unix socket support for dns later * drop all deprecated flags and arguments * fix wrong field name * remove stray node-id file * drop unnecessary patch section in test * drop duplicate test * add test for LeaveOnTerm and SkipLeaveOnInt in client mode * drop "bla" and add clarifying comment for the test * split up tests to support enterprise/non-enterprise tests * drop raft multiplier and derive values during build phase * sanitize runtime config reflectively and add test * detect invalid config fields * fix tests with invalid config fields * use different values for wan sanitiziation test * drop recursor in favor of recursors * allow dns_config.udp_answer_limit to be zero * make sure tests run on machines with multiple ips * Fix failing tests in a few more places by providing a bind address in the test * Gets rid of skipped TestAgent_CheckPerformanceSettings and adds case for builder. * Add porter to server_test.go to make tests there less flaky * go fmt |
||
---|---|---|
.. | ||
template | ||
GNUmakefile | ||
LICENSE | ||
README.md | ||
doc.go | ||
ifaddr.go | ||
ifaddrs.go | ||
ifattr.go | ||
ipaddr.go | ||
ipaddrs.go | ||
ipv4addr.go | ||
ipv6addr.go | ||
rfc.go | ||
route_info.go | ||
route_info_bsd.go | ||
route_info_default.go | ||
route_info_linux.go | ||
route_info_solaris.go | ||
route_info_windows.go | ||
sockaddr.go | ||
sockaddrs.go | ||
unixsock.go |
README.md
go-sockaddr
sockaddr
Library
Socket address convenience functions for Go. go-sockaddr
is a convenience
library that makes doing the right thing with IP addresses easy. go-sockaddr
is loosely modeled after the UNIX sockaddr_t
and creates a union of the family
of sockaddr_t
types (see below for an ascii diagram). Library documentation
is available
at
https://godoc.org/github.com/hashicorp/go-sockaddr.
The primary intent of the library was to make it possible to define heuristics
for selecting the correct IP addresses when a configuration is evaluated at
runtime. See
the
docs,
template
package,
tests,
and
CLI utility
for details and hints as to how to use this library.
For example, with this library it is possible to find an IP address that:
- is attached to a default route
(
GetDefaultInterfaces()
) - is contained within a CIDR block (
IfByNetwork()
) - is an RFC1918 address
(
IfByRFC("1918")
) - is ordered
(
OrderedIfAddrBy(args)
whereargs
includes, but is not limited to,AscIfType
,AscNetworkSize
) - excludes all IPv6 addresses
(
IfByType("^(IPv4)$")
) - is larger than a
/32
(IfByMaskSize(32)
) - is not on a
down
interface (ExcludeIfs("flags", "down")
) - preferences an IPv6 address over an IPv4 address
(
SortIfByType()
+ReverseIfAddrs()
); and - excludes any IP in RFC6890 address
(
IfByRFC("6890")
)
Or any combination or variation therein.
There are also a few simple helper functions such as GetPublicIP
and
GetPrivateIP
which both return strings and select the first public or private
IP address on the default interface, respectively. Similarly, there is also a
helper function called GetInterfaceIP
which returns the first usable IP
address on the named interface.
sockaddr
CLI
Given the possible complexity of the sockaddr
library, there is a CLI utility
that accompanies the library, also
called
sockaddr
.
The
sockaddr
utility exposes nearly all of the functionality of the library and can be used
either as an administrative tool or testing tool. To install
the
sockaddr
,
run:
$ go get -u github.com/hashicorp/go-sockaddr/cmd/sockaddr
If you're familiar with UNIX's sockaddr
struct's, the following diagram
mapping the C sockaddr
(top) to go-sockaddr
structs (bottom) and
interfaces will be helpful:
+-------------------------------------------------------+
| |
| sockaddr |
| SockAddr |
| |
| +--------------+ +----------------------------------+ |
| | sockaddr_un | | | |
| | SockAddrUnix | | sockaddr_in{,6} | |
| +--------------+ | IPAddr | |
| | | |
| | +-------------+ +--------------+ | |
| | | sockaddr_in | | sockaddr_in6 | | |
| | | IPv4Addr | | IPv6Addr | | |
| | +-------------+ +--------------+ | |
| | | |
| +----------------------------------+ |
| |
+-------------------------------------------------------+
Inspiration and Design
There were many subtle inspirations that led to this design, but the most direct
inspiration for the filtering syntax was
OpenBSD's
pf.conf(5)
firewall
syntax that lets you select the first IP address on a given named interface.
The original problem stemmed from:
- needing to create immutable images using Packer that ran the Consul process (Consul can only use one IP address at a time);
- images that may or may not have multiple interfaces or IP addresses at runtime; and
- we didn't want to rely on configuration management to render out the correct IP address if the VM image was being used in an auto-scaling group.
Instead we needed some way to codify a heuristic that would correctly select the right IP address but the input parameters were not known when the image was created.