Project

General

Profile

« Previous | Next » 

Revision e3522ebf

Added by Jim Pingle almost 14 years ago

Fixup relayd to handle DNS load balancing as well as standard TCP load balancing.

View differences:

etc/inc/vslb.inc
219 219
      }
220 220
    }
221 221
  }
222
  if(is_array($protocol_a)) {
223
    for ($i = 0; isset($protocol_a[$i]); $i++) {
224
      $proto = "{$protocol_a[$i]['type']} protocol \"{$protocol_a[$i]['name']}\" {\n";
225
      if(is_array($protocol_a[$i]['lbaction'])) {
226
        if($protocol_a[$i]['lbaction'][0] == "") {
227
          continue;
228
        }
229
        for ($a = 0; isset($protocol_a[$i]['lbaction'][$a]); $a++) {
230
          $proto .= "  " . echo_lbaction($protocol_a[$i]['lbaction'][$a]) . "\n";
231
        }
232
      }
233
      $proto .= "}\n";
234
      $conf .= $proto;
235
    }
236
  }
222
//  if(is_array($protocol_a)) {
223
//    for ($i = 0; isset($protocol_a[$i]); $i++) {
224
//      $proto = "{$protocol_a[$i]['type']} protocol \"{$protocol_a[$i]['name']}\" {\n";
225
//      if(is_array($protocol_a[$i]['lbaction'])) {
226
//        if($protocol_a[$i]['lbaction'][0] == "") {
227
//          continue;
228
//        }
229
//        for ($a = 0; isset($protocol_a[$i]['lbaction'][$a]); $a++) {
230
//          $proto .= "  " . echo_lbaction($protocol_a[$i]['lbaction'][$a]) . "\n";
231
//        }
232
//      }
233
//      $proto .= "}\n";
234
//      $conf .= $proto;
235
//    }
236
//  }
237

  
238
	$conf .= "dns protocol \"dnsproto\" {\n";
239
	$conf .= "	tcp { nodelay, sack, socket buffer 1024, backlog 1000 }\n";
240
	$conf .= "}\n";
241

  
237 242
	if(is_array($vs_a)) {
238 243
		for ($i = 0; isset($vs_a[$i]); $i++) {
239
			switch($vs_a[$i]['mode']) {
240
				case 'relay':
241
					$conf .= "relay \"{$vs_a[$i]['name']}\" {\n";
242
					$conf .= "  listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
244
			if (($vs_a[$i]['mode'] == 'relay') || ($vs_a[$i]['relay_protocol'] == 'dns')) {
245
				$conf .= "relay \"{$vs_a[$i]['name']}\" {\n";
246
				$conf .= "  listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
247

  
248
				if ($vs_a[$i]['relay_protocol'] == "dns") {
249
					$conf .= "  protocol \"dnsproto\"\n";
250
				} else {
243 251
					$conf .= "  protocol \"{$vs_a[$i]['relay_protocol']}\"\n";
244
					$conf .= "  forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
245

  
246
					if (isset($vs_a[$i]['sitedown']) &&  strlen($vs_a[$i]['sitedown']) > 0)
247
						$conf .= "  forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
248
					$conf .= "}\n";
249
					break;
250
				/* Default to Redirect Mode */
251
				case 'redirect_mode':
252
				default:
253
					$conf .= "redirect \"{$vs_a[$i]['name']}\" {\n";
254
					$conf .= "  listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
255
					$conf .= "  forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
256

  
257
					if (isset($config['system']['lb_use_sticky']))
258
						$conf .= "  sticky-address\n";
259

  
260
					# sitedown MUST use the same port as the primary pool - sucks, but it's a relayd thing
261
					if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0)
262
						$conf .= "  forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
263

  
264
					$conf .= "}\n";
265
					break;
252
				}
253
				$lbmode = "";
254
				if ( $pools[$vs_a[$i]['pool']]['mode'] == "loadbalance" ) {
255
					$lbmode = "mode loadbalance";
256
				}
257

  
258
				$conf .= "  forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$lbmode} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
259

  
260
				if (isset($vs_a[$i]['sitedown']) &&  strlen($vs_a[$i]['sitedown']) > 0)
261
					$conf .= "  forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$lbmode} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
262
				$conf .= "}\n";
263
			} else  {
264
				$conf .= "redirect \"{$vs_a[$i]['name']}\" {\n";
265
				$conf .= "  listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
266
				$conf .= "  forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
267

  
268
				if (isset($config['system']['lb_use_sticky']))
269
					$conf .= "  sticky-address\n";
270

  
271
				# sitedown MUST use the same port as the primary pool - sucks, but it's a relayd thing
272
				if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0)
273
					$conf .= "  forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} \n";
274

  
275
				$conf .= "}\n";
266 276
			}
267 277
		}
268 278
	}
......
323 333
*/
324 334
	$rdr_a = array();
325 335
	exec('/usr/local/sbin/relayctl show redirects 2>&1', $rdr_a);
336
	$relay_a = array();
337
	exec('/usr/local/sbin/relayctl show relays 2>&1', $relay_a);
326 338
	$vs = array();
327 339
	for ($i = 0; isset($rdr_a[$i]); $i++) {
328 340
		$line = $rdr_a[$i];
......
334 346
			}
335 347
		}
336 348
	}
349
	for ($i = 0; isset($relay_a[$i]); $i++) {
350
		$line = $relay_a[$i];
351
		if (preg_match("/^[0-9]+/", $line)) {
352
			$regs = array();
353
			if($x = preg_match("/^[0-9]+\s+relay\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) {
354
				$vs[trim($regs[1])] = array();
355
				$vs[trim($regs[1])]['status'] = trim($regs[2]);
356
			}
357
		}
358
	}
337 359
	return $vs;
338 360
}
339 361

  
usr/local/www/load_balancer_virtual_server.php
126 126
			$t->edit_uri('load_balancer_virtual_server_edit.php');
127 127
			$t->my_uri('load_balancer_virtual_server.php');
128 128
			$t->add_column(gettext('Name'),'name',10);
129
			$t->add_column(gettext('Mode'),'mode',10);
129
			$t->add_column(gettext('Protocol'),'relay_protocol',10);
130 130
			$t->add_column(gettext('IP Address'),'ipaddr',15);
131 131
			$t->add_column(gettext('Port'),'port',10);
132 132
			$t->add_column(gettext('Pool'),'pool',15);
usr/local/www/load_balancer_virtual_server_edit.php
194 194
                <tr align="left">
195 195
		  			<td width="22%" valign="top" class="vncellreq"><?=gettext("IP Address"); ?></td>
196 196
                  <td width="78%" class="vtable" colspan="2">
197
                    <input name="ipaddr" type="text" <?if(isset($pconfig['ipaddr'])) echo "value=\"{$pconfig['ipaddr']}\"";?> size="16" maxlength="16">
197
                    <input name="ipaddr" type="text" <?if(isset($pconfig['ipaddr'])) echo "value=\"{$pconfig['ipaddr']}\"";?> size="39" maxlength="39">
198 198
					<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."); ?>
199 199
                  </td>
200 200
			</tr>
......
257 257
                  </td>
258 258
				</tr>
259 259
-->
260
                <tr id="relay" align="left" style="display:none;">
261
		  			<td width="22%" valign="top" class="vncellreq"><?=gettext("Relay Protocol"); ?></td>
262
                  <td width="78%" class="vtable" colspan="2">
263
                  <select id="relay_protocol" name="relay_protocol">
264
                <?php
265
            				for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
266
            					$selected = "";
267
            					if ( $config['load_balancer']['lbprotocol'][$i]['name'] == $pconfig['lbprotocol'] )
268
            						$selected = " SELECTED";
269
            					echo "<option value=\"{$config['load_balancer']['lbprotocol'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbprotocol'][$i]['name']}</option>";
270
            				}
271
            			?>
272
            			</select>
273
                  <br>
274
                  </td>
275
				</tr>
260
		<tr id="relay" align="left">
261
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Relay Protocol"); ?></td>
262
			<td width="78%" class="vtable" colspan="2">
263
			<select id="relay_protocol" name="relay_protocol">
264
			<?php
265
				$lb_def_protos = array("tcp", "dns");
266
				foreach ($lb_def_protos as $lb_proto) {
267
					$selected = "";
268
					if ( $pconfig['relay_protocol'] == $lb_proto )
269
						$selected = " SELECTED";
270
					echo "<option value=\"{$lb_proto}\"{$selected}>{$lb_proto}</option>";
271
				}
272
			?>
273
			</select>
274
			<br>
275
			</td>
276
		</tr>
276 277
                <tr align="left">
277 278
                  <td align="left" valign="bottom">
278 279
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Submit"); ?>">

Also available in: Unified diff