aboutsummaryrefslogtreecommitdiffstats
path: root/config/quagga_ospfd
diff options
context:
space:
mode:
Diffstat (limited to 'config/quagga_ospfd')
-rw-r--r--config/quagga_ospfd/quagga_ospfd.inc128
-rw-r--r--config/quagga_ospfd/quagga_ospfd.xml17
-rw-r--r--config/quagga_ospfd/quagga_ospfd_interfaces.xml6
-rw-r--r--config/quagga_ospfd/quaggactl15
-rw-r--r--config/quagga_ospfd/status_ospfd.php10
5 files changed, 139 insertions, 37 deletions
diff --git a/config/quagga_ospfd/quagga_ospfd.inc b/config/quagga_ospfd/quagga_ospfd.inc
index 755f6c98..598d3c00 100644
--- a/config/quagga_ospfd/quagga_ospfd.inc
+++ b/config/quagga_ospfd/quagga_ospfd.inc
@@ -1,7 +1,7 @@
<?php
/*
quagga_ospfd.inc
- Copyright (C) 2010 Ermal Luçi
+ Copyright (C) 2010 Ermal Lu�i
Copyright (C) 2012 Jim Pingle
part of pfSense
All rights reserved.
@@ -27,6 +27,19 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
+require_once("config.inc");
+require_once("functions.inc");
+require_once("service-utils.inc");
+
+define('PKG_QUAGGA_CONFIG_BASE', '/var/etc/quagga');
+
+$pkg_login = "quagga";
+$pkg_uid = "101";
+$pkg_group = "quagga";
+$pkg_gid = "101";
+$pkg_gecos = "Quagga route daemon pseudo user";
+$pkg_homedir = "/var/etc/quagga";
+$pkg_shell = "/usr/sbin/nologin";
function quagga_ospfd_get_interfaces() {
global $config;
@@ -54,9 +67,11 @@ function quagga_ospfd_get_interfaces() {
}
function quagga_ospfd_install_conf() {
- global $config, $g, $input_errors;
+ global $config, $g, $input_errors, $pkg_login, $pkg_uid, $pkg_group, $pkg_gid, $pkg_gecos, $pkg_homedir, $pkg_shell;
conf_mount_rw();
+ // Since we need to embed this in a string, copy to a var. Can't embed constnats.
+ $quagga_config_base = PKG_QUAGGA_CONFIG_BASE;
if ($config['installedpackages']['quaggaospfd']['rawconfig'] && $config['installedpackages']['quaggaospfd']['rawconfig']['item']) {
// if there is a raw config specifyed in tthe config.xml use that instead of the assisted config
@@ -82,6 +97,7 @@ function quagga_ospfd_install_conf() {
/* Interface Settings */
$passive_interfaces = array();
$interface_networks = array();
+
if ($config['installedpackages']['quaggaospfdinterfaces']['config']) {
foreach ($config['installedpackages']['quaggaospfdinterfaces']['config'] as $conf) {
$realif = get_real_interface($conf['interface']);
@@ -94,9 +110,9 @@ function quagga_ospfd_install_conf() {
}
if ($conf['md5password'] && !empty($conf['password'])) {
$conffile .= " ip ospf authentication message-digest\n";
- $conffile .= " ip ospf message-digest-key 1 md5 \"" . substr($conf['password'], 0, 15) . "\"\n";
+ $conffile .= " ip ospf message-digest-key 1 md5 " . substr($conf['password'], 0, 15) . "\n";
} else if (!empty($conf['password'])) {
- $conffile .= " ip ospf authentication-key \"" . substr($conf['password'], 0, 8) . "\"\n";
+ $conffile .= " ip ospf authentication-key " . substr($conf['password'], 0, 8) . "\n";
}
if (!empty($conf['routerpriorityelections'])) {
$conffile .= " ip ospf priority {$conf['routerpriorityelections']}\n";
@@ -116,7 +132,31 @@ function quagga_ospfd_install_conf() {
if ($interface_subnet == 32)
$interface_subnet = 30;
$subnet = gen_subnet($interface_ip, $interface_subnet);
- $interface_networks[] = "{$subnet}/{$interface_subnet}";
+ if (!empty($conf['interfacearea'])) {
+ $interface_networks[] = array( "subnet" => "{$subnet}/{$interface_subnet}", "area" => $conf['interfacearea']);
+ }
+ else {
+ $interface_networks[] = array( "subnet" => "{$subnet}/{$interface_subnet}", "area" => $ospfd_conf['area']);
+ }
+
+
+
+ }
+ }
+
+
+ $redist = "";
+ $noredist = "";
+ if (is_array($ospfd_conf['row'])) {
+ foreach ($ospfd_conf['row'] as $redistr) {
+ if (empty($redistr['routevalue']))
+ continue;
+ if (isset($redistr['redistribute'])) {
+ $noredist .= " access-list dnr-list deny {$redistr['routevalue']}\n";
+ } else {
+ $area = ($redistr['routearea'] == "") ? $ospfd_conf['area'] : $redistr['routearea'];
+ $redist .= " network {$redistr['routevalue']} area {$area}\n";
+ }
}
}
@@ -139,6 +179,10 @@ function quagga_ospfd_install_conf() {
if ($ospfd_conf['redistributestatic'])
$conffile .= " redistribute static\n";
+
+ if ($ospfd_conf['redistributekernel'])
+ $conffile .= " redistribute kernel\n";
+
if ($ospfd_conf['redistributedefaultroute'])
$conffile .= " default-information originate\n";
@@ -153,25 +197,35 @@ function quagga_ospfd_install_conf() {
if ($ospfd_conf['rfc1583'])
$conffile .= " ospf rfc1583compatibility\n";
- if (is_array($passive_interfaces))
+ if (is_array($passive_interfaces)) {
foreach ($passive_interfaces as $pint)
$conffile .= " passive-interface {$pint}\n";
+ }
- if (is_array($interface_networks))
- foreach ($interface_networks as $ifn)
- if (is_subnet($ifn))
- $conffile .= " network {$ifn} area {$ospfd_conf['area']}\n";
- if (is_array($ospfd_conf['row'])) {
- foreach ($ospfd_conf['row'] as $redistr) {
- if (isset($redistr['redistribute']))
- $conffile .= " no ";
- $conffile .= " network {$redistr['routevalue']} area {$ospfd_conf['area']}\n";
+ if (is_array($interface_networks)) {
+ foreach ($interface_networks as $ifn) {
+ if (is_subnet($ifn['subnet'])) {
+ $conffile .= " network {$ifn['subnet']} area {$ifn['area']}\n";
+ }
}
}
- }
- $fd = fopen("/usr/local/etc/quagga/ospfd.conf", "w");
+ if (!empty($redist))
+ $conffile .= $redist;
+
+ if (!empty($noredist)) {
+ $conffile .= " distribute-list dnr-list out connected\n";
+ $conffile .= " distribute-list dnr-list out kernel\n";
+ $conffile .= " distribute-list dnr-list out static\n";
+ //$conffile .= " distribute-list dnr-list out ospf\n";
+ $conffile .= $noredist;
+ $conffile .= " access-list dnr-list permit any\n";
+ }
+
+ }
+ safe_mkdir($quagga_config_base);
+ $fd = fopen("{$quagga_config_base}/ospfd.conf", "w");
// Write out the configuration file
fwrite($fd, $conffile);
@@ -185,23 +239,43 @@ function quagga_ospfd_install_conf() {
$zebraconffile .= "password {$ospfd_conf['password']}\n";
if ($ospfd_conf['logging'])
$zebraconffile .= "log syslog\n";
- $fd = fopen("/usr/local/etc/quagga/zebra.conf", "w");
+ $fd = fopen("{$quagga_config_base}/zebra.conf", "w");
fwrite($fd, $zebraconffile);
fclose($fd);
// Create rc.d file
$rc_file_stop = <<<EOF
-kill -9 `cat /var/run/quagga/zebra.pid`
-kill -9 `cat /var/run/quagga/ospfd.pid`
+if [ -e /var/run/quagga/zebra.pid ]; then
+ kill -9 `cat /var/run/quagga/zebra.pid`
+ rm -f /var/run/quagga/zebra.pid
+fi
+if [ -e /var/run/quagga/ospfd.pid ]; then
+ kill -9 `cat /var/run/quagga/ospfd.pid`
+ rm -f /var/run/quagga/ospfd.pid
+fi
EOF;
$rc_file_start = <<<EOF
/bin/mkdir -p /var/run/quagga
/bin/mkdir -p /var/log/quagga
-/usr/sbin/chown -R quagga:quagga /usr/local/etc/quagga/
+rm -f /var/run/quagga/zebra.pid
+rm -f /var/run/quagga/ospfd.pid
+
+if [ `pw groupshow {$pkg_group} 2>&1 | grep -c "pw: unknown group"` -gt 0 ]; then
+ /usr/sbin/pw groupadd {$pkg_group} -g {$pkg_gid}
+fi
+if [ `pw usershow {$pkg_login} 2>&1 | grep -c "pw: no such user"` -gt 0 ]; then
+ /usr/sbin/pw useradd {$pkg_login} -u {$pkg_uid} -g {$pkg_gid} -c "{$pkg_gecos}" -d {$pkg_homedir} -s {$pkg_shell}
+fi
+
+/usr/sbin/chown -R quagga:quagga {$quagga_config_base}
/usr/sbin/chown -R quagga:quagga /var/run/quagga
/usr/sbin/chown -R quagga:quagga /var/log/quagga
-/usr/local/sbin/zebra -d
-/usr/local/sbin/ospfd -d
+# Ensure no other copies of the daemons are running or it breaks.
+killall -9 zebra 2>/dev/null
+killall -9 ospfd 2>/dev/null
+sleep 1
+/usr/local/sbin/zebra -d -f {$quagga_config_base}/zebra.conf
+/usr/local/sbin/ospfd -d -f {$quagga_config_base}/ospfd.conf
EOF;
write_rcfile(array(
"file" => "quagga.sh",
@@ -212,8 +286,8 @@ EOF;
// Ensure files have correct permissions
exec("chmod a+rx /usr/local/etc/rc.d/quagga.sh");
- exec("chmod u+rw,go-rw /usr/local/etc/quagga/ospfd.conf");
- exec("chmod u+rw,go-rw /usr/local/etc/quagga/zebra.conf");
+ exec("chmod u+rw,go-rw {$quagga_config_base}/ospfd.conf");
+ exec("chmod u+rw,go-rw {$quagga_config_base}/zebra.conf");
// Kick off newly created rc.d script
exec("/usr/local/etc/rc.d/quagga.sh restart");
@@ -240,6 +314,8 @@ function quagga_ospfd_validate_interface() {
function quagga_ospfd_validate_input() {
global $config, $g, $input_errors;
+ if ($_POST['password'] <> "" && (strpos($_POST['password'], "'") !== false))
+ $input_errors[] = "Password cannot contain a single quote (')";
if (!empty($_POST['routerid']) && !is_ipaddr($_POST['routerid']))
$input_errors[] = "Router ID must be an address.";
if (!is_ipaddr($_POST['area']))
@@ -254,7 +330,7 @@ function quagga_ospfd_validate_input() {
// get the raw ospfd confi file for manual inspection/editing
function quagga_ospfd_get_raw_config() {
- return file_get_contents("/usr/local/etc/quagga/ospfd.conf");
+ return file_get_contents(PKG_QUAGGA_CONFIG_BASE . "/ospfd.conf");
}
// serialize the raw ospfd confi file to config.xml
diff --git a/config/quagga_ospfd/quagga_ospfd.xml b/config/quagga_ospfd/quagga_ospfd.xml
index 3e76c4e4..d1e96efa 100644
--- a/config/quagga_ospfd/quagga_ospfd.xml
+++ b/config/quagga_ospfd/quagga_ospfd.xml
@@ -1,6 +1,6 @@
<packagegui>
<name>quagga_ospfd</name>
- <version>0.1</version>
+ <version>0.5</version>
<title>Services: Quagga OSPFd</title>
<include_file>/usr/local/pkg/quagga_ospfd.inc</include_file>
<aftersaveredirect>pkg_edit.php?xml=quagga_ospfd.xml&amp;id=0</aftersaveredirect>
@@ -122,10 +122,17 @@
<field>
<fielddescr>Redistribute static</fielddescr>
<fieldname>redistributestatic</fieldname>
- <description>Enables the redistribution of static routes</description>
+ <description>Enables the redistribution of static routes (only works if you are using quagga static routes)</description>
<type>checkbox</type>
</field>
<field>
+ <fielddescr>Redistribute Kernel</fielddescr>
+ <fieldname>redistributekernel</fieldname>
+ <description>Enables the redistribution of kernel routing table (this is required if using pfsense static routes)</description>
+ <type>checkbox</type>
+ </field>
+
+ <field>
<fielddescr>SPF Hold Time</fielddescr>
<fieldname>spfholdtime</fieldname>
<description>Set the SPF holdtime in MILLIseconds. The minimum time between two consecutive shortest path first calculations. The default value is 5 seconds; the valid range is 1-5 seconds.</description>
@@ -161,6 +168,12 @@
<type>input</type>
<size>25</size>
</rowhelperfield>
+ <rowhelperfield>
+ <fielddescr>Area ID</fielddescr>
+ <fieldname>routearea</fieldname>
+ <type>input</type>
+ <size>10</size>
+ </rowhelperfield>
</rowhelper>
</field>
</fields>
diff --git a/config/quagga_ospfd/quagga_ospfd_interfaces.xml b/config/quagga_ospfd/quagga_ospfd_interfaces.xml
index e0f55a58..21bc877f 100644
--- a/config/quagga_ospfd/quagga_ospfd_interfaces.xml
+++ b/config/quagga_ospfd/quagga_ospfd_interfaces.xml
@@ -69,6 +69,12 @@
<type>input</type>
</field>
<field>
+ <fielddescr>Area</fielddescr>
+ <fieldname>interfacearea</fieldname>
+ <description>The area for this interface (leave blank for default).</description>
+ <type>input</type>
+ </field>
+ <field>
<fielddescr>Description</fielddescr>
<fieldname>descr</fieldname>
<size>30</size>
diff --git a/config/quagga_ospfd/quaggactl b/config/quagga_ospfd/quaggactl
index 198a8411..6db7232e 100644
--- a/config/quagga_ospfd/quaggactl
+++ b/config/quagga_ospfd/quaggactl
@@ -1,11 +1,12 @@
#!/bin/sh
RC_SCRIPT=/usr/local/etc/rc.d/quagga.sh
+QUAGGA_CONFIG_BASE=/var/etc/quagga
-ZEBRA_CONFIG=/usr/local/etc/quagga/zebra.conf
+ZEBRA_CONFIG=${QUAGGA_CONFIG_BASE}/zebra.conf
ZEBRA_PORT=2601
ZEBRA_PASSWORD=`/usr/bin/grep '^password ' ${ZEBRA_CONFIG} | /usr/bin/awk '{print $2};'`
-OSPF_CONFIG=/usr/local/etc/quagga/ospfd.conf
+OSPF_CONFIG=${QUAGGA_CONFIG_BASE}/ospfd.conf
OSPF_PORT=2604
OSPF_PASSWORD=`/usr/bin/grep '^password ' ${OSPF_CONFIG} | /usr/bin/awk '{print $2};'`
@@ -27,6 +28,10 @@ restart)
$RC_SCRIPT restart
;;
zebra)
+ if [ "`pgrep zebra`" = "" ]; then
+ echo "zebra does not appear to be running"
+ exit 1
+ fi
case $2 in
cpu*)
daemon_command ${ZEBRA_PORT} ${ZEBRA_PASSWORD} "show thread cpu"
@@ -42,7 +47,11 @@ zebra)
daemon_command ${ZEBRA_PORT} ${ZEBRA_PASSWORD} "show ip route"
;;
esac ;;
-ospf)
+ospf*)
+ if [ "`pgrep ospfd`" = "" ]; then
+ echo "ospfd does not appear to be running"
+ exit 1
+ fi
case $2 in
cpu*)
daemon_command ${OSPF_PORT} ${OSPF_PASSWORD} "show thread cpu"
diff --git a/config/quagga_ospfd/status_ospfd.php b/config/quagga_ospfd/status_ospfd.php
index 438347ff..dc6c6aea 100644
--- a/config/quagga_ospfd/status_ospfd.php
+++ b/config/quagga_ospfd/status_ospfd.php
@@ -68,13 +68,11 @@ function doCmdT($title, $command) {
$execOutput = "";
$execStatus = "";
- exec ($command . " 2>&1", $execOutput, $execStatus);
- for ($i = 0; isset($execOutput[$i]); $i++) {
- if ($i > 0) {
- echo "\n";
- }
- echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES);
+ $fd = popen("{$command} 2>&1", "r");
+ while (($line = fgets($fd)) !== FALSE) {
+ echo htmlspecialchars($line, ENT_NOQUOTES);
}
+ pclose($fd);
echo "</pre></tr>\n";
echo "</table>\n";
}