|
@ -2288,8 +2288,17 @@ static int routectl(int cmd, int flags, n2n_route_t *route, int if_idx) { |
|
|
* the TAP device is destroyed. */ |
|
|
* the TAP device is destroyed. */ |
|
|
static int edge_init_routes(n2n_edge_t *eee, n2n_route_t *routes, uint16_t num_routes) { |
|
|
static int edge_init_routes(n2n_edge_t *eee, n2n_route_t *routes, uint16_t num_routes) { |
|
|
#ifdef __linux__ |
|
|
#ifdef __linux__ |
|
|
int i; |
|
|
return edge_init_routes_linux(eee, routes, num_routes); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32 |
|
|
|
|
|
return edge_init_routes_win(eee, routes, num_routes); |
|
|
|
|
|
#endif |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int edge_init_routes_linux(n2n_edge_t *eee, n2n_route_t *routes, uint16_t num_routes) { |
|
|
|
|
|
#ifdef __linux__ |
|
|
|
|
|
int i; |
|
|
for (i = 0; i<num_routes; i++) { |
|
|
for (i = 0; i<num_routes; i++) { |
|
|
n2n_route_t *route = &routes[i]; |
|
|
n2n_route_t *route = &routes[i]; |
|
|
|
|
|
|
|
@ -2365,7 +2374,8 @@ static int edge_init_routes(n2n_edge_t *eee, n2n_route_t *routes, uint16_t num_r |
|
|
|
|
|
|
|
|
if (routectl(RTM_NEWROUTE, NLM_F_CREATE | NLM_F_EXCL, &custom_route, eee->device.if_idx) < 0) |
|
|
if (routectl(RTM_NEWROUTE, NLM_F_CREATE | NLM_F_EXCL, &custom_route, eee->device.if_idx) < 0) |
|
|
return(-1); |
|
|
return(-1); |
|
|
} else { |
|
|
} |
|
|
|
|
|
else { |
|
|
/* ip route add net via n2n_gateway */ |
|
|
/* ip route add net via n2n_gateway */ |
|
|
if (routectl(RTM_NEWROUTE, NLM_F_CREATE | NLM_F_EXCL, route, eee->device.if_idx) < 0) |
|
|
if (routectl(RTM_NEWROUTE, NLM_F_CREATE | NLM_F_EXCL, route, eee->device.if_idx) < 0) |
|
|
return(-1); |
|
|
return(-1); |
|
@ -2376,6 +2386,41 @@ static int edge_init_routes(n2n_edge_t *eee, n2n_route_t *routes, uint16_t num_r |
|
|
return(0); |
|
|
return(0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int edge_init_routes_win(n2n_edge_t *eee, n2n_route_t *routes, uint16_t num_routes) |
|
|
|
|
|
{ |
|
|
|
|
|
#ifdef WIN32 |
|
|
|
|
|
int i; |
|
|
|
|
|
struct in_addr net_addr, gateway; |
|
|
|
|
|
char c_net_addr[32]; |
|
|
|
|
|
char c_gateway[32]; |
|
|
|
|
|
char cmd[256]; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_routes; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
n2n_route_t *route = &routes[i]; |
|
|
|
|
|
if ((route->net_addr == 0) && (route->net_bitlen == 0)) |
|
|
|
|
|
{ |
|
|
|
|
|
traceEvent(TRACE_NORMAL, "Warning: The 0.0.0.0/0 route settings are not supported on Windows"); |
|
|
|
|
|
return (-1); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
/* ip route add net via n2n_gateway */ |
|
|
|
|
|
memcpy(&net_addr, &(route->net_addr), sizeof(net_addr)); |
|
|
|
|
|
memcpy(&gateway, &(route->gateway), sizeof(gateway)); |
|
|
|
|
|
_snprintf(c_net_addr, sizeof(c_net_addr), inet_ntoa(net_addr)); |
|
|
|
|
|
_snprintf(c_gateway, sizeof(c_gateway), inet_ntoa(gateway)); |
|
|
|
|
|
_snprintf(cmd, sizeof(cmd), "route add %s/%d %s > nul", c_net_addr, route->net_bitlen, c_gateway); |
|
|
|
|
|
traceEvent(TRACE_NORMAL, "ROUTE CMD = '%s'\n", cmd); |
|
|
|
|
|
system(cmd); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // WIN32
|
|
|
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* ************************************** */ |
|
|
/* ************************************** */ |
|
|
|
|
|
|
|
|
static void edge_cleanup_routes(n2n_edge_t *eee) { |
|
|
static void edge_cleanup_routes(n2n_edge_t *eee) { |
|
|