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-2019 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, $config;
|
30
|
|
31
|
if (!empty($interface_real)) {
|
32
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
33
|
|
34
|
if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
|
35
|
$ifcfg = $config['interfaces'][$interface];
|
36
|
|
37
|
if (!empty($ifcfg['ipaddrv6'])) {
|
38
|
switch ($ifcfg['ipaddrv6']) {
|
39
|
case 'slaac':
|
40
|
case 'dhcp6':
|
41
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
42
|
if ($ifcfg['ipaddrv6']==='dhcp6' && !(isset($ifcfg['dhcp6usev4iface']) || $ifcfg['ipaddr']==='ppp')) {
|
43
|
break;
|
44
|
}
|
45
|
// bring down dhcp6c if it is running
|
46
|
kill_dhcp6client_process($interface_real,false);
|
47
|
|
48
|
unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf");
|
49
|
|
50
|
// disable router advertisements (and therefore SLAAC)
|
51
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
|
52
|
|
53
|
// remove any autoconfigured IPv6 addresses
|
54
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
55
|
foreach ($ifconfig_output as $output) {
|
56
|
if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
|
57
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
|
58
|
}
|
59
|
}
|
60
|
break;
|
61
|
default:
|
62
|
break;
|
63
|
}
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
}
|
68
|
|
69
|
function interface_ipv6_raise($interface_real) {
|
70
|
global $config;
|
71
|
|
72
|
if (!empty($interface_real)) {
|
73
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
74
|
|
75
|
if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
|
76
|
$ifcfg = $config['interfaces'][$interface];
|
77
|
|
78
|
if (!empty($ifcfg['ipaddrv6'])) {
|
79
|
switch ($ifcfg['ipaddrv6']) {
|
80
|
case 'slaac':
|
81
|
case 'dhcp6':
|
82
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
83
|
if ($ifcfg['ipaddrv6']==='dhcp6' && !(isset($ifcfg['dhcp6usev4iface']) || $ifcfg['ipaddr']==='ppp')) {
|
84
|
break;
|
85
|
}
|
86
|
$pidv6 = find_dhcp6c_process($interface_real);
|
87
|
if (empty($pidv6)) {
|
88
|
// only fire if router advertisements off
|
89
|
// (if router advertisements are on, rtsold might be primed to fire dhcp6c already)
|
90
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
91
|
$start = true;
|
92
|
foreach ($ifconfig_output as $output) {
|
93
|
if (preg_match('{ \A .* ACCEPT_RTADV .* \Z}xmsi', $output)) {
|
94
|
$start = false;
|
95
|
break;
|
96
|
}
|
97
|
}
|
98
|
if ($start) {
|
99
|
interface_dhcpv6_configure($interface, $ifcfg);
|
100
|
}
|
101
|
}
|
102
|
break;
|
103
|
default:
|
104
|
break;
|
105
|
}
|
106
|
}
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
|
111
|
// main entry point
|
112
|
if ($argc != 3) {
|
113
|
goto error;
|
114
|
}
|
115
|
|
116
|
$interface_real = trim($argv[1], " \n\t");
|
117
|
if (empty($interface_real)) {
|
118
|
goto error;
|
119
|
}
|
120
|
|
121
|
switch (strtolower($argv[2])) {
|
122
|
case 'up':
|
123
|
interface_ipv6_raise($interface_real);
|
124
|
break;
|
125
|
case 'down':
|
126
|
interface_ipv6_lower($interface_real);
|
127
|
break;
|
128
|
default:
|
129
|
goto error;
|
130
|
break;
|
131
|
}
|
132
|
|
133
|
exit(0);
|
134
|
|
135
|
error:
|
136
|
if (!empty($argv[0])) {
|
137
|
echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
|
138
|
}
|
139
|
exit(1);
|
140
|
|
141
|
?>
|