summaryrefslogtreecommitdiffstats
path: root/etc/inc/interfaces.inc
diff options
context:
space:
mode:
authorgnhb <gnoahb@gmail.com>2010-03-26 19:41:42 +0700
committerScott Ullrich <sullrich@pfsense.org>2010-03-26 18:12:40 -0400
commit9ebe7028594e47728980699f5417364e73ef438a (patch)
tree138d6256eadb03a155205f9dcbff9bb8b9dbfbcd /etc/inc/interfaces.inc
parenta01d8d8bf76245f10b8259eb4b99ef47a9a77209 (diff)
downloadpfsense-9ebe7028594e47728980699f5417364e73ef438a.zip
pfsense-9ebe7028594e47728980699f5417364e73ef438a.tar.gz
I have PPP with mpd5 working really well now, including setting the APN and APN
Number, and the SIM PIN and wait time for the SIM to settle after the PIN is entered. Still no work on multilink PPP with serial port links. Right now the code creates the mpd.secret file. I tested it using the set auth password <password> syntax in the mpd.conf file and got errors so I kept the mpd.secret file generation. PPP for modems does need the mpd.script file. It's the chat script file for the link establishment. Right now it has to be in /usr/local/sbin/mpd.script, and it's linked to /var/etc/ at boot time when ppp is first configured. I also took away the "Dialcmd" field in the PPP setup page (and a couple others) because the script is rather comprehensive and is designed to handle many modems. My two 3G modems worked without modification to the script. I did have to modify the scrip to handle the setting of APN and SIM PINs. I made the Init String field work, and the default init commands in the ATT&T, Verizion, and Sprint defaults now come up in the Init String field. You also no longer should put an "AT" at the beginning of modem commands entered in the web page because the script does that for you. I implemented interface renaming and that simplified the new code a lot, so that's nice. Now ppp interfaces start with ppp0 and go up as you add more. This patch refers to the ppp-linkup and linkdown scripts in the /usr/local/sbin/ directory so custom PPP linkup and linkdown scripts are not needed anymore. The persistent uptime tracking is still an open issue, but it works within each connected session. I'm already experiencing much smother conditions with mpd5 for PPP on 3G than I was with userland ppp. It's very nice.
Diffstat (limited to 'etc/inc/interfaces.inc')
-rw-r--r--etc/inc/interfaces.inc346
1 files changed, 216 insertions, 130 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc
index 13ba21a..b0fadeb 100644
--- a/etc/inc/interfaces.inc
+++ b/etc/inc/interfaces.inc
@@ -686,9 +686,6 @@ function interfaces_configure() {
interfaces_qinq_configure();
- /* Set up PPP interfaces */
- interfaces_ppp_configure();
-
$iflist = get_configured_interface_with_descr();
$delayed_list = array();
$bridge_list = array();
@@ -824,8 +821,6 @@ function interface_bring_down($interface = "wan", $destroy = false) {
unlink_if_exists("{$g['tmp_path']}/{$realif}up");
unlink_if_exists("{$g['vardb_path']}/{$interface}ip");
unlink_if_exists("{$g['tmp_path']}/{$realif}_router");
-
- interface_ppp_bring_down($realif);
switch ($ifcfg['ipaddr']) {
case "pppoe":
@@ -857,6 +852,10 @@ function interface_bring_down($interface = "wan", $destroy = false) {
mwexec("/usr/sbin/arp -d -i {$realif} -a");
}
break;
+ case "ppp":
+ killbypid("{$g['varrun_path']}/{$realif}.pid");
+ sleep(2);
+ break;
default:
if(does_interface_exist("$realif")) {
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true);
@@ -874,127 +873,227 @@ function interface_bring_down($interface = "wan", $destroy = false) {
return;
}
-function interfaces_ppp_configure($write_config=true) {
+function interface_ppp_configure($ppp_int,$edit=false) {
global $config, $g;
- if(!$g['booting'])
- conf_mount_rw();
- if($g['booting'])
- echo "Configuring PPP interfaces...";
- if($config['ppps']['ppp']) {
- foreach($config['ppps']['ppp'] as $ppp) {
- $dev = substr($ppp['port'], 5);
- interface_ppp_configure($dev,$write_config);
+
+ $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'];
+ }
}
+
+ // 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(!$g['booting'])
- conf_mount_ro();
- if($g['booting'])
- echo "done.\n";
-}
+ if (!file_exists("{$g['varetc_path']}/mpd.script"))
+ if($g['booting'])
+ 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;
+ }
-function interface_ppp_configure($ifcfg,$edit=false) {
- global $config, $g;
-
- /* Remove the /dev/ from the device name. */
- $orig_dev = $ifcfg;
+ // 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 ""
- // ppp (userland) requires a /var/spool/lock directory
- if(!is_dir("/var/spool/lock")) {
- exec("mkdir -p /var/spool/lock");
- exec("chmod a+rw /var/spool/lock/.");
- }
- if ($edit){
- // Construct the ppp.conf file
- $peerfile .= "default:\n";
- $peerfile .= " set log Phase Chat LCP IPCP CCP tun command\n";
- $peerfile .= " ident user-ppp VERSION (built COMPILATIONDATE)\n";
- $peerfile .= " set dial \"ABORT BUSY ABORT NO\\\sCARRIER TIMEOUT 5 \\\n";
- $peerfile .= " \\\"\\\" AT OK-AT-OK ATE1Q0 OK \\\dATDT\\\T TIMEOUT 40 CONNECT\"\n";
- $peerfile .= " enable dns\n";
- $peerfile .= " nat enable yes\n";
- $peerfile .= " set reconnect {$ifcfg['connect-max-attempts']} 5\n";
- $peerfile .= " allow users root\n\n";
-
- // Loop variables
- $i = 0;
- $startingip = 1;
+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
+#
+##################################################################
- // Start ppp.linkup file
- $rclinkup = "default:\n";
- // Start ppp.linkdown file
- $rclinkdown = "default:\n";
+startup:
+ # configure mpd users
+ set user admin pfsense admin
+ set user user pfsense
+ # configure the console
+ set console self 127.0.0.1 5005
+ set console open
+ # configure the web server
+ #set web self 0.0.0.0 5006
+ #set web open
+
+default:
+
+EOD;
+
+ $ip = 1;
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $ppp) {
- $dev = substr($ppp['port'], 5);
- $realif = $ppp['port'];
- $peerfile .= "{$dev}:\n";
- $peerfile .= " set device {$realif}\n";
- if($ppp['dialcmd']) {
- $peerfile .= " set dial " . base64_decode($ppp['dialcmd']) . "\n";
- } else
- $peerfile .= " set dial \"\"\n";
- $peerfile .= " set speed {$ppp['linespeed']}\n";
- if (isset($ppp['defaultgw']))
- $peerfile .= " add default HISADDR\n";
- $peerfile .= " set timeout 0\n";
- $peerfile .= " enable dns\n";
- $endingip = $startingip+1;
+ //$dev = substr($ppp['port'], 5); //Device sans path
+ $id = $ppp['pppid'];
+ $ppp_port = "ppp{$id}";
+
+ $endingip = $ip+1;
if($ppp['localip'] && $ppp['gateway'])
- $peerfile .= " set ifaddr {$ppp['localip']}/0 {$ppp['gateway']}/0 255.255.255.0 0.0.0.0\n";
+ $ranges = "set ipcp ranges {$ppp['localip']}/0 {$ppp['gateway']}/0";
if(!$ppp['localip'] && $ppp['gateway'])
- $peerfile .= " set ifaddr 10.0.0.{$startingip}/0 {$ppp['gateway']}/0 255.255.255.0 0.0.0.0\n";
+ $ranges = "set ipcp ranges 10.0.0.{$ip}/0 {$ppp['gateway']}/0";
if($ppp['localip'] and !$ppp['gateway'])
- $peerfile .= " set ifaddr {$ppp['localip']}/0 10.0.0.{$endingip}/0 255.255.255.0 0.0.0.0\n";
+ $ranges = "set ipcp ranges {$ppp['localip']}/0 10.0.0.{$endingip}/0";
if(!$ppp['localip'] and !$ppp['gateway'])
- $peerfile .= " set ifaddr 10.0.0.{$startingip}/0 10.0.0.{$endingip}/0 255.255.255.0 0.0.0.0\n";
- //$peerfile .= " iface name ppp_{$orig_dev}\n";
- $peerfile .= " set phone \"{$ppp['phone']}\"\n";
- $peerfile .= " set authname \"{$ppp['username']}\"\n";
- $peerfile .= " set authkey \"{$ppp['password']}\"\n";
- // Add a local socket for the daemon so we can query it later
- $peerfile .= " set server /var/run/{$dev}.sock \"\" 0177\n";
- $peerfile .= "\n";
- $i++;
- $startingip++;
- $rclinkup .= "{$dev}:\n";
- $rclinkup .= " ! sh -c \"/etc/rc.conf_mount_rw\"\n";
- $rclinkup .= " ! sh -c \"/bin/echo `date -j +%Y.%m.%d-%H:%M:%S` 00:00:00 >> /conf/ppp-up.{$dev}.log\"\n";
- $rclinkup .= " ! sh -c \"/sbin/ppp-script HISADDR INTERFACE DNS0 DNS1\"\n";
- $rclinkup .= " ! sh -c \"/etc/rc.linkup INTERFACE start\"\n";
- $rclinkup .= " ! sh -c \"/etc/rc.conf_mount_ro\"\n";
- $rclinkup.= " ! sh -c \"/etc/rc.filter_configure_sync\"\n";
- // Link down file
- $rclinkdown .= "{$dev}:\n";
- $rclinkdown .= " ! sh -c \"/etc/rc.conf_mount_rw\"\n";
- $rclinkdown .= " ! sh -c \"/bin/echo `date -j +%Y.%m.%d-%H:%M:%S` UPTIME >> /conf/ppp-up.{$dev}.log\"\n";
- $rclinkdown .= " ! sh -c \"/etc/rc.conf_mount_ro\"\n";
- $rclinkdown .= " ! sh -c \"/bin/rm -f /var/run/{$dev}.if\"\n";
- }
- }
+ $ranges = "set ipcp ranges 10.0.0.{$ip}/0 10.0.0.{$endingip}/0";
+ if ($ppp['username'] <> ""){
+ $user = "{$ppp['username']}";
+ } else {
+ $user = "Mylogin";
+ }
+
+ $mpdconf .= <<<EOD
+{$ppp_port}:
+ create bundle static B{$id}
+ {$ranges}
+ set ipcp yes req-pri-dns
+ set ipcp yes req-sec-dns
+ set iface name {$ppp_port}
+
+EOD;
+ if (isset($ppp['defaultgw'])){
+ $mpdconf .= <<<EOD
+ set iface route default
- // Write out configuration for ppp.conf
- file_put_contents("/etc/ppp/ppp.conf", $peerfile);
+EOD;
+ }
+ $mpdconf .= <<<EOD
+ set iface up-script /usr/local/sbin/ppp-linkup
+ set iface down-script /usr/local/sbin/ppp-linkdown
+# Create link.
+ create link static lnk-{$ppp_port} modem
+ set modem device {$ppp['port']}
+ set modem var \$DialPrefix "DT"
+ set modem var \$Telephone "{$ppp['phone']}"
- // Write out linkup file
- file_put_contents("/etc/ppp/ppp.linkup", $rclinkup);
- file_put_contents("/etc/ppp/ppp.linkdown", $rclinkdown);
- // Make executable
- exec("chmod a+rx /etc/ppp/ppp.linkup");
- exec("chmod a+rx /etc/ppp/ppp.linkdown");
+EOD;
+ $ip++;
+ 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
+ set modem var \$InitString "{$initstr}"
+
+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
+ 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;
+
+ $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
+admin
+pfsense
+link lnk-{$ppp_port}
+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);
}
// Launch specified ppp instance
- if( (!$edit || $g['booting']) && file_exists("/dev/{$orig_dev}")){
- $running = `/bin/pgrep -f "ppp .* $orig_dev"`;
- if(!$running)
- mwexec_bg("/usr/sbin/ppp -background {$orig_dev}");
- }
-}
+ 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*/
+ /* 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;
+ }
+
-function interface_ppp_bring_down($if) {
- if(file_exists("/var/run/{$if}.pid")) {
- $pid = trim(file_get_contents("/var/run/{$if}.pid"));
- mwexec("kill -QUIT {$pid}");
}
}
@@ -1896,15 +1995,15 @@ function interface_configure($interface = "wan", $reloadall = false) {
case 'dhcp':
interface_dhcp_configure($interface);
break;
-
case 'pppoe':
interface_pppoe_configure($interface);
break;
-
case 'pptp':
interface_pptp_configure($interface);
break;
-
+ case 'ppp':
+ interface_ppp_configure($realif);
+ break;
default:
if ($wancfg['ipaddr'] <> "" && $wancfg['subnet'] <> "") {
if (isset($wancfg['ispointtopoint']) && $wancfg['pointtopoint']) {
@@ -1929,9 +2028,6 @@ function interface_configure($interface = "wan", $reloadall = false) {
if (!$g['booting'])
interface_reload_carps($realif);
- if($wancfg['serialport'])
- interface_ppp_configure($wancfg['serialport']);
-
if (!$g['booting']) {
if (link_interface_to_gre($interface)) {
foreach ($config['gres']['gre'] as $gre)
@@ -2570,17 +2666,6 @@ function get_real_interface($interface = "wan") {
if ($interface == $if || $interface == $ifdesc) {
- // PPP Support
- if($config['interfaces'][$if]['serialport']) {
- $dev = $config['interfaces'][$if]['serialport'];
- if(file_exists("/var/run/{$dev}.if")) {
- $wanif = trim(file_get_contents("/var/run/{$dev}.if"));
- } else
- $wanif = "Not connected";
-
- break;
- }
-
$cfg = $config['interfaces'][$if];
// Wireless cloned NIC support (FreeBSD 8+)
@@ -2624,6 +2709,9 @@ function get_real_interface($interface = "wan") {
else
$wanif = "pptp" . substr($if, 3);
break;
+ case "ppp":
+ $wanif = $cfg['if'];
+ break;
default:
$wanif = $cfg['if'];
break;
@@ -2923,16 +3011,14 @@ function get_interfaces_with_gateway() {
/* loop interfaces, check config for outbound */
foreach($config['interfaces'] as $ifdescr => $ifname) {
- if($ifname['serialport']) {
- $ints[] = $ifdescr;
- continue;
- }
+
switch ($ifname['ipaddr']) {
case "dhcp":
case "carpdev-dhcp":
case "pppoe":
case "pptp":
- $ints[] = $ifdescr;
+ case "ppp";
+ $ints[] = $ifdescr;
break;
default:
if ($ifname['pointtopoint'])
OpenPOWER on IntegriCloud