This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Defines | |
#define | TUNNEL_DEVICE "TUNLMNA" |
#define | TUNNEL_DEVICE_B "TUNLMNB" |
Functions | |
void | init_tunneling (void) |
void | close_tunneling (void) |
int | start_tunneling (void) |
start_tunneling: | |
int | restart_tunneling (void) |
int | stop_tunneling (void) |
stop_tunneling: | |
void | check_old_tunnel_expiration (void) |
#define TUNNEL_DEVICE "TUNLMNA" |
#define TUNNEL_DEVICE_B "TUNLMNB" |
void check_old_tunnel_expiration | ( | void | ) |
Definition at line 151 of file mn_tunnel.c.
References LOG2.
00152 { 00153 #ifdef MN_ENABLE_TUNNELING 00154 if (old_tunnel_expire == 0 || 00155 time(NULL) <= old_tunnel_expire) 00156 return; 00157 00158 old_tunnel_expire = 0; 00159 if (dyn_ip_tunnel_del(old_tunnel_device) != 0) { 00160 LOG2(LOG_ERR, "tunnel delete failed for old tunnel\n"); 00161 return; 00162 } 00163 #endif 00164 }
void close_tunneling | ( | void | ) |
Definition at line 178 of file mn_tunnel.c.
References DEBUG(), DEBUG_INFO, real_tunnel_up, reply_waiting_api(), and stop_tunneling().
Referenced by clean_up().
00179 { 00180 DEBUG(DEBUG_INFO, "Close tunneling\n"); 00181 /* clean up tunnel first */ 00182 if (real_tunnel_up) stop_tunneling(); 00183 /* disconnect any waiting api calls */ 00184 reply_waiting_api(API_FAILED, NULL, 0); 00185 }
Here is the call graph for this function:
void init_tunneling | ( | void | ) |
Definition at line 167 of file mn_tunnel.c.
References DEBUG(), DEBUG_INFO, real_tunnel_up, and TUNNEL_DEVICE.
Referenced by mn_init().
00168 { 00169 DEBUG(DEBUG_INFO, "Init tunneling\n"); 00170 00171 dynamics_strlcpy(tunnel_device, TUNNEL_DEVICE, sizeof(tunnel_device)); 00172 real_tunnel_up = 0; 00173 tunnel_b_up = 0; 00174 }
Here is the call graph for this function:
int restart_tunneling | ( | void | ) |
Definition at line 359 of file mn_tunnel.c.
References DEBUG(), DEBUG_INFO, mn_config::enable_fa_decapsulation, mn, OLD_TUNNEL_EXTRA_TIME, real_tunnel_up, start_tunneling(), mn_data::tunnel_addr, TUNNEL_DEVICE, TUNNEL_DEVICE_B, and mn_data::tunnel_up.
00360 { 00361 #ifdef MN_ENABLE_TUNNELING 00362 struct in_addr old; 00363 00364 /* roll tunnel device names */ 00365 if (!tunnel_b_up) { 00366 dynamics_strlcpy(tunnel_device, TUNNEL_DEVICE_B, 00367 sizeof(tunnel_device)); 00368 tunnel_b_up = 1; 00369 } else { 00370 dynamics_strlcpy(tunnel_device, TUNNEL_DEVICE, 00371 sizeof(tunnel_device)); 00372 tunnel_b_up = 0; 00373 } 00374 old.s_addr = mn.tunnel_addr.s_addr; 00375 00376 mn.tunnel_up = 0; 00377 real_tunnel_up = 0; 00378 start_tunneling(); 00379 00380 if (tunnel_b_up) 00381 dynamics_strlcpy(old_tunnel_device, TUNNEL_DEVICE, 00382 sizeof(old_tunnel_device)); 00383 else 00384 dynamics_strlcpy(old_tunnel_device, TUNNEL_DEVICE_B, 00385 sizeof(old_tunnel_device)); 00386 00387 if (!config.enable_fa_decapsulation) { 00388 /* Mark the old tunnel to be deleted */ 00389 old_tunnel_addr.s_addr = old.s_addr; 00390 old_tunnel_expire = time(NULL) + OLD_TUNNEL_EXTRA_TIME; 00391 } 00392 00393 #else 00394 DEBUG(DEBUG_INFO, "Restart tunneling - tunneling disabled\n"); 00395 #endif 00396 return 0; 00397 }
Here is the call graph for this function:
int start_tunneling | ( | void | ) |
start_tunneling:
Create tunnel and set default route to tunnel and set route for FA.
Returns: 0 if successful.
Definition at line 260 of file mn_tunnel.c.
References mn_data::current_adv, DEBUG(), DEBUG_INFO, mn_config::enable_fa_decapsulation, mn_data::fa_addr, mn_config::home_net_addr, mn_config::home_net_addr_plen, agentadv_data::ifindex, agentadv_data::ifname, LOG2, mn, MNDECAPS_ROUTE_DEFAULT, mn_config::mndecaps_route_handling, MNDECAPS_ROUTE_HOME_NET, MNDECAPS_ROUTE_NONE, real_tunnel_up, mn_data::tunnel_addr, mn_data::tunnel_mode, mn_data::tunnel_up, and update_fa_decaps_routes().
00261 { 00262 int failed = 0; 00263 00264 if (real_tunnel_up) { 00265 DEBUG(DEBUG_INFO, "Start tunneling - tunnel is already up\n"); 00266 mn.tunnel_up = 1; 00267 return 0; 00268 } 00269 00270 #ifdef MN_ENABLE_TUNNELING 00271 00272 DEBUG(DEBUG_INFO, "Start tunneling - FA addr %s\n", 00273 inet_ntoa(mn.fa_addr)); 00274 00275 if (mn.tunnel_mode == API_TUNNEL_FULL_HA) { 00276 /* set a host route to the HA so that the default route 00277 * replacing will not kill the route */ 00278 if (dyn_ip_route_to_host(config.ha_ip_addr) != 0) { 00279 LOG2(LOG_ERR, "Could not set host route to the HA\n"); 00280 } 00281 } 00282 00283 if (!config.enable_fa_decapsulation) { 00284 if (make_tunnel(config.mn_home_ip_addr, mn.fa_addr) < 0) 00285 return -1; 00286 00287 switch (config.mndecaps_route_handling) { 00288 case MNDECAPS_ROUTE_DEFAULT: 00289 /* set default route to the tunnel */ 00290 DEBUG(DEBUG_INFO, "Setting default route to %s\n", 00291 tunnel_device); 00292 if (dyn_ip_route_replace_default( 00293 tunnel_device, NULL, 00294 &config.mn_home_ip_addr) != 0) { 00295 LOG2(LOG_ERR, 00296 "Set default route to dev %s failed\n", 00297 tunnel_device); 00298 failed = 1; 00299 } 00300 break; 00301 case MNDECAPS_ROUTE_HOME_NET: 00302 /* only set home net route to the tunnel 00303 * This entry will be automatically removed when the 00304 * tunnel is set down. */ 00305 DEBUG(DEBUG_INFO, "Setting home net route to %s\n", 00306 tunnel_device); 00307 if (dyn_ip_route_replace_net(tunnel_device, 00308 &config.home_net_addr, 00309 config.home_net_addr_plen) 00310 != 0) { 00311 LOG2(LOG_ERR, 00312 "Set home net route to dev %s failed\n", 00313 tunnel_device); 00314 failed = 1; 00315 } 00316 break; 00317 case MNDECAPS_ROUTE_NONE: 00318 DEBUG(DEBUG_INFO, "No route set to %s\n", 00319 tunnel_device); 00320 break; 00321 } 00322 00323 if (failed) { 00324 /* rollback */ 00325 if (dyn_ip_tunnel_del(tunnel_device) != 0) { 00326 DEBUG(DEBUG_INFO, "tunnel delete failed\n"); 00327 } 00328 return -1; 00329 } 00330 } else if (mn.current_adv != NULL) { 00331 /* FA decapsulation and we have heard an advertisement: 00332 * set default route to FA, and remove all routes to 00333 * home network */ 00334 if (update_fa_decaps_routes(mn.current_adv->ifname, 00335 mn.current_adv->ifindex, 00336 mn.fa_addr, 00337 config.home_net_addr, 00338 config.home_net_addr_plen) < 0) 00339 return -1; 00340 } else 00341 LOG2(LOG_WARNING, "start_tunneling() - current_adv == NULL\n"); 00342 00343 #else 00344 DEBUG(DEBUG_INFO, "Start tunneling - tunneling disabled\n"); 00345 #endif 00346 mn.tunnel_addr.s_addr = mn.fa_addr.s_addr; 00347 mn.tunnel_up = 1; 00348 real_tunnel_up = 1; 00349 return 0; 00350 }
Here is the call graph for this function:
int stop_tunneling | ( | void | ) |
stop_tunneling:
Close tunnel, reset routing.
Returns: 0 if successful.
Definition at line 406 of file mn_tunnel.c.
References mn_data::current_adv, DEBUG(), DEBUG_INFO, device_up(), mn_config::enable_fa_decapsulation, IFNAMSIZ, agentadv_data::in_use, LOG2, mn, real_tunnel_up, remove_fa_host_routes(), mn_data::tunnel_mode, and mn_data::tunnel_up.
00407 { 00408 int ret = 1; 00409 char dev[IFNAMSIZ], *home_dev = NULL; 00410 00411 #ifdef MN_ENABLE_TUNNELING 00412 DEBUG(DEBUG_INFO, "Stop tunneling\n"); 00413 00414 if (mn.current_adv == NULL) 00415 LOG2(LOG_WARNING, "stop_tunneling - current_adv == NULL\n"); 00416 00417 if (mn.tunnel_mode == API_TUNNEL_FULL_HA) { 00418 /* remove the host route to the HA */ 00419 dev[0] = '\0'; 00420 if (dyn_ip_route_get(config.ha_ip_addr, dev, IFNAMSIZ) != 0 || 00421 dyn_ip_route_del(config.ha_ip_addr, dev) != 0) { 00422 LOG2(LOG_ERR, "Could not remove host route to the " 00423 "HA (dev=%s)\n", dev); 00424 } 00425 } 00426 00427 if (config.enable_fa_decapsulation) 00428 home_dev = return_home_net_route(); 00429 00430 /* restore default route */ 00431 DEBUG(DEBUG_INFO, "Restoring default route\n"); 00432 if (dyn_ip_route_restore_default(home_dev) != 0 && 00433 device_up(dyn_ip_get_saved_ifindex())) { 00434 LOG2(LOG_ERR, "restoring default route failed\n"); 00435 ret = 0; 00436 } 00437 00438 if (config.enable_fa_decapsulation) { 00439 if (mn.current_adv) 00440 remove_fa_host_routes(1); 00441 } else { 00442 if (dyn_ip_tunnel_del(tunnel_device) != 0) { 00443 LOG2(LOG_ERR, "tunnel delete failed\n"); 00444 ret = 0; 00445 } 00446 if (old_tunnel_expire != 0 && 00447 dyn_ip_tunnel_del(old_tunnel_device) != 0) { 00448 LOG2(LOG_ERR, "tunnel delete failed for old tunnel\n"); 00449 } 00450 old_tunnel_expire = 0; 00451 } 00452 #else 00453 DEBUG(DEBUG_INFO, "Stop tunneling - tunneling disabled\n"); 00454 #endif 00455 mn.tunnel_up = 0; 00456 real_tunnel_up = 0; 00457 if (mn.current_adv != NULL) mn.current_adv->in_use = 0; 00458 return ret; 00459 }
Here is the call graph for this function: