mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 21:15:39 +00:00
655b4f8fc5
I updated the address parsing stuff to return a specific error for unspecified hosts passed as empty strings, and look for that when logging errors. I explicitly did not make parseAddress return a netip.Addr containing an unspecified address because at this layer, in the absence of any host, we don't necessarily know the address family we're dealing with. For the purposes of this code I think this is fine, at least until we implement #12588. Fixes #12979 Signed-off-by: Aaron Klotz <aaron@tailscale.com>
28 lines
545 B
Go
28 lines
545 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build darwin || windows
|
|
|
|
package netns
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"net/netip"
|
|
)
|
|
|
|
var errUnspecifiedHost = errors.New("unspecified host")
|
|
|
|
func parseAddress(address string) (addr netip.Addr, err error) {
|
|
host, _, err := net.SplitHostPort(address)
|
|
if err != nil {
|
|
// error means the string didn't contain a port number, so use the string directly
|
|
host = address
|
|
}
|
|
if host == "" {
|
|
return addr, errUnspecifiedHost
|
|
}
|
|
|
|
return netip.ParseAddr(host)
|
|
}
|