2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * Hochschule fuer Technik Rapperswil
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 #include "android_attr.h"
19 #include "../charonservice.h"
22 #include <utils/debug.h>
25 typedef struct private_android_attr_t private_android_attr_t
;
28 * Private data of an android_attr_t object.
30 struct private_android_attr_t
{
35 android_attr_t
public;
38 METHOD(attribute_handler_t
, handle
, bool,
39 private_android_attr_t
*this, identification_t
*server
,
40 configuration_attribute_type_t type
, chunk_t data
)
42 vpnservice_builder_t
*builder
;
47 case INTERNAL_IP4_DNS
:
48 dns
= host_create_from_chunk(AF_INET
, data
, 0);
50 case INTERNAL_IP6_DNS
:
51 dns
= host_create_from_chunk(AF_INET6
, data
, 0);
57 if (!dns
|| dns
->is_anyaddr(dns
))
63 builder
= charonservice
->get_vpnservice_builder(charonservice
);
64 builder
->add_dns(builder
, dns
);
69 METHOD(attribute_handler_t
, release
, void,
70 private_android_attr_t
*this, identification_t
*server
,
71 configuration_attribute_type_t type
, chunk_t data
)
73 /* DNS servers cannot be removed from an existing TUN device */
76 METHOD(enumerator_t
, enumerate_dns6
, bool,
77 enumerator_t
*this, configuration_attribute_type_t
*type
, chunk_t
*data
)
79 *type
= INTERNAL_IP6_DNS
;
81 this->enumerate
= (void*)return_false
;
85 METHOD(enumerator_t
, enumerate_dns4
, bool,
86 enumerator_t
*this, configuration_attribute_type_t
*type
, chunk_t
*data
)
88 *type
= INTERNAL_IP4_DNS
;
90 this->enumerate
= (void*)_enumerate_dns6
;
94 METHOD(attribute_handler_t
, create_attribute_enumerator
, enumerator_t
*,
95 private_android_attr_t
*this, identification_t
*server
, linked_list_t
*vips
)
97 enumerator_t
*enumerator
;
100 .enumerate
= (void*)_enumerate_dns4
,
101 .destroy
= (void*)free
,
106 METHOD(android_attr_t
, destroy
, void,
107 private_android_attr_t
*this)
113 * Described in header
115 android_attr_t
*android_attr_create()
117 private_android_attr_t
*this;
124 .create_attribute_enumerator
= _create_attribute_enumerator
,
130 return &this->public;