fix unsafe routes darwin (#610)

With Nebula 1.4.0, if you create an unsafe_route that has a collision with an existing route on the system, the unsafe_route will be silently dropped (and the existing system route remains).

With Nebula 1.5.0, this same situation will cause Nebula to fail to start with an error (EEXIST).

This change restores the Nebula 1.4.0 behavior (but with a WARN log as well).
This commit is contained in:
Wade Simmons 2021-12-14 11:52:49 -05:00 committed by GitHub
parent 068a93d1f4
commit e434ba6523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -4,6 +4,7 @@
package overlay
import (
"errors"
"fmt"
"io"
"net"
@ -272,6 +273,9 @@ func (t *tun) Activate() error {
copy(maskAddr.IP[:], mask[:])
err = addRoute(routeSock, routeAddr, maskAddr, linkAddr)
if err != nil {
if errors.Is(err, unix.EEXIST) {
err = fmt.Errorf("unable to add tun route, identical route already exists: %s", t.cidr)
}
return err
}
@ -293,7 +297,12 @@ func (t *tun) Activate() error {
err = addRoute(routeSock, routeAddr, maskAddr, linkAddr)
if err != nil {
return err
if errors.Is(err, unix.EEXIST) {
t.l.WithField("route", r.Cidr).
Warnf("unable to add unsafe_route, identical route already exists")
} else {
return err
}
}
// TODO how to set metric
@ -354,11 +363,11 @@ func addRoute(sock int, addr, mask *netroute.Inet4Addr, link *netroute.LinkAddr)
data, err := r.Marshal()
if err != nil {
return fmt.Errorf("failed to create route.RouteMessage: %v", err)
return fmt.Errorf("failed to create route.RouteMessage: %w", err)
}
_, err = unix.Write(sock, data[:])
if err != nil {
return fmt.Errorf("failed to write route.RouteMessage to socket: %v", err)
return fmt.Errorf("failed to write route.RouteMessage to socket: %w", err)
}
return nil