Skip to content

Commit

Permalink
mac/client/tunsetup.hpp: switch to MacGatewayInfo implementation
Browse files Browse the repository at this point in the history
MacGatewayInfo provides both default gateway for "exclude routes"
and the next-hop address for adding bypass route.

Old MacGWInfo implementation is removed.

Jira: OVPN-1260

Signed-off-by: Lev Stipakov <[email protected]>
  • Loading branch information
lstipakov authored and Razvan Cojocaru committed Oct 11, 2024
1 parent 09697ef commit 0536005
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 114 deletions.
47 changes: 25 additions & 22 deletions openvpn/tun/mac/client/tunsetup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <openvpn/tun/layer.hpp>
#include <openvpn/tun/mac/tunutil.hpp>
#include <openvpn/tun/mac/utun.hpp>
#include <openvpn/tun/mac/macgw.hpp>
#include <openvpn/tun/mac/gw.hpp>
#include <openvpn/tun/mac/macdns_watchdog.hpp>
#include <openvpn/tun/proxy.hpp>
#include <openvpn/tun/mac/macproxy.hpp>
Expand Down Expand Up @@ -303,9 +303,6 @@ class Setup : public TunBuilderSetup::Base
ActionList &destroy,
std::ostream &os)
{
// get default gateway
MacGWInfo gw;

// set local4 and local6 to point to IPv4/6 route configurations
const TunBuilderCapture::RouteAddress *local4 = nullptr;
const TunBuilderCapture::RouteAddress *local6 = nullptr;
Expand Down Expand Up @@ -380,23 +377,27 @@ class Setup : public TunBuilderSetup::Base
// Process exclude routes
if (!pull.exclude_routes.empty())
{
// get default gateways
MacGatewayInfo gw4{IP::Addr::from_ipv4(IPv4::Addr::from_zero())};
MacGatewayInfo gw6{IP::Addr::from_ipv6(IPv6::Addr::from_zero())};

for (std::vector<TunBuilderCapture::Route>::const_iterator i = pull.exclude_routes.begin(); i != pull.exclude_routes.end(); ++i)
{
const TunBuilderCapture::Route &route = *i;
if (route.ipv6)
{
if (!pull.block_ipv6)
{
if (gw.v6.defined())
add_del_route(route.address, route.prefix_length, gw.v6.router.to_string(), gw.v6.iface, R_IPv6 | R_IFACE_HINT, create, destroy);
if (gw6.flags() & MacGatewayInfo::ADDR_DEFINED)
add_del_route(route.address, route.prefix_length, gw6.gateway_addr_str(), gw6.iface(), R_IPv6 | R_IFACE_HINT, create, destroy);
else
os << "NOTE: cannot determine gateway for exclude IPv6 routes" << std::endl;
}
}
else
{
if (gw.v4.defined())
add_del_route(route.address, route.prefix_length, gw.v4.router.to_string(), gw.v4.iface, 0, create, destroy);
if (gw4.flags() & MacGatewayInfo::ADDR_DEFINED)
add_del_route(route.address, route.prefix_length, gw4.gateway_addr_str(), gw4.iface(), 0, create, destroy);
else
os << "NOTE: cannot determine gateway for exclude IPv4 routes" << std::endl;
}
Expand All @@ -406,13 +407,14 @@ class Setup : public TunBuilderSetup::Base
// Process IPv4 redirect-gateway
if (pull.reroute_gw.ipv4)
{
MacGatewayInfo gw4{IP::Addr::from_ipv4(IPv4::Addr::from_string(pull.remote_address.address))};
// add server bypass route
if (gw.v4.defined())
if (gw4.flags() & MacGatewayInfo::ADDR_DEFINED)
{
if (!pull.remote_address.ipv6 && !(pull.reroute_gw.flags & RedirectGatewayFlags::RG_LOCAL))
{
Action::Ptr c, d;
add_del_route(pull.remote_address.address, 32, gw.v4.router.to_string(), gw.v4.iface, 0, c, d);
add_del_route(pull.remote_address.address, 32, gw4.gateway_addr_str(), gw4.iface(), 0, c, d);
create.add(c);
destroy.add(d);
// add_del_route(gw.v4.router.to_string(), 32, "", gw.v4.iface, R_ONLINK, create, destroy); // fixme -- needed for block-local
Expand All @@ -431,13 +433,14 @@ class Setup : public TunBuilderSetup::Base
// Process IPv6 redirect-gateway
if (pull.reroute_gw.ipv6 && !pull.block_ipv6)
{
MacGatewayInfo gw6{IP::Addr::from_ipv6(IPv6::Addr::from_string(pull.remote_address.address))};
// add server bypass route
if (gw.v6.defined())
if (gw6.flags() & MacGatewayInfo::ADDR_DEFINED)
{
if (pull.remote_address.ipv6 && !(pull.reroute_gw.flags & RedirectGatewayFlags::RG_LOCAL))
{
Action::Ptr c, d;
add_del_route(pull.remote_address.address, 128, gw.v6.router.to_string(), gw.v6.iface, R_IPv6 | R_IFACE_HINT, c, d);
add_del_route(pull.remote_address.address, 128, gw6.gateway_addr_str(), gw6.iface(), R_IPv6 | R_IFACE_HINT, c, d);
create.add(c);
destroy.add(d);
// add_del_route(gw.v6.router.to_string(), 128, "", gw.v6.iface, R_IPv6|R_ONLINK, create, destroy); // fixme -- needed for block-local
Expand Down Expand Up @@ -490,17 +493,17 @@ class Setup : public TunBuilderSetup::Base
ActionList &add_cmds,
ActionList &remove_cmds_bypass_gw)
{
MacGWInfo gw;

if (!ipv6)
{
if (gw.v4.defined())
add_del_route(route, 32, gw.v4.router.to_string(), gw.v4.iface, 0, add_cmds, remove_cmds_bypass_gw);
}
else
MacGatewayInfo gw{IP::Addr{route}};
if (gw.flags() & MacGatewayInfo::ADDR_DEFINED)
{
if (gw.v6.defined())
add_del_route(route, 128, gw.v6.router.to_string(), gw.v6.iface, R_IPv6 | R_IFACE_HINT, add_cmds, remove_cmds_bypass_gw);
if (!ipv6)
{
add_del_route(route, 32, gw.gateway_addr_str(), gw.iface(), 0, add_cmds, remove_cmds_bypass_gw);
}
else
{
add_del_route(route, 128, gw.gateway_addr_str(), gw.iface(), R_IPv6 | R_IFACE_HINT, add_cmds, remove_cmds_bypass_gw);
}
}
}
};
Expand Down
92 changes: 0 additions & 92 deletions openvpn/tun/mac/macgw.hpp

This file was deleted.

0 comments on commit 0536005

Please sign in to comment.