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-2013 BSD Perimeter
|
8
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
9
|
* Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
|
10
|
* All rights reserved.
|
11
|
*
|
12
|
* 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
|
*
|
16
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17
|
*
|
18
|
* 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
|
*/
|
24
|
|
25
|
require_once("globals.inc");
|
26
|
require_once("interfaces.inc");
|
27
|
|
28
|
function interface_ipv6_lower($interface_real) {
|
29
|
global $g;
|
30
|
|
31
|
if (empty($interface_real)) {
|
32
|
return;
|
33
|
}
|
34
|
|
35
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
36
|
if (empty($interface)) {
|
37
|
return;
|
38
|
}
|
39
|
|
40
|
$ifcfg = config_get_path("interfaces/{$interface}");
|
41
|
if (empty($interface) || !is_array($ifcfg) ||
|
42
|
!interface_isppp_type($interface) || empty($ifcfg['ipaddrv6'])) {
|
43
|
return;
|
44
|
}
|
45
|
|
46
|
switch ($ifcfg['ipaddrv6']) {
|
47
|
case 'slaac':
|
48
|
case 'dhcp6':
|
49
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
50
|
if ((($ifcfg['ipaddrv6'] == 'dhcp6') && !isset($ifcfg['dhcp6usev4iface'])) ||
|
51
|
(($ifcfg['ipaddrv6'] == 'slaac') && !isset($ifcfg['slaacusev4iface'])) ||
|
52
|
!interface_isppp_type($interface)) {
|
53
|
break;
|
54
|
}
|
55
|
// reconfigure dhcp6c if it is running
|
56
|
interface_dhcpv6_configure($interface, $ifcfg, true);
|
57
|
|
58
|
// disable router advertisements (and therefore SLAAC)
|
59
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
|
60
|
|
61
|
// remove any autoconfigured IPv6 addresses
|
62
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
63
|
foreach ($ifconfig_output as $output) {
|
64
|
/* FIXME there should be a better way to do it */
|
65
|
if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
|
66
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
|
67
|
}
|
68
|
}
|
69
|
break;
|
70
|
default:
|
71
|
break;
|
72
|
}
|
73
|
}
|
74
|
|
75
|
function interface_ipv6_raise($interface_real) {
|
76
|
if (empty($interface_real)) {
|
77
|
return;
|
78
|
}
|
79
|
|
80
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
81
|
if (empty($interface)) {
|
82
|
return;
|
83
|
}
|
84
|
|
85
|
$ifcfg = config_get_path("interfaces/{$interface}");
|
86
|
if (empty($interface) || !is_array($ifcfg) ||
|
87
|
!interface_isppp_type($interface) || empty($ifcfg['ipaddrv6'])) {
|
88
|
return;
|
89
|
}
|
90
|
|
91
|
switch ($ifcfg['ipaddrv6']) {
|
92
|
case 'slaac':
|
93
|
case 'dhcp6':
|
94
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
95
|
if ((($ifcfg['ipaddrv6'] == 'dhcp6') && !isset($ifcfg['dhcp6usev4iface'])) ||
|
96
|
(($ifcfg['ipaddrv6'] == 'slaac') && !isset($ifcfg['slaacusev4iface'])) ||
|
97
|
!interface_isppp_type($interface)) {
|
98
|
break;
|
99
|
}
|
100
|
interface_dhcpv6_configure($interface, $ifcfg);
|
101
|
break;
|
102
|
default:
|
103
|
break;
|
104
|
}
|
105
|
}
|
106
|
|
107
|
// main entry point
|
108
|
if ($argc != 3) {
|
109
|
goto error;
|
110
|
}
|
111
|
|
112
|
$interface_real = trim($argv[1], " \n\t");
|
113
|
if (empty($interface_real)) {
|
114
|
goto error;
|
115
|
}
|
116
|
|
117
|
switch (strtolower($argv[2])) {
|
118
|
case 'up':
|
119
|
interface_ipv6_raise($interface_real);
|
120
|
break;
|
121
|
case 'down':
|
122
|
interface_ipv6_lower($interface_real);
|
123
|
break;
|
124
|
default:
|
125
|
goto error;
|
126
|
break;
|
127
|
}
|
128
|
|
129
|
exit(0);
|
130
|
|
131
|
error:
|
132
|
if (!empty($argv[0])) {
|
133
|
echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
|
134
|
}
|
135
|
exit(1);
|
136
|
|
137
|
?>
|