Imported Upstream version 20070115
[aiccu.git] / common / aiccu_linux.c
blobb86ad6755958302bd970c2021d6c49a4275a97cb
1 /**********************************************************
2 SixXS - Automatic IPv6 Connectivity Configuration Utility
3 ***********************************************************
4 Copyright 2003-2005 SixXS - http://www.sixxs.net
5 ***********************************************************
6 common/aiccu_linux.c - AICCU Linux Abstracted functions
7 ***********************************************************
8 $Author: jeroen $
9 $Id: aiccu_linux.c,v 1.15 2007-01-15 12:18:58 jeroen Exp $
10 $Date: 2007-01-15 12:18:58 $
11 **********************************************************/
13 #include "aiccu.h"
15 bool aiccu_os_install(void)
17 /* Check if IPv6 support is available */
18 if (access("/proc/net/if_inet6", F_OK))
20 /* Doing the modprobe doesn't guarantee success unfortunately */
21 (void)system("modprobe -q ipv6 2>/dev/null >/dev/null");
23 /* Thus test it again */
24 if (access("/proc/net/if_inet6", F_OK))
26 dolog(LOG_ERR, "No IPv6 Stack found! Please check your kernel and module configuration\n");
27 return false;
31 /* Try to load modules (SIT tunnel, TUN/TAP)
32 * They can be kernel builtins and there is no easy
33 * way to check if they are loaded/built except for
34 * trying to use them and fail at that point
36 (void)system("modprobe -q sit 2>/dev/null >/dev/null");
37 (void)system("modprobe -q tun 2>/dev/null >/dev/null");
39 return true;
42 bool aiccu_os_setup(struct TIC_Tunnel *hTunnel)
44 if (hTunnel->uses_tundev == 0)
46 aiccu_exec(
47 "ip tunnel add %s mode sit %s%s remote %s",
48 g_aiccu->ipv6_interface,
49 strcmp(hTunnel->sIPv4_Local, "heartbeat") == 0 ? "" : "local ",
50 strcmp(hTunnel->sIPv4_Local, "heartbeat") == 0 ? "" : hTunnel->sIPv4_Local,
51 hTunnel->sIPv4_POP);
54 aiccu_exec(
55 "ip link set %s up",
56 g_aiccu->ipv6_interface);
58 aiccu_exec(
59 "ip link set mtu %u dev %s",
60 hTunnel->nMTU,
61 g_aiccu->ipv6_interface);
63 if (hTunnel->uses_tundev == 0)
65 aiccu_exec(
66 "ip tunnel change %s ttl 64",
67 g_aiccu->ipv6_interface);
69 else
71 /* Add a LinkLocal address for AYIYA tunnels */
72 aiccu_exec(
73 "ip -6 addr add %s/%u dev %s",
74 hTunnel->sIPv6_LinkLocal,
75 64,
76 g_aiccu->ipv6_interface);
79 aiccu_exec(
80 "ip -6 addr add %s/%u dev %s",
81 hTunnel->sIPv6_Local,
82 hTunnel->nIPv6_PrefixLength,
83 g_aiccu->ipv6_interface);
85 if (g_aiccu->defaultroute)
87 aiccu_exec(
88 "ip -6 ro add %s via %s dev %s",
89 "default",
90 hTunnel->sIPv6_POP,
91 g_aiccu->ipv6_interface);
94 return true;
97 void aiccu_os_reconfig(struct TIC_Tunnel *hTunnel)
99 if (hTunnel->uses_tundev == 0)
101 aiccu_exec(
102 "ip tunnel change %s local %s",
103 g_aiccu->ipv6_interface,
104 hTunnel->sIPv4_Local);
108 void aiccu_os_delete(struct TIC_Tunnel *hTunnel)
110 hTunnel = hTunnel;
111 aiccu_exec(
112 "ip link set %s down",
113 g_aiccu->ipv6_interface);
115 if (hTunnel->uses_tundev == 0)
117 aiccu_exec(
118 "ip tunnel del %s",
119 g_aiccu->ipv6_interface);