Revision d674c2ac

b/src/charon/plugins/attr/attr_provider.c
93 93
/**
94 94
 * Add an attribute entry to the list
95 95
 */
96
static void add_entry(private_attr_provider_t *this, char *key, int nr,
97
					  configuration_attribute_type_t type)
96
static void add_legacy_entry(private_attr_provider_t *this, char *key, int nr,
97
							 configuration_attribute_type_t type)
98 98
{
99 99
	attribute_entry_t *entry;
100 100
	host_t *host;
......
130 130
	}
131 131
}
132 132

  
133
/**
134
 * Key to attribute type mappings, for v4 and v6 attributes
135
 */
136
static struct {
137
	char *name;
138
	configuration_attribute_type_t v4;
139
	configuration_attribute_type_t v6;
140
} keys[] = {
141
	{"address",		INTERNAL_IP4_ADDRESS,	INTERNAL_IP6_ADDRESS},
142
	{"dns",			INTERNAL_IP4_DNS,		INTERNAL_IP6_DNS},
143
	{"nbns",		INTERNAL_IP4_NBNS,		INTERNAL_IP6_NBNS},
144
	{"dhcp",		INTERNAL_IP4_DHCP,		INTERNAL_IP6_DHCP},
145
	{"netmask",		INTERNAL_IP4_NETMASK,	INTERNAL_IP6_NETMASK},
146
	{"server",		INTERNAL_IP4_SERVER,	INTERNAL_IP6_SERVER},
147
};
148

  
149
/**
150
 * Load (numerical) entries from the plugins.attr namespace
151
 */
152
static void load_entries(private_attr_provider_t *this)
153
{
154
	enumerator_t *enumerator, *tokens;
155
	char *key, *value, *token;
156

  
157
	enumerator = lib->settings->create_key_value_enumerator(lib->settings,
158
														"charon.plugins.attr");
159
	while (enumerator->enumerate(enumerator, &key, &value))
160
	{
161
		configuration_attribute_type_t type;
162
		attribute_entry_t *entry;
163
		host_t *host;
164
		int i;
165

  
166
		type = atoi(key);
167
		tokens = enumerator_create_token(value, ",", " ");
168
		while (tokens->enumerate(tokens, &token))
169
		{
170
			host = host_create_from_string(token, 0);
171
			if (!host)
172
			{
173
				DBG1(DBG_CFG, "invalid host in key %s: %s", key, token);
174
				continue;
175
			}
176
			if (!type)
177
			{
178
				for (i = 0; i < countof(keys); i++)
179
				{
180
					if (streq(key, keys[i].name))
181
					{
182
						if (host->get_family(host) == AF_INET)
183
						{
184
							type = keys[i].v4;
185
						}
186
						else
187
						{
188
							type = keys[i].v6;
189
						}
190
					}
191
				}
192
				if (!type)
193
				{
194
					DBG1(DBG_CFG, "mapping attribute type %s failed", key);
195
					break;
196
				}
197
			}
198
			entry = malloc_thing(attribute_entry_t);
199
			entry->type = type;
200
			entry->value = chunk_clone(host->get_address(host));
201
			host->destroy(host);
202
			this->attributes->insert_last(this->attributes, entry);
203
		}
204
		tokens->destroy(tokens);
205
	}
206
	enumerator->destroy(enumerator);
207
}
208

  
133 209
/*
134 210
 * see header file
135 211
 */
......
149 225

  
150 226
	for (i = 1; i <= SERVER_MAX; i++)
151 227
	{
152
		add_entry(this, "dns", i, INTERNAL_IP4_DNS);
153
		add_entry(this, "nbns", i, INTERNAL_IP4_NBNS);
228
		add_legacy_entry(this, "dns", i, INTERNAL_IP4_DNS);
229
		add_legacy_entry(this, "nbns", i, INTERNAL_IP4_NBNS);
154 230
	}
155 231

  
232
	load_entries(this);
233

  
156 234
	return &this->public;
157 235
}
158 236

  

Also available in: Unified diff