2 * Copyright (C) 2011 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "tnc_ifmap_listener.h"
17 #include "tnc_ifmap_soap.h"
22 typedef struct private_tnc_ifmap_listener_t private_tnc_ifmap_listener_t
;
25 * Private data of an tnc_ifmap_listener_t object.
27 struct private_tnc_ifmap_listener_t
{
30 * Public tnc_ifmap_listener_t interface.
32 tnc_ifmap_listener_t
public;
35 * TNC IF-MAP 2.0 SOAP interface
37 tnc_ifmap_soap_t
*ifmap
;
42 * Publish metadata of a single IKE_SA
44 static bool publish_ike_sa(private_tnc_ifmap_listener_t
*this,
45 ike_sa_t
*ike_sa
, bool up
)
48 identification_t
*id
, *eap_id
;
52 ike_sa_id
= ike_sa
->get_unique_id(ike_sa
);
53 id
= ike_sa
->get_other_id(ike_sa
);
54 eap_id
= ike_sa
->get_other_eap_id(ike_sa
);
55 host
= ike_sa
->get_other_host(ike_sa
);
57 /* In the presence of an EAP Identity, treat it as a username */
58 is_user
= !id
->equals(id
, eap_id
);
60 return this->ifmap
->publish_ike_sa(this->ifmap
, ike_sa_id
, eap_id
, is_user
,
65 * Publish all IKE_SA metadata
67 static bool reload_metadata(private_tnc_ifmap_listener_t
*this)
69 enumerator_t
*enumerator
;
73 enumerator
= charon
->controller
->create_ike_sa_enumerator(
74 charon
->controller
, FALSE
);
75 while (enumerator
->enumerate(enumerator
, &ike_sa
))
77 if (ike_sa
->get_state(ike_sa
) != IKE_ESTABLISHED
)
81 if (!publish_ike_sa(this, ike_sa
, TRUE
))
87 enumerator
->destroy(enumerator
);
92 METHOD(listener_t
, ike_updown
, bool,
93 private_tnc_ifmap_listener_t
*this, ike_sa_t
*ike_sa
, bool up
)
95 publish_ike_sa(this, ike_sa
, up
);
100 METHOD(tnc_ifmap_listener_t
, destroy
, void,
101 private_tnc_ifmap_listener_t
*this)
103 DESTROY_IF(this->ifmap
);
110 tnc_ifmap_listener_t
*tnc_ifmap_listener_create(bool reload
)
112 private_tnc_ifmap_listener_t
*this;
117 .ike_updown
= _ike_updown
,
121 .ifmap
= tnc_ifmap_soap_create(),
129 if (!this->ifmap
->newSession(this->ifmap
))
134 if (!this->ifmap
->purgePublisher(this->ifmap
))
141 if (!reload_metadata(this))
148 return &this->public;