From 78a083e14475bc626675c30f28eb28da5bc838e2 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Tue, 10 Oct 2023 22:52:34 -0700 Subject: [PATCH] types/ipproto: drop IPProto from IPProtoVersion Based on https://github.com/golang/go/wiki/CodeReviewComments#package-names. Updates #cleanup Signed-off-by: Maisem Ali --- net/tstun/wrap.go | 16 ++++++++-------- net/tstun/wrap_test.go | 8 ++++---- types/ipproto/ipproto.go | 18 +++++++++--------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/net/tstun/wrap.go b/net/tstun/wrap.go index 2caa24188..bad262b6c 100644 --- a/net/tstun/wrap.go +++ b/net/tstun/wrap.go @@ -673,16 +673,16 @@ func (c *natFamilyConfig) selectSrcIP(oldSrc, dst netip.Addr) netip.Addr { // natConfigFromWGConfig generates a natFamilyConfig from nm, // for the indicated address family. // 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 { return nil } var nativeAddr netip.Addr switch addrFam { - case ipproto.IPProtoVersion4: + case ipproto.Version4: nativeAddr = findV4(wcfg.Addresses) - case ipproto.IPProtoVersion6: + case ipproto.Version6: nativeAddr = findV6(wcfg.Addresses) } 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()) if isExitNode { hasMasqAddrsForFamily := false || - (addrFam == ipproto.IPProtoVersion4 && p.V4MasqAddr != nil && p.V4MasqAddr.IsValid()) || - (addrFam == ipproto.IPProtoVersion6 && p.V6MasqAddr != nil && p.V6MasqAddr.IsValid()) + (addrFam == ipproto.Version4 && p.V4MasqAddr != nil && p.V4MasqAddr.IsValid()) || + (addrFam == ipproto.Version6 && p.V6MasqAddr != nil && p.V6MasqAddr.IsValid()) if hasMasqAddrsForFamily { exitNodeRequiresMasq = true } @@ -714,10 +714,10 @@ func natConfigFromWGConfig(wcfg *wgcfg.Config, addrFam ipproto.IPProtoVersion) * for i := range wcfg.Peers { p := &wcfg.Peers[i] 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 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 mak.Set(&listenAddrs, addrToUse, struct{}{}) } else if exitNodeRequiresMasq { @@ -741,7 +741,7 @@ func natConfigFromWGConfig(wcfg *wgcfg.Config, addrFam ipproto.IPProtoVersion) * // SetNetMap is called when a new NetworkMap is received. 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 if v4 != nil || v6 != nil { cfg = &natConfig{v4: v4, v6: v6} diff --git a/net/tstun/wrap_test.go b/net/tstun/wrap_test.go index 7dd3fd123..94d01a97b 100644 --- a/net/tstun/wrap_test.go +++ b/net/tstun/wrap_test.go @@ -617,7 +617,7 @@ func TestNATCfg(t *testing.T) { p.AllowedIPs = append(p.AllowedIPs, otherAllowedIPs...) return p } - test := func(addrFam ipproto.IPProtoVersion) { + test := func(addrFam ipproto.Version) { var ( noIP netip.Addr @@ -635,7 +635,7 @@ func TestNATCfg(t *testing.T) { exitRoute = netip.MustParsePrefix("0.0.0.0/0") publicIP = netip.MustParseAddr("8.8.8.8") ) - if addrFam == ipproto.IPProtoVersion6 { + if addrFam == ipproto.Version6 { selfNativeIP = netip.MustParseAddr("fd7a:115c:a1e0::a") selfEIP1 = netip.MustParseAddr("fd7a:115c:a1e0::1a") selfEIP2 = netip.MustParseAddr("fd7a:115c:a1e0::1b") @@ -817,8 +817,8 @@ func TestNATCfg(t *testing.T) { }) } } - test(ipproto.IPProtoVersion4) - test(ipproto.IPProtoVersion6) + test(ipproto.Version4) + test(ipproto.Version6) } // TestCaptureHook verifies that the Wrapper.captureHook callback is called diff --git a/types/ipproto/ipproto.go b/types/ipproto/ipproto.go index 8c20d51e4..001b54500 100644 --- a/types/ipproto/ipproto.go +++ b/types/ipproto/ipproto.go @@ -6,23 +6,23 @@ import "fmt" -// IPProtoVersion describes the IP address version. -type IPProtoVersion uint8 +// Version describes the IP address version. +type Version uint8 -// Valid IPProtoVersion values. +// Valid Version values. const ( - IPProtoVersion4 = 4 - IPProtoVersion6 = 6 + Version4 = 4 + Version6 = 6 ) -func (p IPProtoVersion) String() string { +func (p Version) String() string { switch p { - case IPProtoVersion4: + case Version4: return "IPv4" - case IPProtoVersion6: + case Version6: return "IPv6" default: - return fmt.Sprintf("IPProtoVersion-%d", int(p)) + return fmt.Sprintf("Version-%d", int(p)) } }