]> git.ipfire.org Git - ipfire-2.x.git/blob - src/rc.d/rc.red
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[ipfire-2.x.git] / src / rc.d / rc.red
1 #!/usr/bin/perl
2 #
3 # This file is part of the IPCop Firewall.
4 #
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.
9 #
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.
14 #
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
18 #
19 # (c) The SmoothWall Team
20 #
21 # $Id: rc.red,v 1.29.2.56 2005/12/17 08:49:01 gespinasse Exp $
22
23
24 # Clean up our environment (we're running SUID!)
25 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
26 $< = $>;
27
28 use strict;
29 require 'CONFIG_ROOT/general-functions.pl';
30
31 my %pppsettings;
32 my %isdnsettings;
33 my %netsettings;
34 my %dhcpsettings;
35 my $iface;
36
37 # read vars back from file.
38 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
39 &General::readhash("${General::swroot}/isdn/settings", \%isdnsettings);
40 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
41 &General::readhash("${General::swroot}/dhcp/settings", \%dhcpsettings);
42
43 sub dodhcpdial($;$) {
44 my ($iface,$dhcp_name)=@_;
45
46 system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'tcp', '--source-port', '67',
47 '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT');
48 system ('/sbin/iptables', '-A', 'REDINPUT', '-p', 'udp', '--source-port', '67',
49 '--destination-port', '68', '-i', $iface, '-j', 'ACCEPT');
50
51 foreach ("<${General::swroot}/dhcpc/*.info>") { unlink $1 if ( $_ =~ /^([\/\w.-]+)$/ ); }
52 my @dhcpcommand = ('/usr/sbin/dhcpcd');
53 push(@dhcpcommand, ('-N', '-R', "$iface",'-L', "${General::swroot}/dhcpc"));
54
55 #FIXME the only way actually to set debug use is in pppsetup.cgi and 'RED is modem/isdn' interface
56 if ($pppsettings{'DEBUG'} eq 'on') {
57 push(@dhcpcommand, ('-d'));
58 }
59
60 if ($dhcp_name ne '') { push(@dhcpcommand, ('-h', "$dhcp_name")); }
61 if ($netsettings{'RED_TYPE'} eq 'PPTP') { push(@dhcpcommand, '-G'); }
62
63 if (system (@dhcpcommand)) {
64 &General::log('dhcpcd fail');
65 exit 1;
66 } else {
67 &General::log('dhcpcd success');
68 }
69 }
70
71 sub doupdatesettings {
72 # complete cleanup only if settings were changed or clear is ordered
73 system('/sbin/modprobe', '-r', 'pppoatm');
74 system('/sbin/modprobe', '-r', 'pppoe');
75 system('/bin/killall /usr/bin/br2684ctl 2>/dev/null');
76 system('/sbin/modprobe', '-r', 'br2684');
77 system('/sbin/modprobe', '-r', 'clip');
78
79 if ($pppsettings{'TYPE'} ne '3cp4218usbadsl') { system('/sbin/modprobe', '-r', '3cp4218');}
80 if ($pppsettings{'TYPE'} ne 'alcatelusbk') { system('/sbin/modprobe', '-r', 'speedtch');}
81 if ($pppsettings{'TYPE'} ne 'amedynusbadsl') { system('/sbin/modprobe', '-r', 'amedyn');}
82 if ($pppsettings{'TYPE'} ne 'bewanadsl') {
83 system('/sbin/modprobe', '-r', 'unicorn_pci_atm', 'unicorn_usb_atm');}
84 if ($pppsettings{'TYPE'} ne 'conexantpciadsl') { system('/sbin/modprobe', '-r', 'CnxADSL');}
85 if ($pppsettings{'TYPE'} ne 'conexantusbadsl') { system('/sbin/modprobe', '-r', 'cxacru');}
86 if ($pppsettings{'TYPE'} ne 'eagleusbadsl') { system('/sbin/modprobe', '-r', 'eagle-usb');}
87 if ($pppsettings{'TYPE'} ne 'fritzdsl') {
88 system('/sbin/modprobe', '-r', 'fcdsl', 'fcdsl2', 'fcdslsl', 'fcdslusb', 'fcdslslusb');}
89 if ($pppsettings{'TYPE'} ne 'pulsardsl') { system('/sbin/modprobe', '-r', 'pulsar');}
90 sleep 1;
91 if ($pppsettings{'TYPE'} !=~ /^(3cp4218usbadsl|alcatelusbk|amedynusbadsl|bewanadsl|conexantpciadsl|pulsardsl)$/) {
92 system('/sbin/modprobe', '-r', 'atm');
93
94 # remove existing default route (for static address) if it was been changed from setup or web interface SF1175052
95 system ('/sbin/route del default 2>/dev/null');
96
97 # erase in case it was created once with 'persistent' selected but rc.red stop never used : SF1171610
98 unlink ("${General::swroot}/red/iface");
99 }
100 }
101
102 # No output should be sent to the webclient
103 open STDIN, '</dev/zero' or die "Can't read from /dev/zero";
104 open STDOUT, '>/dev/null' or die "Can't write to /dev/null";
105
106 if ($ARGV[0] eq 'start') {
107 if (-e "${General::swroot}/red/active" ||
108 -e '/var/run/ppp-ipcop.pid')
109 {
110 &General::log ("ERROR: Can't start RED when it's still active");
111 exit 1;
112 }
113
114 if ( ( ( ($netsettings{'RED_TYPE'} =~ /^(PPPOE|PPTP)$/) && ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) ) ||
115 ( ( ($pppsettings{'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) || ($pppsettings{'PROTOCOL'} eq 'RFC2364') ) &&
116 ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/) ) ) && ($pppsettings{'RECONNECTION'} ne 'manual') ) {
117 system ('/etc/rc.d/rc.connectioncheck start &');
118 }
119
120 ###
121 ### Red device is ethernet
122 ###
123 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/)
124 {
125 if ($netsettings{'RED_DEV'} ne '')
126 {
127 &General::log("Starting RED device $netsettings{'RED_DEV'}.");
128
129 if ( $netsettings{'RED_TYPE'} eq 'DHCP')
130 {
131 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
132 dodhcpdial($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
133 exit 0;
134 }
135 elsif ( ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} eq 'DHCP') )
136 {
137 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
138 unlink ("${General::swroot}/red/iface");
139 dodhcpdial($netsettings{'RED_DEV'},$netsettings{'RED_DHCP_HOSTNAME'});
140 }
141 elsif ( ( $netsettings{'RED_TYPE'} eq 'STATIC') ||
142 ( $netsettings{'RED_TYPE'} eq 'PPTP') && ( $pppsettings{'METHOD'} ne 'DHCP') )
143 {
144 system ("/sbin/ifconfig",
145 $netsettings{'RED_DEV'}, $netsettings{'RED_ADDRESS'},
146 "netmask", $netsettings{'RED_NETMASK'},
147 "broadcast", $netsettings{'RED_BROADCAST'},"up");
148 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
149 {
150 system("/usr/local/bin/setaliases");
151 system("echo $netsettings{'DNS1'} > ${General::swroot}/red/dns1");
152 system("echo $netsettings{'DNS2'} > ${General::swroot}/red/dns2");
153 system("echo $netsettings{'RED_ADDRESS'} > ${General::swroot}/red/local-ipaddress");
154 system("echo $netsettings{'DEFAULT_GATEWAY'} > ${General::swroot}/red/remote-ipaddress");
155 } elsif ( $netsettings{'RED_TYPE'} eq 'PPTP' ) {
156 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
157 unlink ("${General::swroot}/red/iface");
158 }
159 if ( $netsettings{'DEFAULT_GATEWAY'} ne '' )
160 {
161 system ("/sbin/route","add","default","gw",
162 $netsettings{'DEFAULT_GATEWAY'});
163 }
164 }
165 else
166 {
167 # PPPoE
168 system ("/sbin/ifconfig", $netsettings{'RED_DEV'}, "1.1.1.1",
169 "netmask", "255.255.255.0", "broadcast", "1.1.1.255", "up");
170 }
171
172 if ( $netsettings{'RED_TYPE'} eq 'STATIC')
173 {
174 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $netsettings{'RED_DEV'}; close FILE; }
175 system ("/bin/touch", "${General::swroot}/red/active");
176 system ("/etc/rc.d/rc.updatered");
177 exit 0;
178 }
179 }
180 else
181 {
182 &General::log ("ERROR: Can't start RED when RED device not set!");
183 exit 1;
184 }
185 }
186
187
188 if ($pppsettings{'RECONNECTION'} eq 'dialondemand')
189 {
190 system ('/bin/touch', "${General::swroot}/red/dial-on-demand");
191 }
192
193 if ($pppsettings{'VALID'} ne 'yes') {
194 &General::log("Profile has errors.");
195 exit 1;
196 }
197
198 if (-e "${General::swroot}/ppp/updatesettings") {
199 &doupdatesettings;
200 }
201
202 if (( $pppsettings{'METHOD'} eq 'STATIC') && ( $pppsettings{'DNS'} eq 'Manual')) {
203 system("/usr/local/bin/setaliases");
204 if (open(FILE, ">${General::swroot}/red/dns1")) { print FILE $pppsettings{'DNS1'}; close FILE; }
205 if (open(FILE, ">${General::swroot}/red/dns2")) { print FILE $pppsettings{'DNS2'}; close FILE; }
206 if (open(FILE, ">${General::swroot}/red/local-ipaddress")) { print FILE $pppsettings{'IP'}; close FILE; }
207 if (open(FILE, ">${General::swroot}/red/remote-ipaddress")) { print FILE $pppsettings{'GATEWAY'}; close FILE; }
208 }
209 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
210 &General::log("Dial-on-Demand waiting to dial $pppsettings{'PROFILENAME'}.");
211 } else {
212 &General::log("Dialling $pppsettings{'PROFILENAME'}.");
213 }
214
215 if ($pppsettings{'TYPE'} eq 'modem') { &domodemdial(); }
216 elsif ($pppsettings{'TYPE'} eq 'serial') { &doserialdial(); }
217 elsif ($pppsettings{'TYPE'} eq 'isdn') { &doisdndial(); }
218 elsif ($pppsettings{'TYPE'} eq 'pppoe') { &dopppoedial(); }
219 elsif ($pppsettings{'TYPE'} eq 'pptp') { &dopptpdial(); }
220 elsif ($pppsettings{'TYPE'} eq 'alcatelusbk') { &doalcatelusbkdial(); }
221 elsif ($pppsettings{'TYPE'} eq 'alcatelusb') { &doalcatelusbdial(); }
222 elsif ($pppsettings{'TYPE'} eq 'pulsardsl') { &dopulsardsldial(); }
223 elsif ($pppsettings{'TYPE'} eq 'eciadsl') { &doeciadsldial(); }
224 elsif ($pppsettings{'TYPE'} eq 'fritzdsl') { &dofritzdsldial(); }
225 elsif ($pppsettings{'TYPE'} eq 'bewanadsl') { &dobewanadsldial(); }
226 elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') { &doeagleusbadsldial(); }
227 elsif ($pppsettings{'TYPE'} eq 'conexantusbadsl') { &doconexantusbadsldial(); }
228 elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') { &doconexantpciadsldial(); }
229 elsif ($pppsettings{'TYPE'} eq 'amedynusbadsl') { &doamedynusbadsldial(); }
230 elsif ($pppsettings{'TYPE'} eq '3cp4218usbadsl') { &do3cp4218usbadsldial(); }
231
232 if (-e "${General::swroot}/ppp/updatesettings") {
233 # erase update mark only after specific script had run, allowing specific script to treat the update
234 unlink ("${General::swroot}/ppp/updatesettings");
235 }
236 if ( ($pppsettings{'RECONNECTION'} eq 'dialondemand') || ($pppsettings{'METHOD'} eq 'STATIC') ){
237 system ("/etc/rc.d/rc.updatered");
238 }
239 }
240 elsif ($ARGV[0] eq 'stop')
241 {
242 if (open(IFACE, "${General::swroot}/red/iface")) {
243 $iface = <IFACE>;
244 close IFACE;
245 chomp ($iface);
246 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
247 }
248
249 my $device;
250 if (open(FILE, "${General::swroot}/red/device")) {
251 $device = <FILE>;
252 close FILE;
253 chomp ($device);
254 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
255 }
256
257 unlink "${General::swroot}/red/dial-on-demand";
258 unlink "${General::swroot}/red/active";
259 unlink "${General::swroot}/red/local-ipaddress";
260 unlink "${General::swroot}/red/remote-ipaddress";
261 unlink "${General::swroot}/red/dns1";
262 unlink "${General::swroot}/red/dns2";
263 unlink "${General::swroot}/red/resolv.conf";
264 unlink "${General::swroot}/red/device";
265
266 # stay with keepconnected during transitional rc.red stop ordered by rc.connectioncheck
267 if ( ! -e "${General::swroot}/red/redial") {
268 unlink "${General::swroot}/red/keepconnected";
269 }
270 unlink "${General::swroot}/red/redial";
271
272 # Kill PPPD
273 if (open(FILE, "/var/run/ppp-ipcop.pid")) {
274 my $pid = <FILE>;
275 close FILE;
276 chomp ($pid);
277 $pid =~ /(\d*)/; $pid = $1;
278 system ('/bin/kill', $pid);
279 }
280
281 # Bring down Ethernet interfaces & Kill DHCPC daemons
282 if (($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) && ( $netsettings{'RED_TYPE'} eq 'PPPOE') && $iface ) {
283 system ("/sbin/ifconfig", $iface, "down");
284 }
285 if ($device) {
286 system ("/sbin/ifconfig", $device, "down");
287 }
288
289 my $file;
290 while (($file = glob("${General::swroot}/dhcpc/dhcpcd-*.pid") )) {
291 if (open(FILE, $file)) {
292 my $pid = <FILE>;
293 close FILE;
294 chomp ($pid);
295 $pid =~ /(\d*)/; $pid = $1;
296 system ('/bin/kill', $pid);
297 }
298 }
299
300 if (!system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
301 if ($pppsettings{'GATEWAY'} ne '') {
302 system("/usr/sbin/atmarp -d $pppsettings{'GATEWAY'} 2>/dev/null"); }
303 system('/bin/killall /usr/sbin/atmarpd 2>/dev/null');
304 system ('/sbin/ifconfig', 'atm0', 'down');
305 }
306
307 if ($pppsettings{'TYPE'} eq 'isdn') { system('/etc/rc.d/rc.isdn','stop'); }
308 if ($pppsettings{'TYPE'} eq 'eciadsl') { system('/etc/rc.d/rc.eciadsl', 'stop'); }
309 if ($pppsettings{'TYPE'} eq 'alcatelusbk') { system('/etc/rc.d/rc.alcatelusbk', 'stop'); }
310 if ($pppsettings{'TYPE'} eq 'alcatelusb') { system('/etc/rc.d/rc.alcatelusb', 'stop'); }
311 if ($pppsettings{'TYPE'} eq 'amedynusbadsl') { system('/etc/rc.d/rc.amedynusbadsl', 'stop'); }
312 if ($pppsettings{'TYPE'} eq 'bewanadsl') { system('/etc/rc.d/rc.bewanadsl', 'stop'); }
313 if ($pppsettings{'TYPE'} eq 'conexantpciadsl') { system('/etc/rc.d/rc.conexantpciadsl', 'stop'); }
314 if ($pppsettings{'TYPE'} eq 'conexantusbadsl') { system('/etc/rc.d/rc.conexantusbadsl', 'stop'); }
315 if ($pppsettings{'TYPE'} eq 'eagleusbadsl') { system('/etc/rc.d/rc.eagleusbadsl', 'stop'); }
316 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','stop'); }
317 if ($pppsettings{'TYPE'} eq 'pulsardsl') { system('/etc/rc.d/rc.pulsardsl', 'stop'); }
318 if ($pppsettings{'TYPE'} eq '3cp4218usbadsl') { system('/etc/rc.d/rc.3cp4218usbadsl', 'stop'); }
319
320 if ( ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq 'STATIC') ||
321 ( $netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'PROTOCOL'} eq 'RFC1483' &&
322 $pppsettings{'METHOD'} eq 'STATIC' ) ) {
323 system ("/etc/rc.d/rc.updatered");
324 }
325 }
326 elsif ($ARGV[0] eq 'clear')
327 {
328 &doupdatesettings();
329 &docleanup();
330 }
331
332 exit 0;
333
334 sub docleanup
335 {
336 if ($pppsettings{'TYPE'} eq 'alcatelusbk') { system('/etc/rc.d/rc.alcatelusbk', 'cleanup'); }
337 if ($pppsettings{'TYPE'} eq 'alcatelusb') { system('/etc/rc.d/rc.alcatelusb', 'cleanup'); }
338 if ($pppsettings{'TYPE'} eq 'eciadsl') { system('/etc/rc.d/rc.eciadsl', 'cleanup'); }
339 if ($pppsettings{'TYPE'} eq 'pulsardsl') { system('/etc/rc.d/rc.pulsardsl', 'cleanup'); }
340 if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','cleanup'); }
341 if ($pppsettings{'TYPE'} eq 'bewanadsl') { system('/etc/rc.d/rc.bewanadsl', 'cleanup'); }
342 if ($pppsettings{'TYPE'} eq 'eagleusbadsl') { system('/etc/rc.d/rc.eagleusbadsl', 'cleanup'); }
343 if ($pppsettings{'TYPE'} eq 'conexantusbadsl') { system('/etc/rc.d/rc.conexantusbadsl', 'cleanup'); }
344 if ($pppsettings{'TYPE'} eq 'conexantpciadsl') { system('/etc/rc.d/rc.conexantpciadsl', 'cleanup'); }
345 if ($pppsettings{'TYPE'} eq 'amedynusbadsl') { system('/etc/rc.d/rc.amedynusbadsl', 'cleanup'); }
346 if ($pppsettings{'TYPE'} eq '3cp4218usbadsl') { system('/etc/rc.d/rc.3cp4218usbadsl', 'cleanup'); }
347 }
348
349 sub domodemdial
350 {
351 my @pppcommand = ('/usr/sbin/pppd');
352 my $loginscript = '';
353
354 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
355 system ('/sbin/rmmod acm');
356 sleep 1;
357 system ('/sbin/modprobe acm');
358 }
359
360 my $device = "/dev/${pppsettings{'COMPORT'}}";
361
362 if ($pppsettings{'DNS'} eq 'Automatic') {
363 push(@pppcommand, ('usepeerdns')); }
364
365 if ($pppsettings{'AUTH'} eq 'pap') {
366 push(@pppcommand, ('-chap'));
367 } elsif ($pppsettings{'AUTH'} eq 'chap') {
368 push(@pppcommand, ('-pap'));
369 } elsif ($pppsettings{'AUTH'} eq 'standard-login-script') {
370 $loginscript = 'standardloginscript';
371 } elsif ($pppsettings{'AUTH'} eq 'demon-login-script') {
372 $loginscript = 'demonloginscript';
373 } else {
374 $loginscript = $pppsettings{'LOGINSCRIPT'};
375 }
376
377 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
378 if ($pppsettings{'TIMEOUT'} != 0)
379 {
380 my $seconds = $pppsettings{'TIMEOUT'} * 60;
381 push (@pppcommand, ('idle', $seconds));
382 }
383 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
384 push (@pppcommand, ('demand', 'nopersist'));
385 }
386 push (@pppcommand,
387 ('active-filter',
388 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
389 }
390
391 push (@pppcommand, ('novj', 'novjccomp'));
392
393 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
394 $pppsettings{'DTERATE'}, 'noipdefault',
395 'defaultroute', 'user', $pppsettings{'USERNAME'},
396 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
397 '/etc/ppp/dialer'));
398 if ($pppsettings{'DEBUG'} eq 'on') {
399 push(@pppcommand, ('debug'));
400 }
401
402 system @pppcommand;
403 }
404
405 sub doserialdial
406 {
407 my @pppcommand = ('/usr/sbin/pppd');
408 my $loginscript = '';
409
410 if ($pppsettings{'COMPORT'} =~ /ttyACM/) {
411 system ('/sbin/rmmod acm');
412 sleep 1;
413 system ('/sbin/modprobe acm');
414 }
415
416 my $device = "/dev/${pppsettings{'COMPORT'}}";
417
418 if ($pppsettings{'DNS'} eq 'Automatic') {
419 push(@pppcommand, ('usepeerdns')); }
420
421 if ($pppsettings{'AUTH'} eq 'pap') {
422 push(@pppcommand, ('-chap'));
423 } elsif ($pppsettings{'AUTH'} eq 'chap') {
424 push(@pppcommand, ('-pap'));
425 }
426
427 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
428 if ($pppsettings{'TIMEOUT'} != 0)
429 {
430 my $seconds = $pppsettings{'TIMEOUT'} * 60;
431 push (@pppcommand, ('idle', $seconds));
432 }
433 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
434 push (@pppcommand, ('demand', 'nopersist'));
435 }
436 push (@pppcommand,
437 ('active-filter',
438 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
439 }
440
441 push (@pppcommand, ('novj', 'novjccomp'));
442
443 push (@pppcommand, ('lock', 'modem', 'crtscts', $device,
444 $pppsettings{'DTERATE'}, 'noipdefault',
445 'defaultroute', 'user', $pppsettings{'USERNAME'},
446 'maxfail', $pppsettings{'MAXRETRIES'}, 'connect',
447 '/bin/true'));
448 if ($pppsettings{'DEBUG'} eq 'on') {
449 push(@pppcommand, ('debug'));
450 }
451
452 system @pppcommand;
453 }
454
455 sub doisdndial
456 {
457 my $pppoptions;
458 my $seconds;
459 my $phone;
460
461 if (system ('/etc/rc.d/rc.isdn', 'start')) {
462 &General::log ("ERROR: ISDN module failed to load");
463 exit 1;
464 }
465
466 $seconds = $pppsettings{'TIMEOUT'} * 60;
467 if ($pppsettings{'USEDOV'} eq 'on')
468 {
469 $phone = 'v' . $pppsettings{'TELEPHONE'};
470 }
471 else
472 {
473 $phone = $pppsettings{'TELEPHONE'};
474 };
475
476 if ($pppsettings{'COMPORT'} eq 'isdn2')
477 {
478 system('/usr/sbin/isdnctrl','addif','ippp0');
479 system('/usr/sbin/isdnctrl','addslave','ippp0','ippp1');
480 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
481 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
482 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
483 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
484 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
485 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
486 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
487 system('/usr/sbin/isdnctrl','l2_prot','ippp1','hdlc');
488 system('/usr/sbin/isdnctrl','l3_prot','ippp1','trans');
489 system('/usr/sbin/isdnctrl','encap','ippp1','syncppp');
490 system('/usr/sbin/isdnctrl','dialmax','ippp1',$pppsettings{'MAXRETRIES'});
491 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
492 system('/usr/sbin/isdnctrl','addphone','ippp1','out',$phone);
493 system('/usr/sbin/isdnctrl','huptimeout','ippp1',$seconds);
494 system('/usr/sbin/isdnctrl','dialmode','ippp1','auto');
495
496 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault','+mp',
497 'defaultroute','user',$pppsettings{'USERNAME'},
498 'name',$pppsettings{'USERNAME'},
499 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
500 'pidfile','/var/run/ppp-ipcop.pid','/dev/ippp0','/dev/ippp1');
501 if ($pppsettings{'DEBUG'} eq 'on') {
502 push(@pppcommand, ('debug'));
503 }
504 if ($pppsettings{'AUTH'} eq 'pap') {
505 push(@pppcommand, ('-chap'));
506 } elsif ($pppsettings{'AUTH'} eq 'chap') {
507 push(@pppcommand, ('-pap'));
508 }
509 system (@pppcommand);
510 }
511 else
512 {
513 system('/usr/sbin/isdnctrl','addif','ippp0');
514 system('/usr/sbin/isdnctrl','l2_prot','ippp0','hdlc');
515 system('/usr/sbin/isdnctrl','l3_prot','ippp0','trans');
516 system('/usr/sbin/isdnctrl','encap','ippp0','syncppp');
517 system('/usr/sbin/isdnctrl','dialmax','ippp0',$pppsettings{'MAXRETRIES'});
518 system('/usr/sbin/isdnctrl','eaz','ippp0',$isdnsettings{'MSN'});
519 system('/usr/sbin/isdnctrl','addphone','ippp0','out',$phone);
520 system('/usr/sbin/isdnctrl','huptimeout','ippp0',$seconds);
521
522 my @pppcommand = ('/usr/sbin/ipppd','ms-get-dns','noipdefault',
523 'defaultroute','user',$pppsettings{'USERNAME'},
524 'name',$pppsettings{'USERNAME'},
525 'active-filter','outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0',
526 'pidfile','/var/run/ppp-ipcop.pid','/dev/ippp0');
527 if ($pppsettings{'DEBUG'} eq 'on') {
528 push(@pppcommand, ('debug'));
529 }
530 if ($pppsettings{'AUTH'} eq 'pap') {
531 push(@pppcommand, ('-chap'));
532 } elsif ($pppsettings{'AUTH'} eq 'chap') {
533 push(@pppcommand, ('-pap'));
534 }
535 system (@pppcommand);
536 }
537
538 sleep 1;
539
540 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
541 system('/usr/sbin/isdnctrl','dialmode','ippp0','auto');
542 system('/sbin/ifconfig','ippp0','10.112.112.112','pointopoint','10.112.112.113');
543 system('/sbin/ifconfig','ippp0','-arp','-broadcast');
544 system('/sbin/route','add','default','dev','ippp0');
545 } else {
546 system('/usr/sbin/isdnctrl', 'dial', 'ippp0');
547
548 }
549
550 system('/bin/killall', 'ibod');
551 if ($pppsettings{'COMPORT'} eq 'isdn2') {
552 if ($pppsettings{'USEIBOD'} eq 'on') {
553 system("/usr/sbin/ibod &");
554 } else {
555 system('/usr/sbin/isdnctrl', 'addlink', 'ippp0');
556 }
557 }
558 }
559
560 sub dopppoedial
561 {
562 if ($pppsettings{'METHOD'} ne 'PPPOE_PLUGIN') {
563 my @pppcommand = ('/usr/sbin/pppd', 'pty');
564 my @pppoecommand = ('/usr/sbin/pppoe', '-p','/var/run/pppoe.pid','-I',
565 $netsettings{'RED_DEV'}, '-T', '80', '-U', '-m', '1412');
566
567 if ($pppsettings{'SERVICENAME'}) {
568 push(@pppoecommand, ('-S', $pppsettings{'SERVICENAME'})); }
569 if ($pppsettings{'CONCENTRATORNAME'}) {
570 push(@pppoecommand, ('-C', $pppsettings{'CONCENTRATORNAME'})); }
571
572 push(@pppcommand, "@pppoecommand");
573
574 if ($pppsettings{'DNS'} eq 'Automatic') {
575 push(@pppcommand, ('usepeerdns'));
576 }
577
578 if ($pppsettings{'AUTH'} eq 'pap') {
579 push(@pppcommand, ('-chap'));
580 } elsif ($pppsettings{'AUTH'} eq 'chap') {
581 push(@pppcommand, ('-pap'));
582 }
583
584 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
585 if ($pppsettings{'TIMEOUT'} != 0) {
586 my $seconds = $pppsettings{'TIMEOUT'} * 60;
587 push(@pppcommand, ('idle', "$seconds"));
588 }
589 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
590 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
591 }
592 push (@pppcommand,
593 ('active-filter',
594 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
595 }
596
597 push(@pppcommand, ('noipdefault', 'default-asyncmap',
598 'defaultroute', 'hide-password', 'local',
599 'mtu', '1492', 'mru', '1492', 'noaccomp', 'noccp',
600 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
601 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
602 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
603 'maxfail',$pppsettings{'MAXRETRIES'}));
604 if ($pppsettings{'DEBUG'} eq 'on') {
605 push(@pppcommand, ('debug'));
606 }
607
608 system (@pppcommand);
609 } else {
610 # PPPoE plugin
611 system ('/sbin/modprobe pppoe');
612 my @pppcommand = ('/usr/sbin/pppd');
613 push(@pppcommand,'plugin','rp-pppoe.so',"$netsettings{'RED_DEV'}");
614 if ($pppsettings{'DNS'} eq 'Automatic') {
615 push(@pppcommand, ('usepeerdns'));
616 }
617 if ($pppsettings{'AUTH'} eq 'pap') {
618 push(@pppcommand, ('-chap'));
619 } elsif ($pppsettings{'AUTH'} eq 'chap') {
620 push(@pppcommand, ('-pap'));
621 }
622 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
623 if ($pppsettings{'TIMEOUT'} != 0) {
624 my $seconds = $pppsettings{'TIMEOUT'} * 60;
625 push(@pppcommand, ('idle', "$seconds"));
626 }
627 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
628 push (@pppcommand, ('demand','nopersist'));
629 }
630 push (@pppcommand,
631 ('active-filter',
632 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
633 }
634 push(@pppcommand, ('noipdefault', 'defaultroute', 'hide-password', 'ipcp-accept-local',
635 'ipcp-accept-remote', 'passive', 'noccp','nopcomp', 'novjccomp',
636 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
637 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
638 'maxfail',$pppsettings{'MAXRETRIES'}));
639 if ($pppsettings{'DEBUG'} eq 'on') {
640 push(@pppcommand, ('debug'));
641 }
642
643 system (@pppcommand);
644 }
645 }
646
647 sub dopptpdial
648 {
649 my %pptpdhcpc;
650 my $routerip = $pppsettings{'ROUTERIP'} ? $pppsettings{'ROUTERIP'} : "10.0.0.138";
651 if ( $pppsettings{'METHOD'} eq 'DHCP' && open(FILE, "${General::swroot}/red/device")) {
652 my $device = <FILE>;
653 close FILE;
654 chomp ($device);
655 $device =~ /([a-zA-Z0-9]*)/; $device = $1;
656 if (&General::readhash("${General::swroot}/dhcpc/dhcpcd-$device.info", \%pptpdhcpc)) {
657 system("/sbin/route add -host $routerip gw $pptpdhcpc{'GATEWAY'}");
658 } else {
659 system("/sbin/route add -host $routerip dev $device");
660 }
661 }
662
663 my @pppcommand = ('/usr/sbin/pppd', 'pty');
664 my @pptpcommand = ('/usr/sbin/pptp', $routerip, '--nobuffer', '--nolaunchpppd', '--sync');
665 if ($pppsettings{'PHONEBOOK'}) {
666 push (@pptpcommand, ('--phone ', $pppsettings{'PHONEBOOK'}));
667 }
668
669 push(@pppcommand, "@pptpcommand");
670
671 if ($pppsettings{'DNS'} eq 'Automatic') {
672 push(@pppcommand, ('usepeerdns'));
673 }
674 if ($pppsettings{'AUTH'} eq 'pap') {
675 push(@pppcommand, ('-chap'));
676 } elsif ($pppsettings{'AUTH'} eq 'chap') {
677 push(@pppcommand, ('-pap'));
678 }
679
680 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
681 if ($pppsettings{'TIMEOUT'} != 0) {
682 my $seconds = $pppsettings{'TIMEOUT'} * 60;
683 push(@pppcommand, ('idle', "$seconds"));
684 }
685 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
686 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
687 }
688 push (@pppcommand,
689 ('active-filter',
690 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
691 }
692
693 push(@pppcommand, ('noipdefault', 'default-asyncmap',
694 'defaultroute', 'hide-password', 'local','noaccomp', 'noccp',
695 'nobsdcomp', 'nodeflate', 'nopcomp', 'novj', 'novjccomp',
696 'user', $pppsettings{'USERNAME'}, 'lcp-echo-interval', '20',
697 'lcp-echo-failure', '3', 'lcp-max-configure', '50',
698 'maxfail',$pppsettings{'MAXRETRIES'},'sync'));
699 if ($pppsettings{'DEBUG'} eq 'on') {
700 push(@pppcommand, ('debug'));
701 }
702
703 system (@pppcommand);
704 }
705
706 sub doalcatelusbdial
707 {
708 if (system ('/etc/rc.d/rc.alcatelusb','start')) {
709 &General::log( "ERROR: Failed to connect to Alcatel USB modem");
710 exit 1;
711 }
712
713 if ($pppsettings{'PROTOCOL'} eq 'RFC1483') {
714 if (open(FILE, ">${General::swroot}/red/device")) { print FILE 'tap0'; close FILE; }
715 $netsettings{'RED_DEV'} = 'tap0';
716 &dopppoedial();
717 } else {
718 # PPPoA
719 my @pppcommand = ('/usr/sbin/pppd', 'pty');
720 my @pppoacommand = ('/usr/sbin/pppoa3','-c','-m','1','-vpi',$pppsettings{'VPI'},'-vci',$pppsettings{'VCI'});
721
722 push(@pppcommand, "@pppoacommand");
723
724 if ($pppsettings{'DNS'} eq 'Automatic') {
725 push(@pppcommand, ('usepeerdns'));
726 }
727 if ($pppsettings{'AUTH'} eq 'pap') {
728 push(@pppcommand, ('-chap'));
729 } elsif ($pppsettings{'AUTH'} eq 'chap') {
730 push(@pppcommand, ('-pap'));
731 }
732
733 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
734 if ($pppsettings{'TIMEOUT'} != 0) {
735 my $seconds = $pppsettings{'TIMEOUT'} * 60;
736 push(@pppcommand, ('idle', "$seconds"));
737 }
738 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
739 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
740 }
741 push (@pppcommand,
742 ('active-filter',
743 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
744 }
745
746 push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user',
747 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
748 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
749 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
750 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
751 if ($pppsettings{'DEBUG'} eq 'on') {
752 push(@pppcommand, ('debug'));
753 }
754
755 system (@pppcommand);
756 }
757 }
758
759 sub doeciadsldial
760 {
761 if (system ('/etc/rc.d/rc.eciadsl','start')) {
762 &General::log ("ERROR: ECI ADSL failed to start");
763 exit 1;
764 }
765 if ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
766 if ($pppsettings {'ENCAP'} =~ /^(0|1)$/) {
767 $iface = "tap0";
768 } else {
769 $iface = "tun0";
770 }
771
772 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; }
773
774 if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) {
775 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $iface; close FILE; }
776 $netsettings{'RED_DEV'} = $iface;
777 &dopppoedial();
778 } elsif ($pppsettings{'METHOD'} eq 'STATIC') {
779 my @staticcommand = ('/sbin/ifconfig');
780 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}));
781 if ($pppsettings{'BROADCAST'} ne '') {
782 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
783 }
784 system (@staticcommand);
785 system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'});
786 system ("/bin/touch", "${General::swroot}/red/active");
787 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; }
788 } elsif ($pppsettings {'METHOD'} eq 'DHCP') {
789 # FIXME dhcp does not support tun0 interface (routed IP)
790 dodhcpdial($iface,$pppsettings{'DHCP_HOSTNAME'});
791 }
792 } else {
793 # PPPoA
794 my ($VID2, $PID2, $CHIP, $ALTP, $ECIMODE);
795 open (MODEMS, "/etc/eciadsl/modems.db") or die 'Unable to open modems database.';
796 while (my $line = <MODEMS>) {
797 $line =~ s/\s*\t+\s*/|/g;
798 $line =~ /^(.+)\|(.+)\|(.+)\|(.+)\|(.+)\|(.+)\|(.+)\|(.+)$/;
799 if ( $1 eq $pppsettings{'MODEM'} ) {
800 $VID2=$4 ; $PID2=$5; $CHIP=$6; $ALTP=$8;
801 }
802 }
803 close (MODEMS);
804 if ( $VID2 eq '') {
805 &General::log("$pppsettings{'MODEM'} not found in modems.db");
806 exit 1;
807 }
808 if ( $CHIP eq '' ) {
809 &General::log ("error in modems.db reading for $pppsettings{'MODEM'}");
810 exit 1;
811 }
812 if ($pppsettings {'ENCAP'} eq '1') {
813 $ECIMODE = "LLC_RFC2364";
814 } else {
815 $ECIMODE = "VCM_RFC2364";
816 }
817
818 my @pppcommand = ('/usr/sbin/pppd', 'pty');
819 my @pppoecicommand = ("/usr/sbin/eciadsl-pppoeci",'-alt', "$ALTP",'-vpi',$pppsettings{'VPI'},'-vci',$pppsettings{'VCI'},
820 '-vendor',"0x$VID2",'-product',"0x$PID2",'-mode',$ECIMODE);
821 push(@pppcommand, "@pppoecicommand");
822
823 if ($pppsettings{'DNS'} eq 'Automatic') {
824 push(@pppcommand, ('usepeerdns'));
825 }
826 if ($pppsettings{'AUTH'} eq 'pap') {
827 push(@pppcommand, ('-chap'));
828 } elsif ($pppsettings{'AUTH'} eq 'chap') {
829 push(@pppcommand, ('-pap'));
830 }
831
832 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
833 if ($pppsettings{'TIMEOUT'} != 0) {
834 my $seconds = $pppsettings{'TIMEOUT'} * 60;
835 push(@pppcommand, ('idle', "$seconds"));
836 }
837 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
838 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
839 }
840 push (@pppcommand,
841 ('active-filter',
842 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
843 }
844
845 push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user',
846 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
847 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
848 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
849 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
850 if ($pppsettings{'DEBUG'} eq 'on') {
851 push(@pppcommand, ('debug'));
852 }
853
854 system (@pppcommand);
855 }
856 }
857
858 sub dofritzdsldial
859 {
860 my $controller;
861
862 if (system ('/etc/rc.d/rc.fritzdsl','start')) {
863 &General::log ("ERROR: Fritz DSL module failed to load");
864 exit 1;
865 }
866
867 # controller number
868 if ($pppsettings{'TYPE'} eq 'fritzdsl') {
869 if ( ! system ('/bin/grep', '1244:2700', '/proc/pci')) {
870 $controller=1; # fcdslsl
871 } elsif (! system('/bin/grep', '1244:2900', '/proc/pci')) {
872 $controller=2; # fcdsl2
873 } elsif (! system('/bin/grep', '1131:5402', '/proc/pci')) {
874 $controller=2; # fdsl
875 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=2300', '/proc/bus/usb/devices')) {
876 $controller=1; # fcdslusb
877 } elsif (! system('/bin/grep', 'Vendor=057c ProdID=3500', '/proc/bus/usb/devices')) {
878 $controller=1; # fcdslslusb
879 }
880 }
881 my @pppcommand = ('/usr/sbin/pppd');
882 my @capiplugin;
883
884 if ($pppsettings{'DNS'} eq 'Automatic') {
885 push(@pppcommand, ('usepeerdns'));
886 }
887
888 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
889 if ($pppsettings{'TIMEOUT'} != 0) {
890 my $seconds = $pppsettings{'TIMEOUT'} * 60;
891 push(@pppcommand, ('idle', "$seconds"));
892 }
893 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
894 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
895 }
896 push (@pppcommand,
897 ('active-filter',
898 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
899 }
900
901 push(@pppcommand, ('noipdefault', 'defaultroute', 'sync', 'user',
902 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
903 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
904 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
905 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
906
907 if ($pppsettings{'DEBUG'} eq 'on') {
908 push(@pppcommand, ('debug'));
909 }
910
911 if ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
912 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoe',
913 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
914 } else {
915 if ($pppsettings {'ENCAP'} eq '1') {
916 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoallc',
917 'controller', $controller, 'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
918 } else {
919 @capiplugin = ('plugin', 'capiplugin.so', 'protocol', 'adslpppoa',
920 'controller', $controller,'vpi', $pppsettings{'VPI'},'vci',$pppsettings{'VCI'});
921 }
922 }
923 push(@pppcommand, @capiplugin);
924 push(@pppcommand, '/dev/null');
925
926 system (@pppcommand);
927 }
928
929 sub doeagleusbadsldial
930 {
931 if (system ('/etc/rc.d/rc.eagleusbadsl','start')) {
932 &General::log ("ERROR: EAGLE-USB ADSL MODEM failed to start");
933 exit 1;
934 }
935 $iface=`/usr/sbin/eaglectrl -i 2>/dev/null | /usr/bin/tr -d '\012'`;
936 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
937
938 if ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
939 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; }
940 if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) {
941 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $iface; close FILE; }
942 $netsettings{'RED_DEV'} = $iface;
943 &dopppoedial();
944 } elsif ($pppsettings{'METHOD'} eq 'STATIC') {
945 my @staticcommand = ('/sbin/ifconfig');
946 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}));
947 if ($pppsettings{'BROADCAST'} ne '') {
948 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
949 }
950 system (@staticcommand);
951 system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'});
952 system ("/bin/touch", "${General::swroot}/red/active");
953 } elsif ($pppsettings {'METHOD'} eq 'DHCP') {
954 dodhcpdial($iface,$pppsettings{'DHCP_HOSTNAME'});
955 }
956 } else {
957 # PPPoA
958 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $iface; close FILE; }
959 $netsettings{'RED_DEV'} = $iface;
960 my @pppcommand = ('/usr/sbin/pppd','pty');
961 push(@pppcommand,"/usr/sbin/pppoa -I $iface ");
962
963 if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));}
964
965 if ($pppsettings{'AUTH'} eq 'pap') {
966 push(@pppcommand, ('-chap'));
967 } elsif ($pppsettings{'AUTH'} eq 'chap') {
968 push(@pppcommand, ('-pap'));
969 }
970
971 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
972 if ($pppsettings{'TIMEOUT'} != 0) {
973 my $seconds = $pppsettings{'TIMEOUT'} * 60;
974 push(@pppcommand, ('idle', "$seconds"));
975 }
976 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
977 push (@pppcommand, ('demand','nopersist','connect','/bin/true'));
978 }
979 push (@pppcommand,
980 ('active-filter',
981 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
982 }
983 push(@pppcommand, ('noipdefault', 'defaultroute', 'user',
984 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
985 'noaccomp', 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
986 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
987 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
988
989 if ($pppsettings{'DEBUG'} eq 'on') {
990 push(@pppcommand, ('debug'));
991 }
992
993 system (@pppcommand);
994 }
995 }
996
997 sub dopulsardsldial
998 {
999 if (system ('/etc/rc.d/rc.pulsardsl','start')) {
1000 &General::log ("ERROR: PULSAR ADSL modem failed to start");
1001 exit 1;
1002 }
1003 doatmdial();
1004 }
1005
1006 sub dobewanadsldial
1007 {
1008 if (system ('/etc/rc.d/rc.bewanadsl','start')) {
1009 &General::log ("ERROR: Bewan ADSL MODEM failed to start");
1010 exit 1;
1011 }
1012 doatmdial();
1013 }
1014
1015 sub doalcatelusbkdial
1016 {
1017 if (system ('/etc/rc.d/rc.alcatelusbk','start')) {
1018 &General::log ("ERROR: Alcatel USB kernel mode driver failed to start");
1019 exit 1;
1020 }
1021 doatmdial();
1022 }
1023
1024 sub doconexantusbadsldial
1025 {
1026 if (system ('/etc/rc.d/rc.conexantusbadsl','start')) {
1027 &General::log ("ERROR: Conexant USB ADSL modem failed to start");
1028 exit 1;
1029 }
1030 doatmdial();
1031
1032 }
1033
1034 sub doconexantpciadsldial
1035 {
1036 if (system ('/etc/rc.d/rc.conexantpciadsl','start')) {
1037 &General::log ("ERROR: Conexant PCI ADSL modem failed to start");
1038 exit 1;
1039 }
1040 doatmdial();
1041
1042 }
1043
1044 sub doamedynusbadsldial
1045 {
1046 if (system ('/etc/rc.d/rc.amedynusbadsl','start')) {
1047 &General::log ("ERROR: Zyxel 630-11/Asus AAM6000UG USB ADSL modem failed to start");
1048 exit 1;
1049 }
1050 doatmdial();
1051
1052 }
1053
1054 sub do3cp4218usbadsldial
1055 {
1056 if (system ('/etc/rc.d/rc.3cp4218usbadsl','start')) {
1057 &General::log ("ERROR: 3Com USB AccessRunner modem failed to start");
1058 exit 1;
1059 }
1060 doatmdial();
1061 }
1062
1063 sub doatmdial
1064 {
1065 my $ENCAP;
1066 if ($pppsettings {'PROTOCOL'} eq 'RFC2364') {
1067 system ('/sbin/modprobe pppoatm');
1068 my @pppcommand = ('/usr/sbin/pppd');
1069 if ($pppsettings{'ENCAP'} eq '0') { $ENCAP='vc-encaps'; } else { $ENCAP='llc-encaps'; }
1070 push(@pppcommand,'plugin', 'pppoatm.so',$pppsettings{'VPI'}.".".$pppsettings{'VCI'},"$ENCAP");
1071 if ($pppsettings{'DNS'} eq 'Automatic') { push(@pppcommand, ('usepeerdns'));}
1072 if ($pppsettings{'AUTH'} eq 'pap') {
1073 push(@pppcommand, ('-chap'));
1074 } elsif ($pppsettings{'AUTH'} eq 'chap') {
1075 push(@pppcommand, ('-pap'));
1076 }
1077 if ($pppsettings{'RECONNECTION'} ne 'persistent') {
1078 if ($pppsettings{'TIMEOUT'} != 0) {
1079 my $seconds = $pppsettings{'TIMEOUT'} * 60;
1080 push(@pppcommand, ('idle', "$seconds"));
1081 }
1082 if ($pppsettings{'RECONNECTION'} eq 'dialondemand') {
1083 push (@pppcommand, ('demand','nopersist'));
1084 }
1085 push (@pppcommand,
1086 ('active-filter',
1087 'outbound and not icmp[0] == 3 and not tcp[13] & 4 != 0 ' ));
1088 }
1089 push(@pppcommand, ('noipdefault', 'defaultroute', 'user',
1090 $pppsettings{'USERNAME'}, 'ipcp-accept-local', 'ipcp-accept-remote', 'passive',
1091 'nopcomp', 'noccp', 'novj', 'nobsdcomp',
1092 'nodeflate', 'lcp-echo-interval', '20', 'lcp-echo-failure', '3',
1093 'lcp-max-configure', '50', 'maxfail', $pppsettings{'MAXRETRIES'}));
1094
1095 if ($pppsettings{'DEBUG'} eq 'on') {
1096 push(@pppcommand, ('debug'));
1097 }
1098
1099 system (@pppcommand);
1100 } elsif ($pppsettings {'PROTOCOL'} eq 'RFC1483') {
1101 if ($pppsettings {'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) {
1102 my $itf='0';
1103 my $device = "nas$itf";
1104 if (open(FILE, ">${General::swroot}/red/device")) { print FILE $device; close FILE; }
1105 $netsettings{'RED_DEV'} = $device;
1106 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
1107 system ('/sbin/modprobe br2684');
1108 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
1109 sleep 3;
1110 }
1111 system ('/sbin/ifconfig',"$device",'up');
1112 &dopppoedial();
1113 } elsif ($pppsettings{'ENCAP'} =~ /^(0|1)$/) {
1114 my $itf='0';
1115 $iface = "nas$itf";
1116 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; }
1117 if (system ('/bin/ps -ef | /bin/grep -q [b]r2684ctl')) {
1118 system ('/sbin/modprobe br2684');
1119 system ('/usr/bin/br2684ctl', '-b', '-c', "$itf", '-e', $pppsettings{'ENCAP'}, '-a', "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
1120 sleep 3;
1121 }
1122 system ('/sbin/ifconfig',"$iface",'up');
1123
1124 if ($pppsettings{'METHOD'} eq 'STATIC') {
1125 my @staticcommand = ('/sbin/ifconfig');
1126 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}));
1127 if ($pppsettings{'BROADCAST'} ne '') {
1128 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
1129 }
1130 system (@staticcommand);
1131 system ("/sbin/route","add","default","gw",$pppsettings{'GATEWAY'});
1132 system ("/bin/touch", "${General::swroot}/red/active");
1133 system ("/etc/rc.d/rc.updatered");
1134 } elsif ($pppsettings {'METHOD'} eq 'DHCP') {
1135 dodhcpdial($iface,$pppsettings{'DHCP_HOSTNAME'});
1136 }
1137 } elsif ($pppsettings{'ENCAP'} =~ /^(2|3)$/) {
1138 my $itf='0';
1139 $iface = "atm$itf";
1140 if (open(FILE, ">${General::swroot}/red/iface")) { print FILE $iface; close FILE; }
1141 if (system ('/bin/ps -ef | /bin/grep -q [a]tmarpd')) {
1142 if (system ('/usr/sbin/atmarpd -b -l syslog')) {
1143 &General::log('atmarpd fail');
1144 exit 1;
1145 }
1146 # it will fail on all attempt after the first because interface still exist
1147 system ("/usr/sbin/atmarp -c $iface 2>/dev/null");
1148
1149 if ($pppsettings{'METHOD'} eq 'STATIC') {
1150 my @staticcommand = ('/sbin/ifconfig');
1151 push(@staticcommand, ($iface, $pppsettings{'IP'},'netmask', $pppsettings{'NETMASK'}, 'up'));
1152 if ($pppsettings{'BROADCAST'} ne '') {
1153 push(@staticcommand, ('broadcast', $pppsettings{'BROADCAST'}));
1154 }
1155 system (@staticcommand);
1156 # we have to wait a bit before launching atmarp -s
1157 sleep 2;
1158 my @atmarp = ('/usr/sbin/atmarp', '-s', $pppsettings{'GATEWAY'}, "$itf.$pppsettings{'VPI'}.$pppsettings{'VCI'}");
1159 if ($pppsettings{'ENCAP'} eq '3') {
1160 push(@atmarp, 'null' ); # routed ip vc encap
1161 }
1162 system (@atmarp);
1163 system ("/sbin/route", "add", "default", "gw", $pppsettings{'GATEWAY'});
1164 system ("/bin/touch", "${General::swroot}/red/active");
1165 }
1166 }
1167 }
1168 }
1169 }