mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-19 20:39:23 +01:00
User Ip as next hop for default routes on darwin
This commit is contained in:
parent
272ade07a8
commit
b0b755b08b
@ -53,6 +53,7 @@ type DefaultManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface, statusRecorder *peer.Status, initialRoutes []*route.Route) *DefaultManager {
|
func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface, statusRecorder *peer.Status, initialRoutes []*route.Route) *DefaultManager {
|
||||||
|
tunIP = netip.MustParseAddr(wgInterface.Address().IP.String())
|
||||||
mCTX, cancel := context.WithCancel(ctx)
|
mCTX, cancel := context.WithCancel(ctx)
|
||||||
dm := &DefaultManager{
|
dm := &DefaultManager{
|
||||||
ctx: mCTX,
|
ctx: mCTX,
|
||||||
|
@ -28,6 +28,8 @@ var splitDefaultv6_2 = netip.PrefixFrom(netip.AddrFrom16([16]byte{0x80}), 1)
|
|||||||
var ErrRouteNotFound = errors.New("route not found")
|
var ErrRouteNotFound = errors.New("route not found")
|
||||||
var ErrRouteNotAllowed = errors.New("route not allowed")
|
var ErrRouteNotAllowed = errors.New("route not allowed")
|
||||||
|
|
||||||
|
var tunIP netip.Addr
|
||||||
|
|
||||||
// TODO: fix: for default our wg address now appears as the default gw
|
// TODO: fix: for default our wg address now appears as the default gw
|
||||||
func addRouteForCurrentDefaultGateway(prefix netip.Prefix) error {
|
func addRouteForCurrentDefaultGateway(prefix netip.Prefix) error {
|
||||||
addr := netip.IPv4Unspecified()
|
addr := netip.IPv4Unspecified()
|
||||||
@ -196,10 +198,10 @@ func addRouteToNonVPNIntf(prefix netip.Prefix, vpnIntf *iface.WGIface, initialNe
|
|||||||
// in two /1 prefixes to avoid replacing the existing default route
|
// in two /1 prefixes to avoid replacing the existing default route
|
||||||
func genericAddVPNRoute(prefix netip.Prefix, intf *net.Interface) error {
|
func genericAddVPNRoute(prefix netip.Prefix, intf *net.Interface) error {
|
||||||
if prefix == defaultv4 {
|
if prefix == defaultv4 {
|
||||||
if err := addToRouteTable(splitDefaultv4_1, netip.Addr{}, intf); err != nil {
|
if err := addToRouteTable(splitDefaultv4_1, tunIP, intf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := addToRouteTable(splitDefaultv4_2, netip.Addr{}, intf); err != nil {
|
if err := addToRouteTable(splitDefaultv4_2, tunIP, intf); err != nil {
|
||||||
if err2 := removeFromRouteTable(splitDefaultv4_1, netip.Addr{}, intf); err2 != nil {
|
if err2 := removeFromRouteTable(splitDefaultv4_1, netip.Addr{}, intf); err2 != nil {
|
||||||
log.Warnf("Failed to rollback route addition: %s", err2)
|
log.Warnf("Failed to rollback route addition: %s", err2)
|
||||||
}
|
}
|
||||||
@ -266,10 +268,10 @@ func addNonExistingRoute(prefix netip.Prefix, intf *net.Interface) error {
|
|||||||
func genericRemoveVPNRoute(prefix netip.Prefix, intf *net.Interface) error {
|
func genericRemoveVPNRoute(prefix netip.Prefix, intf *net.Interface) error {
|
||||||
if prefix == defaultv4 {
|
if prefix == defaultv4 {
|
||||||
var result *multierror.Error
|
var result *multierror.Error
|
||||||
if err := removeFromRouteTable(splitDefaultv4_1, netip.Addr{}, intf); err != nil {
|
if err := removeFromRouteTable(splitDefaultv4_1, tunIP, intf); err != nil {
|
||||||
result = multierror.Append(result, err)
|
result = multierror.Append(result, err)
|
||||||
}
|
}
|
||||||
if err := removeFromRouteTable(splitDefaultv4_2, netip.Addr{}, intf); err != nil {
|
if err := removeFromRouteTable(splitDefaultv4_2, tunIP, intf); err != nil {
|
||||||
result = multierror.Append(result, err)
|
result = multierror.Append(result, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +52,10 @@ func routeCmd(action string, prefix netip.Prefix, nexthop netip.Addr, intf *net.
|
|||||||
|
|
||||||
args := []string{"-n", action, inet, network}
|
args := []string{"-n", action, inet, network}
|
||||||
if nexthop.IsValid() {
|
if nexthop.IsValid() {
|
||||||
|
log.Debugf("route %s %s via %s", action, prefix, nexthop)
|
||||||
args = append(args, nexthop.Unmap().String())
|
args = append(args, nexthop.Unmap().String())
|
||||||
} else if intf != nil {
|
} else if intf != nil {
|
||||||
|
log.Debugf("route %s %s via %s, iptun: %s", action, prefix, intf.Name, tunIP)
|
||||||
args = append(args, "-interface", intf.Name)
|
args = append(args, "-interface", intf.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user