File: aiccu_linux.c

package info (click to toggle)
aiccu 20070115-9
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 540 kB
  • ctags: 616
  • sloc: ansic: 4,660; sh: 442; makefile: 367
file content (122 lines) | stat: -rwxr-xr-x 2,900 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**********************************************************
 SixXS - Automatic IPv6 Connectivity Configuration Utility
***********************************************************
 Copyright 2003-2005 SixXS - http://www.sixxs.net
***********************************************************
 common/aiccu_linux.c - AICCU Linux Abstracted functions
***********************************************************
 $Author: jeroen $
 $Id: aiccu_linux.c,v 1.15 2007-01-15 12:18:58 jeroen Exp $
 $Date: 2007-01-15 12:18:58 $
**********************************************************/

#include "aiccu.h"

bool aiccu_os_install(void)
{
	/* Check if IPv6 support is available */
	if (access("/proc/net/if_inet6", F_OK))
	{
		/* Doing the modprobe doesn't guarantee success unfortunately */
		(void)system("modprobe -q ipv6 2>/dev/null >/dev/null");

		/* Thus test it again */
		if (access("/proc/net/if_inet6", F_OK))
		{
			dolog(LOG_ERR, "No IPv6 Stack found! Please check your kernel and module configuration\n");
			return false;
		}
	}

	/* Try to load modules (SIT tunnel, TUN/TAP)
	 * They can be kernel builtins and there is no easy
	 * way to check if they are loaded/built except for
	 * trying to use them and fail at that point
	 */
	(void)system("modprobe -q sit 2>/dev/null >/dev/null");
	(void)system("modprobe -q tun 2>/dev/null >/dev/null");

	return true;
}

bool aiccu_os_setup(struct TIC_Tunnel *hTunnel)
{
	if (hTunnel->uses_tundev == 0)
	{
		aiccu_exec(
			"ip tunnel add %s mode sit %s%s remote %s",
			g_aiccu->ipv6_interface,
			strcmp(hTunnel->sIPv4_Local, "heartbeat") == 0 ? "" : "local ",
			strcmp(hTunnel->sIPv4_Local, "heartbeat") == 0 ? "" : hTunnel->sIPv4_Local,
			hTunnel->sIPv4_POP);
	}

	aiccu_exec(
		"ip link set %s up",
		g_aiccu->ipv6_interface);

	aiccu_exec(
		"ip link set mtu %u dev %s",
		hTunnel->nMTU,
		g_aiccu->ipv6_interface);

	if (hTunnel->uses_tundev == 0)
	{
		aiccu_exec(
			"ip tunnel change %s ttl 64",
			g_aiccu->ipv6_interface);
	}
	else
	{
		/* Add a LinkLocal address for AYIYA tunnels */
		aiccu_exec(
			"ip -6 addr add %s/%u dev %s",
			hTunnel->sIPv6_LinkLocal,
			64,
			g_aiccu->ipv6_interface);
	}

	aiccu_exec(
		"ip -6 addr add %s/%u dev %s",
		hTunnel->sIPv6_Local,
		hTunnel->nIPv6_PrefixLength,
		g_aiccu->ipv6_interface);

	if (g_aiccu->defaultroute)
	{
		aiccu_exec(
			"ip -6 ro add %s via %s dev %s",
			"default",
			hTunnel->sIPv6_POP,
			g_aiccu->ipv6_interface);
	}

	return true;
}

void aiccu_os_reconfig(struct TIC_Tunnel *hTunnel)
{
	if (hTunnel->uses_tundev == 0)
	{
		aiccu_exec(
			"ip tunnel change %s local %s",
			g_aiccu->ipv6_interface,
			hTunnel->sIPv4_Local);
	}
}

void aiccu_os_delete(struct TIC_Tunnel *hTunnel)
{
	hTunnel = hTunnel;
	aiccu_exec(
		"ip link set %s down",
		g_aiccu->ipv6_interface);

	if (hTunnel->uses_tundev == 0)
	{
		aiccu_exec(
			"ip tunnel del %s",
			g_aiccu->ipv6_interface);
	}
}