]>
Commit | Line | Data |
---|---|---|
d98f6a46 SS |
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 | **********************************************************/ | |
12 | ||
13 | #include "aiccu.h" | |
14 | ||
15 | bool aiccu_os_install(void) | |
16 | { | |
17 | /* Check if IPv6 support is available */ | |
18 | if (access("/proc/net/if_inet6", F_OK)) | |
19 | { | |
20 | /* Doing the modprobe doesn't guarantee success unfortunately */ | |
21 | (void)system("modprobe -q ipv6 2>/dev/null >/dev/null"); | |
22 | ||
23 | /* Thus test it again */ | |
24 | if (access("/proc/net/if_inet6", F_OK)) | |
25 | { | |
26 | dolog(LOG_ERR, "No IPv6 Stack found! Please check your kernel and module configuration\n"); | |
27 | return false; | |
28 | } | |
29 | } | |
30 | ||
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 | |
35 | */ | |
36 | (void)system("modprobe -q sit 2>/dev/null >/dev/null"); | |
37 | (void)system("modprobe -q tun 2>/dev/null >/dev/null"); | |
38 | ||
39 | return true; | |
40 | } | |
41 | ||
42 | bool aiccu_os_setup(struct TIC_Tunnel *hTunnel) | |
43 | { | |
0268def7 SS |
44 | char buffer[1024]; |
45 | ||
d98f6a46 SS |
46 | if (hTunnel->uses_tundev == 0) |
47 | { | |
48 | aiccu_exec( | |
49 | "ip tunnel add %s mode sit %s%s remote %s", | |
50 | g_aiccu->ipv6_interface, | |
51 | strcmp(hTunnel->sIPv4_Local, "heartbeat") == 0 ? "" : "local ", | |
52 | strcmp(hTunnel->sIPv4_Local, "heartbeat") == 0 ? "" : hTunnel->sIPv4_Local, | |
53 | hTunnel->sIPv4_POP); | |
54 | } | |
55 | ||
56 | aiccu_exec( | |
57 | "ip link set %s up", | |
58 | g_aiccu->ipv6_interface); | |
59 | ||
60 | aiccu_exec( | |
61 | "ip link set mtu %u dev %s", | |
62 | hTunnel->nMTU, | |
63 | g_aiccu->ipv6_interface); | |
64 | ||
65 | if (hTunnel->uses_tundev == 0) | |
66 | { | |
67 | aiccu_exec( | |
68 | "ip tunnel change %s ttl 64", | |
69 | g_aiccu->ipv6_interface); | |
70 | } | |
71 | else | |
72 | { | |
73 | /* Add a LinkLocal address for AYIYA tunnels */ | |
74 | aiccu_exec( | |
75 | "ip -6 addr add %s/%u dev %s", | |
76 | hTunnel->sIPv6_LinkLocal, | |
77 | 64, | |
78 | g_aiccu->ipv6_interface); | |
79 | } | |
80 | ||
81 | aiccu_exec( | |
82 | "ip -6 addr add %s/%u dev %s", | |
83 | hTunnel->sIPv6_Local, | |
84 | hTunnel->nIPv6_PrefixLength, | |
85 | g_aiccu->ipv6_interface); | |
86 | ||
87 | if (g_aiccu->defaultroute) | |
88 | { | |
89 | aiccu_exec( | |
90 | "ip -6 ro add %s via %s dev %s", | |
91 | "default", | |
92 | hTunnel->sIPv6_POP, | |
93 | g_aiccu->ipv6_interface); | |
94 | } | |
95 | ||
0268def7 SS |
96 | if (g_aiccu->setupscript) |
97 | { | |
98 | setenv("ACTION", "up", 1); | |
99 | setenv("TUNNEL_TYPE", hTunnel->sType, 1); | |
100 | setenv("INTERFACE", g_aiccu->ipv6_interface, 1); | |
101 | setenv("REMOTE_ADDRESS", hTunnel->sIPv6_POP, 1); | |
102 | ||
103 | snprintf(buffer, sizeof(buffer), "%s/%u", | |
104 | hTunnel->sIPv6_Local, hTunnel->nIPv6_PrefixLength); | |
105 | setenv("LOCAL_ADDRESS", buffer, 1); | |
106 | setenv("LINK_LOCAL_ADDRESS", hTunnel->sIPv6_LinkLocal, 1); | |
107 | ||
108 | snprintf(buffer, sizeof(buffer), "%u", hTunnel->nMTU); | |
109 | setenv("MTU", buffer, 1); | |
110 | ||
111 | aiccu_exec("%s", g_aiccu->setupscript); | |
112 | } | |
113 | ||
d98f6a46 SS |
114 | return true; |
115 | } | |
116 | ||
117 | void aiccu_os_reconfig(struct TIC_Tunnel *hTunnel) | |
118 | { | |
119 | if (hTunnel->uses_tundev == 0) | |
120 | { | |
121 | aiccu_exec( | |
122 | "ip tunnel change %s local %s", | |
123 | g_aiccu->ipv6_interface, | |
124 | hTunnel->sIPv4_Local); | |
125 | } | |
126 | } | |
127 | ||
128 | void aiccu_os_delete(struct TIC_Tunnel *hTunnel) | |
129 | { | |
130 | hTunnel = hTunnel; | |
131 | aiccu_exec( | |
132 | "ip link set %s down", | |
133 | g_aiccu->ipv6_interface); | |
134 | ||
135 | if (hTunnel->uses_tundev == 0) | |
136 | { | |
137 | aiccu_exec( | |
138 | "ip tunnel del %s", | |
139 | g_aiccu->ipv6_interface); | |
140 | } | |
0268def7 SS |
141 | |
142 | { | |
143 | setenv("ACTION", "down", 1); | |
144 | setenv("INTERFACE", g_aiccu->ipv6_interface, 1); | |
145 | ||
146 | aiccu_exec("%s", g_aiccu->setupscript); | |
147 | } | |
d98f6a46 SS |
148 | } |
149 |