Annotation of embedaddon/strongswan/src/charon-nm/nm/nm_handler.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2016 Tobias Brunner
! 3: * Copyright (C) 2009 Martin Willi
! 4: * HSR Hochschule fuer Technik Rapperswil
! 5: *
! 6: * This program is free software; you can redistribute it and/or modify it
! 7: * under the terms of the GNU General Public License as published by the
! 8: * Free Software Foundation; either version 2 of the License, or (at your
! 9: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 10: *
! 11: * This program is distributed in the hope that it will be useful, but
! 12: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 13: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 14: * for more details.
! 15: */
! 16:
! 17: #include "nm_handler.h"
! 18:
! 19: #include <daemon.h>
! 20: #include <collections/array.h>
! 21:
! 22: typedef struct private_nm_handler_t private_nm_handler_t;
! 23:
! 24: /**
! 25: * Private data of an nm_handler_t object.
! 26: */
! 27: struct private_nm_handler_t {
! 28:
! 29: /**
! 30: * Public nm_handler_t interface.
! 31: */
! 32: nm_handler_t public;
! 33:
! 34: /**
! 35: * Received DNS server attributes, chunk_t
! 36: */
! 37: array_t *dns;
! 38:
! 39: /**
! 40: * Received IPv6 DNS server attributes, chunk_t
! 41: */
! 42: array_t *dns6;
! 43:
! 44: /**
! 45: * Received NBNS server attributes, chunk_t
! 46: */
! 47: array_t *nbns;
! 48: };
! 49:
! 50: METHOD(attribute_handler_t, handle, bool,
! 51: private_nm_handler_t *this, ike_sa_t *ike_sa,
! 52: configuration_attribute_type_t type, chunk_t data)
! 53: {
! 54: array_t *list;
! 55:
! 56: switch (type)
! 57: {
! 58: case INTERNAL_IP4_DNS:
! 59: list = this->dns;
! 60: break;
! 61: case INTERNAL_IP6_DNS:
! 62: list = this->dns6;
! 63: break;
! 64: case INTERNAL_IP4_NBNS:
! 65: list = this->nbns;
! 66: break;
! 67: default:
! 68: return FALSE;
! 69: }
! 70: data = chunk_clone(data);
! 71: array_insert(list, ARRAY_TAIL, &data);
! 72: return TRUE;
! 73: }
! 74:
! 75: METHOD(enumerator_t, enumerate_dns6, bool,
! 76: enumerator_t *this, va_list args)
! 77: {
! 78: configuration_attribute_type_t *type;
! 79: chunk_t *data;
! 80:
! 81: VA_ARGS_VGET(args, type, data);
! 82: *type = INTERNAL_IP6_DNS;
! 83: *data = chunk_empty;
! 84: this->venumerate = (void*)return_false;
! 85: return TRUE;
! 86: }
! 87:
! 88: METHOD(enumerator_t, enumerate_nbns, bool,
! 89: enumerator_t *this, va_list args)
! 90: {
! 91: configuration_attribute_type_t *type;
! 92: chunk_t *data;
! 93:
! 94: VA_ARGS_VGET(args, type, data);
! 95: *type = INTERNAL_IP4_NBNS;
! 96: *data = chunk_empty;
! 97: /* enumerate IPv6 DNS server as next attribute ... */
! 98: this->venumerate = _enumerate_dns6;
! 99: return TRUE;
! 100: }
! 101:
! 102: /**
! 103: * Implementation of create_attribute_enumerator().enumerate() for DNS
! 104: */
! 105: METHOD(enumerator_t, enumerate_dns, bool,
! 106: enumerator_t *this, va_list args)
! 107: {
! 108: configuration_attribute_type_t *type;
! 109: chunk_t *data;
! 110:
! 111: VA_ARGS_VGET(args, type, data);
! 112: *type = INTERNAL_IP4_DNS;
! 113: *data = chunk_empty;
! 114: /* enumerate WINS server as next attribute ... */
! 115: this->venumerate = _enumerate_nbns;
! 116: return TRUE;
! 117: }
! 118:
! 119: METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t*,
! 120: private_nm_handler_t *this, ike_sa_t *ike_sa, linked_list_t *vips)
! 121: {
! 122: if (vips->get_count(vips))
! 123: {
! 124: enumerator_t *enumerator;
! 125:
! 126: INIT(enumerator,
! 127: /* enumerate DNS attribute first ... */
! 128: .enumerate = enumerator_enumerate_default,
! 129: .venumerate = _enumerate_dns,
! 130: .destroy = (void*)free,
! 131: );
! 132: return enumerator;
! 133: }
! 134: return enumerator_create_empty();
! 135: }
! 136:
! 137: METHOD(nm_handler_t, create_enumerator, enumerator_t*,
! 138: private_nm_handler_t *this, configuration_attribute_type_t type)
! 139: {
! 140: array_t *list;
! 141:
! 142: switch (type)
! 143: {
! 144: case INTERNAL_IP4_DNS:
! 145: list = this->dns;
! 146: break;
! 147: case INTERNAL_IP6_DNS:
! 148: list = this->dns6;
! 149: break;
! 150: case INTERNAL_IP4_NBNS:
! 151: list = this->nbns;
! 152: break;
! 153: default:
! 154: return enumerator_create_empty();
! 155: }
! 156: return array_create_enumerator(list);
! 157: }
! 158:
! 159: METHOD(nm_handler_t, reset, void,
! 160: private_nm_handler_t *this)
! 161: {
! 162: chunk_t chunk;
! 163:
! 164: while (array_remove(this->dns, ARRAY_TAIL, &chunk))
! 165: {
! 166: chunk_free(&chunk);
! 167: }
! 168: while (array_remove(this->dns6, ARRAY_TAIL, &chunk))
! 169: {
! 170: chunk_free(&chunk);
! 171: }
! 172: while (array_remove(this->nbns, ARRAY_TAIL, &chunk))
! 173: {
! 174: chunk_free(&chunk);
! 175: }
! 176: }
! 177:
! 178: METHOD(nm_handler_t, destroy, void,
! 179: private_nm_handler_t *this)
! 180: {
! 181: reset(this);
! 182: array_destroy(this->dns);
! 183: array_destroy(this->dns6);
! 184: array_destroy(this->nbns);
! 185: free(this);
! 186: }
! 187:
! 188: /**
! 189: * See header
! 190: */
! 191: nm_handler_t *nm_handler_create()
! 192: {
! 193: private_nm_handler_t *this;
! 194:
! 195: INIT(this,
! 196: .public = {
! 197: .handler = {
! 198: .handle = _handle,
! 199: .release = nop,
! 200: .create_attribute_enumerator = _create_attribute_enumerator,
! 201: },
! 202: .create_enumerator = _create_enumerator,
! 203: .reset = _reset,
! 204: .destroy = _destroy,
! 205: },
! 206: .dns = array_create(sizeof(chunk_t), 0),
! 207: .dns6 = array_create(sizeof(chunk_t), 0),
! 208: .nbns = array_create(sizeof(chunk_t), 0),
! 209: );
! 210:
! 211: return &this->public;
! 212: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>