libhydra: Move kernel interface to libcharon
[strongswan.git] / src / starter / netkey.c
1 /* strongSwan netkey starter
2 * Copyright (C) 2001-2002 Mathieu Lafon - Arkoon Network Security
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <stdlib.h>
18
19 #include <library.h>
20 #include <utils/debug.h>
21
22 #include "files.h"
23
24 bool starter_netkey_init(void)
25 {
26 struct stat stb;
27
28 if (stat(PROC_NETKEY, &stb) != 0)
29 {
30 /* af_key module makes the netkey proc interface visible */
31 if (stat(PROC_MODULES, &stb) == 0)
32 {
33 ignore_result(system("modprobe -qv af_key"));
34 }
35
36 /* now test again */
37 if (stat(PROC_NETKEY, &stb) != 0)
38 {
39 DBG2(DBG_APP, "kernel appears to lack the native netkey IPsec stack");
40 return FALSE;
41 }
42 }
43
44 /* make sure that all required IPsec modules are loaded */
45 if (stat(PROC_MODULES, &stb) == 0)
46 {
47 ignore_result(system("modprobe -qv ah4"));
48 ignore_result(system("modprobe -qv esp4"));
49 ignore_result(system("modprobe -qv ipcomp"));
50 ignore_result(system("modprobe -qv xfrm4_tunnel"));
51 ignore_result(system("modprobe -qv xfrm_user"));
52 }
53
54 DBG2(DBG_APP, "found netkey IPsec stack");
55 return TRUE;
56 }