Return to roam_job.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libcharon / processing / jobs |
1.1 misho 1: /* 2: * Copyright (C) 2007 Martin Willi 3: * HSR Hochschule fuer Technik Rapperswil 4: * 5: * This program is free software; you can redistribute it and/or modify it 6: * under the terms of the GNU General Public License as published by the 7: * Free Software Foundation; either version 2 of the License, or (at your 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 9: * 10: * This program is distributed in the hope that it will be useful, but 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13: * for more details. 14: */ 15: 16: #include <stdlib.h> 17: 18: #include "roam_job.h" 19: 20: #include <sa/ike_sa.h> 21: #include <daemon.h> 22: 23: 24: typedef struct private_roam_job_t private_roam_job_t; 25: 26: /** 27: * Private data of an roam_job_t Object 28: */ 29: struct private_roam_job_t { 30: /** 31: * public roam_job_t interface 32: */ 33: roam_job_t public; 34: 35: /** 36: * has the address list changed, or the routing only? 37: */ 38: bool address; 39: }; 40: 41: METHOD(job_t, destroy, void, 42: private_roam_job_t *this) 43: { 44: free(this); 45: } 46: 47: METHOD(job_t, execute, job_requeue_t, 48: private_roam_job_t *this) 49: { 50: ike_sa_t *ike_sa; 51: linked_list_t *list; 52: ike_sa_id_t *id; 53: enumerator_t *enumerator; 54: 55: /* enumerator over all IKE_SAs gives us no way to checkin_and_destroy 56: * after a DESTROY_ME, so we check out each available IKE_SA by hand. */ 57: list = linked_list_create(); 58: enumerator = charon->ike_sa_manager->create_enumerator( 59: charon->ike_sa_manager, TRUE); 60: while (enumerator->enumerate(enumerator, &ike_sa)) 61: { 62: id = ike_sa->get_id(ike_sa); 63: list->insert_last(list, id->clone(id)); 64: } 65: enumerator->destroy(enumerator); 66: 67: while (list->remove_last(list, (void**)&id) == SUCCESS) 68: { 69: ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, id); 70: if (ike_sa) 71: { 72: if (ike_sa->roam(ike_sa, this->address) == DESTROY_ME) 73: { 74: charon->ike_sa_manager->checkin_and_destroy( 75: charon->ike_sa_manager, ike_sa); 76: } 77: else 78: { 79: charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); 80: } 81: } 82: id->destroy(id); 83: } 84: list->destroy(list); 85: return JOB_REQUEUE_NONE; 86: } 87: 88: METHOD(job_t, get_priority, job_priority_t, 89: private_roam_job_t *this) 90: { 91: return JOB_PRIO_MEDIUM; 92: } 93: 94: /* 95: * Described in header 96: */ 97: roam_job_t *roam_job_create(bool address) 98: { 99: private_roam_job_t *this; 100: 101: INIT(this, 102: .public = { 103: .job_interface = { 104: .execute = _execute, 105: .get_priority = _get_priority, 106: .destroy = _destroy, 107: }, 108: }, 109: .address = address, 110: ); 111: 112: return &this->public; 113: } 114: