Project

General

Profile

Download (3.95 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/*
4
	ppp-ipv6
5

    
6
	PPP IPv6 helper
7

    
8
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig	/usr/local/sbin/dhcp6c
9

    
10
*/
11

    
12
require_once("globals.inc");
13
require_once("interfaces.inc");
14

    
15
function interface_ipv6_lower($interface_real) {
16
	global $g, $config;
17

    
18
	if (!empty($interface_real)) {
19
		$interface = convert_real_interface_to_friendly_interface_name($interface_real);
20

    
21
		if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
22
			$ifcfg = $config['interfaces'][$interface];
23

    
24
            if (!empty($ifcfg['ipaddrv6'])) {
25
                switch ($ifcfg['ipaddrv6']) {
26
                    case 'slaac':
27
                    case 'dhcp6':
28
                        // bring down dhcp6c if it is running
29
                        $pidv6 = find_dhcp6c_process($interface_real);
30
                        if ($pidv6) {
31
                            posix_kill($pidv6, SIGTERM);
32
                            sleep(3);
33
                        }
34
                        unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf");
35

    
36
                        // disable router advertisements (and therefore SLAAC)
37
                        mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 -accept_rtadv");
38

    
39
                        // remove any autoconfigured IPv6 addresses
40
                        exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
41
                        foreach ($ifconfig_output as $output) {
42
                            if (preg_match('{ \A \s+ inet6 \s+ (\S+) .* autoconf .* \Z}xmsi', $output, $matches)) {
43
                                mwexec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6 " . escapeshellarg($matches[1]) . " delete");
44
                            }
45
                        }
46
                        break;
47
                    default:
48
                        break;
49
                }
50
            }
51
		}
52
	}
53
}
54

    
55
function interface_ipv6_raise($interface_real) {
56
	global $config;
57

    
58
	if (!empty($interface_real)) {
59
		$interface = convert_real_interface_to_friendly_interface_name($interface_real);
60

    
61
		if (!empty($interface) && is_array($config['interfaces'][$interface]) && interface_isppp_type($interface)) {
62
			$ifcfg = $config['interfaces'][$interface];
63

    
64
            if (!empty($ifcfg['ipaddrv6'])) {
65
                switch ($ifcfg['ipaddrv6']) {
66
                    case 'slaac':
67
                    case 'dhcp6':
68
                        $pidv6 = find_dhcp6c_process($interface_real);
69
                        if (empty($pidv6)) {
70
                            // only fire if router advertisements off
71
                            // (if router advertisements are on, rtsold might be primed to fire dhcp6c already)
72
                            exec("/sbin/ifconfig " . escapeshellarg($interface_real) . " inet6", $ifconfig_output);
73
                            $start = true;
74
                            foreach ($ifconfig_output as $output) {
75
                                if (preg_match('{ \A .* ACCEPT_RTADV .* \Z}xmsi', $output)) {
76
                                    $start = false;
77
                                    break;
78
                                }
79
                            }
80
                            if ($start) {
81
                                interface_dhcpv6_configure($interface, $ifcfg);
82
                            }
83
                        }
84
                        break;
85
                    default:
86
                        break;
87
                }
88
            }
89
		}
90
	}
91
}
92

    
93
// main entry point
94
if ($argc != 3) {
95
	goto error;
96
}
97

    
98
$interface_real = trim($argv[1], " \n\t");
99
if (empty($interface_real)) {
100
	goto error;
101
}
102

    
103
switch (strtolower($argv[2])) {
104
	case 'up':
105
		interface_ipv6_raise($interface_real);
106
		break;
107
	case 'down':
108
		interface_ipv6_lower($interface_real);
109
		break;
110
	default:
111
		goto error;
112
		break;
113
}
114

    
115
exit(0);
116

    
117
error:
118
if (!empty($argv[0])) {
119
	echo("Usage: " . substr(strrchr('/' . $argv[0], '/'), 1) . " <PPP interface> up|down\n");
120
}
121
exit(1);
122

    
123
?>
(12-12/23)