diff options
author | Ermal <eri@pfsense.org> | 2010-03-27 00:05:37 +0000 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2010-03-27 00:05:37 +0000 |
commit | 611ae8521469576569a8d9c0d306668fe1b20dfe (patch) | |
tree | f16b941d545194ba2db9a794dc66080cc5b4895f /etc/inc/interfaces.inc | |
parent | 3ad5fd63f0b5a7fa7b1f291b44ba37c0ccf88cd1 (diff) | |
download | pfsense-611ae8521469576569a8d9c0d306668fe1b20dfe.zip pfsense-611ae8521469576569a8d9c0d306668fe1b20dfe.tar.gz |
Redo most of the ppp interface handling to be consistent with the other mpd5 configurations. This way there is no more special handling for ppp around.
Diffstat (limited to 'etc/inc/interfaces.inc')
-rw-r--r-- | etc/inc/interfaces.inc | 324 |
1 files changed, 127 insertions, 197 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 4d24665..35f728a 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -873,67 +873,46 @@ function interface_bring_down($interface = "wan", $destroy = false) { return; } -function interface_ppp_configure($ppp_int,$edit=false) { +function interface_ppp_configure($interface) { global $config, $g; - $serial_device = 0; - if ($ppp_int <> -1) - if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { - foreach ($config['ppps']['ppp'] as $ppp) { - if ($ppp_int == "ppp".$ppp['pppid']) - $serial_device = $ppp['port']; - } + $wancfg =& $config['interfaces'][$interface]; + if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { + foreach ($config['ppps']['ppp'] as $ppp) { + if ($wancfg['if'] == basename($ppp['port'])) + break; } - + } + if (!$ppp || empty($ppp['port'])) + return; + + if ($ifname == "wan") + $pppid = "0"; + else + $pppid = substr($ifname, 3); + + $pppif = "ppp{$pppid}"; + // mpd5 requires a /var/spool/lock directory if(!is_dir("/var/spool/lock")) { exec("/bin/mkdir -p /var/spool/lock"); exec("/bin/chmod a+rw /var/spool/lock/."); } if (!file_exists("{$g['varetc_path']}/mpd.script")) - if($g['booting']) - mwexec("/bin/ln -s /usr/local/sbin/mpd.script {$g['varetc_path']}/."); + mwexec("/bin/ln -s /usr/local/sbin/mpd.script {$g['varetc_path']}/."); - if ($edit || $g['booting']){ - if($g['booting']) - echo " configuring PPP on {$ppp_int} interface...\n"; - /* generate mpd.conf */ - $fd = fopen("{$g['varetc_path']}/mpd-ppp.conf", "w"); - if (!$fd) { - printf("Error: cannot open mpd-ppp.conf in interface_ppp_configure().\n"); - return 1; - } - /* generate mpd.secret */ - $fds = fopen("{$g['varetc_path']}/mpd.secret", "w"); - if (!$fds) { - printf("Error: cannot open mpd.secret in interface_ppp_configure().\n"); - return 1; - } - - // Create mpd.secret file - - $secret = <<<EOD -################################################################# -# -# MPD secrets file -# Entries are for authentication in either or both directions, as well -# as telnet console login. Auto generated from /etc/inc/interfaces.inc -# {$g['varetc_path']}/mpd.secret -# -################################################################## -Mylogin "" + if($g['booting']) + echo " configuring PPP on {$pppif} interface...\n"; -EOD; - // Construct the mpd.conf file - $mpdconf = <<<EOD -################################################################# -# -# MPD Configuration file -# Auto generated by pfSense from /etc/inc/interfaces.inc -# {$g['varetc_path']}/mpd_ppp.conf -# -################################################################## + /* generate mpd.conf */ + $fd = fopen("{$g['varetc_path']}/mpd_{$interface}.conf", "w"); + if (!$fd) { + log_error("Error: cannot open mpd_{$interface}.conf in interface_ppp_configure().\n"); + return 1; + } + // Construct the mpd.conf file + $mpdconf = <<<EOD startup: # configure mpd users set user admin pfsense admin @@ -942,159 +921,137 @@ startup: set console self 127.0.0.1 5005 set console open # configure the web server + set web close #set web self 0.0.0.0 5006 #set web open -default: +EOD; + if (is_ipaddr($ppp['localip'])) + $localip = $ppp['localip']; + else + $localip = '0.0.0.0'; + if (is_ipaddr($ppp['gateway'])) + $localgw = $ppp['gateway']; + else + $localgw = "10.0.0.{$pppid}"; + + $mpdconf .= <<<EOD +default: +pppclient: + create bundle static {$interface} + set iface name {$pppif} + set iface up-script /usr/local/sbin/ppp-linkup + set iface down-script /usr/local/sbin/ppp-linkdown + set ipcp ranges {$localip}/0 {$localgw}/0 + EOD; - $ip = 1; - - if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { - foreach ($config['ppps']['ppp'] as $ppp) { - //$dev = substr($ppp['port'], 5); //Device sans path - $id = $ppp['pppid']; - $ppp_port = "ppp{$id}"; - - $endingip = $ip+1; - if($ppp['localip'] && $ppp['gateway']) - $ranges = "set ipcp ranges {$ppp['localip']}/0 {$ppp['gateway']}/0"; - if(!$ppp['localip'] && $ppp['gateway']) - $ranges = "set ipcp ranges 10.0.0.{$ip}/0 {$ppp['gateway']}/0"; - if($ppp['localip'] and !$ppp['gateway']) - $ranges = "set ipcp ranges {$ppp['localip']}/0 10.0.0.{$endingip}/0"; - if(!$ppp['localip'] and !$ppp['gateway']) - $ranges = "set ipcp ranges 10.0.0.{$ip}/0 10.0.0.{$endingip}/0"; - $ip++; - if ($ppp['username'] <> ""){ - $user = "{$ppp['username']}"; - } else { - $user = "Mylogin"; - } - - $mpdconf .= <<<EOD -{$ppp_port}: - create bundle static B{$id} - {$ranges} + if (isset($config['system']['dnsallowoverride'])) { + $mpdconf .= <<<EOD set ipcp yes req-pri-dns set ipcp yes req-sec-dns - set iface name {$ppp_port} EOD; - if (isset($ppp['defaultgw'])){ - $mpdconf .= <<<EOD + } + + if (isset($ppp['defaultgw'])) { + $mpdconf .= <<<EOD set iface route default EOD; - } - $mpdconf .= <<<EOD - set iface up-script /usr/local/sbin/ppp-linkup - set iface down-script /usr/local/sbin/ppp-linkdown + } + + $mpdconf .= <<<EOD # Create link. - create link static lnk-{$ppp_port} modem + create link static lnk{$interface} modem +# We expect to be authenticated by peer using any protocol. + set link disable chap pap + set link accept chap pap eap + set link enable no-orig-auth +# To make Ringback work we should specify how to handle incoming calls originated by it. + #set link enable incoming + set link action bundle {$interface} + +EOD; + + if (!empty($ppp['username'])) { + $mpdconf .= <<<EOD +# Configure the account name. Password will be taken from mpd.secret. + set auth authname "{$ppp['username']}" + set auth password "{$ppp['password']}" + +EOD; + } + + $mpdconf .= <<<EOD set modem device {$ppp['port']} + set modem script DialPeer + set modem idle-script Ringback + set modem watch -cd set modem var \$DialPrefix "DT" set modem var \$Telephone "{$ppp['phone']}" EOD; - if (isset($ppp['connect-timeout'])){ - $mpdconf .= <<<EOD + if (isset($ppp['connect-timeout'])) { + $mpdconf .= <<<EOD set modem var \$ConnectTimeout "{$ppp['connect-timeout']}" EOD; - } - if (isset($ppp['initstr'])){ - $initstr = base64_decode($ppp['initstr']); - $mpdconf .= <<<EOD + } + if (isset($ppp['initstr'])) { + $initstr = base64_decode($ppp['initstr']); + $mpdconf .= <<<EOD set modem var \$InitString "{$initstr}" EOD; - } - if (isset($ppp['simpin'])){ - $mpdconf .= <<<EOD + } + if (isset($ppp['simpin'])) { + $mpdconf .= <<<EOD set modem var \$SimPin "{$ppp['simpin']}" set modem var \$PinWait "{$ppp['pin-wait']}" EOD; - } - if (isset($ppp['apn'])){ - $mpdconf .= <<<EOD + } + if (isset($ppp['apn'])) { + $mpdconf .= <<<EOD set modem var \$APN "{$ppp['apn']}" set modem var \$APNum "{$ppp['apnum']}" EOD; - } - $mpdconf .= <<<EOD - set modem script DialPeer - set modem idle-script Ringback - set modem watch -cd -# We expect to be authenticated by peer using any protocol. - set link disable chap pap - set link accept chap pap eap - set link enable no-orig-auth -# Configure the account name. Password will be taken from mpd.secret. - set auth authname {$user} -# To make Ringback work we should specify how to handle incoming calls originated by it. - #set link enable incoming - set link action bundle B{$id} - open + } -EOD; + $mpdconf .= "\topen"; - $fdlnkq = fopen("{$g['varetc_path']}/{$ppp_port}.query", "w"); - if (!$fdlnkq) { - printf("Error: cannot open {$ppp_port}.query in interface_ppp_configure().\n"); - return 1; - } - $linkquery = <<<EOD + // Write out configuration for mpd_ppp.conf and mpd.secret + fwrite($fd, $mpdconf); + fclose($fd); + + $fdlnkq = fopen("{$g['varetc_path']}/mpd_{$interface}.query", "w"); + if (!$fdlnkq) { + /* NOTE: It is not fatal if we cannot write the query."); + log_error("Error: cannot open mpd_{$interface}.query in interface_ppp_configure().\n"); + } else { + $linkquery = <<<EOD admin pfsense -link lnk-{$ppp_port} +link lnk{$interface} show iface exit EOD; - // Write out linkquery file for each configured PPP interface. - fwrite($fdlnkq, $linkquery); - fclose($fdlnkq); - - - if ($ppp['username'] <> ""){ - $secret .= <<<EOD -{$ppp['username']} "{$ppp['password']}" - -EOD; - - } - } - } - - // Write out configuration for mpd_ppp.conf and mpd.secret - fwrite($fd, $mpdconf); - fclose($fd); - fwrite($fds, $secret); - fclose($fds); - sleep(2); + // Write out linkquery file for each configured PPP interface. + fwrite($fdlnkq, $linkquery); + fclose($fdlnkq); } + // Launch specified ppp instance - if( (!$edit || $g['booting']) && file_exists("{$serial_device}")){ - $timeout = 15; - /* if mpd is active, lets take it down -> accomplished by starting mpd with the -k flag*/ + if( (file_exists("{$ppp['port']}")) { /* fire up mpd */ - if (file_exists("{$g['tmp_path']}/{$ppp_int}_router")) - mwexec("/bin/rm -r {$g['tmp_path']}/{$ppp_int}_router"); - mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd-ppp.conf -p {$g['varrun_path']}/{$ppp_int}.pid -s ppp {$ppp_int}"); - /* Wait for mpd5 to bring up connection, but don't wait longer than $timeout */ - for ($i=0; $i < $timeout; $i++){ - sleep(1); - if (file_exists("{$g['tmp_path']}/{$ppp_int}_router")) - break; - } - - - } + mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/ppp_{$interface}.pid -s {$interface} pppclient"); + } else + log_error("Device {$ppp['port']} has disappeared."); } function interfaces_carp_setup() { @@ -2002,20 +1959,14 @@ function interface_configure($interface = "wan", $reloadall = false) { interface_pptp_configure($interface); break; case 'ppp': - interface_ppp_configure($realif); + interface_ppp_configure($interface); break; default: if ($wancfg['ipaddr'] <> "" && $wancfg['subnet'] <> "") { - if (isset($wancfg['ispointtopoint']) && $wancfg['pointtopoint']) { - mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " " . - escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']) . - " " . escapeshellarg($wancfg['pointtopoint']) . " up"); - } else { - if($wancfg['ipaddr'] && $wancfg['subnet']) - mwexec("/sbin/ifconfig " . escapeshellarg($realif) . - " " . escapeshellarg($wancfg['ipaddr'] . "/" . - $wancfg['subnet'])); - } + if($wancfg['ipaddr'] && $wancfg['subnet']) + mwexec("/sbin/ifconfig " . escapeshellarg($realif) . + " " . escapeshellarg($wancfg['ipaddr'] . "/" . + $wancfg['subnet'])); } if (is_ipaddr($wancfg['gateway'])) @@ -2288,12 +2239,6 @@ EOD; if(file_exists("{$g['varrun_path']}/pppoe_{$interface}.pid") and $g['booting']) { /* if we are booting and mpd has already been started then don't start again. */ } else { - /* if mpd is active, lets take it down */ - if(file_exists("{$g['varrun_path']}/pppoe_{$interface}.pid")) { - killbypid("{$g['varrun_path']}/pppoe_{$interface}.pid"); - sleep(3); - } - /* Bring the parent interface up */ if($wancfg['if']) interfaces_bring_up($wancfg['if']); @@ -2301,7 +2246,7 @@ EOD; log_error("Could not bring wancfg['if'] up in interface_pppoe_configure()"); /* fire up mpd */ - mwexec("/usr/local/sbin/mpd5 -b -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/pppoe_{$interface}.pid pppoeclient"); + mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/pppoe_{$interface}.pid -s {$interface} pppoeclient"); } /* sleep until wan is up - or 30 seconds, whichever comes first */ @@ -2435,7 +2380,7 @@ EOD; else log_error("Could not bring interface wancfg['if'] up in interface_pptp_configure()"); /* fire up mpd */ - mwexec("/usr/local/sbin/mpd5 -b -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/pptp_{$interface}.pid pptp"); + mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/pptp_{$interface}.pid -s {$interface} pptp"); return 0; } @@ -2710,7 +2655,10 @@ function get_real_interface($interface = "wan") { $wanif = "pptp" . substr($if, 3); break; case "ppp": - $wanif = $cfg['if']; + if ($if == "wan") + $wanif = "ppp0"; + else + $wanif = "ppp" . substr($if, 3); break; default: $wanif = $cfg['if']; @@ -3021,10 +2969,8 @@ function get_interfaces_with_gateway() { $ints[] = $ifdescr; break; default: - if ($ifname['pointtopoint']) - $ints[] = $ifdescr; - else if (!empty($ifname['gateway'])) - $ints[] = $ifdescr; + if (!empty($ifname['gateway'])) + $ints[] = $ifdescr; break; } } @@ -3072,22 +3018,6 @@ function is_altq_capable($int) { return false; } -/****f* interfaces/is_interface_ppp - * NAME - * is_interface_ppp - Returns if an interface is ppp - * RESULT - * $tmp - Returns if an interface is ppp - ******/ -function is_interface_ppp($interface) { - global $config, $g; - - $friendly = convert_real_interface_to_friendly_interface_name($interface); - if(isset($config['interfaces'][$friendly]['serialport'])) - return true; - - return false; -} - /****f* interfaces/is_interface_wireless * NAME * is_interface_wireless - Returns if an interface is wireless |