comparison mod_firewall/mod_firewall.lua @ 6556:7477e97a9045

mod_firewall: Apply pre-reload state before re-reading config This change makes load/reload a bit more robust. module.load() runs before module.restore() and it reads from the config and updates the state (if needed). However, after this, module.restore() could run and apply the old state again.
author Matthew Wild <mwild1@gmail.com>
date Sun, 24 May 2026 20:03:20 +0100
parents d81bb13c0e87
children 15a7749c7acb
comparison
equal deleted inserted replaced
6555:d81bb13c0e87 6556:7477e97a9045
798 module:log_status(n_wanted == n_loaded and "info" or "warn", "Loaded %d of %d scripts", n_loaded, n_wanted); 798 module:log_status(n_wanted == n_loaded and "info" or "warn", "Loaded %d of %d scripts", n_loaded, n_wanted);
799 end 799 end
800 800
801 function module.load() 801 function module.load()
802 if not prosody.arg then return end -- Don't run in prosodyctl 802 if not prosody.arg then return end -- Don't run in prosodyctl
803
804 local state = module.saved_state;
805 if state then
806 active_definitions = state.active_definitions;
807 loaded_scripts = state.loaded_scripts;
808 end
809
803 local firewall_scripts = module:get_option_set("firewall_scripts", {}); 810 local firewall_scripts = module:get_option_set("firewall_scripts", {});
804 load_unload_scripts(firewall_scripts); 811 load_unload_scripts(firewall_scripts);
805 -- Replace contents of definitions table (shared) with active definitions 812 -- Replace contents of definitions table (shared) with active definitions
806 for k in it.keys(definitions) do definitions[k] = nil; end 813 for k in it.keys(definitions) do definitions[k] = nil; end
807 for k,v in pairs(active_definitions) do definitions[k] = v; end 814 for k,v in pairs(active_definitions) do definitions[k] = v; end
808 end 815 end
809 816
810 function module.save() 817 function module.save()
811 return { active_definitions = active_definitions, loaded_scripts = loaded_scripts }; 818 return { active_definitions = active_definitions, loaded_scripts = loaded_scripts };
812 end
813
814 function module.restore(state)
815 active_definitions = state.active_definitions;
816 loaded_scripts = state.loaded_scripts;
817 end 819 end
818 820
819 module:hook_global("config-reloaded", function () 821 module:hook_global("config-reloaded", function ()
820 load_unload_scripts(module:get_option_set("firewall_scripts", {})); 822 load_unload_scripts(module:get_option_set("firewall_scripts", {}));
821 end); 823 end);