debug and logging improvements
[strongswan.git] / src / charon / testing / kernel_interface_test.c
1 /**
2 * @file kernel_interface_test.h
3 *
4 * @brief Tests for the kernel_interface_t class.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <unistd.h>
24
25 #include "kernel_interface_test.h"
26
27 #include <daemon.h>
28 #include <threads/kernel_interface.h>
29 #include <utils/logger.h>
30 #include <utils/host.h>
31
32
33 /*
34 * described in Header-File
35 */
36 void test_kernel_interface(protected_tester_t *tester)
37 {
38 kernel_interface_t *kernel_interface;
39 u_int32_t spi;
40 host_t *me, *other, *left, *right;
41 status_t status;
42 prf_plus_t *prf_plus;
43 prf_t *prf;
44 u_int8_t key_bytes[] = {
45 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
46 };
47 chunk_t key = chunk_from_buf(key_bytes);
48 algorithm_t int_alg = {AUTH_HMAC_MD5_96, 0};
49 algorithm_t enc_alg = {ENCR_AES_CBC, 128};
50
51 prf = prf_create(PRF_HMAC_MD5);
52 prf->set_key(prf, key);
53 prf_plus = prf_plus_create(prf, key);
54
55 kernel_interface = kernel_interface_create();
56
57 me = host_create(AF_INET, "192.168.0.2", 0);
58 other = host_create(AF_INET, "192.168.0.3", 0);
59
60 status = kernel_interface->get_spi(kernel_interface, me, other, PROTO_ESP, 1234, &spi);
61 tester->assert_true(tester, status == SUCCESS, "spi get");
62
63 status = kernel_interface->add_sa(kernel_interface, me, other, spi, PROTO_ESP, 1234, 0, 0, &enc_alg, &int_alg, prf_plus, TRUE);
64 tester->assert_true(tester, status == SUCCESS, "add sa");
65
66 left = host_create(AF_INET, "10.1.0.0", 0);
67 right = host_create(AF_INET, "10.2.0.0", 0);
68
69 status = kernel_interface->add_policy(kernel_interface, me, other, left, right, 24, 24, XFRM_POLICY_OUT, 0, PROTO_ESP, 1234);
70 tester->assert_true(tester, status == SUCCESS, "add policy OUT");
71 status = kernel_interface->add_policy(kernel_interface, me, other, left, right, 24, 24, XFRM_POLICY_IN, 0, PROTO_ESP, 1234);
72 tester->assert_true(tester, status == SUCCESS, "add policy IN");
73 status = kernel_interface->add_policy(kernel_interface, me, other, left, right, 24, 24, XFRM_POLICY_FWD, 0, PROTO_ESP, 1234);
74 tester->assert_true(tester, status == SUCCESS, "add policy FWD");
75
76
77 kernel_interface->del_sa(kernel_interface, other, spi, PROTO_ESP);
78
79 sleep(10);
80
81 me->destroy(me);
82 other->destroy(other);
83 left->destroy(left);
84 right->destroy(right);
85
86
87
88 kernel_interface->destroy(kernel_interface);
89
90 }