aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/threads/kernel_interface.c
blob: 7b0c163ce5a3bd7b2a7a639f8768f1bd5749f8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
/**
 * @file kernel_interface.c
 *
 * @brief Implementation of kernel_interface_t.
 *
 */

/*
 * Copyright (C) 2005 Jan Hutter, Martin Willi
 * Hochschule fuer Technik Rapperswil
 * Copyright (C) 2003 Herbert Xu.
 * 
 * Contains modified parts from pluto.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#include "kernel_interface.h"

#include <daemon.h>
#include <utils/allocator.h>
#include <utils/linked_list.h>


#define KERNEL_ESP 50
#define KERNEL_AH 51

#define SPD_PRIORITY 1024

#define XFRM_DATA_LENGTH 512


typedef struct xfrm_data_t xfrm_data_t;

/**
 * Lenght/Type/data struct for userdata in xfrm
 * We dont use the "I-don't-know-where-they-come-from"-structs
 * used in the kernel.
 */
struct xfrm_data_t {
	/**
	 * length of the data
	 */
	u_int16_t length;
	
	/**
	 * type of data 
	 */
	u_int16_t type;
	
	/**
	 * and the data itself, for different purposes
	 */
	union {
		/** algorithm */
		struct xfrm_algo algo;
		/** policy tmpl */
		struct xfrm_user_tmpl tmpl[2];
	};
};


typedef struct netlink_message_t netlink_message_t;

/**
 * Representation of ANY netlink message used
 */
struct netlink_message_t {
	
	/**
	 * header of the netlink message 
	 */
	struct nlmsghdr hdr;

	union {
		/** error message */
		struct nlmsgerr e;
		/** message for spi allocation */
		struct xfrm_userspi_info spi;
		/** message for SA manipulation */
		struct xfrm_usersa_id sa_id;
		/** message for SA installation */
		struct xfrm_usersa_info sa;
		/** message for policy manipulation */
		struct xfrm_userpolicy_id policy_id;
		/** message for policy installation */
		struct xfrm_userpolicy_info policy;
	};
	u_int8_t data[XFRM_DATA_LENGTH];
};


typedef struct private_kernel_interface_t private_kernel_interface_t;

 /**
 * @brief Private Variables and Functions of kernel_interface class.
 *
 */
struct private_kernel_interface_t {
	/**
	 * Public part of the kernel_interface_t object.
	 */
	kernel_interface_t public;
	
	/**
	 * Netlink communication socket.
	 */
	int socket;
	
	pid_t pid;
	/**
	 * Sequence number for messages.
	 */
	u_int32_t seq;
	
	/** 
	 * List of responded messages.
	 */
	linked_list_t *responses;
	
	/**
	 * Thread which receives messages.
	 */
	pthread_t thread;
	
	/**
	 * Mutex locks access to replies list.
	 */
	pthread_mutex_t mutex;
	
	/**
	 * Condvar allows signaling of threads waiting for a reply.
	 */
	pthread_cond_t condvar;
	
	/**
	 * Function for the thread, receives messages.
	 */
	void (*receive_messages) (private_kernel_interface_t *this);
	
	/**
	 * Sends a netlink_message_t down to the kernel and wait for reply.
	 */
	status_t (*send_message) (private_kernel_interface_t *this, netlink_message_t *request, netlink_message_t **response);
};

/**
 * In the kernel, algorithms are identified as strings, we use our
 * mapping functions...
 * Algorithms for encryption.
 * TODO: Add missing algorithm strings
 */
mapping_t kernel_encryption_algs_m[] = {
	{ENCR_DES_IV64, ""},
	{ENCR_DES, "des"},
	{ENCR_3DES, "des3_ede"},
	{ENCR_RC5, ""},
	{ENCR_IDEA, "idea"},
	{ENCR_CAST, "cast128"},
	{ENCR_BLOWFISH, "blowfish"},
	{ENCR_3IDEA, ""},
	{ENCR_DES_IV32, ""},
	{ENCR_NULL, ""},
	{ENCR_AES_CBC, "aes"},
	{ENCR_AES_CTR, ""},
	{MAPPING_END, NULL}
};
/**
 * In the kernel, algorithms are identified as strings, we use our
 * mapping functions...
 * Algorithms for integrity protection.
 * TODO: Add missing algorithm strings
 */
mapping_t kernel_integrity_algs_m[] = {
	{AUTH_HMAC_MD5_96, "md5"},
	{AUTH_HMAC_SHA1_96, "sha1"},
	{AUTH_DES_MAC, ""},
	{AUTH_KPDK_MD5, ""},
	{AUTH_AES_XCBC_96, ""},
	{MAPPING_END, NULL}
};

/**
 * Implementation of kernel_interface_t.get_spi.
 */
static status_t get_spi(private_kernel_interface_t *this, 
						host_t *src, host_t *dest, 
						protocol_id_t protocol, u_int32_t reqid,
						u_int32_t *spi)
{
	netlink_message_t request, *response;
	status_t status = SUCCESS;
	
	memset(&request, 0, sizeof(request));
	request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.spi)));
	request.hdr.nlmsg_flags = NLM_F_REQUEST;
	request.hdr.nlmsg_type = XFRM_MSG_ALLOCSPI;
	request.spi.info.saddr = src->get_xfrm_addr(src);
	request.spi.info.id.daddr = dest->get_xfrm_addr(dest);
	request.spi.info.mode = TRUE; /* tunnel mode */
	request.spi.info.reqid = reqid;
	request.spi.info.id.proto = (protocol == ESP) ? KERNEL_ESP : KERNEL_AH;
	request.spi.info.family = PF_INET;
	request.spi.min = 0xc0000000;
	request.spi.max = 0xcFFFFFFF;
	
	if (this->send_message(this, &request, &response) != SUCCESS)
	{
		status = FAILED;
	}
	else if (response->hdr.nlmsg_type == NLMSG_ERROR)
	{
		status = FAILED;
	}
	else if (response->hdr.nlmsg_type != XFRM_MSG_NEWSA)
	{
		status = FAILED;
	}
	else if (response->hdr.nlmsg_len < NLMSG_LENGTH(sizeof(response->sa)))
	{
		status = FAILED;
	}
	
	*spi = response->sa.id.spi;
	allocator_free(response);
	
	return status;
}

/**
 * Implementation of kernel_interface_t.add_sa.
 */
static status_t add_sa(	private_kernel_interface_t *this,
						host_t *me,
						host_t *other,
						u_int32_t spi,
						int protocol,
						u_int32_t reqid,
						encryption_algorithm_t enc_alg,
						chunk_t encryption_key,
						integrity_algorithm_t int_alg,
						chunk_t integrity_key,
						bool replace)
{
	netlink_message_t request, *response;
	memset(&request, 0, sizeof(request));
	status_t status;
	
	request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
	request.hdr.nlmsg_type = replace ? XFRM_MSG_UPDSA : XFRM_MSG_NEWSA;
	
	request.sa.saddr = me->get_xfrm_addr(me);
	request.sa.id.daddr = other->get_xfrm_addr(other);
	
	request.sa.id.spi = spi;
	request.sa.id.proto = (protocol == ESP) ? KERNEL_ESP : KERNEL_AH;
	request.sa.family = me->get_family(me);
	request.sa.mode = TRUE; /* tunnel mode */
	request.sa.replay_window = 0; //sa->replay_window; ???
	request.sa.reqid = reqid;
	request.sa.lft.soft_byte_limit = XFRM_INF;
	request.sa.lft.soft_packet_limit = XFRM_INF;
	request.sa.lft.hard_byte_limit = XFRM_INF;
	request.sa.lft.hard_packet_limit = XFRM_INF;
	
	request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.sa)));
	
	if (enc_alg != ENCR_UNDEFINED)
	{
		xfrm_data_t *data = (xfrm_data_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
		
		data->type = XFRMA_ALG_CRYPT;
		data->length = 4 + sizeof(data->algo) + encryption_key.len;
		data->algo.alg_key_len = encryption_key.len * 8;
		request.hdr.nlmsg_len += data->length;
		if (request.hdr.nlmsg_len > sizeof(request))
		{
			return FAILED;
		}
		strcpy(data->algo.alg_name, mapping_find(kernel_encryption_algs_m, enc_alg));
		memcpy(data->algo.alg_key, encryption_key.ptr, encryption_key.len);
	}
	
	if (int_alg != AUTH_UNDEFINED)
	{
		xfrm_data_t *data = (xfrm_data_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
		
		data->type = XFRMA_ALG_AUTH;
		data->length = 4 + sizeof(data->algo) + integrity_key.len;
		data->algo.alg_key_len = integrity_key.len * 8;
		request.hdr.nlmsg_len += data->length;
		if (request.hdr.nlmsg_len > sizeof(request))
		{
			return FAILED;
		}
		strcpy(data->algo.alg_name, mapping_find(kernel_integrity_algs_m, int_alg));
		memcpy(data->algo.alg_key, integrity_key.ptr, integrity_key.len);
	}
	
	/* TODO: add IPComp here*/
	
	if (this->send_message(this, &request, &response) != SUCCESS)
	{
		status = FAILED;
	}
	else if (response->hdr.nlmsg_type != NLMSG_ERROR)
	{
		status = FAILED;
	}
	else if (response->e.error)
	{
		status = FAILED;
	}
	
	allocator_free(response);
	return SUCCESS;
}

static status_t del_sa(	private_kernel_interface_t *this,
						host_t *dst,
						u_int32_t spi,
						protocol_id_t protocol)
{
	netlink_message_t request, *response;
	memset(&request, 0, sizeof(request));
	status_t status;
	
	request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
	request.hdr.nlmsg_type = XFRM_MSG_DELSA;
	
	request.sa_id.daddr = dst->get_xfrm_addr(dst);
	
	request.sa_id.spi = spi;
	request.sa_id.proto = (protocol == ESP) ? KERNEL_ESP : KERNEL_AH;
	request.sa_id.family = dst->get_family(dst);
	
	request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.sa_id)));
	
	if (this->send_message(this, &request, &response) != SUCCESS)
	{
		status = FAILED;
	}
	else if (response->hdr.nlmsg_type != NLMSG_ERROR)
	{
		status = FAILED;
	}
	else if (response->e.error)
	{
		status = FAILED;
	}
	
	allocator_free(response);
	return SUCCESS;
}

/**
 * Implementation of kernel_interface_t.add_policy.
 */
static status_t add_policy(private_kernel_interface_t *this, 
						  host_t *me, host_t *other, 
						  host_t *src, host_t *dst,
						  u_int8_t src_hostbits, u_int8_t dst_hostbits,
						  int direction, int upper_proto, 
						  bool ah, bool esp,
						  u_int32_t reqid)
{
	netlink_message_t request, *response;
	status_t status = SUCCESS;
	
	memset(&request, 0, sizeof(request));
	request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;

	request.policy.sel.sport = htons(src->get_port(src));
	request.policy.sel.dport = htons(dst->get_port(dst));
	request.policy.sel.sport_mask = (request.policy.sel.sport) ? ~0 : 0;
	request.policy.sel.dport_mask = (request.policy.sel.dport) ? ~0 : 0;
	request.policy.sel.saddr = src->get_xfrm_addr(src);
	request.policy.sel.daddr = dst->get_xfrm_addr(dst);
	request.policy.sel.prefixlen_s = src_hostbits;
	request.policy.sel.prefixlen_d = dst_hostbits;
	request.policy.sel.proto = upper_proto;
	request.policy.sel.family = src->get_family(src);

	request.hdr.nlmsg_type = XFRM_MSG_NEWPOLICY;
	request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.policy)));

	request.policy.dir = direction;
	request.policy.priority = SPD_PRIORITY;
	request.policy.action = XFRM_POLICY_ALLOW;
	request.policy.share = XFRM_SHARE_ANY;
	
	request.policy.lft.soft_byte_limit = XFRM_INF;
	request.policy.lft.soft_packet_limit = XFRM_INF;
	request.policy.lft.hard_byte_limit = XFRM_INF;
	request.policy.lft.hard_packet_limit = XFRM_INF;
	
	if (esp || ah)
	{
		xfrm_data_t *data;
		int tmpl_pos = 0;
		data = (xfrm_data_t*)(((u_int8_t*)&request) + request.hdr.nlmsg_len);
		data->type = XFRMA_TMPL;
		if (esp)
		{
			data->tmpl[tmpl_pos].reqid = reqid;
			data->tmpl[tmpl_pos].id.proto = KERNEL_ESP;
			data->tmpl[tmpl_pos].aalgos = data->tmpl[tmpl_pos].ealgos = data->tmpl[tmpl_pos].calgos = ~0;
			data->tmpl[tmpl_pos].mode = TRUE;
			
			data->tmpl[tmpl_pos].saddr = me->get_xfrm_addr(me);
			data->tmpl[tmpl_pos].id.daddr = me->get_xfrm_addr(other);
			
			tmpl_pos++;
		}	
		if (ah)
		{
			data->tmpl[tmpl_pos].reqid = reqid;
			data->tmpl[tmpl_pos].id.proto = KERNEL_AH;
			data->tmpl[tmpl_pos].aalgos = data->tmpl[tmpl_pos].ealgos = data->tmpl[tmpl_pos].calgos = ~0;
			data->tmpl[tmpl_pos].mode = TRUE;
			
			data->tmpl[tmpl_pos].saddr = me->get_xfrm_addr(me);
			data->tmpl[tmpl_pos].id.daddr = other->get_xfrm_addr(other);
			
			tmpl_pos++;
		}
		data->length = 4 + sizeof(struct xfrm_user_tmpl) * tmpl_pos;
		request.hdr.nlmsg_len += data->length;
	}
	
	if (this->send_message(this, &request, &response) != SUCCESS)
	{
		status = FAILED;
	}
	else if (response->hdr.nlmsg_type != NLMSG_ERROR)
	{
		status = FAILED;
	}
	else if (response->e.error)
	{
		status = FAILED;
	}
	
	allocator_free(response);
	return status;
}

/**
 * Implementation of kernel_interface_t.del_policy.
 */
static status_t del_policy(private_kernel_interface_t *this, 
						   host_t *me, host_t *other, 
						   host_t *src, host_t *dst,
						   u_int8_t src_hostbits, u_int8_t dst_hostbits,
						   int direction, int upper_proto)
{
	netlink_message_t request, *response;
	status_t status = SUCCESS;
	
	memset(&request, 0, sizeof(request));
	request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;

	request.policy_id.sel.sport = htons(src->get_port(src));
	request.policy_id.sel.dport = htons(dst->get_port(dst));
	request.policy_id.sel.sport_mask = (request.policy.sel.sport) ? ~0 : 0;
	request.policy_id.sel.dport_mask = (request.policy.sel.dport) ? ~0 : 0;
	request.policy_id.sel.saddr = src->get_xfrm_addr(src);
	request.policy_id.sel.daddr = dst->get_xfrm_addr(dst);
	request.policy_id.sel.prefixlen_s = src_hostbits;
	request.policy_id.sel.prefixlen_d = dst_hostbits;
	request.policy_id.sel.proto = upper_proto;
	request.policy_id.sel.family = src->get_family(src);
	
	request.policy_id.dir = direction;

	request.hdr.nlmsg_type = XFRM_MSG_DELPOLICY;
	request.hdr.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request.policy_id)));
	
	if (this->send_message(this, &request, &response) != SUCCESS)
	{
		status = FAILED;
	}
	else if (response->hdr.nlmsg_type != NLMSG_ERROR)
	{
		status = FAILED;
	}
	else if (response->e.error)
	{
		status = FAILED;
	}
	
	allocator_free(response);
	return status;
}

/**
 * Implementation of private_kernel_interface_t.send_message.
 */
static status_t send_message(private_kernel_interface_t *this, netlink_message_t *request, netlink_message_t **response)
{
	size_t length;
	struct sockaddr_nl addr;
	
	request->hdr.nlmsg_seq = ++this->seq;
	request->hdr.nlmsg_pid = this->pid;
	
	memset(&addr, 0, sizeof(struct sockaddr_nl));
	addr.nl_family = AF_NETLINK;
	addr.nl_pid = 0;
	addr.nl_groups = 0;
	
	length = sendto(this->socket,(void *)request, request->hdr.nlmsg_len, 0, (struct sockaddr *)&addr, sizeof(addr));
	
	if (length < 0)
	{
		return FAILED;
	}
	else if (length != request->hdr.nlmsg_len)
	{
		return FAILED;
	}
	
	pthread_mutex_lock(&(this->mutex));
	
	while (TRUE)
	{
		iterator_t *iterator; 
		bool found = FALSE;
		/* search list, break if found */
		iterator = this->responses->create_iterator(this->responses, TRUE);
		while (iterator->has_next(iterator))
		{
			netlink_message_t *listed_response;
			iterator->current(iterator, (void**)&listed_response);
			if (listed_response->hdr.nlmsg_seq == request->hdr.nlmsg_seq)
			{
				/* matches our request, this is the reply */
				*response = listed_response;
				found = TRUE;
				break;
			}
		}
		iterator->destroy(iterator);
		
		if (found)
		{
			break;
		}
		/* TODO: we should time out, if something goes wrong!??? */
		pthread_cond_wait(&(this->condvar), &(this->mutex));
	}
	
	pthread_mutex_unlock(&(this->mutex));
	
	return SUCCESS;
}

/**
 * Implementation of private_kernel_interface_t.receive_messages.
 */
static void receive_messages(private_kernel_interface_t *this)
{
	while(TRUE) 
	{
		netlink_message_t response, *listed_response;
		while (TRUE)
		{
			struct sockaddr_nl addr;
			socklen_t addr_length;
			size_t length;
			
			addr_length = sizeof(addr);
			
			response.hdr.nlmsg_type = XFRM_MSG_NEWSA;
			length = recvfrom(this->socket, &response, sizeof(response), 0, (struct sockaddr*)&addr, &addr_length);
			if (length < 0)
			{
				if (errno == EINTR)
				{
					/* interrupted, try again */
					continue;
				}
				charon->kill(charon, "receiving from netlink socket failed");
			}
			if (!NLMSG_OK(&response.hdr, length))
			{
				/* bad netlink message */
				continue;
			}
			if (addr.nl_pid != 0)
			{
				/* not from kernel. not interested, try another one */
				continue;
			}
			break;
		}
		
		/* got a valid message.
		 * requests are handled on our own, 
		 * responses are listed for the requesters
		 */
		if (response.hdr.nlmsg_flags & NLM_F_REQUEST)
		{
			/* handle request */	
		}
		else
		{
			/* add response to queue */			
			listed_response = allocator_alloc(sizeof(response));
			memcpy(listed_response, &response, sizeof(response));

			pthread_mutex_lock(&(this->mutex));
			this->responses->insert_last(this->responses, (void*)listed_response);
			pthread_mutex_unlock(&(this->mutex));
			/* signal ALL waiting threads */
			pthread_cond_broadcast(&(this->condvar));
		}
		/* get the next one */
	}
}

/**
 * Implementation of kernel_interface_t.destroy.
 */
static void destroy(private_kernel_interface_t *this)
{	
	pthread_cancel(this->thread);
	pthread_join(this->thread, NULL);
	close(this->socket);
	this->responses->destroy(this->responses);
	allocator_free(this);
}

/*
 * Described in header.
 */
kernel_interface_t *kernel_interface_create()
{
	private_kernel_interface_t *this = allocator_alloc_thing(private_kernel_interface_t);
	
	/* public functions */
	this->public.get_spi = (status_t(*)(kernel_interface_t*,host_t*,host_t*,protocol_id_t,u_int32_t,u_int32_t*))get_spi;
	this->public.add_sa  = (status_t(*)(kernel_interface_t *,host_t*,host_t*,u_int32_t,protocol_id_t,u_int32_t,encryption_algorithm_t,chunk_t,integrity_algorithm_t,chunk_t,bool))add_sa;
	this->public.add_policy = (status_t(*)(kernel_interface_t*,host_t*, host_t*,host_t*,host_t*,u_int8_t,u_int8_t,int,int,bool,bool,u_int32_t))add_policy;
	this->public.del_sa = (status_t(*)(kernel_interface_t*,host_t*,u_int32_t,protocol_id_t))del_sa;
	this->public.del_policy = (status_t(*)(kernel_interface_t*,host_t*,host_t*,host_t*,host_t*,u_int8_t,u_int8_t,int,int))del_policy;
	
	this->public.destroy = (void(*)(kernel_interface_t*)) destroy;

	/* private members */
	this->receive_messages = receive_messages;
	this->send_message = send_message;
	this->pid = getpid();
	this->responses = linked_list_create();
	pthread_mutex_init(&(this->mutex),NULL);
	pthread_cond_init(&(this->condvar),NULL);
	this->seq = 0;
	this->socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_XFRM);
	if (this->socket <= 0)
	{
		allocator_free(this);
		charon->kill(charon, "Unable to create netlink socket");	
	}
	
	if (pthread_create(&(this->thread), NULL, (void*(*)(void*))this->receive_messages, this) != 0)
	{
		close(this->socket);
		allocator_free(this);
		charon->kill(charon, "Unable to create netlink thread");
	}
	
	charon->logger_manager->enable_logger_level(charon->logger_manager, TESTER, FULL);
	return (&this->public);
}