2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 revosec AG
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 "unity_narrow.h"
20 typedef struct private_unity_narrow_t private_unity_narrow_t
;
23 * Private data of an unity_narrow_t object.
25 struct private_unity_narrow_t
{
28 * Public unity_narrow_t interface.
30 unity_narrow_t
public;
33 * Unity attribute handler
35 unity_handler_t
*handler
;
38 METHOD(listener_t
, narrow
, bool,
39 private_unity_narrow_t
*this, ike_sa_t
*ike_sa
, child_sa_t
*child_sa
,
40 narrow_hook_t type
, linked_list_t
*local
, linked_list_t
*remote
)
42 traffic_selector_t
*current
, *orig
= NULL
;
43 enumerator_t
*enumerator
;
45 if (type
== NARROW_INITIATOR_POST_AUTH
&&
46 remote
->get_count(remote
) == 1)
48 enumerator
= this->handler
->create_include_enumerator(this->handler
,
49 ike_sa
->get_unique_id(ike_sa
));
50 while (enumerator
->enumerate(enumerator
, ¤t
))
53 { /* got one, replace original TS */
54 remote
->remove_first(remote
, (void**)&orig
);
56 remote
->insert_last(remote
, orig
->get_subset(orig
, current
));
58 enumerator
->destroy(enumerator
);
61 DBG1(DBG_CFG
, "narrowed CHILD_SA to %N %#R",
62 configuration_attribute_type_names
,
63 UNITY_SPLIT_INCLUDE
, remote
);
70 METHOD(unity_narrow_t
, destroy
, void,
71 private_unity_narrow_t
*this)
79 unity_narrow_t
*unity_narrow_create(unity_handler_t
*handler
)
81 private_unity_narrow_t
*this;