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"
23 typedef struct private_tnc_ifmap_listener_t private_tnc_ifmap_listener_t
;
26 * Private data of an tnc_ifmap_listener_t object.
28 struct private_tnc_ifmap_listener_t
{
31 * Public tnc_ifmap_listener_t interface.
33 tnc_ifmap_listener_t
public;
36 * TNC IF-MAP 2.0 SOAP interface
38 tnc_ifmap_soap_t
*ifmap
;
43 * Publish metadata of a single IKE_SA
45 static bool publish_ike_sa(private_tnc_ifmap_listener_t
*this,
46 ike_sa_t
*ike_sa
, bool up
)
49 identification_t
*id
, *eap_id
;
53 ike_sa_id
= ike_sa
->get_unique_id(ike_sa
);
54 id
= ike_sa
->get_other_id(ike_sa
);
55 eap_id
= ike_sa
->get_other_eap_id(ike_sa
);
56 host
= ike_sa
->get_other_host(ike_sa
);
58 /* In the presence of an EAP Identity, treat it as a username */
59 is_user
= !id
->equals(id
, eap_id
);
61 return this->ifmap
->publish_ike_sa(this->ifmap
, ike_sa_id
, eap_id
, is_user
,
66 * Publish PEP device-ip metadata
68 static bool publish_device_ip_addresses(private_tnc_ifmap_listener_t
*this)
70 enumerator_t
*enumerator
;
74 enumerator
= hydra
->kernel_interface
->create_address_enumerator(
75 hydra
->kernel_interface
, FALSE
, FALSE
);
76 while (enumerator
->enumerate(enumerator
, &host
))
78 if (!this->ifmap
->publish_device_ip(this->ifmap
, host
))
84 enumerator
->destroy(enumerator
);
90 * Publish all IKE_SA metadata
92 static bool reload_metadata(private_tnc_ifmap_listener_t
*this)
94 enumerator_t
*enumerator
;
98 enumerator
= charon
->controller
->create_ike_sa_enumerator(
99 charon
->controller
, FALSE
);
100 while (enumerator
->enumerate(enumerator
, &ike_sa
))
102 if (ike_sa
->get_state(ike_sa
) != IKE_ESTABLISHED
)
106 if (!publish_ike_sa(this, ike_sa
, TRUE
))
112 enumerator
->destroy(enumerator
);
117 METHOD(listener_t
, ike_updown
, bool,
118 private_tnc_ifmap_listener_t
*this, ike_sa_t
*ike_sa
, bool up
)
120 publish_ike_sa(this, ike_sa
, up
);
125 METHOD(tnc_ifmap_listener_t
, destroy
, void,
126 private_tnc_ifmap_listener_t
*this)
128 DESTROY_IF(this->ifmap
);
135 tnc_ifmap_listener_t
*tnc_ifmap_listener_create(bool reload
)
137 private_tnc_ifmap_listener_t
*this;
142 .ike_updown
= _ike_updown
,
146 .ifmap
= tnc_ifmap_soap_create(),
154 if (!this->ifmap
->newSession(this->ifmap
))
159 if (!this->ifmap
->purgePublisher(this->ifmap
))
164 if (!publish_device_ip_addresses(this))
171 if (!reload_metadata(this))
178 return &this->public;