if ( rl && rl->flags & RG_ENABLE )
{
+ bool local = BOOL_CAST(rl->flags & RG_LOCAL);
if (!(rl->spec.flags & RTSA_REMOTE_ENDPOINT) && (rl->flags & RG_REROUTE_GW))
{
msg (M_WARN, "%s VPN gateway parameter (--route-gateway or --ifconfig) is missing", err);
}
- else if (!(rl->rgi.flags & RGI_ADDR_DEFINED))
+ /*
+ * check if a default route is defined, unless:
+ * - we are connecting to a remote host in our network
+ * - we are connecting to a non-IPv4 remote host (i.e. we use IPv6)
+ */
+ else if (!(rl->rgi.flags & RGI_ADDR_DEFINED) && !local
+ && (rl->spec.remote_host != IPV4_INVALID_ADDR))
{
msg (M_WARN, "%s Cannot read current default gateway from system", err);
}
}
else
{
- bool local = BOOL_CAST(rl->flags & RG_LOCAL);
if (rl->flags & RG_AUTO_LOCAL) {
const int tla = rl->spec.remote_host_local;
if (tla == TLA_NONLOCAL)
}
else
{
- /* delete default route */
- del_route3 (0,
- 0,
- rl->rgi.gateway.addr,
- tt,
- flags | ROUTE_REF_GW,
- &rl->rgi,
- es);
+ /* don't try to remove the def route if it does not exist */
+ if (rl->rgi.flags & RGI_ADDR_DEFINED)
+ {
+ /* delete default route */
+ del_route3 (0,
+ 0,
+ rl->rgi.gateway.addr,
+ tt,
+ flags | ROUTE_REF_GW,
+ &rl->rgi,
+ es);
+ }
/* add new default route */
add_route3 (0,
&rl->rgi,
es);
- /* restore original default route */
- add_route3 (0,
- 0,
- rl->rgi.gateway.addr,
- tt,
- flags | ROUTE_REF_GW,
- &rl->rgi,
- es);
+ /* restore original default route if there was any */
+ if (rl->rgi.flags & RGI_ADDR_DEFINED)
+ {
+ /* restore original default route */
+ add_route3 (0,
+ 0,
+ rl->rgi.gateway.addr,
+ tt,
+ flags | ROUTE_REF_GW,
+ &rl->rgi,
+ es);
+ }
}
}