Project

General

Profile

Download (5.11 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-2016 Electric Sheep Fencing, LLC
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
                        $pidv6 = find_dhcp6c_process($interface_real);
45
                        if ($pidv6) {
46
                            posix_kill($pidv6, SIGTERM);
47
                            sleep(3);
48
                        }
49
                        unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf");
50

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

    
54
                        // remove any autoconfigured IPv6 addresses
55
                        exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
56
                        foreach ($ifconfig_output as $output) {
57
                            if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
58
                                mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
59
                            }
60
                        }
61
                        break;
62
                    default:
63
                        break;
64
                }
65
            }
66
		}
67
	}
68
}
69

    
70
function interface_ipv6_raise($interface_real) {
71
	global $config;
72

    
73
	if (!empty($interface_real)) {
74
		$interface = convert_real_interface_to_friendly_interface_name($interface_real);
75

    
76
		if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
77
			$ifcfg = $config['interfaces'][$interface];
78

    
79
            if (!empty($ifcfg['ipaddrv6'])) {
80
                switch ($ifcfg['ipaddrv6']) {
81
                    case 'slaac':
82
                    case 'dhcp6':
83
                        // Take no action if dhcp6 is active on the parent interface, not the PPP interface
84
                        if ($ifcfg['ipaddrv6']==='dhcp6' && !(isset($ifcfg['dhcp6usev4iface']) || $ifcfg['ipaddr']==='ppp')) {
85
                            break;
86
                        }
87
                        $pidv6 = find_dhcp6c_process($interface_real);
88
                        if (empty($pidv6)) {
89
                            // only fire if router advertisements off
90
                            // (if router advertisements are on, rtsold might be primed to fire dhcp6c already)
91
                            exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
92
                            $start = true;
93
                            foreach ($ifconfig_output as $output) {
94
                                if (preg_match('{ \A .* ACCEPT_RTADV .* \Z}xmsi', $output)) {
95
                                    $start = false;
96
                                    break;
97
                                }
98
                            }
99
                            if ($start) {
100
                                interface_dhcpv6_configure($interface, $ifcfg);
101
                            }
102
                        }
103
                        break;
104
                    default:
105
                        break;
106
                }
107
            }
108
		}
109
	}
110
}
111

    
112
// main entry point
113
if ($argc != 3) {
114
	goto error;
115
}
116

    
117
$interface_real = trim($argv[1], " \n\t");
118
if (empty($interface_real)) {
119
	goto error;
120
}
121

    
122
switch (strtolower($argv[2])) {
123
	case 'up':
124
		interface_ipv6_raise($interface_real);
125
		break;
126
	case 'down':
127
		interface_ipv6_lower($interface_real);
128
		break;
129
	default:
130
		goto error;
131
		break;
132
}
133

    
134
exit(0);
135

    
136
error:
137
if (!empty($argv[0])) {
138
	echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
139
}
140
exit(1);
141

    
142
?>
(13-13/24)