/*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2020 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
* HSR Hochschule fuer Technik Rapperswil
*/
#include "android_attr.h"
-#include "../charonservice.h"
#include <utils/debug.h>
#include <library.h>
private_android_attr_t *this, ike_sa_t *ike_sa,
configuration_attribute_type_t type, chunk_t data)
{
- vpnservice_builder_t *builder;
- host_t *dns;
+ host_t *dns = NULL;
+ bool handled = FALSE;
switch (type)
{
dns = host_create_from_chunk(AF_INET6, data, 0);
break;
default:
- return FALSE;
+ break;
}
-
- if (!dns || dns->is_anyaddr(dns))
+ if (dns && !dns->is_anyaddr(dns))
{
- DESTROY_IF(dns);
- return FALSE;
+ DBG1(DBG_IKE, "installing DNS server %H", dns);
+ /* we don't actually handle them here, they are added to the TUN device
+ * explicitly when necessary, we still mark them as handled */
+ handled = TRUE;
}
- DBG1(DBG_IKE, "installing DNS server %H", dns);
- builder = charonservice->get_vpnservice_builder(charonservice);
- builder->add_dns(builder, dns);
- dns->destroy(dns);
- return TRUE;
+ DESTROY_IF(dns);
+ return handled;
}
METHOD(attribute_handler_t, release, void,
/*
- * Copyright (C) 2010-2018 Tobias Brunner
+ * Copyright (C) 2010-2020 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
* HSR Hochschule fuer Technik Rapperswil
return success;
}
+/**
+ * Add DNS servers to the builder
+ */
+static bool add_dns_servers(vpnservice_builder_t *builder, ike_sa_t *ike_sa)
+{
+ enumerator_t *enumerator;
+ configuration_attribute_type_t type;
+ chunk_t data;
+ bool handled;
+ host_t *dns;
+
+ enumerator = ike_sa->create_attribute_enumerator(ike_sa);
+ while (enumerator->enumerate(enumerator, &type, &data, &handled))
+ {
+ switch (type)
+ {
+ case INTERNAL_IP4_DNS:
+ dns = host_create_from_chunk(AF_INET, data, 0);
+ break;
+ case INTERNAL_IP6_DNS:
+ dns = host_create_from_chunk(AF_INET6, data, 0);
+ break;
+ default:
+ continue;
+ }
+ if (dns && !dns->is_anyaddr(dns))
+ {
+ builder->add_dns(builder, dns);
+ }
+ DESTROY_IF(dns);
+ }
+ enumerator->destroy(enumerator);
+ return TRUE;
+}
+
/**
* Setup a new TUN device for the supplied SAs, also queues a job that
* reads packets from this device.
DBG1(DBG_DMN, "setting up TUN device failed, no virtual IP found");
return FALSE;
}
- if (!add_routes(builder, child_sa) ||
+ if (!add_dns_servers(builder, ike_sa) ||
+ !add_routes(builder, child_sa) ||
!builder->set_mtu(builder, this->mtu))
{
return FALSE;