Return to delete_child_sa_job.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libcharon / processing / jobs |
1.1 misho 1: /* 2: * Copyright (C) 2017 Tobias Brunner 3: * Copyright (C) 2006 Martin Willi 4: * HSR Hochschule fuer Technik Rapperswil 5: * 6: * This program is free software; you can redistribute it and/or modify it 7: * under the terms of the GNU General Public License as published by the 8: * Free Software Foundation; either version 2 of the License, or (at your 9: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 10: * 11: * This program is distributed in the hope that it will be useful, but 12: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14: * for more details. 15: */ 16: 17: #include "delete_child_sa_job.h" 18: 19: #include <daemon.h> 20: 21: 22: typedef struct private_delete_child_sa_job_t private_delete_child_sa_job_t; 23: 24: /** 25: * Private data of an delete_child_sa_job_t object. 26: */ 27: struct private_delete_child_sa_job_t { 28: 29: /** 30: * Public delete_child_sa_job_t interface. 31: */ 32: delete_child_sa_job_t public; 33: 34: /** 35: * Protocol of the CHILD_SA (ESP/AH) 36: */ 37: protocol_id_t protocol; 38: 39: /** 40: * Inbound SPI of the CHILD_SA 41: */ 42: uint32_t spi; 43: 44: /** 45: * SA destination address 46: */ 47: host_t *dst; 48: 49: /** 50: * Delete for an expired CHILD_SA 51: */ 52: bool expired; 53: 54: /** 55: * Unique ID of the CHILD_SA 56: */ 57: uint32_t id; 58: }; 59: 60: METHOD(job_t, destroy, void, 61: private_delete_child_sa_job_t *this) 62: { 63: DESTROY_IF(this->dst); 64: free(this); 65: } 66: 67: METHOD(job_t, execute, job_requeue_t, 68: private_delete_child_sa_job_t *this) 69: { 70: ike_sa_t *ike_sa; 71: 72: if (this->id) 73: { 74: child_sa_t *child_sa; 75: 76: ike_sa = charon->child_sa_manager->checkout_by_id( 77: charon->child_sa_manager, this->id, &child_sa); 78: if (!ike_sa) 79: { 80: DBG1(DBG_JOB, "CHILD_SA {%d} not found for delete", this->id); 81: } 82: else 83: { 84: this->spi = child_sa->get_spi(child_sa, TRUE); 85: this->protocol = child_sa->get_protocol(child_sa); 86: } 87: } 88: else 89: { 90: ike_sa = charon->child_sa_manager->checkout(charon->child_sa_manager, 91: this->protocol, this->spi, this->dst, NULL); 92: if (!ike_sa) 93: { 94: DBG1(DBG_JOB, "CHILD_SA %N/0x%08x/%H not found for delete", 95: protocol_id_names, this->protocol, htonl(this->spi), this->dst); 96: } 97: } 98: 99: if (ike_sa) 100: { 101: ike_sa->delete_child_sa(ike_sa, this->protocol, this->spi, 102: this->expired); 103: charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); 104: } 105: return JOB_REQUEUE_NONE; 106: } 107: 108: METHOD(job_t, get_priority, job_priority_t, 109: private_delete_child_sa_job_t *this) 110: { 111: return JOB_PRIO_MEDIUM; 112: } 113: 114: /* 115: * Described in header 116: */ 117: delete_child_sa_job_t *delete_child_sa_job_create(protocol_id_t protocol, 118: uint32_t spi, host_t *dst, bool expired) 119: { 120: private_delete_child_sa_job_t *this; 121: 122: INIT(this, 123: .public = { 124: .job_interface = { 125: .execute = _execute, 126: .get_priority = _get_priority, 127: .destroy = _destroy, 128: }, 129: }, 130: .protocol = protocol, 131: .spi = spi, 132: .dst = dst->clone(dst), 133: .expired = expired, 134: ); 135: 136: return &this->public; 137: } 138: 139: /* 140: * Described in header 141: */ 142: delete_child_sa_job_t *delete_child_sa_job_create_id(uint32_t id) 143: { 144: private_delete_child_sa_job_t *this; 145: 146: INIT(this, 147: .public = { 148: .job_interface = { 149: .execute = _execute, 150: .get_priority = _get_priority, 151: .destroy = _destroy, 152: }, 153: }, 154: .id = id, 155: ); 156: 157: return &this->public; 158: }