util: make virFirewallRuleToString() global

Although the next commit will eliminate the one current use of
virFirewallRuleToString(), a future commit will once again have a use
for it, but in a different source file so it will need to be a global
function rather than static. Make that change now so that we don't get
a compile error from having an unused static function in the next
commit.

(The arg list is also changed to include the name of the command as a
separate argument rather than just assuming that it can be derived
from the rule's layer (which is correct for iptables, but won't be
correct for nftables)).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Laine Stump 2022-04-21 17:42:30 -04:00
parent 2d1c22a015
commit 4dce6eee5c
3 changed files with 12 additions and 5 deletions

View File

@ -2352,6 +2352,7 @@ virFirewallRuleAddArgFormat;
virFirewallRuleAddArgList; virFirewallRuleAddArgList;
virFirewallRuleAddArgSet; virFirewallRuleAddArgSet;
virFirewallRuleGetArgCount; virFirewallRuleGetArgCount;
virFirewallRuleToString;
virFirewallStartRollback; virFirewallStartRollback;
virFirewallStartTransaction; virFirewallStartTransaction;

View File

@ -461,14 +461,14 @@ void virFirewallStartRollback(virFirewall *firewall,
} }
static char * char *
virFirewallRuleToString(virFirewallRule *rule) virFirewallRuleToString(const char *cmd,
virFirewallRule *rule)
{ {
const char *bin = virFirewallLayerCommandTypeToString(rule->layer);
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i; size_t i;
virBufferAdd(&buf, bin, -1); virBufferAdd(&buf, cmd, -1);
for (i = 0; i < rule->argsLen; i++) { for (i = 0; i < rule->argsLen; i++) {
virBufferAddLit(&buf, " "); virBufferAddLit(&buf, " ");
virBufferAdd(&buf, rule->args[i], -1); virBufferAdd(&buf, rule->args[i], -1);
@ -477,6 +477,7 @@ virFirewallRuleToString(virFirewallRule *rule)
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
static int static int
virFirewallApplyRuleDirect(virFirewallRule *rule, virFirewallApplyRuleDirect(virFirewallRule *rule,
bool ignoreErrors, bool ignoreErrors,
@ -529,8 +530,10 @@ virFirewallApplyRule(virFirewall *firewall,
bool ignoreErrors) bool ignoreErrors)
{ {
g_autofree char *output = NULL; g_autofree char *output = NULL;
g_autofree char *str = virFirewallRuleToString(rule);
g_auto(GStrv) lines = NULL; g_auto(GStrv) lines = NULL;
g_autofree char *str
= virFirewallRuleToString(virFirewallLayerCommandTypeToString(rule->layer), rule);
VIR_INFO("Applying rule '%s'", NULLSTR(str)); VIR_INFO("Applying rule '%s'", NULLSTR(str));
if (rule->ignoreErrors) if (rule->ignoreErrors)

View File

@ -89,6 +89,9 @@ void virFirewallRuleAddArgList(virFirewall *firewall,
size_t virFirewallRuleGetArgCount(virFirewallRule *rule); size_t virFirewallRuleGetArgCount(virFirewallRule *rule);
char *virFirewallRuleToString(const char *cmd,
virFirewallRule *rule);
typedef enum { typedef enum {
/* Ignore all errors when applying rules, so no /* Ignore all errors when applying rules, so no
* rollback block will be required */ * rollback block will be required */