summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2011-09-27 17:13:02 -0400
committerjim-p <jimp@pfsense.org>2011-09-27 17:13:02 -0400
commitb6d748733b3e9975d482ca88d8a9f082629f2774 (patch)
treee9d42c1c618868bfe8b5d58d14a628ac5559d0b4
parent3ff395661614dd31967a95ed832e9aaec2883c45 (diff)
downloadpfsense-b6d748733b3e9975d482ca88d8a9f082629f2774.zip
pfsense-b6d748733b3e9975d482ca88d8a9f082629f2774.tar.gz
Fixup relayd to handle DNS load balancing as well as standard TCP load balancing.
-rw-r--r--etc/inc/vslb.inc104
-rwxr-xr-xusr/local/www/load_balancer_virtual_server.php2
-rwxr-xr-xusr/local/www/load_balancer_virtual_server_edit.php35
3 files changed, 82 insertions, 59 deletions
diff --git a/etc/inc/vslb.inc b/etc/inc/vslb.inc
index c26b785..54416b9 100644
--- a/etc/inc/vslb.inc
+++ b/etc/inc/vslb.inc
@@ -219,50 +219,60 @@ function relayd_configure() {
}
}
}
- if(is_array($protocol_a)) {
- for ($i = 0; isset($protocol_a[$i]); $i++) {
- $proto = "{$protocol_a[$i]['type']} protocol \"{$protocol_a[$i]['name']}\" {\n";
- if(is_array($protocol_a[$i]['lbaction'])) {
- if($protocol_a[$i]['lbaction'][0] == "") {
- continue;
- }
- for ($a = 0; isset($protocol_a[$i]['lbaction'][$a]); $a++) {
- $proto .= " " . echo_lbaction($protocol_a[$i]['lbaction'][$a]) . "\n";
- }
- }
- $proto .= "}\n";
- $conf .= $proto;
- }
- }
+// if(is_array($protocol_a)) {
+// for ($i = 0; isset($protocol_a[$i]); $i++) {
+// $proto = "{$protocol_a[$i]['type']} protocol \"{$protocol_a[$i]['name']}\" {\n";
+// if(is_array($protocol_a[$i]['lbaction'])) {
+// if($protocol_a[$i]['lbaction'][0] == "") {
+// continue;
+// }
+// for ($a = 0; isset($protocol_a[$i]['lbaction'][$a]); $a++) {
+// $proto .= " " . echo_lbaction($protocol_a[$i]['lbaction'][$a]) . "\n";
+// }
+// }
+// $proto .= "}\n";
+// $conf .= $proto;
+// }
+// }
+
+ $conf .= "dns protocol \"dnsproto\" {\n";
+ $conf .= " tcp { nodelay, sack, socket buffer 1024, backlog 1000 }\n";
+ $conf .= "}\n";
+
if(is_array($vs_a)) {
for ($i = 0; isset($vs_a[$i]); $i++) {
- switch($vs_a[$i]['mode']) {
- case 'relay':
- $conf .= "relay \"{$vs_a[$i]['name']}\" {\n";
- $conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
+ if (($vs_a[$i]['mode'] == 'relay') || ($vs_a[$i]['relay_protocol'] == 'dns')) {
+ $conf .= "relay \"{$vs_a[$i]['name']}\" {\n";
+ $conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
+
+ if ($vs_a[$i]['relay_protocol'] == "dns") {
+ $conf .= " protocol \"dnsproto\"\n";
+ } else {
$conf .= " protocol \"{$vs_a[$i]['relay_protocol']}\"\n";
- $conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
-
- if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0)
- $conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
- $conf .= "}\n";
- break;
- /* Default to Redirect Mode */
- case 'redirect_mode':
- default:
- $conf .= "redirect \"{$vs_a[$i]['name']}\" {\n";
- $conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
- $conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
-
- if (isset($config['system']['lb_use_sticky']))
- $conf .= " sticky-address\n";
-
- # sitedown MUST use the same port as the primary pool - sucks, but it's a relayd thing
- if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0)
- $conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
-
- $conf .= "}\n";
- break;
+ }
+ $lbmode = "";
+ if ( $pools[$vs_a[$i]['pool']]['mode'] == "loadbalance" ) {
+ $lbmode = "mode loadbalance";
+ }
+
+ $conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$lbmode} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
+
+ if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0)
+ $conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$lbmode} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
+ $conf .= "}\n";
+ } else {
+ $conf .= "redirect \"{$vs_a[$i]['name']}\" {\n";
+ $conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
+ $conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
+
+ if (isset($config['system']['lb_use_sticky']))
+ $conf .= " sticky-address\n";
+
+ # sitedown MUST use the same port as the primary pool - sucks, but it's a relayd thing
+ if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0)
+ $conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
+
+ $conf .= "}\n";
}
}
}
@@ -323,6 +333,8 @@ Id Type Name Avlblty Status
*/
$rdr_a = array();
exec('/usr/local/sbin/relayctl show redirects 2>&1', $rdr_a);
+ $relay_a = array();
+ exec('/usr/local/sbin/relayctl show relays 2>&1', $relay_a);
$vs = array();
for ($i = 0; isset($rdr_a[$i]); $i++) {
$line = $rdr_a[$i];
@@ -334,6 +346,16 @@ Id Type Name Avlblty Status
}
}
}
+ for ($i = 0; isset($relay_a[$i]); $i++) {
+ $line = $relay_a[$i];
+ if (preg_match("/^[0-9]+/", $line)) {
+ $regs = array();
+ if($x = preg_match("/^[0-9]+\s+relay\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) {
+ $vs[trim($regs[1])] = array();
+ $vs[trim($regs[1])]['status'] = trim($regs[2]);
+ }
+ }
+ }
return $vs;
}
diff --git a/usr/local/www/load_balancer_virtual_server.php b/usr/local/www/load_balancer_virtual_server.php
index 69ea9a4..624f418 100755
--- a/usr/local/www/load_balancer_virtual_server.php
+++ b/usr/local/www/load_balancer_virtual_server.php
@@ -126,7 +126,7 @@ include("head.inc");
$t->edit_uri('load_balancer_virtual_server_edit.php');
$t->my_uri('load_balancer_virtual_server.php');
$t->add_column(gettext('Name'),'name',10);
- $t->add_column(gettext('Mode'),'mode',10);
+ $t->add_column(gettext('Protocol'),'relay_protocol',10);
$t->add_column(gettext('IP Address'),'ipaddr',15);
$t->add_column(gettext('Port'),'port',10);
$t->add_column(gettext('Pool'),'pool',15);
diff --git a/usr/local/www/load_balancer_virtual_server_edit.php b/usr/local/www/load_balancer_virtual_server_edit.php
index 96a557c..8340a93 100755
--- a/usr/local/www/load_balancer_virtual_server_edit.php
+++ b/usr/local/www/load_balancer_virtual_server_edit.php
@@ -194,7 +194,7 @@ document.observe("dom:loaded", function() {
<tr align="left">
<td width="22%" valign="top" class="vncellreq"><?=gettext("IP Address"); ?></td>
<td width="78%" class="vtable" colspan="2">
- <input name="ipaddr" type="text" <?if(isset($pconfig['ipaddr'])) echo "value=\"{$pconfig['ipaddr']}\"";?> size="16" maxlength="16">
+ <input name="ipaddr" type="text" <?if(isset($pconfig['ipaddr'])) echo "value=\"{$pconfig['ipaddr']}\"";?> size="39" maxlength="39">
<br><?=gettext("This is normally the WAN IP address that you would like the server to listen on. All connections to this IP and port will be forwarded to the pool cluster."); ?>
</td>
</tr>
@@ -257,22 +257,23 @@ document.observe("dom:loaded", function() {
</td>
</tr>
-->
- <tr id="relay" align="left" style="display:none;">
- <td width="22%" valign="top" class="vncellreq"><?=gettext("Relay Protocol"); ?></td>
- <td width="78%" class="vtable" colspan="2">
- <select id="relay_protocol" name="relay_protocol">
- <?php
- for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
- $selected = "";
- if ( $config['load_balancer']['lbprotocol'][$i]['name'] == $pconfig['lbprotocol'] )
- $selected = " SELECTED";
- echo "<option value=\"{$config['load_balancer']['lbprotocol'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbprotocol'][$i]['name']}</option>";
- }
- ?>
- </select>
- <br>
- </td>
- </tr>
+ <tr id="relay" align="left">
+ <td width="22%" valign="top" class="vncellreq"><?=gettext("Relay Protocol"); ?></td>
+ <td width="78%" class="vtable" colspan="2">
+ <select id="relay_protocol" name="relay_protocol">
+ <?php
+ $lb_def_protos = array("tcp", "dns");
+ foreach ($lb_def_protos as $lb_proto) {
+ $selected = "";
+ if ( $pconfig['relay_protocol'] == $lb_proto )
+ $selected = " SELECTED";
+ echo "<option value=\"{$lb_proto}\"{$selected}>{$lb_proto}</option>";
+ }
+ ?>
+ </select>
+ <br>
+ </td>
+ </tr>
<tr align="left">
<td align="left" valign="bottom">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Submit"); ?>">
OpenPOWER on IntegriCloud