]>
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");
89 # No output should be sent to the webclient
90 open STDIN
, '</dev/zero' or die "Can't read from /dev/zero";
91 open STDOUT
, '>/dev/null' or die "Can't write to /dev/null";
93 if ($ARGV[0] eq 'start') {
94 if (-e
"${General::swroot}/red/active" ||
95 -e
'/var/run/ppp-ipfire.pid')
97 &General
::log ("ERROR: Can't start RED when it's still active");
101 if ( ( ( ($netsettings{'RED_TYPE'} =~ /^(PPPOE|PPTP)$/) && ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) ) ||
102 ( ( ($pppsettings{'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) || ($pppsettings{'PROTOCOL'} eq 'RFC2364') ) &&
103 ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/) ) ) && ($pppsettings{'RECONNECTION'} ne 'manual') ) {
104 system ('/etc/rc.d/init.d/connectioncheck start &');
108 ### Red device is ethernet
110 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/)
112 if ($netsettings{'RED_DEV'} ne '')
114 &General
::log("Starting RED device $netsettings{'RED_DEV'}.");
116 if ( $netsettings{'RED_TYPE'} eq 'DHCP')
118 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
119 dodhcpdial
($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
122 elsif ( ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} eq 'DHCP') )
124 if (open(FILE
, ">${General::swroot}/red/device")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
125 unlink ("${General::swroot}/red/iface");
126 dodhcpdial
($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
128 elsif ( ( $netsettings{'RED_TYPE'} eq 'STATIC') ||
129 ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} ne 'DHCP') )
131 system ("/sbin/ifconfig",
132 $netsettings{'RED_DEV'}, $netsettings{'RED_ADDRESS'},
133 "netmask", $netsettings{'RED_NETMASK'},
134 "broadcast", $netsettings{'RED_BROADCAST'},"up");
135 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
137 system("/usr/local/bin/setaliases");
138 system("echo $netsettings{'DNS1'} > ${General::swroot}/red/dns1");
139 system("echo $netsettings{'DNS2'} > ${General::swroot}/red/dns2");
140 system("echo $netsettings{'RED_ADDRESS'} > ${General::swroot}/red/local-ipaddress");
141 system("echo $netsettings{'DEFAULT_GATEWAY'} > ${General::swroot}/red/remote-ipaddress");
142 } elsif ( $netsettings{'RED_TYPE'} eq 'PPTP' ) {
143 if (open(FILE
, ">${General::swroot}/red/device")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
144 unlink ("${General::swroot}/red/iface");
146 if ( $netsettings{'DEFAULT_GATEWAY'} ne '' )
148 system ("/sbin/route","add","default","gw",
149 $netsettings{'DEFAULT_GATEWAY'});
155 system ("/sbin/ifconfig", $netsettings{'RED_DEV'}, "1.1.1.1",
156 "netmask", "255.255.255.0", "broadcast", "1.1.1.255", "up");
159 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
161 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$netsettings{'RED_DEV'}; close FILE
; }
162 system ("/bin/touch", "${General::swroot}/red/active");
163 system ("/etc/rc.d/init.d/network red update");
169 &General
::log ("ERROR: Can't start RED when RED device not set!");
175 if ($pppsettings{'RECONNECTION'} eq 'dialondemand')
177 system ('/bin/touch', "${General::swroot}/red/dial-on-demand");
180 if ($pppsettings{'VALID'} ne 'yes') {
181 &General
::log("Profile has errors.");
185 if (-e
"${General::swroot}/ppp/updatesettings") {
189 if (( $pppsettings{'METHOD'} eq 'STATIC') && ( $pppsettings{'DNS'} eq 'Manual')) {
190 system("/usr/local/bin/setaliases");
191 if (open(FILE
, ">${General::swroot}/red/dns1")) { print FILE
$pppsettings{'DNS1'}; close FILE
; }
192 if (open(FILE
, ">${General::swroot}/red/dns2")) { print FILE
$pppsettings{'DNS2'}; close FILE
; }
193 if (open(FILE
, ">${General::swroot}/red/local-ipaddress")) { print FILE
$pppsettings{'IP'}; close FILE
; }
194 if (open(FILE
, ">${General::swroot}/red/remote-ipaddress")) { print FILE
$pppsettings{'GATEWAY'}; close FILE
; }
196 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
197 &General
::log("Dial-on-Demand waiting to dial $pppsettings{'PROFILENAME'}.");
199 &General
::log("Dialling $pppsettings{'PROFILENAME'}.");
202 if ($pppsettings{'TYPE'} eq 'modem') { &domodemdial
(); }
203 elsif ($pppsettings{'TYPE'} eq 'serial') { &doserialdial
(); }
204 elsif ($pppsettings{'TYPE'} eq 'isdn') { &doisdndial
(); }
205 elsif ($pppsettings{'TYPE'} eq 'pppoe') { &dopppoedial
(); }
206 elsif ($pppsettings{'TYPE'} eq 'pptp') { &dopptpdial
(); }
207 elsif ($pppsettings{'TYPE'} eq 'fritzdsl') { &dofritzdsldial
(); }
209 if (-e
"${General::swroot}/ppp/updatesettings") {
210 # erase update mark only after specific script had run, allowing specific script to treat the update
211 unlink ("${General::swroot}/ppp/updatesettings");
213 if ( ($pppsettings{'RECONNECTION'} eq 'dialondemand') || ($pppsettings{'METHOD'} eq 'STATIC') ){
214 system ("/etc/rc.d/init.d/network red update");
217 elsif ($ARGV[0] eq 'stop')
219 if (open(IFACE
, "${General::swroot}/red/iface")) {
223 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
227 if (open(FILE
, "${General::swroot}/red/device")) {
231 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
234 unlink "${General::swroot}/red/dial-on-demand";
235 unlink "${General::swroot}/red/active";
236 unlink "${General::swroot}/red/local-ipaddress";
237 unlink "${General::swroot}/red/remote-ipaddress";
238 unlink "${General::swroot}/red/dns1";
239 unlink "${General::swroot}/red/dns2";
240 unlink "${General::swroot}/red/resolv.conf";
241 unlink "${General::swroot}/red/device";
243 # stay with keepconnected during transitional rc.red stop ordered by connectioncheck
244 if ( ! -e
"${General::swroot}/red/redial") {
245 unlink "${General::swroot}/red/keepconnected";
247 unlink "${General::swroot}/red/redial";
250 if (open(FILE
, "/var/run/ppp-ipfire.pid")) {
254 $pid =~ /(\d*)/; $pid = $1;
255 system ('/bin/kill', $pid);
258 # Bring down Ethernet interfaces & Kill DHCPC daemons
259 if (($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) && ( $netsettings{'RED_TYPE'} eq 'PPPOE') && $iface ) {
260 system ("/sbin/ifconfig", $iface, "down");
263 system ("/sbin/ifconfig", $device, "down");
267 while (($file = glob("/var/run/dhcpcd-*.pid") )) {
268 if (open(FILE
, $file)) {
272 $pid =~ /(\d*)/; $pid = $1;
273 system ('/bin/kill', $pid);
277 if (!system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
278 if ($pppsettings{'GATEWAY'} ne '') {
279 system("/usr/sbin/atmarp -d $pppsettings{'GATEWAY'} 2>/dev/null"); }
280 system('/bin/killall /usr/sbin/atmarpd 2>/dev/null');
281 system ('/sbin/ifconfig', 'atm0', 'down');
284 if ($pppsettings{'TYPE'} eq 'isdn') { system('/etc/rc.d/rc.isdn','stop'); }
285 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','stop'); }
287 if ( ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq 'STATIC') ||
288 ( $netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'PROTOCOL'} eq 'RFC1483' &&
289 $pppsettings{'METHOD'} eq 'STATIC' ) ) {
290 system ("/etc/rc.d/init.d/network red update");
293 elsif ($ARGV[0] eq 'clear')
303 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','cleanup'); }
308 my @pppcommand = ('/usr/sbin/pppd');
309 my $loginscript = '';
311 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
312 system ('/sbin/rmmod acm');
314 system ('/sbin/modprobe acm');
317 my $device = "/dev/${pppsettings{'COMPORT'}}";
319 if ($pppsettings{'DNS'} eq 'Automatic') {
320 push(@pppcommand, ('usepeerdns')); }
322 if ($pppsettings{'AUTH'} eq 'pap') {
323 push(@pppcommand, ('-chap'));
324 } elsif ($pppsettings{'AUTH'} eq 'chap') {
325 push(@pppcommand, ('-pap'));
326 } elsif ($pppsettings{'AUTH'} eq 'standard-login-script') {
327 $loginscript = 'standardloginscript';
328 } elsif ($pppsettings{'AUTH'} eq 'demon-login-script') {
329 $loginscript = 'demonloginscript';
331 $loginscript = $pppsettings{'LOGINSCRIPT'};
334 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
335 if ($pppsettings{'TIMEOUT'} != 0)
337 my $seconds = $pppsettings{'TIMEOUT'} * 60;
338 push (@pppcommand, ('idle', $seconds));
340 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
341 push (@pppcommand, ('demand', 'nopersist'));
345 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
348 push (@pppcommand, ('novj', 'novjccomp'));
350 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
351 $pppsettings{'DTERATE'}, 'noipdefault',
352 'defaultroute', 'user', $pppsettings{'USERNAME'},
353 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
355 if ($pppsettings{'DEBUG'} eq 'on') {
356 push(@pppcommand, ('debug'));
364 my @pppcommand = ('/usr/sbin/pppd');
365 my $loginscript = '';
367 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
368 system ('/sbin/rmmod acm');
370 system ('/sbin/modprobe acm');
373 my $device = "/dev/${pppsettings{'COMPORT'}}";
375 if ($pppsettings{'DNS'} eq 'Automatic') {
376 push(@pppcommand, ('usepeerdns')); }
378 if ($pppsettings{'AUTH'} eq 'pap') {
379 push(@pppcommand, ('-chap'));
380 } elsif ($pppsettings{'AUTH'} eq 'chap') {
381 push(@pppcommand, ('-pap'));
384 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
385 if ($pppsettings{'TIMEOUT'} != 0)
387 my $seconds = $pppsettings{'TIMEOUT'} * 60;
388 push (@pppcommand, ('idle', $seconds));
390 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
391 push (@pppcommand, ('demand', 'nopersist'));
395 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
398 push (@pppcommand, ('novj', 'novjccomp'));
400 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
401 $pppsettings{'DTERATE'}, 'noipdefault',
402 'defaultroute', 'user', $pppsettings{'USERNAME'},
403 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
405 if ($pppsettings{'DEBUG'} eq 'on') {
406 push(@pppcommand, ('debug'));
418 if (system ('/etc/rc.d/rc.isdn', 'start')) {
419 &General
::log ("ERROR: ISDN module failed to load");
423 $seconds = $pppsettings{'TIMEOUT'} * 60;
424 if ($pppsettings{'USEDOV'} eq 'on')
426 $phone = 'v' . $pppsettings{'TELEPHONE'};
430 $phone = $pppsettings{'TELEPHONE'};
433 if ($pppsettings{'COMPORT'} eq 'isdn2')
435 system('/usr/sbin/isdnctrl','addif','ippp0');
436 system('/usr/sbin/isdnctrl','addslave','ippp0','ippp1');
437 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
438 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
439 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
440 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
441 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
442 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
443 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
444 system('/usr/sbin/isdnctrl','l2_prot','ippp1','hdlc');
445 system('/usr/sbin/isdnctrl','l3_prot','ippp1','trans');
446 system('/usr/sbin/isdnctrl','encap','ippp1','syncppp');
447 system('/usr/sbin/isdnctrl','dialmax','ippp1',$pppsettings{'MAXRETRIES'});
448 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
449 system('/usr/sbin/isdnctrl','addphone','ippp1','out',$phone);
450 system('/usr/sbin/isdnctrl','huptimeout','ippp1',$seconds);
451 system('/usr/sbin/isdnctrl','dialmode','ippp1','auto');
453 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault','+mp',
454 'defaultroute','user',$pppsettings{'USERNAME'},
455 'name',$pppsettings{'USERNAME'},
456 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
457 'pidfile','/var/run/ppp-ipfire.pid','/dev/ippp0','/dev/ippp1');
458 if ($pppsettings{'DEBUG'} eq 'on') {
459 push(@pppcommand, ('debug'));
461 if ($pppsettings{'AUTH'} eq 'pap') {
462 push(@pppcommand, ('-chap'));
463 } elsif ($pppsettings{'AUTH'} eq 'chap') {
464 push(@pppcommand, ('-pap'));
466 system (@pppcommand);
470 system('/usr/sbin/isdnctrl','addif','ippp0');
471 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
472 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
473 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
474 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
475 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
476 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
477 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
479 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault',
480 'defaultroute','user',$pppsettings{'USERNAME'},
481 'name',$pppsettings{'USERNAME'},
482 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
483 'pidfile','/var/run/ppp-ipfire.pid','/dev/ippp0');
484 if ($pppsettings{'DEBUG'} eq 'on') {
485 push(@pppcommand, ('debug'));
487 if ($pppsettings{'AUTH'} eq 'pap') {
488 push(@pppcommand, ('-chap'));
489 } elsif ($pppsettings{'AUTH'} eq 'chap') {
490 push(@pppcommand, ('-pap'));
492 system (@pppcommand);
497 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
498 system('/usr/sbin/isdnctrl','dialmode','ippp0','auto');
499 system('/sbin/ifconfig','ippp0','10.112.112.112','pointopoint','10.112.112.113');
500 system('/sbin/ifconfig','ippp0','-arp','-broadcast');
501 system('/sbin/route','add','default','dev','ippp0');
503 system('/usr/sbin/isdnctrl', 'dial', 'ippp0');
507 system('/bin/killall', 'ibod');
508 if ($pppsettings{'COMPORT'} eq 'isdn2') {
509 if ($pppsettings{'USEIBOD'} eq 'on') {
510 system("/usr/sbin/ibod &");
512 system('/usr/sbin/isdnctrl', 'addlink', 'ippp0');
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 if ( $pppsettings{'METHOD'} eq 'DHCP' && open(FILE
, "${General::swroot}/red/device")) {
612 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
613 if (&General
::readhash
("${General::swroot}/dhcpc/dhcpcd-$device.info", \
%pptpdhcpc)) {
614 system("/sbin/route add -host $routerip gw $pptpdhcpc{'GATEWAY'}");
616 system("/sbin/route add -host $routerip dev $device");
620 my @pppcommand = ('/usr/sbin/pppd', 'pty');
621 my @pptpcommand = ('/usr/sbin/pptp', $routerip, '--nobuffer', '--nolaunchpppd', '--sync');
622 if ($pppsettings{'PHONEBOOK'}) {
623 push (@pptpcommand, ('--phone ', $pppsettings{'PHONEBOOK'}));
626 push(@pppcommand, "@pptpcommand");
628 if ($pppsettings{'DNS'} eq 'Automatic') {
629 push(@pppcommand, ('usepeerdns'));
631 if ($pppsettings{'AUTH'} eq 'pap') {
632 push(@pppcommand, ('-chap'));
633 } elsif ($pppsettings{'AUTH'} eq 'chap') {
634 push(@pppcommand, ('-pap'));
637 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
638 if ($pppsettings{'TIMEOUT'} != 0) {
639 my $seconds = $pppsettings{'TIMEOUT'} * 60;
640 push(@pppcommand, ('idle', "$seconds"));
642 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
643 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
647 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
650 push(@pppcommand, ('noipdefault', 'default-asyncmap',
651 'defaultroute', 'hide-password', 'local','noaccomp', 'noccp',
652 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
653 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
654 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
655 'maxfail',$pppsettings{'MAXRETRIES'},'sync'));
656 if ($pppsettings{'DEBUG'} eq 'on') {
657 push(@pppcommand, ('debug'));
660 system (@pppcommand);
667 if (system ('/etc/rc.d/rc.fritzdsl','start')) {
668 &General
::log ("ERROR: Fritz DSL module failed to load");
673 if ($pppsettings{'TYPE'} eq 'fritzdsl') {
674 if ( ! system ('/bin/grep', '1244:2700', '/proc/pci')) {
675 $controller=1; # fcdslsl
676 } elsif (! system('/bin/grep', '1244:2900', '/proc/pci')) {
677 $controller=2; # fcdsl2
678 } elsif (! system('/bin/grep', '1131:5402', '/proc/pci')) {
679 $controller=2; # fdsl
680 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=2300', '/proc/bus/usb/devices')) {
681 $controller=1; # fcdslusb
682 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=3500', '/proc/bus/usb/devices')) {
683 $controller=1; # fcdslslusb
686 my @pppcommand = ('/usr/sbin/pppd');
689 if ($pppsettings{'DNS'} eq 'Automatic') {
690 push(@pppcommand, ('usepeerdns'));
693 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
694 if ($pppsettings{'TIMEOUT'} != 0) {
695 my $seconds = $pppsettings{'TIMEOUT'} * 60;
696 push(@pppcommand, ('idle', "$seconds"));
698 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
699 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
703 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
706 push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user',
707 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
708 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
709 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
710 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
712 if ($pppsettings{'DEBUG'} eq 'on') {
713 push(@pppcommand, ('debug'));
716 if ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
717 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoe',
718 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
720 if ($pppsettings {'ENCAP'} eq '1') {
721 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoallc',
722 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
724 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoa',
725 'controller', $controller,'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
728 push(@pppcommand, @capiplugin);
729 push(@pppcommand, '/dev/null');
731 system (@pppcommand);
737 if ($pppsettings {'PROTOCOL'} eq 'RFC2364') {
738 system ('/sbin/modprobe pppoatm');
739 my @pppcommand = ('/usr/sbin/pppd');
740 if ($pppsettings{'ENCAP'} eq '0') { $ENCAP='vc-encaps'; } else { $ENCAP='llc-encaps'; }
741 push(@pppcommand,'plugin', 'pppoatm.so',$pppsettings{'VPI'}.".".$pppsettings{'VCI'},"$ENCAP");
742 if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));}
743 if ($pppsettings{'AUTH'} eq 'pap') {
744 push(@pppcommand, ('-chap'));
745 } elsif ($pppsettings{'AUTH'} eq 'chap') {
746 push(@pppcommand, ('-pap'));
748 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
749 if ($pppsettings{'TIMEOUT'} != 0) {
750 my $seconds = $pppsettings{'TIMEOUT'} * 60;
751 push(@pppcommand, ('idle', "$seconds"));
753 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
754 push (@pppcommand, ('demand','nopersist'));
758 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
760 push(@pppcommand, ('noipdefault', 'defaultroute', 'user',
761 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
762 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
763 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
764 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
766 if ($pppsettings{'DEBUG'} eq 'on') {
767 push(@pppcommand, ('debug'));
770 system (@pppcommand);
771 } elsif ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
772 if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) {
774 my $device = "nas$itf";
775 if (open(FILE
, ">${General::swroot}/red/device")) { print FILE
$device; close FILE
; }
776 $netsettings{'RED_DEV'} = $device;
777 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
778 system ('/sbin/modprobe br2684');
779 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
782 system ('/sbin/ifconfig',"$device",'up');
784 } elsif ($pppsettings{'ENCAP'} =~ /^(0|1)$/) {
787 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$iface; close FILE
; }
788 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
789 system ('/sbin/modprobe br2684');
790 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
793 system ('/sbin/ifconfig',"$iface",'up');
795 if ($pppsettings{'METHOD'} eq 'STATIC') {
796 my @staticcommand = ('/sbin/ifconfig');
797 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}));
798 if ($pppsettings{'BROADCAST'} ne '') {
799 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
801 system (@staticcommand);
802 system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'});
803 system ("/bin/touch", "${General::swroot}/red/active");
804 system ("/etc/rc.d/init.d/network red update");
805 } elsif ($pppsettings {'METHOD'} eq 'DHCP') {
806 dodhcpdial
($iface,$pppsettings{'DHCP_HOSTNAME'});
808 } elsif ($pppsettings{'ENCAP'} =~ /^(2|3)$/) {
811 if (open(FILE
, ">${General::swroot}/red/iface")) { print FILE
$iface; close FILE
; }
812 if (system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
813 if (system ('/usr/sbin/atmarpd -b -l syslog')) {
814 &General
::log('atmarpd fail');
817 # it will fail on all attempt after the first because interface still exist
818 system ("/usr/sbin/atmarp -c $iface 2>/dev/null");
820 if ($pppsettings{'METHOD'} eq 'STATIC') {
821 my @staticcommand = ('/sbin/ifconfig');
822 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}, 'up'));
823 if ($pppsettings{'BROADCAST'} ne '') {
824 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
826 system (@staticcommand);
827 # we have to wait a bit before launching atmarp -s
829 my @atmarp = ('/usr/sbin/atmarp', '-s', $pppsettings{'GATEWAY'}, "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
830 if ($pppsettings{'ENCAP'} eq '3') {
831 push(@atmarp, 'null' ); # routed ip vc encap
834 system ("/sbin/route", "add", "default", "gw", $pppsettings{'GATEWAY'});
835 system ("/bin/touch", "${General::swroot}/red/active");