1 |
05a73e0e
|
David Wood
|
#!/usr/local/bin/php -f
|
2 |
|
|
<?php
|
3 |
|
|
/*
|
4 |
ac24dc24
|
Renato Botelho
|
* ppp-ipv6
|
5 |
|
|
*
|
6 |
|
|
* part of pfSense (https://www.pfsense.org)
|
7 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
8 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
9 |
37d60e23
|
Luiz Souza
|
* Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
|
10 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
11 |
|
|
*
|
12 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
13 |
|
|
* you may not use this file except in compliance with the License.
|
14 |
|
|
* You may obtain a copy of the License at
|
15 |
ac24dc24
|
Renato Botelho
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17 |
ac24dc24
|
Renato Botelho
|
*
|
18 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
19 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
20 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
21 |
|
|
* See the License for the specific language governing permissions and
|
22 |
|
|
* limitations under the License.
|
23 |
ac24dc24
|
Renato Botelho
|
*/
|
24 |
05a73e0e
|
David Wood
|
|
25 |
|
|
require_once("globals.inc");
|
26 |
|
|
require_once("interfaces.inc");
|
27 |
|
|
|
28 |
|
|
function interface_ipv6_lower($interface_real) {
|
29 |
63d6bb4f
|
Marcos Mendoza
|
global $g;
|
30 |
05a73e0e
|
David Wood
|
|
31 |
|
|
if (!empty($interface_real)) {
|
32 |
|
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
33 |
5843f3bf
|
Marcos Mendoza
|
if (empty($interface)) {
|
34 |
|
|
return;
|
35 |
|
|
}
|
36 |
05a73e0e
|
David Wood
|
|
37 |
63d6bb4f
|
Marcos Mendoza
|
$ifcfg = config_get_path("interfaces/{$interface}");
|
38 |
|
|
if (!empty($interface) && is_array($ifcfg) && interface_isppp_type($interface)) {
|
39 |
5e6a51bb
|
Renato Botelho do Couto
|
if (!empty($ifcfg['ipaddrv6'])) {
|
40 |
|
|
switch ($ifcfg['ipaddrv6']) {
|
41 |
|
|
case 'slaac':
|
42 |
|
|
case 'dhcp6':
|
43 |
|
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
44 |
|
|
if ((($ifcfg['ipaddrv6'] == 'dhcp6') && !isset($ifcfg['dhcp6usev4iface'])) ||
|
45 |
|
|
(($ifcfg['ipaddrv6'] == 'slaac') && !isset($ifcfg['slaacusev4iface'])) ||
|
46 |
|
|
!interface_isppp_type($interface)) {
|
47 |
|
|
break;
|
48 |
|
|
}
|
49 |
|
|
// reconfigure dhcp6c if it is running
|
50 |
|
|
interface_dhcpv6_configure($interface, $ifcfg, true);
|
51 |
05a73e0e
|
David Wood
|
|
52 |
5e6a51bb
|
Renato Botelho do Couto
|
// disable router advertisements (and therefore SLAAC)
|
53 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
|
54 |
05a73e0e
|
David Wood
|
|
55 |
5e6a51bb
|
Renato Botelho do Couto
|
// remove any autoconfigured IPv6 addresses
|
56 |
|
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
57 |
|
|
foreach ($ifconfig_output as $output) {
|
58 |
|
|
if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
|
59 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
break;
|
63 |
|
|
default:
|
64 |
|
|
break;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
05a73e0e
|
David Wood
|
}
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
function interface_ipv6_raise($interface_real) {
|
72 |
|
|
if (!empty($interface_real)) {
|
73 |
|
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
74 |
5843f3bf
|
Marcos Mendoza
|
if (empty($interface)) {
|
75 |
|
|
return;
|
76 |
|
|
}
|
77 |
05a73e0e
|
David Wood
|
|
78 |
63d6bb4f
|
Marcos Mendoza
|
$ifcfg = config_get_path("interfaces/{$interface}");
|
79 |
|
|
if (!empty($interface) && is_array($ifcfg) && interface_isppp_type($interface)) {
|
80 |
5e6a51bb
|
Renato Botelho do Couto
|
if (!empty($ifcfg['ipaddrv6'])) {
|
81 |
|
|
switch ($ifcfg['ipaddrv6']) {
|
82 |
|
|
case 'slaac':
|
83 |
|
|
case 'dhcp6':
|
84 |
|
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
85 |
|
|
if ((($ifcfg['ipaddrv6'] == 'dhcp6') && !isset($ifcfg['dhcp6usev4iface'])) ||
|
86 |
|
|
(($ifcfg['ipaddrv6'] == 'slaac') && !isset($ifcfg['slaacusev4iface'])) ||
|
87 |
|
|
!interface_isppp_type($interface)) {
|
88 |
|
|
break;
|
89 |
|
|
}
|
90 |
|
|
interface_dhcpv6_configure($interface, $ifcfg);
|
91 |
|
|
break;
|
92 |
|
|
default:
|
93 |
|
|
break;
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
05a73e0e
|
David Wood
|
}
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
// main entry point
|
101 |
|
|
if ($argc != 3) {
|
102 |
|
|
goto error;
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
$interface_real = trim($argv[1], " \n\t");
|
106 |
|
|
if (empty($interface_real)) {
|
107 |
|
|
goto error;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
switch (strtolower($argv[2])) {
|
111 |
5e6a51bb
|
Renato Botelho do Couto
|
case 'up':
|
112 |
|
|
interface_ipv6_raise($interface_real);
|
113 |
|
|
break;
|
114 |
|
|
case 'down':
|
115 |
|
|
interface_ipv6_lower($interface_real);
|
116 |
|
|
break;
|
117 |
|
|
default:
|
118 |
|
|
goto error;
|
119 |
|
|
break;
|
120 |
05a73e0e
|
David Wood
|
}
|
121 |
|
|
|
122 |
|
|
exit(0);
|
123 |
|
|
|
124 |
|
|
error:
|
125 |
|
|
if (!empty($argv[0])) {
|
126 |
|
|
echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
|
127 |
|
|
}
|
128 |
|
|
exit(1);
|
129 |
|
|
|
130 |
|
|
?>
|