diff --git a/Shorewall-core/lib.cli b/Shorewall-core/lib.cli index c318763de..0a6c45890 100644 --- a/Shorewall-core/lib.cli +++ b/Shorewall-core/lib.cli @@ -42,16 +42,6 @@ fi . ${SHAREDIR}/shorewall/lib.base - -# -# Fatal Error -# -fatal_error() # $@ = Message -{ - echo " ERROR: $@" >&2 - exit 2 -} - # # Issue an error message and die # @@ -4239,10 +4229,29 @@ shorewall_cli() { get_config [ -n "$g_debugging" ] && set -x # - # Undocumented way to call functions in the libraries directly + # Way to call functions in the libraries directly # shift - $@ + + if [ $# -gt 0 ]; then + # + # First look for it here + # + if type $1 2> /dev/null | fgrep -q 'is a function'; then + # + # It's a shell function -- call it + # + $@ + else + # + # It isn't a function visible to this script -- try + # the compiled firewall + # + run_it $g_firewall $g_debugging call $@ + fi + else + usage 1 + fi ;; help) shift diff --git a/Shorewall-core/lib.common b/Shorewall-core/lib.common index 67b7c3352..5d0ec7ca1 100644 --- a/Shorewall-core/lib.common +++ b/Shorewall-core/lib.common @@ -70,6 +70,15 @@ startup_error() # $* = Error Message exit 2 } +# +# Fatal Error +# +fatal_error() # $@ = Message +{ + echo " ERROR: $@" >&2 + exit 2 +} + # # Get the Shorewall version of the passed script # diff --git a/Shorewall-lite/manpages/shorewall-lite.xml b/Shorewall-lite/manpages/shorewall-lite.xml index 17ee1dedb..9e8251e50 100644 --- a/Shorewall-lite/manpages/shorewall-lite.xml +++ b/Shorewall-lite/manpages/shorewall-lite.xml @@ -47,6 +47,19 @@ address + + shorewall-lite + + | + + -options + + + + address + + shorewall-lite @@ -665,6 +678,24 @@ + + call function [ + parameter ... ] + + + Added in Shorewall 4.6.10. Allows you to call a function in + one of the Shorewall libraries or in your compiled script. function + must name the shell function to be called. The listed parameters are + passed to the function. + + The function is first searched for in + lib.base, lib.common, + lib.cli and lib.cli-std + (Shorewall and Shorewall6 only). If it is not found, the call + command is passed to the generated script to be executed. + + + clear [-] diff --git a/Shorewall/Perl/prog.footer b/Shorewall/Perl/prog.footer index 3c62c2dcc..d7c32cb9c 100644 --- a/Shorewall/Perl/prog.footer +++ b/Shorewall/Perl/prog.footer @@ -429,11 +429,27 @@ case "$COMMAND" in ;; call) # - # Undocumented way to call functions in the libraries directly + # Way to call functions in the generated script directly # detect_configuration + shift - $@ + + if [ $# -gt 0 ]; then + # + # See what it is + # + if type $1 2> /dev/null | fgrep -q 'is a function'; then + # + # It's a shell function -- call it + # + $@ + else + fatal_error "$1 is not a known shell function" + fi + else + usage 1 + fi ;; version) [ $# -ne 1 ] && usage 2 diff --git a/Shorewall/manpages/shorewall.xml b/Shorewall/manpages/shorewall.xml index 4f8d35809..5fa8b48cf 100644 --- a/Shorewall/manpages/shorewall.xml +++ b/Shorewall/manpages/shorewall.xml @@ -49,6 +49,21 @@ address + + shorewall + + | + + -options + + + + functionparameter + ... + + shorewall @@ -918,6 +933,24 @@ + + call function [ + parameter ... ] + + + Added in Shorewall 4.6.10. Allows you to call a function in + one of the Shorewall libraries or in your compiled script. function + must name the shell function to be called. The listed parameters are + passed to the function. + + The function is first searched for in + lib.base, lib.common, + lib.cli and lib.cli-std + (Shorewall and Shorewall6 only). If it is not found, the call + command is passed to the generated script to be executed. + + + check [-] [-] [-] [-] diff --git a/Shorewall6-lite/manpages/shorewall6-lite.xml b/Shorewall6-lite/manpages/shorewall6-lite.xml index 4e704c4d5..402b2c662 100644 --- a/Shorewall6-lite/manpages/shorewall6-lite.xml +++ b/Shorewall6-lite/manpages/shorewall6-lite.xml @@ -47,6 +47,21 @@ address + + shorewall6-lite + + | + + -options + + + + functionparameter + ... + + shorewall6-lite @@ -655,6 +670,24 @@ + + call function [ + parameter ... ] + + + Added in Shorewall 4.6.10. Allows you to call a function in + one of the Shorewall libraries or in your compiled script. function + must name the shell function to be called. The listed parameters are + passed to the function. + + The function is first searched for in + lib.base, lib.common, + lib.cli and lib.cli-std + (Shorewall and Shorewall6 only). If it is not found, the call + command is passed to the generated script to be executed. + + + clear [-] diff --git a/Shorewall6/manpages/shorewall6.xml b/Shorewall6/manpages/shorewall6.xml index 4dc92dd62..e95c09d96 100644 --- a/Shorewall6/manpages/shorewall6.xml +++ b/Shorewall6/manpages/shorewall6.xml @@ -48,6 +48,21 @@ address + + shorewall6 + + | + + -options + + + + functionparameter + ... + + shorewall6 @@ -848,6 +863,24 @@ + + call function [ + parameter ... ] + + + Added in Shorewall 4.6.10. Allows you to call a function in + one of the Shorewall libraries or in your compiled script. function + must name the shell function to be called. The listed parameters are + passed to the function. + + The function is first searched for in + lib.base, lib.common, + lib.cli and lib.cli-std + (Shorewall and Shorewall6 only). If it is not found, the call + command is passed to the generated script to be executed. + + + check [-] [-] [-] [-]