2021-07-13 17:45:09 +00:00
|
|
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package vms
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
"net/netip"
|
2021-08-31 23:36:01 +00:00
|
|
|
"runtime"
|
2021-07-13 17:45:09 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"tailscale.com/net/interfaces"
|
|
|
|
)
|
|
|
|
|
|
|
|
func deriveBindhost(t *testing.T) string {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
ifName, err := interfaces.DefaultRouteInterface()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var ret string
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
err = interfaces.ForeachInterfaceAddress(func(i interfaces.Interface, prefix netip.Prefix) {
|
2021-07-13 17:45:09 +00:00
|
|
|
if ret != "" || i.Name != ifName {
|
|
|
|
return
|
|
|
|
}
|
2022-07-25 03:08:42 +00:00
|
|
|
ret = prefix.Addr().String()
|
2021-07-13 17:45:09 +00:00
|
|
|
})
|
|
|
|
if ret != "" {
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Fatal("can't find a bindhost")
|
|
|
|
return "unreachable"
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeriveBindhost(t *testing.T) {
|
2021-08-31 23:36:01 +00:00
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
t.Skip("requires GOOS=linux")
|
|
|
|
}
|
2021-07-13 17:45:09 +00:00
|
|
|
t.Log(deriveBindhost(t))
|
|
|
|
}
|
|
|
|
|
|
|
|
type nopWriteCloser struct {
|
|
|
|
io.Writer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nwc nopWriteCloser) Close() error { return nil }
|