mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-21 14:11:56 +00:00
types/ipproto: drop IPProto from IPProtoVersion
Based on https://github.com/golang/go/wiki/CodeReviewComments#package-names. Updates #cleanup Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
05a1f5bf71
commit
78a083e144
@ -673,16 +673,16 @@ func (c *natFamilyConfig) selectSrcIP(oldSrc, dst netip.Addr) netip.Addr {
|
|||||||
// natConfigFromWGConfig generates a natFamilyConfig from nm,
|
// natConfigFromWGConfig generates a natFamilyConfig from nm,
|
||||||
// for the indicated address family.
|
// for the indicated address family.
|
||||||
// If NAT is not required for that address family, it returns nil.
|
// If NAT is not required for that address family, it returns nil.
|
||||||
func natConfigFromWGConfig(wcfg *wgcfg.Config, addrFam ipproto.IPProtoVersion) *natFamilyConfig {
|
func natConfigFromWGConfig(wcfg *wgcfg.Config, addrFam ipproto.Version) *natFamilyConfig {
|
||||||
if wcfg == nil {
|
if wcfg == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var nativeAddr netip.Addr
|
var nativeAddr netip.Addr
|
||||||
switch addrFam {
|
switch addrFam {
|
||||||
case ipproto.IPProtoVersion4:
|
case ipproto.Version4:
|
||||||
nativeAddr = findV4(wcfg.Addresses)
|
nativeAddr = findV4(wcfg.Addresses)
|
||||||
case ipproto.IPProtoVersion6:
|
case ipproto.Version6:
|
||||||
nativeAddr = findV6(wcfg.Addresses)
|
nativeAddr = findV6(wcfg.Addresses)
|
||||||
}
|
}
|
||||||
if !nativeAddr.IsValid() {
|
if !nativeAddr.IsValid() {
|
||||||
@ -703,8 +703,8 @@ func natConfigFromWGConfig(wcfg *wgcfg.Config, addrFam ipproto.IPProtoVersion) *
|
|||||||
isExitNode := slices.Contains(p.AllowedIPs, tsaddr.AllIPv4()) || slices.Contains(p.AllowedIPs, tsaddr.AllIPv6())
|
isExitNode := slices.Contains(p.AllowedIPs, tsaddr.AllIPv4()) || slices.Contains(p.AllowedIPs, tsaddr.AllIPv6())
|
||||||
if isExitNode {
|
if isExitNode {
|
||||||
hasMasqAddrsForFamily := false ||
|
hasMasqAddrsForFamily := false ||
|
||||||
(addrFam == ipproto.IPProtoVersion4 && p.V4MasqAddr != nil && p.V4MasqAddr.IsValid()) ||
|
(addrFam == ipproto.Version4 && p.V4MasqAddr != nil && p.V4MasqAddr.IsValid()) ||
|
||||||
(addrFam == ipproto.IPProtoVersion6 && p.V6MasqAddr != nil && p.V6MasqAddr.IsValid())
|
(addrFam == ipproto.Version6 && p.V6MasqAddr != nil && p.V6MasqAddr.IsValid())
|
||||||
if hasMasqAddrsForFamily {
|
if hasMasqAddrsForFamily {
|
||||||
exitNodeRequiresMasq = true
|
exitNodeRequiresMasq = true
|
||||||
}
|
}
|
||||||
@ -714,10 +714,10 @@ func natConfigFromWGConfig(wcfg *wgcfg.Config, addrFam ipproto.IPProtoVersion) *
|
|||||||
for i := range wcfg.Peers {
|
for i := range wcfg.Peers {
|
||||||
p := &wcfg.Peers[i]
|
p := &wcfg.Peers[i]
|
||||||
var addrToUse netip.Addr
|
var addrToUse netip.Addr
|
||||||
if addrFam == ipproto.IPProtoVersion4 && p.V4MasqAddr != nil && p.V4MasqAddr.IsValid() {
|
if addrFam == ipproto.Version4 && p.V4MasqAddr != nil && p.V4MasqAddr.IsValid() {
|
||||||
addrToUse = *p.V4MasqAddr
|
addrToUse = *p.V4MasqAddr
|
||||||
mak.Set(&listenAddrs, addrToUse, struct{}{})
|
mak.Set(&listenAddrs, addrToUse, struct{}{})
|
||||||
} else if addrFam == ipproto.IPProtoVersion6 && p.V6MasqAddr != nil && p.V6MasqAddr.IsValid() {
|
} else if addrFam == ipproto.Version6 && p.V6MasqAddr != nil && p.V6MasqAddr.IsValid() {
|
||||||
addrToUse = *p.V6MasqAddr
|
addrToUse = *p.V6MasqAddr
|
||||||
mak.Set(&listenAddrs, addrToUse, struct{}{})
|
mak.Set(&listenAddrs, addrToUse, struct{}{})
|
||||||
} else if exitNodeRequiresMasq {
|
} else if exitNodeRequiresMasq {
|
||||||
@ -741,7 +741,7 @@ func natConfigFromWGConfig(wcfg *wgcfg.Config, addrFam ipproto.IPProtoVersion) *
|
|||||||
|
|
||||||
// SetNetMap is called when a new NetworkMap is received.
|
// SetNetMap is called when a new NetworkMap is received.
|
||||||
func (t *Wrapper) SetWGConfig(wcfg *wgcfg.Config) {
|
func (t *Wrapper) SetWGConfig(wcfg *wgcfg.Config) {
|
||||||
v4, v6 := natConfigFromWGConfig(wcfg, ipproto.IPProtoVersion4), natConfigFromWGConfig(wcfg, ipproto.IPProtoVersion6)
|
v4, v6 := natConfigFromWGConfig(wcfg, ipproto.Version4), natConfigFromWGConfig(wcfg, ipproto.Version6)
|
||||||
var cfg *natConfig
|
var cfg *natConfig
|
||||||
if v4 != nil || v6 != nil {
|
if v4 != nil || v6 != nil {
|
||||||
cfg = &natConfig{v4: v4, v6: v6}
|
cfg = &natConfig{v4: v4, v6: v6}
|
||||||
|
@ -617,7 +617,7 @@ func TestNATCfg(t *testing.T) {
|
|||||||
p.AllowedIPs = append(p.AllowedIPs, otherAllowedIPs...)
|
p.AllowedIPs = append(p.AllowedIPs, otherAllowedIPs...)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
test := func(addrFam ipproto.IPProtoVersion) {
|
test := func(addrFam ipproto.Version) {
|
||||||
var (
|
var (
|
||||||
noIP netip.Addr
|
noIP netip.Addr
|
||||||
|
|
||||||
@ -635,7 +635,7 @@ func TestNATCfg(t *testing.T) {
|
|||||||
exitRoute = netip.MustParsePrefix("0.0.0.0/0")
|
exitRoute = netip.MustParsePrefix("0.0.0.0/0")
|
||||||
publicIP = netip.MustParseAddr("8.8.8.8")
|
publicIP = netip.MustParseAddr("8.8.8.8")
|
||||||
)
|
)
|
||||||
if addrFam == ipproto.IPProtoVersion6 {
|
if addrFam == ipproto.Version6 {
|
||||||
selfNativeIP = netip.MustParseAddr("fd7a:115c:a1e0::a")
|
selfNativeIP = netip.MustParseAddr("fd7a:115c:a1e0::a")
|
||||||
selfEIP1 = netip.MustParseAddr("fd7a:115c:a1e0::1a")
|
selfEIP1 = netip.MustParseAddr("fd7a:115c:a1e0::1a")
|
||||||
selfEIP2 = netip.MustParseAddr("fd7a:115c:a1e0::1b")
|
selfEIP2 = netip.MustParseAddr("fd7a:115c:a1e0::1b")
|
||||||
@ -817,8 +817,8 @@ func TestNATCfg(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
test(ipproto.IPProtoVersion4)
|
test(ipproto.Version4)
|
||||||
test(ipproto.IPProtoVersion6)
|
test(ipproto.Version6)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestCaptureHook verifies that the Wrapper.captureHook callback is called
|
// TestCaptureHook verifies that the Wrapper.captureHook callback is called
|
||||||
|
@ -6,23 +6,23 @@ package ipproto
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// IPProtoVersion describes the IP address version.
|
// Version describes the IP address version.
|
||||||
type IPProtoVersion uint8
|
type Version uint8
|
||||||
|
|
||||||
// Valid IPProtoVersion values.
|
// Valid Version values.
|
||||||
const (
|
const (
|
||||||
IPProtoVersion4 = 4
|
Version4 = 4
|
||||||
IPProtoVersion6 = 6
|
Version6 = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p IPProtoVersion) String() string {
|
func (p Version) String() string {
|
||||||
switch p {
|
switch p {
|
||||||
case IPProtoVersion4:
|
case Version4:
|
||||||
return "IPv4"
|
return "IPv4"
|
||||||
case IPProtoVersion6:
|
case Version6:
|
||||||
return "IPv6"
|
return "IPv6"
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("IPProtoVersion-%d", int(p))
|
return fmt.Sprintf("Version-%d", int(p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user