File tree 4 files changed +25
-26
lines changed
4 files changed +25
-26
lines changed Original file line number Diff line number Diff line change @@ -34,12 +34,5 @@ func SkipAuthRemoteAddress(addr string) bool {
34
34
}
35
35
36
36
func skipAuth (addr netip.Addr ) bool {
37
- if addr .IsValid () {
38
- for _ , prefix := range skipAuthPrefixes {
39
- if prefix .Contains (addr .Unmap ()) {
40
- return true
41
- }
42
- }
43
- }
44
- return false
37
+ return prefixesContains (skipAuthPrefixes , addr )
45
38
}
Original file line number Diff line number Diff line change @@ -31,27 +31,17 @@ func IsRemoteAddrDisAllowed(addr net.Addr) bool {
31
31
if err := m .SetRemoteAddr (addr ); err != nil {
32
32
return false
33
33
}
34
- return isAllowed (m .AddrPort ().Addr ().Unmap ()) && ! isDisAllowed (m .AddrPort ().Addr ().Unmap ())
34
+ ipAddr := m .AddrPort ().Addr ()
35
+ if ipAddr .IsValid () {
36
+ return isAllowed (ipAddr ) && ! isDisAllowed (ipAddr )
37
+ }
38
+ return false
35
39
}
36
40
37
41
func isAllowed (addr netip.Addr ) bool {
38
- if addr .IsValid () {
39
- for _ , prefix := range lanAllowedIPs {
40
- if prefix .Contains (addr ) {
41
- return true
42
- }
43
- }
44
- }
45
- return false
42
+ return prefixesContains (lanAllowedIPs , addr )
46
43
}
47
44
48
45
func isDisAllowed (addr netip.Addr ) bool {
49
- if addr .IsValid () {
50
- for _ , prefix := range lanDisAllowedIPs {
51
- if prefix .Contains (addr ) {
52
- return true
53
- }
54
- }
55
- }
56
- return false
46
+ return prefixesContains (lanDisAllowedIPs , addr )
57
47
}
Original file line number Diff line number Diff line change @@ -61,3 +61,19 @@ func parseHTTPAddr(request *http.Request) *C.Metadata {
61
61
62
62
return metadata
63
63
}
64
+
65
+ func prefixesContains (prefixes []netip.Prefix , addr netip.Addr ) bool {
66
+ if len (prefixes ) == 0 {
67
+ return false
68
+ }
69
+ if ! addr .IsValid () {
70
+ return false
71
+ }
72
+ addr = addr .Unmap ().WithZone ("" ) // netip.Prefix.Contains returns false if ip has an IPv6 zone
73
+ for _ , prefix := range prefixes {
74
+ if prefix .Contains (addr ) {
75
+ return true
76
+ }
77
+ }
78
+ return false
79
+ }
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ func (i *IPCIDR) Match(metadata *C.Metadata) (bool, string) {
40
40
if i .isSourceIP {
41
41
ip = metadata .SrcIP
42
42
}
43
- return ip .IsValid () && i .ipnet .Contains (ip ), i .adapter
43
+ return ip .IsValid () && i .ipnet .Contains (ip . WithZone ( "" ) ), i .adapter
44
44
}
45
45
46
46
func (i * IPCIDR ) Adapter () string {
You can’t perform that action at this time.
0 commit comments