I guess the plan is to have stateful failover on DHCP WAN?Please update the thread if you find any good solutions as I would like to have the same.Currently I just keep my WAN interfaces without CARP so when a failover occurs it drops all external sessions but at least I still have Internet access.
It actually sounds like you are doing what I am after. How are you achieving that? For instance, just in basic testing on my BACKUP, if I run 'ifconfig vtnet0 down' all interfaces go down and 'ifconfig vtnet0 up' brings all interfaces up. It's bizarre.
Quote from: bubbagump on January 19, 2021, 11:01:26 pmIt actually sounds like you are doing what I am after. How are you achieving that? For instance, just in basic testing on my BACKUP, if I run 'ifconfig vtnet0 down' all interfaces go down and 'ifconfig vtnet0 up' brings all interfaces up. It's bizarre.I run CARP on all interfaces except for WAN. The WAN interface on each firewall is just configured like "normal" with DHCP.So the gateway for clients is the CARP LAN IP, and outbound traffic goes out via the WAN of the current CARP master.
If you have both firewalls on DHCP, I assume only one of them gets the lease?Assuming that is so, the second one probably has no internet access, so how do you update it and things like that?
#!/usr/local/bin/php<?phprequire_once("config.inc");require_once("interfaces.inc");require_once("util.inc");$subsystem = !empty($argv[1]) ? $argv[1] : '';$type = !empty($argv[2]) ? $argv[2] : '';if ($type != 'MASTER' && $type != 'BACKUP') { log_error("Carp '$type' event unknown from source '{$subsystem}'"); exit(1);}if (!strstr($subsystem, '@')) { log_error("Carp '$type' event triggered from wrong source '{$subsystem}'"); exit(1);}foreach($config['interfaces'] as $ifkey => $interface) { if ($ifkey=='wan') { // could change this to match on wan* interfaces for multi-wan setups, maybe? if ($type == 'BACKUP') { log_error("Carp Status is now Backup!"); log_error("Shutting interface: {$interface['if']}"); shell_exec("/sbin/ifconfig {$interface['if']} down"); log_error("Stopping DHCPD"); shell_exec('pluginctl -s dhcpd stop'); } else if ($type == 'MASTER') { log_error("Carp Status is now Master!"); log_error("Starting interface: {$interface['if']}"); shell_exec("/sbin/ifconfig {$interface['if']} up"); log_error("Restarting DHCPD"); shell_exec('pluginctl -s dhcpd restart'); shell_exec("dhclient {$interface['if']}"); } }}?>
<?phprequire_once("config.inc");require_once("interfaces.inc");require_once("util.inc");$subsystem = !empty($argv[1]) ? $argv[1] : '';$type = !empty($argv[2]) ? $argv[2] : '';if ($type != 'MASTER' && $type != 'BACKUP') { log_error("Carp '$type' event unknown from source '{$subsystem}'"); exit(1);}if (!strstr($subsystem, '@')) { log_error("Carp '$type' event triggered from wrong source '{$subsystem}'"); exit(1);}foreach($config['interfaces'] as $ifkey => $interface) { if ($ifkey=='wan') { // could change this to match on wan* interfaces for multi-wan setups, maybe? if ($type == 'BACKUP') { log_error("Carp Status is now Backup!"); log_error("Shutting interface: {$interface['if']}"); shell_exec("/sbin/ifconfig {$interface['if']} down"); log_error("Stopping DHCPD"); shell_exec('pluginctl -s dhcpd stop'); } else if ($type == 'MASTER') { log_error("Carp Status is now Master!"); log_error("Starting interface: {$interface['if']}"); shell_exec("/sbin/ifconfig {$interface['if']} up"); log_error("Restarting DHCPD"); shell_exec('pluginctl -s dhcpd restart'); shell_exec("dhclient {$interface['if']}"); } }}?>
$ifkey = 'wan';if ($type === "MASTER") { log_error("enable interface '$ifkey' due CARP event '$type'"); $config['interfaces'][$ifkey]['enable'] = '1'; write_config("enable interface '$ifkey' due CARP event '$type'", false); interface_configure(false, $ifkey, false, false);} else { log_error("disable interface '$ifkey' due CARP event '$type'"); unset($config['interfaces'][$ifkey]['enable']); write_config("disable interface '$ifkey' due CARP event '$type'", false); interface_configure(false, $ifkey, false, false);}
I am trying to do this on Dual WAN using Spali's script and the primary kicks but the secondary WAN just sits there.bitcore's solution works, though I don't know if we need to kill the dhcp server on the backup.. if it all works correct, dhcp should failover to the backup when the primary fails.. if you sync all leases, the backup should take over as dhcp server. If anyone sees this before I figure it out.. how can I tweak Spali's script to kick both WAN interfaces when there is a failure?
We've effectively arrived on the same method to achieve this. Except your calls, Spali, are probably much better since you are using the config system's normal calls (which I'm not familiar with. I'm instead smashing in console commands via exec, equivalent to using a hammer. (unsanitized code execution risks here!)