fw_add_masquerade: remove unused function arguments

Similar to the previous commit.  All callers pass NULL.  This will
ease initial nftables backend implementation (less features to cover).

Add the function parameters as local variables and let compiler
remove branches.  Followup patch can remove the if (NULL) conditionals.
This commit is contained in:
Florian Westphal 2020-06-19 12:41:49 +02:00 committed by Lennart Poettering
parent 67b3732a53
commit 7509c7fdf9
4 changed files with 11 additions and 23 deletions

View File

@ -266,7 +266,7 @@ static int address_set_masquerade(Address *address, bool add) {
if (r < 0)
return r;
r = fw_add_masquerade(add, AF_INET, 0, &masked, address->prefixlen, NULL, NULL, 0);
r = fw_add_masquerade(add, AF_INET, &masked, address->prefixlen);
if (r < 0)
return r;

View File

@ -81,12 +81,8 @@ static int entry_fill_basics(
int fw_add_masquerade(
bool add,
int af,
int protocol,
const union in_addr_union *source,
unsigned source_prefixlen,
const char *out_interface,
const union in_addr_union *destination,
unsigned destination_prefixlen) {
unsigned source_prefixlen) {
static const xt_chainlabel chain = "POSTROUTING";
_cleanup_(iptc_freep) struct xtc_handle *h = NULL;
@ -94,14 +90,14 @@ int fw_add_masquerade(
struct ipt_entry_target *t;
size_t sz;
struct nf_nat_ipv4_multi_range_compat *mr;
int r;
int r, protocol = 0;
const char *out_interface = NULL;
const union in_addr_union *destination = NULL;
unsigned destination_prefixlen = 0;
if (af != AF_INET)
return -EOPNOTSUPP;
if (!IN_SET(protocol, 0, IPPROTO_TCP, IPPROTO_UDP))
return -EOPNOTSUPP;
h = iptc_init("nat");
if (!h)
return -errno;

View File

@ -11,12 +11,8 @@
int fw_add_masquerade(
bool add,
int af,
int protocol,
const union in_addr_union *source,
unsigned source_prefixlen,
const char *out_interface,
const union in_addr_union *destination,
unsigned destination_prefixlen);
unsigned source_prefixlen);
int fw_add_local_dnat(
bool add,
@ -32,12 +28,8 @@ int fw_add_local_dnat(
static inline int fw_add_masquerade(
bool add,
int af,
int protocol,
const union in_addr_union *source,
unsigned source_prefixlen,
const char *out_interface,
const union in_addr_union *destination,
unsigned destination_prefixlen) {
unsigned source_prefixlen) {
return -EOPNOTSUPP;
}

View File

@ -10,15 +10,15 @@ int main(int argc, char *argv[]) {
int r;
test_setup_logging(LOG_DEBUG);
r = fw_add_masquerade(true, AF_INET, 0, NULL, 0, "foobar", NULL, 0);
r = fw_add_masquerade(true, AF_INET, NULL, 0);
if (r < 0)
log_error_errno(r, "Failed to modify firewall: %m");
r = fw_add_masquerade(true, AF_INET, 0, NULL, 0, "foobar", NULL, 0);
r = fw_add_masquerade(true, AF_INET, NULL, 0);
if (r < 0)
log_error_errno(r, "Failed to modify firewall: %m");
r = fw_add_masquerade(false, AF_INET, 0, NULL, 0, "foobar", NULL, 0);
r = fw_add_masquerade(false, AF_INET, NULL, 0);
if (r < 0)
log_error_errno(r, "Failed to modify firewall: %m");