Project

General

Profile

Download (3.68 KB) Statistics
| Branch: | Tag: | Revision:
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
		$interface = convert_real_interface_to_friendly_interface_name($interface_real);
33
		if (empty($interface)) {
34
			return;
35
		}
36

    
37
		$ifcfg = config_get_path("interfaces/{$interface}");
38
		if (!empty($interface) && is_array($ifcfg) && interface_isppp_type($interface)) {
39
			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

    
52
					// disable router advertisements (and therefore SLAAC)
53
					mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
54

    
55
					// 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
		}
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
		if (empty($interface)) {
75
			return;
76
		}
77

    
78
		$ifcfg = config_get_path("interfaces/{$interface}");
79
		if (!empty($interface) && is_array($ifcfg) && interface_isppp_type($interface)) {
80
			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
		}
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
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
}
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
?>
(20-20/37)