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:
parent
068a93d1f4
commit
e434ba6523
|
@ -4,6 +4,7 @@
|
||||||
package overlay
|
package overlay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
@ -272,6 +273,9 @@ func (t *tun) Activate() error {
|
||||||
copy(maskAddr.IP[:], mask[:])
|
copy(maskAddr.IP[:], mask[:])
|
||||||
err = addRoute(routeSock, routeAddr, maskAddr, linkAddr)
|
err = addRoute(routeSock, routeAddr, maskAddr, linkAddr)
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +297,12 @@ func (t *tun) Activate() error {
|
||||||
|
|
||||||
err = addRoute(routeSock, routeAddr, maskAddr, linkAddr)
|
err = addRoute(routeSock, routeAddr, maskAddr, linkAddr)
|
||||||
if err != nil {
|
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
|
// TODO how to set metric
|
||||||
|
@ -354,11 +363,11 @@ func addRoute(sock int, addr, mask *netroute.Inet4Addr, link *netroute.LinkAddr)
|
||||||
|
|
||||||
data, err := r.Marshal()
|
data, err := r.Marshal()
|
||||||
if err != nil {
|
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[:])
|
_, err = unix.Write(sock, data[:])
|
||||||
if err != nil {
|
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
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue