]>
git.saurik.com Git - apple/network_cmds.git/blob - ip6conf.tproj/ip6config
3 # Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
5 # @APPLE_LICENSE_HEADER_START@
7 # "Portions Copyright (c) 2002 Apple Computer, Inc. All Rights
8 # Reserved. This file contains Original Code and/or Modifications of
9 # Original Code as defined in and that are subject to the Apple Public
10 # Source License Version 1.0 (the 'License'). You may not use this file
11 # except in compliance with the License. Please obtain a copy of the
12 # License at http://www.apple.com/publicsource and read it before using
15 # The Original Code and all software distributed under the License are
16 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
20 # License for the specific language governing rights and limitations
23 # @APPLE_LICENSE_HEADER_END@
25 # Setup IPv6 for Darwin
26 # - Startup/shutdown IPv6 on the given interface
27 # - Startup/shutdown 6to4 on the given interface
28 # - Start/stop router advertisement.
30 # Setup 6to4 IPv6, for NetBSD (and maybe others)
32 # (c) Copyright 2000 Hubert Feyrer <hubert@feyrer.de>
36 # Directory for conf file
37 $etcdir="/private/etc";
38 require "$etcdir/6to4.conf";
42 ###########################################################################
46 # Some sanity checks - check for link-local address and stf
48 if (`ifconfig -a | grep fe80: | wc -l` <= 0 or
49 `ifconfig -a | grep stf | wc -l` <= 0) {
50 die "$0: It seems your kernel does not support IPv6 or 6to4 (stf).\n";
54 # Take the requested interface from the user
55 # Figure out addressing, etc.
57 $localadr4 = `ifconfig $ARGV[1] inet | grep inet | grep -v "10.*.*.*"| \
58 grep -v "172.[^16-31].*.*" | grep -v "192.168.*.*" | \
59 grep -v "169.254.*.*" | grep -v alias`;
60 $localadr4 =~ s/^.*inet\s*//;
61 $localadr4 =~ s/\s.*$//;
64 @l4c = split('\.', $localadr4);
65 $prefix = sprintf("2002:%02x%02x:%02x%02x", @l4c[0..3]);
67 $localadr6 = sprintf("$prefix:%04x", $v6_net);
70 # Anycast is default in 6to4.conf file
72 if ($peer eq "6to4-anycast") {
73 # magic values from rfc 3068
74 $remoteadr4 = "192.88.99.1";
75 $remoteadr6 = "2002:c058:6301::";
78 chomp($remoteadr4 = `host $peer`);
79 $remoteadr4 =~ s/^.*address //;
81 chomp($remoteadr6 = `host
-t AAAA
$peer`);
82 $remoteadr6 =~ s/^.*address //;
87 ###########################################################################
91 print " start-v6 all | stop-v6 all\n";
92 print " start-v6 [interface] | stop-v6 [interface]\n";
93 print " start-stf [interface] | stop-stf\n";
94 print " start-rtadvd | stop-rtadvd\n";
96 ###########################################################################
99 # Process options - just help for now
113 if ($ARGV[0] eq "start-v6" or $ARGV[0] eq "v6-start") {
114 if ($ARGV[1] eq "all") {
115 print "Starting IPv6 on all interfaces.\n";
119 print "Starting IPv6 on $ARGV[1].\n";
120 system "ip6 -u $ARGV[1]";
125 elsif ($ARGV[0] eq "stop-v6" or $ARGV[0] eq "v6-stop") {
126 if ($ARGV[1] eq "all") {
127 print "Stopping IPv6 on all interfaces.\n";
131 print "Stopping IPv6 on $ARGV[1].\n";
132 system "ip6 -d $ARGV[1]";
137 elsif ($ARGV[0] eq "start-stf" or $ARGV[0] eq "stf-start") {
139 print "Starting 6to4 on $ARGV[1].\n";
140 system "ifconfig stf0 inet6 $localadr6:$hostbits6 prefixlen $v6_prefixlen alias";
141 system "route add -inet6 default $remoteadr6";
143 system "ifconfig $in_if inet6 $prefix:$v6_innernet:$hostbits6";
148 elsif ($ARGV[0] eq "stop-stf" or $ARGV[0] eq "stf-stop") {
149 print "Stopping 6to4.\n";
150 system "ifconfig stf0 down";
151 $cmd="ifconfig stf0 inet6 " .
153 "| sed -e 's/inet6//' " .
154 "-e 's/prefix.*//g' " .
157 foreach $ip ( split('\s+', `$cmd`)) {
158 system "ifconfig stf0 inet6 -alias $ip";
160 system "route delete -inet6 default";
163 # Start router advertisement
164 elsif ($ARGV[0] eq "rtadvd-start" or $ARGV[0] eq "start-rtadvd") {
165 print "WARNING: Setting up router advertisement should be done with great care\n";
166 print "because of a number of security issues. You should make sure this is\n";
167 print "allowed on your network and possibly fine-tune rtadvd.conf.\n";
169 print "Are you sure you want to start router advertisement (yes/no) ?: ";
172 if ($_ eq "yes" or $_ eq "y") {
173 if ( -f "/var/run/rtadvd.pid" ) {
174 print "rtadvd already running!\n";
176 print "Starting router advertisement.\n";
177 system "sysctl -w net.inet6.ip6.forwarding=1";
178 system "sysctl -w net.inet6.ip6.accept_rtadv=0";
180 system "rtadvd @ARGV";
184 elsif ($_ eq "no" or $_ eq "n") {
185 print "Router advertisement startup aborted.\n";
189 print "Invalid entry! Try again.\n";
190 print "Are you sure you want to start router advertisement? (yes/no): ";
195 # Stop router advertisement
196 elsif ($ARGV[0] eq "rtadvd-stop" or $ARGV[0] eq "stop-rtadvd") {
197 if ( -f "/var/run/rtadvd.pid" ) {
198 print "Stopping router advertisement.\n";
199 $pid = `cat
/var/run
/rtadvd
.pid
`;
200 system "kill -TERM $pid";
201 system "rm -f /var/run/rtadvd.pid";
202 system "rm -f /var/run/6to4-rtadvd.conf.$pid";
204 print "no rtadvd running!\n";