]> git.ipfire.org Git - thirdparty/strongswan.git/blame - programs/charon/testing/kernel_interface_test.c
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / programs / charon / testing / kernel_interface_test.c
CommitLineData
ba425b87
MW
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
24#include "kernel_interface_test.h"
25
26#include <daemon.h>
27#include <threads/kernel_interface.h>
ba425b87 28#include <utils/logger.h>
68621281 29#include <utils/host.h>
ba425b87
MW
30
31
32/*
33 * described in Header-File
34 */
51d56047 35void test_kernel_interface(protected_tester_t *tester)
ba425b87
MW
36{
37 kernel_interface_t *kernel_interface;
38 u_int32_t spi;
a527a426 39 host_t *me, *other, *left, *right;
ba425b87
MW
40 status_t status;
41
42 u_int8_t enc_key_bytes[] = {
43 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
44 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
45 };
46
47 u_int8_t inc_key_bytes[] = {
48 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
49 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
50 };
51
52 chunk_t enc_key,inc_key;
53 enc_key.ptr = enc_key_bytes;
54 enc_key.len = sizeof(enc_key_bytes);
55 inc_key.ptr = inc_key_bytes;
56 inc_key.len = sizeof(inc_key_bytes);
57
58
59
60 kernel_interface = kernel_interface_create();
61
a527a426
MW
62 me = host_create(AF_INET, "192.168.0.2", 0);
63 other = host_create(AF_INET, "192.168.0.3", 0);
64
65 status = kernel_interface->get_spi(kernel_interface, me, other, 50, 1234, &spi);
30b5b412 66 tester->assert_true(tester, status == SUCCESS, "spi get");
ba425b87 67
a527a426
MW
68 status = kernel_interface->add_sa(kernel_interface, me, other, spi, 50, 1234, ENCR_AES_CBC, enc_key,AUTH_UNDEFINED,inc_key,TRUE);
69 tester->assert_true(tester, status == SUCCESS, "add sa");
70
71 left = host_create(AF_INET, "10.1.0.0", 0);
72 right = host_create(AF_INET, "10.2.0.0", 0);
73
74 status = kernel_interface->add_policy(kernel_interface, me, other, left, right, 16, 16, XFRM_POLICY_OUT, 0, TRUE, FALSE, 1234);
75 tester->assert_true(tester, status == SUCCESS, "add policy");
76
ba425b87
MW
77 me->destroy(me);
78 other->destroy(other);
a527a426
MW
79 left->destroy(left);
80 right->destroy(right);
ba425b87
MW
81
82 kernel_interface->destroy(kernel_interface);
83
84}