SOLVED: PPP config for 3G/GPRS/EDGE modem - updated



  • See this thread . . .

    http://forum.pfsense.org/index.php/topic,15404.msg81426.html#msg81426 (some copied below)

    Some problems with the ppp implementation:
    1. the PPP specific files in /etc/ppp/peers do not get deleted when a PPP interface is deleted
    2. the function interface_ppp_configure in /etc/inc/interfaces.inc writes the ppp connect and chat scripts in /etc/ppp/peers every time interface_ppp_configure is called. This is unnecessary writing to the file system (for embedded) and it slows down the process of bringing a ppp interface up or, down and then up again.
    3. the function interface_ppp_configure creates a new ppp interface every time you try to use it to bring an existing ppp interface up.

    I've removed the ability of the interface_ppp_configure function to start and stop the pppd daemon. It makes more sense to integrate pppd control with the existing pfsense infrastructure for bringing interfaces up and down. This allows scripts like /etc/rc.interface_wan_configure to actually bring the pppd interface up and connect to the remote gateway.

    So, if you want to fix the configuration of PPP as in WAN interface through the webGUI, do this . . . .

    changes to make 2.0 ALPHA-ALPHA work with PPP over GPRS/EDGE

    the next command is for embedded versions only to make the filesystem writeable.
    at the command line for embedded versions only. . .

    pfsense:~# mount -u -w /dev/ufs/pfSense

    All versions continue here. This is unified diff format. The .bak files are the original from pfsense build 2.0 June 11. http://snapshots.pfsense.org/FreeBSD_RELENG_7_2/pfSense_HEAD/embedded/pfSense-2.0-ALPHA-ALPHA-20090611-1712.img.gz


    –- /etc/inc/interfaces.inc.bak 2009-06-16 12:24:14.000000000 +0700
    +++ /etc/inc/interfaces.inc 2009-06-19 12:47:01.000000000 +0700
    @@ -40,12 +40,20 @@
    require_once("globals.inc");

    function interfaces_bring_up($interface) {

    • global $config;
      if(!$interface) {
      log_error("bring_interface_up was called but no variable defined.");
      log_error( "Backtrace: " . var_dump(debug_backtrace()) );
      return;
      }
    • if(strstr($interface,"ppp")) {
    • $dev = $config['interfaces']['wan']['serialport'];
    • mwexec("/usr/sbin/pppd call ppp_{$dev}");
    • sleep(11);
    • log_error("Executed pppd");
    • } else {
      mwexec("/sbin/ifconfig " . escapeshellarg($interface) . " up");
    • }
      }

    /*
    @@ -823,8 +831,12 @@
    mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " down");
    break;
    default:

    • if (strstr($realif, "ppp")){
    • killbypid("{$g['varrun_path']}/{$realif}.pid");
    • } else {
      mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete");
      mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " down");
    • }
      break;
      }

    @@ -851,35 +863,28 @@
            }
    }

    -function interface_ppp_configure($ifcfg) {
    +function interface_ppp_configure($ifcfg, $edit = false) {
    global $config, $g;

    • /* Remove  the /dev/ from the device name. */
    • $dev = substr($ifcfg['port'], 5);
    • $dev = $ifcfg['port'];

    $realif  = $ifcfg['pppif'];

    • if ($realif <> "") {
    • $i = 0;
    • while ($realif != "ppp{$i}")
    • $i++;
    • if(file_exists("/var/run/ppp{$i}.pid")) {
    • $pid = trim(file_get_contents("/var/run/ppp{$i}.pid"));
    • mwexec("kill {$pid}");
    • }
    • }
    • if ($realif <> "")
    • killbypid("{$g['varrun_path']}/{$realif}.pid");

    if ($g['booting'] || $realif <> "") {
    -                mwexec("/sbin/ifconfig {$realif} destroy");
                    mwexec("/sbin/ifconfig {$realif} create");
    -        } else
    -                $realif = exec("/sbin/ifconfig ppp create");
    +        }

    • if ($edit) {
    • if ($realif == "")
      +                $realif = exec("/sbin/ifconfig ppp create");

    $peerfile = "lcp-echo-failure 0\n";
    $peerfile .= "lcp-echo-interval 0\n";
    $peerfile .= "connect /etc/ppp/peers/ppp{$dev}-connect-chat\n";
    //$peerfile .= "disconnect /etc/ppp/peers/ppp{$dev}-disconnect-chat\n";

    • $peerfile .= "{$ifcfg['port']} {$ifcfg['linespeed']}\n";
    • $peerfile .= "/dev/{$ifcfg['port']} {$ifcfg['linespeed']}\n";
      $peerfile .= "crtscts\n";
      if ($ifcfg['connect-max-attempts'] <> "")
      $peerfile .= "connect-max-attempts {$ifcfg['connect-max-attempts']}";
      @@ -903,7 +908,7 @@
      $peerfile .= "persist\n";
      $peerfile .= "debug\n";
      // KD - test
    • //$peerfile .= "defaultroute\n";
    • $peerfile .= "defaultroute\n";
      //$peerfile .= "nodetach\n";
      // KD - so I know where to look!
      $peerfile .= "# created by /etc/inc/interfaces.inc\n";
      @@ -947,9 +952,9 @@
      file_put_contents("/etc/ppp/peers/ppp{$dev}-connect-chat", $chatfile);
      chmod("/etc/ppp/peers/ppp{$dev}-connect-chat", 0755);
      conf_mount_ro();
    • sleep(1);
    • mwexec("/usr/sbin/pppd call ppp_{$dev}");
    • }
      +// sleep(1);
      +// mwexec("/usr/sbin/pppd call ppp_{$dev}");

    return $realif;
    }


    –- /usr/local/www/interfaces_assign.php.bak 2009-06-16 10:40:07.000000000 +0700
    +++ /usr/local/www/interfaces_assign.php 2009-06-16 13:32:19.000000000 +0700
    @@ -110,7 +110,8 @@
    if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
    $i = 0;
    foreach ($config['ppps']['ppp'] as $ppp) {

    • $portname = 'ppp_' . basename($ppp['port']);
    • /* $portname = 'ppp_' . basename($ppp['port']); */
    • $portname = $ppp['pppif'];
      $portlist[$portname] = $ppp;
      $portlist[$portname]['isppp'] = true;
      $i++;
      @@ -177,9 +178,9 @@

    if (!is_array($ifport)) {
    $config['interfaces'][$ifname]['if'] = $ifport;

    • if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
    • if (preg_match('/^ppp\d+/', $ifport, $matches)) {
      $config['interfaces'][$ifname]['pointtopoint'] = true;
    • $config['interfaces'][$ifname]['serialport'] = $matches[1];
    • $config['interfaces'][$ifname]['serialport'] = $portlist[$ifport]['port'];
      }

    /* check for wireless interfaces, set or clear ['wireless'] */


    –- /usr/local/www/interfaces_ppp_edit.php.bak 2009-06-16 10:39:57.000000000 +0700
    +++ /usr/local/www/interfaces_ppp_edit.php 2009-06-16 11:49:02.000000000 +0700
    @@ -101,7 +101,7 @@
    $ppp['connect-max-attempts'] = $_POST['connect-max-attempts'];
    $ppp['descr'] = $_POST['descr'];
    $ppp['pppif'] = $_POST['pppif'];

    • $ppp['pppif'] = interface_ppp_configure($ppp);
    • $ppp['pppif'] = interface_ppp_configure($ppp,true);
                      if ($ppp['pppif'] == "" || !stristr($ppp['pppif'], "ppp"))
                              $input_errors[] = "Error occurred creating PPP interface. Check System log for details";
                      else {
      @@ -140,7 +140,7 @@
      foreach ($portlist as $port) {
      if(preg_match("/.(lock|init)$/", $port))
      continue;
    • echo "<option value="&quot;".trim($port)."&quot;";<br">+ echo "</option> <option value="&quot;".trim(substr($port,5))."&quot;";" <br="">if ($pconfig['port'] == $port)
      echo "selected";
      echo ">{$port}</option>";

    This one is just cleaner . . .

    –- /usr/local/www/interfaces_ppp.php.bak 2009-06-16 11:55:52.000000000 +0700
    +++ /usr/local/www/interfaces_ppp.php 2009-06-16 11:57:34.000000000 +0700
    @@ -64,15 +64,8 @@
    $input_errors[] = "This PPP interface cannot be deleted because it is still being used as an interface.";
    } else {
    $realif  = $a_ppps[$_GET['id']]['pppif'];

    • if ($realif <> "") {
      -                $i = 0;
      -                while ($realif != "ppp{$i}")
      -                        $i++;
      -                if (file_exists("/var/run/ppp{$i}.pid")) {
      -                        $pid = trim(file_get_contents("/var/run/ppp{$i}.pid"));
      -                        mwexec("kill {$pid}");
      -                }
      -        }
    • if ($realif <> "")
      +      killbypid("{$g['varrun_path']}/{$realif}.pid");

    mwexec("/sbin/ifconfig  {$realif} destroy");
    unset($a_ppps[$_GET['id']]);


    EDIT: pfSense routing packets. I'm updating this post behind the pfSense box running as a GPRS/EDGE router. I had to uncheck the "Block Private IPs" and "Block bogons" on the WAN interface configuration. I overlooked that for the longest time. The PPP link is using the 10.X.X.X address space. Oops. :)

    Finally, I still don't know how to keep pfSense (or BSD routed) from deleting this default route after a few minutes.

    **EDIT: pfSense is no longer deleting the default route after a few minutes because the start up function causes pfSense to wait until the link is up before proceeding to do other configuration functions. **

    Everything works great. Now I just need a couple of buttons in the GUI to start, stop, and restart the PPP link. And a URL that did these things would be great too.
    interfaces.inc.patch.txt
    interfaces_assign.php.patch.txt
    interfaces_ppp.php.patch.txt
    interfaces_ppp_edit.php.patch.txt



  • Bump



  • Thanks, but 2.0 will be on FreeBSD 8, which doesn't have kernel PPP at all, so the current way of doing PPP will be pulled and completely replaced before 2.0 is final.



  • Hi gnhb,

    Does your wan ppp link automatically work after a reboot or are you having to manually drop the ppp link and restarting it once booted to get the default route to appear?

    I'm interested as I'm trying to get my 3G link to come up automatically, I used the changes you posted here to make it work this far.

    Cheers.



  • My link comes up automatically at boot or reboot. I added extra log messages to make sure everything was happening in the right order. pfSense executes additional functions after executing the "connect ppp" function. If pppd isn't finished creating the link before the additional functions execute, traffic will not route properly.

    What country are you in?

    GNHB


Log in to reply