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 |
|
Fixup relayd to handle DNS load balancing as well as standard TCP load balancing.