Project

General

Profile

Download (3.88 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/*
4
	ppp-ipv6
5

    
6
	PPP IPv6 helper
7

    
8
*/
9

    
10
require_once("globals.inc");
11
require_once("interfaces.inc");
12

    
13
function interface_ipv6_lower($interface_real) {
14
	global $g, $config;
15

    
16
	if (!empty($interface_real)) {
17
		$interface = convert_real_interface_to_friendly_interface_name($interface_real);
18

    
19
		if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
20
			$ifcfg = $config['interfaces'][$interface];
21

    
22
            if (!empty($ifcfg['ipaddrv6'])) {
23
                switch ($ifcfg['ipaddrv6']) {
24
                    case 'slaac':
25
                    case 'dhcp6':
26
                        // bring down dhcp6c if it is running
27
                        $pidv6 = find_dhcp6c_process($interface_real);
28
                        if ($pidv6) {
29
                            posix_kill($pidv6, SIGTERM);
30
                            sleep(3);
31
                        }
32
                        unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf");
33

    
34
                        // disable router advertisements (and therefore SLAAC)
35
                        mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
36

    
37
                        // remove any autoconfigured IPv6 addresses
38
                        exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
39
                        foreach ($ifconfig_output as $output) {
40
                            if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
41
                                mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
42
                            }
43
                        }
44
                        break;
45
                    default:
46
                        break;
47
                }
48
            }
49
		}
50
	}
51
}
52

    
53
function interface_ipv6_raise($interface_real) {
54
	global $config;
55

    
56
	if (!empty($interface_real)) {
57
		$interface = convert_real_interface_to_friendly_interface_name($interface_real);
58

    
59
		if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
60
			$ifcfg = $config['interfaces'][$interface];
61

    
62
            if (!empty($ifcfg['ipaddrv6'])) {
63
                switch ($ifcfg['ipaddrv6']) {
64
                    case 'slaac':
65
                    case 'dhcp6':
66
                        $pidv6 = find_dhcp6c_process($interface_real);
67
                        if (empty($pidv6)) {
68
                            // only fire if router advertisements off
69
                            // (if router advertisements are on, rtsold might be primed to fire dhcp6c already)
70
                            exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
71
                            $start = true;
72
                            foreach ($ifconfig_output as $output) {
73
                                if (preg_match('{ \A .* ACCEPT_RTADV .* \Z}xmsi', $output)) {
74
                                    $start = false;
75
                                    break;
76
                                }
77
                            }
78
                            if ($start) {
79
                                interface_dhcpv6_configure($interface, $ifcfg);
80
                            }
81
                        }
82
                        break;
83
                    default:
84
                        break;
85
                }
86
            }
87
		}
88
	}
89
}
90

    
91
// main entry point
92
if ($argc != 3) {
93
	goto error;
94
}
95

    
96
$interface_real = trim($argv[1], " \n\t");
97
if (empty($interface_real)) {
98
	goto error;
99
}
100

    
101
switch (strtolower($argv[2])) {
102
	case 'up':
103
		interface_ipv6_raise($interface_real);
104
		break;
105
	case 'down':
106
		interface_ipv6_lower($interface_real);
107
		break;
108
	default:
109
		goto error;
110
		break;
111
}
112

    
113
exit(0);
114

    
115
error:
116
if (!empty($argv[0])) {
117
	echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
118
}
119
exit(1);
120

    
121
?>
(12-12/23)