Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfa33b1

Browse files
committed
fix(kube-proxy) avoid add zero-masked loadBalancerSourceRanges to ipset
Signed-off-by: roc <roc@imroc.cc>
1 parent033ffc7 commitbfa33b1

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

‎pkg/proxy/serviceport.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package proxy
1919
import (
2020
"fmt"
2121
"net"
22+
"slices"
2223
"strings"
2324

2425
v1"k8s.io/api/core/v1"
@@ -205,7 +206,12 @@ func newBaseServiceInfo(service *v1.Service, ipFamily v1.IPFamily, port *v1.Serv
205206
}
206207

207208
cidrFamilyMap:=proxyutil.MapCIDRsByIPFamily(loadBalancerSourceRanges)
208-
info.loadBalancerSourceRanges=cidrFamilyMap[ipFamily]
209+
cidrs:=cidrFamilyMap[ipFamily]
210+
// zero-masked cidr means "allow any", which same as the empty loadBalancerSourceRanges.
211+
ifslices.ContainsFunc(cidrs,proxyutil.IsZeroCIDR) {
212+
cidrs= []*net.IPNet{}
213+
}
214+
info.loadBalancerSourceRanges=cidrs
209215

210216
// Filter Load Balancer Ingress IPs to correct IP family. While proxying load
211217
// balancers might choose to proxy connections from an LB IP of one family to a

‎pkg/proxy/util/nodeport_addresses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func NewNodePortAddresses(family v1.IPFamily, cidrStrings []string) *NodePortAdd
6868
}
6969
}
7070

71-
ifIsZeroCIDR(str) {
71+
ifIsZeroCIDR(cidr) {
7272
// Ignore everything else
7373
npa.cidrs= []*net.IPNet{cidr}
7474
npa.matchAll=true

‎pkg/proxy/util/utils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ const (
4545

4646
// IsZeroCIDR checks whether the input CIDR string is either
4747
// the IPv4 or IPv6 zero CIDR
48-
funcIsZeroCIDR(cidrstring)bool {
49-
ifcidr==IPv4ZeroCIDR||cidr==IPv6ZeroCIDR {
50-
returntrue
48+
funcIsZeroCIDR(cidr*net.IPNet)bool {
49+
ifcidr==nil {
50+
returnfalse
5151
}
52-
returnfalse
52+
prefixLen,_:=cidr.Mask.Size()
53+
returnprefixLen==0
5354
}
5455

5556
// ShouldSkipService checks if a given service should skip proxying

‎pkg/proxy/util/utils_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ func TestIsZeroCIDR(t *testing.T) {
682682
}
683683
for_,tc:=rangetestCases {
684684
t.Run(tc.name,func(t*testing.T) {
685-
ifgot:=IsZeroCIDR(tc.input);tc.expected!=got {
685+
_,cidr,_:=netutils.ParseCIDRSloppy(tc.input)
686+
ifgot:=IsZeroCIDR(cidr);tc.expected!=got {
686687
t.Errorf("IsZeroCIDR() = %t, want %t",got,tc.expected)
687688
}
688689
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp