Skip to content

Commit b791001

Browse files
committed
fix: darwin: extra error check that route exists
1 parent 51dc24f commit b791001

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/meshnet/system/routes/routes_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func SetDefaultIPv4Gateway(ctx context.Context, gateway Gateway) error {
5454

5555
// Add adds a route to the interface with the given name.
5656
func Add(ctx context.Context, ifaceName string, addr netip.Prefix) error {
57-
out, err := common.ExecOutput(ctx, "route", "-n", "add", "-"+getFamily(addr.Addr()), addr.Masked().String(), "-interface", ifaceName)
57+
_, err := common.ExecOutput(ctx, "route", "-n", "add", "-"+getFamily(addr.Addr()), addr.Masked().String(), "-interface", ifaceName)
5858
if err != nil {
59-
if strings.Contains(string(out), "already in table") || strings.Contains(string(out), "exists") {
59+
if strings.Contains(err.Error(), "already in table") || strings.Contains(err.Error(), "exists") {
6060
return ErrRouteExists
6161
}
6262
return err

pkg/meshnet/system/routes/routes_freebsd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func SetDefaultIPv4Gateway(ctx context.Context, gateway Gateway) error {
5555

5656
// Add adds a route to the interface with the given name.
5757
func Add(ctx context.Context, ifaceName string, addr netip.Prefix) error {
58-
out, err := common.ExecOutput(ctx, "route", "-n", "add", "-"+getFamily(addr.Addr()), addr.Masked().String(), "-interface", ifaceName)
58+
_, err := common.ExecOutput(ctx, "route", "-n", "add", "-"+getFamily(addr.Addr()), addr.Masked().String(), "-interface", ifaceName)
5959
if err != nil {
60-
if strings.Contains(string(out), "already in table") || strings.Contains(string(out), "exists") {
60+
if strings.Contains(err.Error(), "already in table") || strings.Contains(err.Error(), "exists") {
6161
return ErrRouteExists
6262
}
6363
return err

0 commit comments

Comments
 (0)