mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-20 03:29:19 +02:00
validate-mtu, nexthop and tun address config
This commit is contained in:
@@ -261,6 +261,12 @@ func (c *clientNetwork) recalculateRouteAndUpdatePeerAndSystem() error {
|
|||||||
return fmt.Errorf("remove route from peer: %v", err)
|
return fmt.Errorf("remove route from peer: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if c.network == netip.MustParsePrefix("0.0.0.0/0") {
|
||||||
|
s, err := c.statusRecorder.GetPeer(c.routes[chosen].Peer)
|
||||||
|
if err == nil && s.IP != "" {
|
||||||
|
exitIP = netip.MustParseAddr(s.IP)
|
||||||
|
}
|
||||||
|
}
|
||||||
// otherwise add the route to the system
|
// otherwise add the route to the system
|
||||||
if err := addVPNRoute(c.network, c.getAsInterface()); err != nil {
|
if err := addVPNRoute(c.network, c.getAsInterface()); err != nil {
|
||||||
return fmt.Errorf("route %s couldn't be added for peer %s, err: %v",
|
return fmt.Errorf("route %s couldn't be added for peer %s, err: %v",
|
||||||
|
@@ -29,6 +29,7 @@ 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
|
var tunIP netip.Addr
|
||||||
|
var exitIP 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 {
|
||||||
@@ -198,10 +199,14 @@ 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, tunIP, intf); err != nil {
|
ip := tunIP
|
||||||
|
if exitIP.IsValid() {
|
||||||
|
ip = exitIP
|
||||||
|
}
|
||||||
|
if err := addToRouteTable(splitDefaultv4_1, ip, intf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := addToRouteTable(splitDefaultv4_2, tunIP, intf); err != nil {
|
if err := addToRouteTable(splitDefaultv4_2, ip, 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)
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultMTU = 1280
|
DefaultMTU = 1420
|
||||||
DefaultWgPort = 51820
|
DefaultWgPort = 51820
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
package iface
|
package iface
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/netip"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/pion/transport/v3"
|
"github.com/pion/transport/v3"
|
||||||
@@ -119,7 +120,9 @@ func (t *tunDevice) Wrapper() *DeviceWrapper {
|
|||||||
|
|
||||||
// assignAddr Adds IP address to the tunnel interface and network route based on the range provided
|
// assignAddr Adds IP address to the tunnel interface and network route based on the range provided
|
||||||
func (t *tunDevice) assignAddr() error {
|
func (t *tunDevice) assignAddr() error {
|
||||||
cmd := exec.Command("ifconfig", t.name, "inet", t.address.IP.String(), t.address.IP.String())
|
np := netip.MustParseAddr(t.address.IP.String())
|
||||||
|
|
||||||
|
cmd := exec.Command("ifconfig", t.name, "inet", t.address.IP.String(), np.Prev().String())
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
log.Infof(`adding address command "%v" failed with output %s and error: `, cmd.String(), out)
|
log.Infof(`adding address command "%v" failed with output %s and error: `, cmd.String(), out)
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user