mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-24 03:18:57 +00:00
proxier: use IPSet from k8s.io/utils/net to store local addresses
This allows the proxier to cache local addresses instead of fetching all local addresses every time in IsLocalIP. Signed-off-by: Andrew Sy Kim <kiman@vmware.com>
This commit is contained in:
committed by
andrewsykim
parent
77feb1126e
commit
1653476e3f
@@ -123,23 +123,25 @@ func IsProxyableHostname(ctx context.Context, resolv Resolver, hostname string)
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsLocalIP checks if a given IP address is bound to an interface
|
||||
// on the local system
|
||||
func IsLocalIP(ip string) (bool, error) {
|
||||
// GetLocalAddrs returns a list of all network addresses on the local system
|
||||
func GetLocalAddrs() ([]net.IP, error) {
|
||||
var localAddrs []net.IP
|
||||
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return false, err
|
||||
return nil, err
|
||||
}
|
||||
for i := range addrs {
|
||||
intf, _, err := net.ParseCIDR(addrs[i].String())
|
||||
|
||||
for _, addr := range addrs {
|
||||
ip, _, err := net.ParseCIDR(addr.String())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if net.ParseIP(ip).Equal(intf) {
|
||||
return true, nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
localAddrs = append(localAddrs, ip)
|
||||
}
|
||||
return false, nil
|
||||
|
||||
return localAddrs, nil
|
||||
}
|
||||
|
||||
// ShouldSkipService checks if a given service should skip proxying
|
||||
|
Reference in New Issue
Block a user