2013-03-04 16:30:40 +00:00
|
|
|
/*
|
|
|
|
* virfirewall.h: integration with firewalls
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:51 +00:00
|
|
|
#pragma once
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2019-06-18 16:12:51 +00:00
|
|
|
#include "internal.h"
|
2013-03-04 16:30:40 +00:00
|
|
|
|
|
|
|
typedef struct _virFirewall virFirewall;
|
|
|
|
|
|
|
|
typedef struct _virFirewallRule virFirewallRule;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VIR_FIREWALL_LAYER_ETHERNET,
|
|
|
|
VIR_FIREWALL_LAYER_IPV4,
|
|
|
|
VIR_FIREWALL_LAYER_IPV6,
|
|
|
|
|
|
|
|
VIR_FIREWALL_LAYER_LAST,
|
|
|
|
} virFirewallLayer;
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virFirewall *virFirewallNew(void);
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallFree(virFirewall *firewall);
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2017-01-02 18:15:30 +00:00
|
|
|
/**
|
|
|
|
* virFirewallAddRule:
|
|
|
|
* @firewall: firewall ruleset to add to
|
|
|
|
* @layer: the firewall layer to change
|
|
|
|
* @...: NULL terminated list of strings for the rule
|
|
|
|
*
|
|
|
|
* Add any type of rule to the firewall ruleset.
|
|
|
|
*
|
|
|
|
* Returns the new rule
|
|
|
|
*/
|
2019-06-18 16:12:51 +00:00
|
|
|
#define virFirewallAddRule(firewall, layer, ...) \
|
2017-01-04 11:47:01 +00:00
|
|
|
virFirewallAddRuleFull(firewall, layer, false, NULL, NULL, __VA_ARGS__)
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
typedef int (*virFirewallQueryCallback)(virFirewall *firewall,
|
2018-12-04 16:33:28 +00:00
|
|
|
virFirewallLayer layer,
|
2013-03-04 16:30:40 +00:00
|
|
|
const char *const *lines,
|
|
|
|
void *opaque);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virFirewallRule *virFirewallAddRuleFull(virFirewall *firewall,
|
2013-03-04 16:30:40 +00:00
|
|
|
virFirewallLayer layer,
|
|
|
|
bool ignoreErrors,
|
|
|
|
virFirewallQueryCallback cb,
|
|
|
|
void *opaque,
|
|
|
|
...)
|
2019-10-14 12:13:31 +00:00
|
|
|
G_GNUC_NULL_TERMINATED;
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallRemoveRule(virFirewall *firewall,
|
|
|
|
virFirewallRule *rule);
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallRuleAddArg(virFirewall *firewall,
|
|
|
|
virFirewallRule *rule,
|
2013-03-04 16:30:40 +00:00
|
|
|
const char *arg)
|
|
|
|
ATTRIBUTE_NONNULL(3);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallRuleAddArgFormat(virFirewall *firewall,
|
|
|
|
virFirewallRule *rule,
|
2013-03-04 16:30:40 +00:00
|
|
|
const char *fmt, ...)
|
2019-10-15 11:35:07 +00:00
|
|
|
ATTRIBUTE_NONNULL(3) G_GNUC_PRINTF(3, 4);
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallRuleAddArgSet(virFirewall *firewall,
|
|
|
|
virFirewallRule *rule,
|
2013-03-04 16:30:40 +00:00
|
|
|
const char *const *args)
|
|
|
|
ATTRIBUTE_NONNULL(3);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallRuleAddArgList(virFirewall *firewall,
|
|
|
|
virFirewallRule *rule,
|
2013-03-04 16:30:40 +00:00
|
|
|
...)
|
2019-10-14 12:13:31 +00:00
|
|
|
G_GNUC_NULL_TERMINATED;
|
2013-03-04 16:30:40 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
size_t virFirewallRuleGetArgCount(virFirewallRule *rule);
|
2013-03-04 16:30:40 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* Ignore all errors when applying rules, so no
|
|
|
|
* rollback block will be required */
|
|
|
|
VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS = (1 << 0),
|
|
|
|
} virFirewallTransactionFlags;
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallStartTransaction(virFirewall *firewall,
|
2013-03-04 16:30:40 +00:00
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* Execute previous rollback block before this
|
|
|
|
* one, to chain cleanup */
|
|
|
|
VIR_FIREWALL_ROLLBACK_INHERIT_PREVIOUS = (1 << 0),
|
|
|
|
} virFirewallRollbackFlags;
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFirewallStartRollback(virFirewall *firewall,
|
2013-03-04 16:30:40 +00:00
|
|
|
unsigned int flags);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
int virFirewallApply(virFirewall *firewall);
|
2013-03-04 16:30:40 +00:00
|
|
|
|
util: synchronize with firewalld before we start calling iptables directly
When it is starting up, firewalld will delete all existing iptables
rules and chains before adding its own rules. If libvirtd were to try
to directly add iptables rules during the time before firewalld has
finished initializing, firewalld would end up deleting the rules that
libvirtd has just added.
Currently this isn't a problem, since libvirtd only adds iptables
rules via the firewalld "passthrough command" API, and so firewalld is
able to properly serialize everything. However, we will soon be
changing libvirtd to add its iptables and ebtables rules by directly
calling iptables/ebtables rather than via firewalld, thus removing the
serialization of libvirtd adding rules vs. firewalld deleting rules.
This will especially apparent (if we don't fix it in advance, as this
patch does) when libvirtd is responding to the dbus NameOwnerChanged
event, which is used to learn when firewalld has been restarted. In
that case, dbus sends the event before firewalld has been able to
complete its initialization, so when libvirt responds to the event by
adding back its iptables rules (with direct calls to
/usr/bin/iptables), some of those rules are added before firewalld has
a chance to do its "remove everything" startup protocol. The usual
result of this is that libvirt will successfully add its private
chains (e.g. LIBVIRT_INP, etc), but then fail when it tries to add a
rule jumping to one of those chains (because in the interim, firewalld
has deleted the new chains).
The solution is for libvirt to preface it's direct calling to iptables
with a iptables command sent via firewalld's passthrough command
API. Since commands sent to firewalld are completed synchronously, and
since firewalld won't service them until it has completed its own
initialization, this will assure that by the time libvirt starts
calling iptables to add rules, that firewalld will not be following up
by deleting any of those rules.
To minimize the amount of extra overhead, we request the simplest
iptables command possible: "iptables -V" (and aside from logging a
debug message, we ignore the result, for good measure).
(This patch is being done *before* the patch that switches to calling
iptables directly, so that everything will function properly with any
fractional part of the series applied).
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-23 19:39:40 +00:00
|
|
|
void virFirewallBackendSynchronize(void);
|
|
|
|
|
2019-10-15 12:47:50 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virFirewall, virFirewallFree);
|