Skip to content

Commit

Permalink
fix: darwin: extra error check that route exists
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Nov 7, 2023
1 parent 51dc24f commit b791001
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/meshnet/system/routes/routes_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func SetDefaultIPv4Gateway(ctx context.Context, gateway Gateway) error {

// Add adds a route to the interface with the given name.
func Add(ctx context.Context, ifaceName string, addr netip.Prefix) error {
out, err := common.ExecOutput(ctx, "route", "-n", "add", "-"+getFamily(addr.Addr()), addr.Masked().String(), "-interface", ifaceName)
_, err := common.ExecOutput(ctx, "route", "-n", "add", "-"+getFamily(addr.Addr()), addr.Masked().String(), "-interface", ifaceName)
if err != nil {
if strings.Contains(string(out), "already in table") || strings.Contains(string(out), "exists") {
if strings.Contains(err.Error(), "already in table") || strings.Contains(err.Error(), "exists") {
return ErrRouteExists
}
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/meshnet/system/routes/routes_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func SetDefaultIPv4Gateway(ctx context.Context, gateway Gateway) error {

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

0 comments on commit b791001

Please sign in to comment.