]>
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")); }
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 if ($pppsettings{'METHOD'} ne 'PPPOE_PLUGIN') {
519 my @pppcommand = ('/usr/sbin/pppd', 'pty');
520 my @pppoecommand = ('/usr/sbin/pppoe', '-p','/var/run/pppoe.pid','-I',
521 $netsettings{'RED_DEV'}, '-T', '80', '-U', '-m', '1412');
523 if ($pppsettings{'SERVICENAME'}) {
524 push(@pppoecommand, ('-S', $pppsettings{'SERVICENAME'})); }
525 if ($pppsettings{'CONCENTRATORNAME'}) {
526 push(@pppoecommand, ('-C', $pppsettings{'CONCENTRATORNAME'})); }
528 push(@pppcommand, "@pppoecommand");
530 if ($pppsettings{'DNS'} eq 'Automatic') {
531 push(@pppcommand, ('usepeerdns'));
534 if ($pppsettings{'AUTH'} eq 'pap') {
535 push(@pppcommand, ('-chap'));
536 } elsif ($pppsettings{'AUTH'} eq 'chap') {
537 push(@pppcommand, ('-pap'));
540 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
541 if ($pppsettings{'TIMEOUT'} != 0) {
542 my $seconds = $pppsettings{'TIMEOUT'} * 60;
543 push(@pppcommand, ('idle', "$seconds"));
545 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
546 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
550 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
553 push(@pppcommand, ('noipdefault', 'default-asyncmap',
554 'defaultroute', 'hide-password', 'local',
555 'mtu', '1492', 'mru', '1492', 'noaccomp', 'noccp',
556 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
557 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
558 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
559 'maxfail',$pppsettings{'MAXRETRIES'}));
560 if ($pppsettings{'DEBUG'} eq 'on') {
561 push(@pppcommand, ('debug'));
564 system (@pppcommand);
567 system ('/sbin/modprobe pppoe');
568 my @pppcommand = ('/usr/sbin/pppd');
569 push(@pppcommand,'plugin','rp-pppoe.so',"$netsettings{'RED_DEV'}");
570 if ($pppsettings{'DNS'} eq 'Automatic') {
571 push(@pppcommand, ('usepeerdns'));
573 if ($pppsettings{'AUTH'} eq 'pap') {
574 push(@pppcommand, ('-chap'));
575 } elsif ($pppsettings{'AUTH'} eq 'chap') {
576 push(@pppcommand, ('-pap'));
578 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
579 if ($pppsettings{'TIMEOUT'} != 0) {
580 my $seconds = $pppsettings{'TIMEOUT'} * 60;
581 push(@pppcommand, ('idle', "$seconds"));
583 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
584 push (@pppcommand, ('demand','nopersist'));
588 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
590 push(@pppcommand, ('noipdefault', 'defaultroute', 'hide-password', 'ipcp-accept-local',
591 'ipcp-accept-remote', 'passive', 'noccp','nopcomp', 'novjccomp',
592 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
593 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
594 'maxfail',$pppsettings{'MAXRETRIES'}));
595 if ($pppsettings{'DEBUG'} eq 'on') {
596 push(@pppcommand, ('debug'));
599 system (@pppcommand);
606 my $routerip = $pppsettings{'ROUTERIP'} ?
$pppsettings{'ROUTERIP'} : "10.0.0.138";
607 if ( $pppsettings{'METHOD'} eq 'DHCP' && open(FILE
, "${General::swroot}/red/device")) {
611 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
612 if (&General
::readhash
("${General::swroot}/dhcpc/dhcpcd-$device.info", \
%pptpdhcpc)) {
613 system("/sbin/route add -host $routerip gw $pptpdhcpc{'GATEWAY'}");
615 system("/sbin/route add -host $routerip dev $device");
619 my @pppcommand = ('/usr/sbin/pppd', 'pty');
620 my @pptpcommand = ('/usr/sbin/pptp', $routerip, '--nobuffer', '--nolaunchpppd', '--sync');
621 if ($pppsettings{'PHONEBOOK'}) {
622 push (@pptpcommand, ('--phone ', $pppsettings{'PHONEBOOK'}));
625 push(@pppcommand, "@pptpcommand");
627 if ($pppsettings{'DNS'} eq 'Automatic') {
628 push(@pppcommand, ('usepeerdns'));
630 if ($pppsettings{'AUTH'} eq 'pap') {
631 push(@pppcommand, ('-chap'));
632 } elsif ($pppsettings{'AUTH'} eq 'chap') {
633 push(@pppcommand, ('-pap'));
636 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
637 if ($pppsettings{'TIMEOUT'} != 0) {
638 my $seconds = $pppsettings{'TIMEOUT'} * 60;
639 push(@pppcommand, ('idle', "$seconds"));
641 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
642 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
646 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
649 push(@pppcommand, ('noipdefault', 'default-asyncmap',
650 'defaultroute', 'hide-password', 'local','noaccomp', 'noccp',
651 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
652 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
653 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
654 'maxfail',$pppsettings{'MAXRETRIES'},'sync'));
655 if ($pppsettings{'DEBUG'} eq 'on') {
656 push(@pppcommand, ('debug'));
659 system (@pppcommand);
666 if (system ('/etc/rc.d/rc.fritzdsl','start')) {
667 &General
::log ("ERROR: Fritz DSL module failed to load");
672 if ($pppsettings{'TYPE'} eq 'fritzdsl') {
673 if ( ! system ('/bin/grep', '1244:2700', '/proc/pci')) {
674 $controller=1; # fcdslsl
675 } elsif (! system('/bin/grep', '1244:2900', '/proc/pci')) {
676 $controller=2; # fcdsl2
677 } elsif (! system('/bin/grep', '1131:5402', '/proc/pci')) {
678 $controller=2; # fdsl
679 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=2300', '/proc/bus/usb/devices')) {
680 $controller=1; # fcdslusb
681 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=3500', '/proc/bus/usb/devices')) {
682 $controller=1; # fcdslslusb
685 my @pppcommand = ('/usr/sbin/pppd');
688 if ($pppsettings{'DNS'} eq 'Automatic') {
689 push(@pppcommand, ('usepeerdns'));
692 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
693 if ($pppsettings{'TIMEOUT'} != 0) {
694 my $seconds = $pppsettings{'TIMEOUT'} * 60;
695 push(@pppcommand, ('idle', "$seconds"));
697 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
698 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
702 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
705 push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user',
706 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
707 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
708 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
709 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
711 if ($pppsettings{'DEBUG'} eq 'on') {
712 push(@pppcommand, ('debug'));
715 if ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
716 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoe',
717 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
719 if ($pppsettings {'ENCAP'} eq '1') {
720 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoallc',
721 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
723 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoa',
724 'controller', $controller,'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
727 push(@pppcommand, @capiplugin);
728 push(@pppcommand, '/dev/null');
730 system (@pppcommand);
736 if ($pppsettings {'PROTOCOL'} eq 'RFC2364') {
737 system ('/sbin/modprobe pppoatm');
738 my @pppcommand = ('/usr/sbin/pppd');
739 if ($pppsettings{'ENCAP'} eq '0') { $ENCAP='vc-encaps'; } else { $ENCAP='llc-encaps'; }
740 push(@pppcommand,'plugin', 'pppoatm.so',$pppsettings{'VPI'}.".".$pppsettings{'VCI'},"$ENCAP");
741 if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));}
742 if ($pppsettings{'AUTH'} eq 'pap') {
743 push(@pppcommand, ('-chap'));
744 } elsif ($pppsettings{'AUTH'} eq 'chap') {
745 push(@pppcommand, ('-pap'));
747 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
748 if ($pppsettings{'TIMEOUT'} != 0) {
749 my $seconds = $pppsettings{'TIMEOUT'} * 60;
750 push(@pppcommand, ('idle', "$seconds"));
752 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
753 push (@pppcommand, ('demand','nopersist'));
757 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
759 push(@pppcommand, ('noipdefault', 'defaultroute', 'user',
760 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
761 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
762 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
763 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
765 if ($pppsettings{'DEBUG'} eq 'on') {
766 push(@pppcommand, ('debug'));
769 system (@pppcommand);
770 } elsif ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
771 if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) {
773 my $device = "nas$itf";
774 if (open(FILE
, ">${General::swroot}/red/device")) { print FILE
$device; close FILE
; }
775 $netsettings{'RED_DEV'} = $device;
776 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
777 system ('/sbin/modprobe br2684');
778 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
781 system ('/sbin/ifconfig',"$device",'up');
783 } elsif ($pppsettings{'ENCAP'} =~ /^(0|1)$/) {
786 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$iface; close FILE
; }
787 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
788 system ('/sbin/modprobe br2684');
789 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
792 system ('/sbin/ifconfig',"$iface",'up');
794 if ($pppsettings{'METHOD'} eq 'STATIC') {
795 my @staticcommand = ('/sbin/ifconfig');
796 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}));
797 if ($pppsettings{'BROADCAST'} ne '') {
798 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
800 system (@staticcommand);
801 system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'});
802 system ("/bin/touch", "${General::swroot}/red/active");
803 system ("/etc/rc.d/init.d/network red update");
804 } elsif ($pppsettings {'METHOD'} eq 'DHCP') {
805 dodhcpdial
($iface,$pppsettings{'DHCP_HOSTNAME'});
807 } elsif ($pppsettings{'ENCAP'} =~ /^(2|3)$/) {
810 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$iface; close FILE
; }
811 if (system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
812 if (system ('/usr/sbin/atmarpd -b -l syslog')) {
813 &General
::log('atmarpd fail');
816 # it will fail on all attempt after the first because interface still exist
817 system ("/usr/sbin/atmarp -c $iface 2>/dev/null");
819 if ($pppsettings{'METHOD'} eq 'STATIC') {
820 my @staticcommand = ('/sbin/ifconfig');
821 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}, 'up'));
822 if ($pppsettings{'BROADCAST'} ne '') {
823 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
825 system (@staticcommand);
826 # we have to wait a bit before launching atmarp -s
828 my @atmarp = ('/usr/sbin/atmarp', '-s', $pppsettings{'GATEWAY'}, "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
829 if ($pppsettings{'ENCAP'} eq '3') {
830 push(@atmarp, 'null' ); # routed ip vc encap
833 system ("/sbin/route", "add", "default", "gw", $pppsettings{'GATEWAY'});
834 system ("/bin/touch", "${General::swroot}/red/active");