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-2018 Rubicon Communications, LLC (Netgate)
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
* you may not use this file except in compliance with the License.
|
12
|
* You may obtain a copy of the License at
|
13
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* Unless required by applicable law or agreed to in writing, software
|
17
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
* See the License for the specific language governing permissions and
|
20
|
* limitations under the License.
|
21
|
*/
|
22
|
|
23
|
require_once("globals.inc");
|
24
|
require_once("interfaces.inc");
|
25
|
|
26
|
function interface_ipv6_lower($interface_real) {
|
27
|
global $g, $config;
|
28
|
|
29
|
if (!empty($interface_real)) {
|
30
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
31
|
|
32
|
if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
|
33
|
$ifcfg = $config['interfaces'][$interface];
|
34
|
|
35
|
if (!empty($ifcfg['ipaddrv6'])) {
|
36
|
switch ($ifcfg['ipaddrv6']) {
|
37
|
case 'slaac':
|
38
|
case 'dhcp6':
|
39
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
40
|
if ($ifcfg['ipaddrv6']==='dhcp6' && !(isset($ifcfg['dhcp6usev4iface']) || $ifcfg['ipaddr']==='ppp')) {
|
41
|
break;
|
42
|
}
|
43
|
// bring down dhcp6c if it is running
|
44
|
kill_dhcp6client_process($interface_real,false);
|
45
|
|
46
|
unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf");
|
47
|
|
48
|
// disable router advertisements (and therefore SLAAC)
|
49
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
|
50
|
|
51
|
// remove any autoconfigured IPv6 addresses
|
52
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
53
|
foreach ($ifconfig_output as $output) {
|
54
|
if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
|
55
|
mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
|
56
|
}
|
57
|
}
|
58
|
break;
|
59
|
default:
|
60
|
break;
|
61
|
}
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
}
|
66
|
|
67
|
function interface_ipv6_raise($interface_real) {
|
68
|
global $config;
|
69
|
|
70
|
if (!empty($interface_real)) {
|
71
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
72
|
|
73
|
if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
|
74
|
$ifcfg = $config['interfaces'][$interface];
|
75
|
|
76
|
if (!empty($ifcfg['ipaddrv6'])) {
|
77
|
switch ($ifcfg['ipaddrv6']) {
|
78
|
case 'slaac':
|
79
|
case 'dhcp6':
|
80
|
// Take no action if dhcp6 is active on the parent interface, not the PPP interface
|
81
|
if ($ifcfg['ipaddrv6']==='dhcp6' && !(isset($ifcfg['dhcp6usev4iface']) || $ifcfg['ipaddr']==='ppp')) {
|
82
|
break;
|
83
|
}
|
84
|
$pidv6 = find_dhcp6c_process($interface_real);
|
85
|
if (empty($pidv6)) {
|
86
|
// only fire if router advertisements off
|
87
|
// (if router advertisements are on, rtsold might be primed to fire dhcp6c already)
|
88
|
exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
|
89
|
$start = true;
|
90
|
foreach ($ifconfig_output as $output) {
|
91
|
if (preg_match('{ \A .* ACCEPT_RTADV .* \Z}xmsi', $output)) {
|
92
|
$start = false;
|
93
|
break;
|
94
|
}
|
95
|
}
|
96
|
if ($start) {
|
97
|
interface_dhcpv6_configure($interface, $ifcfg);
|
98
|
}
|
99
|
}
|
100
|
break;
|
101
|
default:
|
102
|
break;
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
}
|
107
|
}
|
108
|
|
109
|
// main entry point
|
110
|
if ($argc != 3) {
|
111
|
goto error;
|
112
|
}
|
113
|
|
114
|
$interface_real = trim($argv[1], " \n\t");
|
115
|
if (empty($interface_real)) {
|
116
|
goto error;
|
117
|
}
|
118
|
|
119
|
switch (strtolower($argv[2])) {
|
120
|
case 'up':
|
121
|
interface_ipv6_raise($interface_real);
|
122
|
break;
|
123
|
case 'down':
|
124
|
interface_ipv6_lower($interface_real);
|
125
|
break;
|
126
|
default:
|
127
|
goto error;
|
128
|
break;
|
129
|
}
|
130
|
|
131
|
exit(0);
|
132
|
|
133
|
error:
|
134
|
if (!empty($argv[0])) {
|
135
|
echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
|
136
|
}
|
137
|
exit(1);
|
138
|
|
139
|
?>
|