Skip to content

Commit

Permalink
fix: trim command output space correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
linfan committed May 26, 2022
1 parent 3bd4d4f commit 6a71b72
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99
gopkg.in/yaml.v3 v3.0.0
k8s.io/api v0.22.0
k8s.io/apimachinery v0.22.0
k8s.io/client-go v0.22.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99 h1:dbuHpmKjkDzSOMKAWl10QNlgaZUd3V1q99xc81tt2Kc=
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gvisor.dev/gvisor v0.0.0-20220405222207-795f4f0139bb h1:AFXQ8bzBy3bvv18rPD8bjDGzylB0PZrMJWQKuXxvR7Y=
gvisor.dev/gvisor v0.0.0-20220405222207-795f4f0139bb/go.mod h1:tWwEcFvJavs154OdjFCw78axNrsDlz4Zh8jvPqwcpGI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
2 changes: 1 addition & 1 deletion pkg/kt/command/connect/tun2socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func setupTunRoute() error {
}
}
if failedRoutes := tun.Ins().CheckRoute(cidrs); len(failedRoutes) > 0 {
log.Warn().Msgf("Cannot establish route to %v", failedRoutes)
log.Warn().Msgf("Skipped route to %v", failedRoutes)
}
return nil
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/kt/service/tun/tun_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ func (s *Cli) CheckRoute(ipRange []string) []string {
found := false
for _, line := range strings.Split(out, util.Eol) {
ip := strings.Split(ir, "/")[0]
if strings.HasPrefix(line, ip) {
if strings.HasSuffix(line, s.GetName()) {
found = true
}
if strings.HasPrefix(line, ip) && strings.HasSuffix(strings.TrimSpace(line), s.GetName()) {
found = true
break
}
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/kt/service/tun/tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ func (s *Cli) CheckRoute(ipRange []string) []string {
for _, ir := range ipRange {
found := false
for _, line := range strings.Split(out, util.Eol) {
if strings.HasPrefix(line, ir) {
if strings.HasSuffix(line, s.GetName()) {
found = true
}
if strings.HasPrefix(line, ir) && strings.HasSuffix(strings.TrimSpace(line), s.GetName()) {
found = true
break
}
}
Expand Down

0 comments on commit 6a71b72

Please sign in to comment.