1
|
#!/usr/local/bin/php -f
|
2
|
<?php
|
3
|
/*
|
4
|
* ppp-ipv6
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Redistribution and use in source and binary forms, with or without
|
11
|
* modification, are permitted provided that the following conditions are met:
|
12
|
*
|
13
|
* 1. Redistributions of source code must retain the above copyright notice,
|
14
|
* this list of conditions and the following disclaimer.
|
15
|
*
|
16
|
* 2. Redistributions in binary form must reproduce the above copyright
|
17
|
* notice, this list of conditions and the following disclaimer in
|
18
|
* the documentation and/or other materials provided with the
|
19
|
* distribution.
|
20
|
*
|
21
|
* 3. All advertising materials mentioning features or use of this software
|
22
|
* must display the following acknowledgment:
|
23
|
* "This product includes software developed by the pfSense Project
|
24
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
25
|
*
|
26
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27
|
* endorse or promote products derived from this software without
|
28
|
* prior written permission. For written permission, please contact
|
29
|
* coreteam@pfsense.org.
|
30
|
*
|
31
|
* 5. Products derived from this software may not be called "pfSense"
|
32
|
* nor may "pfSense" appear in their names without prior written
|
33
|
* permission of the Electric Sheep Fencing, LLC.
|
34
|
*
|
35
|
* 6. Redistributions of any form whatsoever must retain the following
|
36
|
* acknowledgment:
|
37
|
*
|
38
|
* "This product includes software developed by the pfSense Project
|
39
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40
|
*
|
41
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53
|
*/
|
54
|
|
55
|
require_once("globals.inc");
|
56
|
require_once("interfaces.inc");
|
57
|
|
58
|
function interface_ipv6_lower($interface_real) {
|
59
|
global $g, $config;
|
60
|
|
61
|
if (!empty($interface_real)) {
|
62
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
63
|
|
64
|
if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
|
65
|
$ifcfg = $config['interfaces'][$interface];
|
66
|
|
67
|
if (!empty($ifcfg['ipaddrv6'])) {
|
68
|
switch ($ifcfg['ipaddrv6']) {
|
69
|
case 'slaac':
|
70
|
case 'dhcp6':
|
71
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
72
|
if ($ifcfg['ipaddrv6']==='dhcp6' && !(isset($ifcfg['dhcp6usev4iface']) || $ifcfg['ipaddr']==='ppp')) {
|
73
|
break;
|
74
|
}
|
75
|
// bring down dhcp6c if it is running
|
76
|
$pidv6 = find_dhcp6c_process($interface_real);
|
77
|
if ($pidv6) {
|
78
|
posix_kill($pidv6, SIGTERM);
|
79
|
sleep(3);
|
80
|
}
|
81
|
unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf");
|
82
|
|
83
|
// disable router advertisements (and therefore SLAAC)
|
84
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
|
85
|
|
86
|
// remove any autoconfigured IPv6 addresses
|
87
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
88
|
foreach ($ifconfig_output as $output) {
|
89
|
if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
|
90
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
|
91
|
}
|
92
|
}
|
93
|
break;
|
94
|
default:
|
95
|
break;
|
96
|
}
|
97
|
}
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
|
102
|
function interface_ipv6_raise($interface_real) {
|
103
|
global $config;
|
104
|
|
105
|
if (!empty($interface_real)) {
|
106
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
107
|
|
108
|
if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
|
109
|
$ifcfg = $config['interfaces'][$interface];
|
110
|
|
111
|
if (!empty($ifcfg['ipaddrv6'])) {
|
112
|
switch ($ifcfg['ipaddrv6']) {
|
113
|
case 'slaac':
|
114
|
case 'dhcp6':
|
115
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
116
|
if ($ifcfg['ipaddrv6']==='dhcp6' && !(isset($ifcfg['dhcp6usev4iface']) || $ifcfg['ipaddr']==='ppp')) {
|
117
|
break;
|
118
|
}
|
119
|
$pidv6 = find_dhcp6c_process($interface_real);
|
120
|
if (empty($pidv6)) {
|
121
|
// only fire if router advertisements off
|
122
|
// (if router advertisements are on, rtsold might be primed to fire dhcp6c already)
|
123
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
124
|
$start = true;
|
125
|
foreach ($ifconfig_output as $output) {
|
126
|
if (preg_match('{ \A .* ACCEPT_RTADV .* \Z}xmsi', $output)) {
|
127
|
$start = false;
|
128
|
break;
|
129
|
}
|
130
|
}
|
131
|
if ($start) {
|
132
|
interface_dhcpv6_configure($interface, $ifcfg);
|
133
|
}
|
134
|
}
|
135
|
break;
|
136
|
default:
|
137
|
break;
|
138
|
}
|
139
|
}
|
140
|
}
|
141
|
}
|
142
|
}
|
143
|
|
144
|
// main entry point
|
145
|
if ($argc != 3) {
|
146
|
goto error;
|
147
|
}
|
148
|
|
149
|
$interface_real = trim($argv[1], " \n\t");
|
150
|
if (empty($interface_real)) {
|
151
|
goto error;
|
152
|
}
|
153
|
|
154
|
switch (strtolower($argv[2])) {
|
155
|
case 'up':
|
156
|
interface_ipv6_raise($interface_real);
|
157
|
break;
|
158
|
case 'down':
|
159
|
interface_ipv6_lower($interface_real);
|
160
|
break;
|
161
|
default:
|
162
|
goto error;
|
163
|
break;
|
164
|
}
|
165
|
|
166
|
exit(0);
|
167
|
|
168
|
error:
|
169
|
if (!empty($argv[0])) {
|
170
|
echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
|
171
|
}
|
172
|
exit(1);
|
173
|
|
174
|
?>
|