mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
fix: ignore loopback ip
This commit is contained in:
@@ -80,7 +80,7 @@ func CmdConnect(f cmdutil.Factory) *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !sshConf.IsEmpty() {
|
||||
if !sshConf.IsEmpty() && !sshConf.IsLoopback() {
|
||||
if ip := util.GetAPIServerFromKubeConfigBytes(bytes); ip != nil {
|
||||
extraRoute.ExtraCIDR = append(extraRoute.ExtraCIDR, ip.String())
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func CmdProxy(f cmdutil.Factory) *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !sshConf.IsEmpty() {
|
||||
if !sshConf.IsEmpty() && !sshConf.IsLoopback() {
|
||||
if ip := util.GetAPIServerFromKubeConfigBytes(bytes); ip != nil {
|
||||
extraRoute.ExtraCIDR = append(extraRoute.ExtraCIDR, ip.String())
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func CmdSync(f cmdutil.Factory) *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !sshConf.IsEmpty() {
|
||||
if !sshConf.IsEmpty() && !sshConf.IsLoopback() {
|
||||
if ip := util.GetAPIServerFromKubeConfigBytes(bytes); ip != nil {
|
||||
extraRoute.ExtraCIDR = append(extraRoute.ExtraCIDR, ip.String())
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func (option *Options) Connect(ctx context.Context, sshConfig *pkgssh.SshConfig,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !sshConfig.IsEmpty() {
|
||||
if !sshConfig.IsEmpty() && !sshConfig.IsLoopback() {
|
||||
if ip := util.GetAPIServerFromKubeConfigBytes(kubeConfigBytes); ip != nil {
|
||||
option.ExtraRouteInfo.ExtraCIDR = append(option.ExtraRouteInfo.ExtraCIDR, ip.String())
|
||||
}
|
||||
|
||||
@@ -113,6 +113,28 @@ func (conf SshConfig) IsEmpty() bool {
|
||||
return conf.ConfigAlias == "" && conf.Addr == "" && conf.Jump == ""
|
||||
}
|
||||
|
||||
// IsLoopback TODO support alias and proxyJump
|
||||
func (conf SshConfig) IsLoopback() bool {
|
||||
if conf.Addr != "" {
|
||||
var host string
|
||||
var err error
|
||||
if host, _, err = net.SplitHostPort(conf.Addr); err != nil {
|
||||
host = conf.Addr
|
||||
}
|
||||
ip, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, i := range ip {
|
||||
if i.IsLoopback() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (conf SshConfig) GetAuth() ([]ssh.AuthMethod, error) {
|
||||
host, _, _ := net.SplitHostPort(conf.Addr)
|
||||
var auth []ssh.AuthMethod
|
||||
|
||||
Reference in New Issue
Block a user