]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/red
3 # This file is part of the IPCop Firewall.
5 # IPCop is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # IPCop is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with IPCop; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # (c) The SmoothWall Team
22 # Clean up our environment (we're running SUID!)
23 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
27 require '/var/ipfire/general-functions.pl';
35 # read vars back from file.
36 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
37 &General
::readhash
("${General::swroot}/isdn/settings", \
%isdnsettings);
38 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
39 &General
::readhash
("${General::swroot}/dhcp/settings", \
%dhcpsettings);
42 my ($iface,$dhcp_name)=@_;
44 system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'tcp', '--source-port', '67',
45 '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT');
46 system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'udp', '--source-port', '67',
47 '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT');
49 foreach ("<${General::swroot}/dhcpc/*.info>") { unlink $1 if ( $_ =~ /^([\/\w
.-]+)$/ ); }
50 my @dhcpcommand = ('/sbin/dhcpcd');
51 push(@dhcpcommand, ('-N', '-R', "$iface",'-L', "${General::swroot}/dhcpc"));
53 #FIXME the only way actually to set debug use is in pppsetup.cgi and 'RED is modem/isdn' interface
54 if ($pppsettings{'DEBUG'} eq 'on') {
55 push(@dhcpcommand, ('-d'));
58 if ($dhcp_name ne '') { push(@dhcpcommand, ('-h', "$dhcp_name", "&>/dev/null")); }
59 if ($netsettings{'RED_TYPE'} eq 'PPTP') { push(@dhcpcommand, '-G'); }
61 if (system (@dhcpcommand)) {
62 &General
::log('dhcpcd fail');
65 &General
::log('dhcpcd success');
69 sub doupdatesettings
{
70 # complete cleanup only if settings were changed or clear is ordered
71 system('/sbin/modprobe', '-r', 'pppoatm');
72 system('/sbin/modprobe', '-r', 'pppoe');
73 system('/bin/killall /usr/bin/br2684ctl 2>/dev/null');
74 system('/sbin/modprobe', '-r', 'br2684');
75 system('/sbin/modprobe', '-r', 'clip');
77 if ($pppsettings{'TYPE'} ne 'fritzdsl') {
78 system('/sbin/modprobe', '-r', 'fcdsl', 'fcdsl2', 'fcdslsl', 'fcdslusb', 'fcdslslusb');}
81 # remove existing default route (for static address) if it was been changed from setup or web interface SF1175052
82 system ('/sbin/route del default 2>/dev/null');
84 # erase in case it was created once with 'persistent' selected but rc.red stop never used : SF1171610
85 unlink ("${General::swroot}/red/iface");
88 # No output should be sent to the webclient
89 open STDIN
, '</dev/zero' or die "Can't read from /dev/zero";
90 open STDOUT
, '>/dev/null' or die "Can't write to /dev/null";
92 if ($ARGV[0] eq 'start') {
93 if (-e
"${General::swroot}/red/active" ||
94 -e
'/var/run/ppp-ipfire.pid')
96 &General
::log ("ERROR: Can't start RED when it's still active");
100 if ( ( ( ($netsettings{'RED_TYPE'} =~ /^(PPPOE|PPTP)$/) && ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) ) ||
101 ( ( ($pppsettings{'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) || ($pppsettings{'PROTOCOL'} eq 'RFC2364') ) &&
102 ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/) ) ) && ($pppsettings{'RECONNECTION'} ne 'manual') ) {
103 system ('/etc/rc.d/init.d/connectioncheck start &');
107 ### Red device is ethernet
109 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/)
111 if ($netsettings{'RED_DEV'} ne '')
113 &General
::log("Starting RED device $netsettings{'RED_DEV'}.");
115 if ( $netsettings{'RED_TYPE'} eq 'DHCP')
117 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
118 dodhcpdial
($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
121 elsif ( ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} eq 'DHCP') )
123 if (open(FILE
, ">${General::swroot}/red/device")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
124 unlink ("${General::swroot}/red/iface");
125 dodhcpdial
($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
127 elsif ( ( $netsettings{'RED_TYPE'} eq 'STATIC') ||
128 ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} ne 'DHCP') )
130 system ("/sbin/ifconfig",
131 $netsettings{'RED_DEV'}, $netsettings{'RED_ADDRESS'},
132 "netmask", $netsettings{'RED_NETMASK'},
133 "broadcast", $netsettings{'RED_BROADCAST'},"up");
134 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
136 system("/usr/local/bin/setaliases");
137 system("echo $netsettings{'DNS1'} > ${General::swroot}/red/dns1");
138 system("echo $netsettings{'DNS2'} > ${General::swroot}/red/dns2");
139 system("echo $netsettings{'RED_ADDRESS'} > ${General::swroot}/red/local-ipaddress");
140 system("echo $netsettings{'DEFAULT_GATEWAY'} > ${General::swroot}/red/remote-ipaddress");
141 } elsif ( $netsettings{'RED_TYPE'} eq 'PPTP' ) {
142 if (open(FILE
, ">${General::swroot}/red/device")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
143 unlink ("${General::swroot}/red/iface");
145 if ( $netsettings{'DEFAULT_GATEWAY'} ne '' )
147 system ("/sbin/route","add","default","gw",
148 $netsettings{'DEFAULT_GATEWAY'});
154 system ("/sbin/ifconfig", $netsettings{'RED_DEV'}, "1.1.1.1",
155 "netmask", "255.255.255.0", "broadcast", "1.1.1.255", "up");
158 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
160 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
161 system ("/bin/touch", "${General::swroot}/red/active");
162 system ("/etc/rc.d/init.d/network red update");
168 &General
::log ("ERROR: Can't start RED when RED device not set!");
174 if ($pppsettings{'RECONNECTION'} eq 'dialondemand')
176 system ('/bin/touch', "${General::swroot}/red/dial-on-demand");
179 if ($pppsettings{'VALID'} ne 'yes') {
180 &General
::log("Profile has errors.");
184 if (-e
"${General::swroot}/ppp/updatesettings") {
188 if (( $pppsettings{'METHOD'} eq 'STATIC') && ( $pppsettings{'DNS'} eq 'Manual')) {
189 system("/usr/local/bin/setaliases");
190 if (open(FILE
, ">${General::swroot}/red/dns1")) { print FILE
$pppsettings{'DNS1'}; close FILE
; }
191 if (open(FILE
, ">${General::swroot}/red/dns2")) { print FILE
$pppsettings{'DNS2'}; close FILE
; }
192 if (open(FILE
, ">${General::swroot}/red/local-ipaddress")) { print FILE
$pppsettings{'IP'}; close FILE
; }
193 if (open(FILE
, ">${General::swroot}/red/remote-ipaddress")) { print FILE
$pppsettings{'GATEWAY'}; close FILE
; }
195 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
196 &General
::log("Dial-on-Demand waiting to dial $pppsettings{'PROFILENAME'}.");
198 &General
::log("Dialling $pppsettings{'PROFILENAME'}.");
201 if ($pppsettings{'TYPE'} eq 'modem') { &domodemdial
(); }
202 elsif ($pppsettings{'TYPE'} eq 'serial') { &doserialdial
(); }
203 elsif ($pppsettings{'TYPE'} eq 'isdn') { &doisdndial
(); }
204 elsif ($pppsettings{'TYPE'} eq 'pppoe') { &dopppoedial
(); }
205 elsif ($pppsettings{'TYPE'} eq 'pptp') { &dopptpdial
(); }
206 elsif ($pppsettings{'TYPE'} eq 'fritzdsl') { &dofritzdsldial
(); }
208 if (-e
"${General::swroot}/ppp/updatesettings") {
209 # erase update mark only after specific script had run, allowing specific script to treat the update
210 unlink ("${General::swroot}/ppp/updatesettings");
212 if ( ($pppsettings{'RECONNECTION'} eq 'dialondemand') || ($pppsettings{'METHOD'} eq 'STATIC') ){
213 system ("/etc/rc.d/init.d/network red update");
216 elsif ($ARGV[0] eq 'stop')
218 if (open(IFACE
, "${General::swroot}/red/iface")) {
222 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
226 if (open(FILE
, "${General::swroot}/red/device")) {
230 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
233 unlink "${General::swroot}/red/dial-on-demand";
234 unlink "${General::swroot}/red/active";
235 unlink "${General::swroot}/red/local-ipaddress";
236 unlink "${General::swroot}/red/remote-ipaddress";
237 unlink "${General::swroot}/red/dns1";
238 unlink "${General::swroot}/red/dns2";
239 unlink "${General::swroot}/red/resolv.conf";
240 unlink "${General::swroot}/red/device";
242 # stay with keepconnected during transitional rc.red stop ordered by connectioncheck
243 if ( ! -e
"${General::swroot}/red/redial") {
244 unlink "${General::swroot}/red/keepconnected";
246 unlink "${General::swroot}/red/redial";
249 if (open(FILE
, "/var/run/ppp-ipfire.pid")) {
253 $pid =~ /(\d*)/; $pid = $1;
254 system ('/bin/kill', $pid);
257 # Bring down Ethernet interfaces & Kill DHCPC daemons
258 if (($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) && ( $netsettings{'RED_TYPE'} eq 'PPPOE') && $iface ) {
259 system ("/sbin/ifconfig", $iface, "down");
262 system ("/sbin/ifconfig", $device, "down");
266 while (($file = glob("/var/run/dhcpcd-*.pid") )) {
267 if (open(FILE
, $file)) {
271 $pid =~ /(\d*)/; $pid = $1;
272 system ('/bin/kill', $pid);
276 if (!system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
277 if ($pppsettings{'GATEWAY'} ne '') {
278 system("/usr/sbin/atmarp -d $pppsettings{'GATEWAY'} 2>/dev/null"); }
279 system('/bin/killall /usr/sbin/atmarpd 2>/dev/null');
280 system ('/sbin/ifconfig', 'atm0', 'down');
283 if ($pppsettings{'TYPE'} eq 'isdn') { system('/etc/rc.d/rc.isdn','stop'); }
284 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','stop'); }
286 if ( ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq 'STATIC') ||
287 ( $netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'PROTOCOL'} eq 'RFC1483' &&
288 $pppsettings{'METHOD'} eq 'STATIC' ) ) {
289 system ("/etc/rc.d/init.d/network red update");
292 elsif ($ARGV[0] eq 'clear')
302 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','cleanup'); }
307 my @pppcommand = ('/usr/sbin/pppd');
308 my $loginscript = '';
310 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
311 system ('/sbin/rmmod acm');
313 system ('/sbin/modprobe acm');
316 my $device = "/dev/${pppsettings{'COMPORT'}}";
318 if ($pppsettings{'DNS'} eq 'Automatic') {
319 push(@pppcommand, ('usepeerdns')); }
321 if ($pppsettings{'AUTH'} eq 'pap') {
322 push(@pppcommand, ('-chap'));
323 } elsif ($pppsettings{'AUTH'} eq 'chap') {
324 push(@pppcommand, ('-pap'));
325 } elsif ($pppsettings{'AUTH'} eq 'standard-login-script') {
326 $loginscript = 'standardloginscript';
327 } elsif ($pppsettings{'AUTH'} eq 'demon-login-script') {
328 $loginscript = 'demonloginscript';
330 $loginscript = $pppsettings{'LOGINSCRIPT'};
333 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
334 if ($pppsettings{'TIMEOUT'} != 0)
336 my $seconds = $pppsettings{'TIMEOUT'} * 60;
337 push (@pppcommand, ('idle', $seconds));
339 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
340 push (@pppcommand, ('demand', 'nopersist'));
344 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
347 push (@pppcommand, ('novj', 'novjccomp'));
349 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
350 $pppsettings{'DTERATE'}, 'noipdefault',
351 'defaultroute', 'user', $pppsettings{'USERNAME'},
352 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
354 if ($pppsettings{'DEBUG'} eq 'on') {
355 push(@pppcommand, ('debug'));
363 my @pppcommand = ('/usr/sbin/pppd');
364 my $loginscript = '';
366 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
367 system ('/sbin/rmmod acm');
369 system ('/sbin/modprobe acm');
372 my $device = "/dev/${pppsettings{'COMPORT'}}";
374 if ($pppsettings{'DNS'} eq 'Automatic') {
375 push(@pppcommand, ('usepeerdns')); }
377 if ($pppsettings{'AUTH'} eq 'pap') {
378 push(@pppcommand, ('-chap'));
379 } elsif ($pppsettings{'AUTH'} eq 'chap') {
380 push(@pppcommand, ('-pap'));
383 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
384 if ($pppsettings{'TIMEOUT'} != 0)
386 my $seconds = $pppsettings{'TIMEOUT'} * 60;
387 push (@pppcommand, ('idle', $seconds));
389 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
390 push (@pppcommand, ('demand', 'nopersist'));
394 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
397 push (@pppcommand, ('novj', 'novjccomp'));
399 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
400 $pppsettings{'DTERATE'}, 'noipdefault',
401 'defaultroute', 'user', $pppsettings{'USERNAME'},
402 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
404 if ($pppsettings{'DEBUG'} eq 'on') {
405 push(@pppcommand, ('debug'));
417 if (system ('/etc/rc.d/rc.isdn', 'start')) {
418 &General
::log ("ERROR: ISDN module failed to load");
422 $seconds = $pppsettings{'TIMEOUT'} * 60;
423 if ($pppsettings{'USEDOV'} eq 'on')
425 $phone = 'v' . $pppsettings{'TELEPHONE'};
429 $phone = $pppsettings{'TELEPHONE'};
432 if ($pppsettings{'COMPORT'} eq 'isdn2')
434 system('/usr/sbin/isdnctrl','addif','ippp0');
435 system('/usr/sbin/isdnctrl','addslave','ippp0','ippp1');
436 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
437 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
438 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
439 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
440 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
441 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
442 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
443 system('/usr/sbin/isdnctrl','l2_prot','ippp1','hdlc');
444 system('/usr/sbin/isdnctrl','l3_prot','ippp1','trans');
445 system('/usr/sbin/isdnctrl','encap','ippp1','syncppp');
446 system('/usr/sbin/isdnctrl','dialmax','ippp1',$pppsettings{'MAXRETRIES'});
447 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
448 system('/usr/sbin/isdnctrl','addphone','ippp1','out',$phone);
449 system('/usr/sbin/isdnctrl','huptimeout','ippp1',$seconds);
450 system('/usr/sbin/isdnctrl','dialmode','ippp1','auto');
452 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault','+mp',
453 'defaultroute','user',$pppsettings{'USERNAME'},
454 'name',$pppsettings{'USERNAME'},
455 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
456 'pidfile','/var/run/ppp-ipfire.pid','/dev/ippp0','/dev/ippp1');
457 if ($pppsettings{'DEBUG'} eq 'on') {
458 push(@pppcommand, ('debug'));
460 if ($pppsettings{'AUTH'} eq 'pap') {
461 push(@pppcommand, ('-chap'));
462 } elsif ($pppsettings{'AUTH'} eq 'chap') {
463 push(@pppcommand, ('-pap'));
465 system (@pppcommand);
469 system('/usr/sbin/isdnctrl','addif','ippp0');
470 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
471 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
472 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
473 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
474 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
475 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
476 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
478 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault',
479 'defaultroute','user',$pppsettings{'USERNAME'},
480 'name',$pppsettings{'USERNAME'},
481 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
482 'pidfile','/var/run/ppp-ipfire.pid','/dev/ippp0');
483 if ($pppsettings{'DEBUG'} eq 'on') {
484 push(@pppcommand, ('debug'));
486 if ($pppsettings{'AUTH'} eq 'pap') {
487 push(@pppcommand, ('-chap'));
488 } elsif ($pppsettings{'AUTH'} eq 'chap') {
489 push(@pppcommand, ('-pap'));
491 system (@pppcommand);
496 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
497 system('/usr/sbin/isdnctrl','dialmode','ippp0','auto');
498 system('/sbin/ifconfig','ippp0','10.112.112.112','pointopoint','10.112.112.113');
499 system('/sbin/ifconfig','ippp0','-arp','-broadcast');
500 system('/sbin/route','add','default','dev','ippp0');
502 system('/usr/sbin/isdnctrl', 'dial', 'ippp0');
506 system('/bin/killall', 'ibod');
507 if ($pppsettings{'COMPORT'} eq 'isdn2') {
508 if ($pppsettings{'USEIBOD'} eq 'on') {
509 system("/usr/sbin/ibod &");
511 system('/usr/sbin/isdnctrl', 'addlink', 'ippp0');
518 system("mknod /dev/ppp c 108 0 2>/dev/null");
519 if ($pppsettings{'METHOD'} ne 'PPPOE_PLUGIN') {
520 my @pppcommand = ('/usr/sbin/pppd', 'pty');
521 my @pppoecommand = ('/usr/sbin/pppoe', '-p','/var/run/pppoe.pid','-I',
522 $netsettings{'RED_DEV'}, '-T', '80', '-U', '-m', '1412');
524 if ($pppsettings{'SERVICENAME'}) {
525 push(@pppoecommand, ('-S', $pppsettings{'SERVICENAME'})); }
526 if ($pppsettings{'CONCENTRATORNAME'}) {
527 push(@pppoecommand, ('-C', $pppsettings{'CONCENTRATORNAME'})); }
529 push(@pppcommand, "@pppoecommand");
531 if ($pppsettings{'DNS'} eq 'Automatic') {
532 push(@pppcommand, ('usepeerdns'));
535 if ($pppsettings{'AUTH'} eq 'pap') {
536 push(@pppcommand, ('-chap'));
537 } elsif ($pppsettings{'AUTH'} eq 'chap') {
538 push(@pppcommand, ('-pap'));
541 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
542 if ($pppsettings{'TIMEOUT'} != 0) {
543 my $seconds = $pppsettings{'TIMEOUT'} * 60;
544 push(@pppcommand, ('idle', "$seconds"));
546 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
547 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
551 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
554 push(@pppcommand, ('noipdefault', 'default-asyncmap',
555 'defaultroute', 'hide-password', 'local',
556 'mtu', '1492', 'mru', '1492', 'noaccomp', 'noccp',
557 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
558 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
559 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
560 'maxfail',$pppsettings{'MAXRETRIES'}));
561 if ($pppsettings{'DEBUG'} eq 'on') {
562 push(@pppcommand, ('debug'));
565 system (@pppcommand);
568 system ('/sbin/modprobe pppoe');
569 my @pppcommand = ('/usr/sbin/pppd');
570 push(@pppcommand,'plugin','rp-pppoe.so',"$netsettings{'RED_DEV'}");
571 if ($pppsettings{'DNS'} eq 'Automatic') {
572 push(@pppcommand, ('usepeerdns'));
574 if ($pppsettings{'AUTH'} eq 'pap') {
575 push(@pppcommand, ('-chap'));
576 } elsif ($pppsettings{'AUTH'} eq 'chap') {
577 push(@pppcommand, ('-pap'));
579 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
580 if ($pppsettings{'TIMEOUT'} != 0) {
581 my $seconds = $pppsettings{'TIMEOUT'} * 60;
582 push(@pppcommand, ('idle', "$seconds"));
584 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
585 push (@pppcommand, ('demand','nopersist'));
589 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
591 push(@pppcommand, ('noipdefault', 'defaultroute', 'hide-password', 'ipcp-accept-local',
592 'ipcp-accept-remote', 'passive', 'noccp','nopcomp', 'novjccomp',
593 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
594 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
595 'maxfail',$pppsettings{'MAXRETRIES'}));
596 if ($pppsettings{'DEBUG'} eq 'on') {
597 push(@pppcommand, ('debug'));
600 system (@pppcommand);
607 my $routerip = $pppsettings{'ROUTERIP'} ?
$pppsettings{'ROUTERIP'} : "10.0.0.138";
608 system("mknod /dev/ppp c 108 0 2>/dev/null");
609 if ( $pppsettings{'METHOD'} eq 'DHCP' && open(FILE
, "${General::swroot}/red/device")) {
613 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
614 if (&General
::readhash
("${General::swroot}/dhcpc/dhcpcd-$device.info", \
%pptpdhcpc)) {
615 system("/sbin/route add -host $routerip gw $pptpdhcpc{'GATEWAY'}");
617 system("/sbin/route add -host $routerip dev $device");
621 my @pppcommand = ('/usr/sbin/pppd', 'pty');
622 my @pptpcommand = ('/usr/sbin/pptp', $routerip, '--nobuffer', '--nolaunchpppd', '--sync');
623 if ($pppsettings{'PHONEBOOK'}) {
624 push (@pptpcommand, ('--phone ', $pppsettings{'PHONEBOOK'}));
627 push(@pppcommand, "@pptpcommand");
629 if ($pppsettings{'DNS'} eq 'Automatic') {
630 push(@pppcommand, ('usepeerdns'));
632 if ($pppsettings{'AUTH'} eq 'pap') {
633 push(@pppcommand, ('-chap'));
634 } elsif ($pppsettings{'AUTH'} eq 'chap') {
635 push(@pppcommand, ('-pap'));
638 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
639 if ($pppsettings{'TIMEOUT'} != 0) {
640 my $seconds = $pppsettings{'TIMEOUT'} * 60;
641 push(@pppcommand, ('idle', "$seconds"));
643 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
644 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
648 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
651 push(@pppcommand, ('noipdefault', 'default-asyncmap',
652 'defaultroute', 'hide-password', 'local','noaccomp', 'noccp',
653 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
654 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
655 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
656 'maxfail',$pppsettings{'MAXRETRIES'},'sync'));
657 if ($pppsettings{'DEBUG'} eq 'on') {
658 push(@pppcommand, ('debug'));
661 system (@pppcommand);
668 if (system ('/etc/rc.d/rc.fritzdsl','start')) {
669 &General
::log ("ERROR: Fritz DSL module failed to load");
674 if ($pppsettings{'TYPE'} eq 'fritzdsl') {
675 if ( ! system ('/bin/grep', '1244:2700', '/proc/pci')) {
676 $controller=1; # fcdslsl
677 } elsif (! system('/bin/grep', '1244:2900', '/proc/pci')) {
678 $controller=2; # fcdsl2
679 } elsif (! system('/bin/grep', '1131:5402', '/proc/pci')) {
680 $controller=2; # fdsl
681 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=2300', '/proc/bus/usb/devices')) {
682 $controller=1; # fcdslusb
683 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=3500', '/proc/bus/usb/devices')) {
684 $controller=1; # fcdslslusb
687 system("mknod /dev/ppp c 108 0 2>/dev/null");
688 my @pppcommand = ('/usr/sbin/pppd');
691 if ($pppsettings{'DNS'} eq 'Automatic') {
692 push(@pppcommand, ('usepeerdns'));
695 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
696 if ($pppsettings{'TIMEOUT'} != 0) {
697 my $seconds = $pppsettings{'TIMEOUT'} * 60;
698 push(@pppcommand, ('idle', "$seconds"));
700 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
701 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
705 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
708 push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user',
709 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
710 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
711 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
712 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
714 if ($pppsettings{'DEBUG'} eq 'on') {
715 push(@pppcommand, ('debug'));
718 if ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
719 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoe',
720 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
722 if ($pppsettings {'ENCAP'} eq '1') {
723 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoallc',
724 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
726 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoa',
727 'controller', $controller,'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
730 push(@pppcommand, @capiplugin);
731 push(@pppcommand, '/dev/null');
733 system (@pppcommand);
739 system("mknod /dev/ppp c 108 0 2>/dev/null");
740 if ($pppsettings {'PROTOCOL'} eq 'RFC2364') {
741 system ('/sbin/modprobe pppoatm');
742 my @pppcommand = ('/usr/sbin/pppd');
743 if ($pppsettings{'ENCAP'} eq '0') { $ENCAP='vc-encaps'; } else { $ENCAP='llc-encaps'; }
744 push(@pppcommand,'plugin', 'pppoatm.so',$pppsettings{'VPI'}.".".$pppsettings{'VCI'},"$ENCAP");
745 if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));}
746 if ($pppsettings{'AUTH'} eq 'pap') {
747 push(@pppcommand, ('-chap'));
748 } elsif ($pppsettings{'AUTH'} eq 'chap') {
749 push(@pppcommand, ('-pap'));
751 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
752 if ($pppsettings{'TIMEOUT'} != 0) {
753 my $seconds = $pppsettings{'TIMEOUT'} * 60;
754 push(@pppcommand, ('idle', "$seconds"));
756 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
757 push (@pppcommand, ('demand','nopersist'));
761 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
763 push(@pppcommand, ('noipdefault', 'defaultroute', 'user',
764 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
765 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
766 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
767 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
769 if ($pppsettings{'DEBUG'} eq 'on') {
770 push(@pppcommand, ('debug'));
773 system (@pppcommand);
774 } elsif ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
775 if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) {
777 my $device = "nas$itf";
778 if (open(FILE
, ">${General::swroot}/red/device")) { print FILE
$device; close FILE
; }
779 $netsettings{'RED_DEV'} = $device;
780 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
781 system ('/sbin/modprobe br2684');
782 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
785 system ('/sbin/ifconfig',"$device",'up');
787 } elsif ($pppsettings{'ENCAP'} =~ /^(0|1)$/) {
790 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$iface; close FILE
; }
791 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
792 system ('/sbin/modprobe br2684');
793 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
796 system ('/sbin/ifconfig',"$iface",'up');
798 if ($pppsettings{'METHOD'} eq 'STATIC') {
799 my @staticcommand = ('/sbin/ifconfig');
800 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}));
801 if ($pppsettings{'BROADCAST'} ne '') {
802 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
804 system (@staticcommand);
805 system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'});
806 system ("/bin/touch", "${General::swroot}/red/active");
807 system ("/etc/rc.d/init.d/network red update");
808 } elsif ($pppsettings {'METHOD'} eq 'DHCP') {
809 dodhcpdial
($iface,$pppsettings{'DHCP_HOSTNAME'});
811 } elsif ($pppsettings{'ENCAP'} =~ /^(2|3)$/) {
814 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$iface; close FILE
; }
815 if (system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
816 if (system ('/usr/sbin/atmarpd -b -l syslog')) {
817 &General
::log('atmarpd fail');
820 # it will fail on all attempt after the first because interface still exist
821 system ("/usr/sbin/atmarp -c $iface 2>/dev/null");
823 if ($pppsettings{'METHOD'} eq 'STATIC') {
824 my @staticcommand = ('/sbin/ifconfig');
825 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}, 'up'));
826 if ($pppsettings{'BROADCAST'} ne '') {
827 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
829 system (@staticcommand);
830 # we have to wait a bit before launching atmarp -s
832 my @atmarp = ('/usr/sbin/atmarp', '-s', $pppsettings{'GATEWAY'}, "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
833 if ($pppsettings{'ENCAP'} eq '3') {
834 push(@atmarp, 'null' ); # routed ip vc encap
837 system ("/sbin/route", "add", "default", "gw", $pppsettings{'GATEWAY'});
838 system ("/bin/touch", "${General::swroot}/red/active");