summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-15 11:38:55 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-15 13:44:39 +0200
commit59577d241658b4206e12697f998d48dc87f7e023 (patch)
treef8dc584e9e268d8900a3e18eb517999611624979 /src/network
parentmachine: add MachineImage interface (diff)
downloadsystemd-59577d241658b4206e12697f998d48dc87f7e023.tar.xz
systemd-59577d241658b4206e12697f998d48dc87f7e023.zip
network: add AF_TO_ADDRESS_FAMILY() helper
Make some code a bit shorter.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-address.c7
-rw-r--r--src/network/networkd-dhcp-common.c2
-rw-r--r--src/network/networkd-routing-policy-rule.c1
-rw-r--r--src/network/networkd-sysctl.c6
4 files changed, 5 insertions, 11 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 0e06149f33..1e37e6e85a 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -644,12 +644,7 @@ static int address_set_masquerade(Address *address, bool add) {
if (!address->link->network)
return 0;
- if (address->family == AF_INET &&
- !FLAGS_SET(address->link->network->ip_masquerade, ADDRESS_FAMILY_IPV4))
- return 0;
-
- if (address->family == AF_INET6 &&
- !FLAGS_SET(address->link->network->ip_masquerade, ADDRESS_FAMILY_IPV6))
+ if (!FLAGS_SET(address->link->network->ip_masquerade, AF_TO_ADDRESS_FAMILY(address->family)))
return 0;
if (address->scope >= RT_SCOPE_LINK)
diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c
index 1799d04212..8b64dfe8f0 100644
--- a/src/network/networkd-dhcp-common.c
+++ b/src/network/networkd-dhcp-common.c
@@ -71,7 +71,7 @@ bool link_dhcp_enabled(Link *link, int family) {
if (!link->network)
return false;
- return link->network->dhcp & (family == AF_INET ? ADDRESS_FAMILY_IPV4 : ADDRESS_FAMILY_IPV6);
+ return link->network->dhcp & AF_TO_ADDRESS_FAMILY(family);
}
void network_adjust_dhcp(Network *network) {
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index ec050e3a2d..e2c76616dd 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -12,6 +12,7 @@
#include "hashmap.h"
#include "ip-protocol-list.h"
#include "netlink-util.h"
+#include "network-util.h"
#include "networkd-manager.h"
#include "networkd-queue.h"
#include "networkd-route-util.h"
diff --git a/src/network/networkd-sysctl.c b/src/network/networkd-sysctl.c
index c0762b9b70..17a2c6da38 100644
--- a/src/network/networkd-sysctl.c
+++ b/src/network/networkd-sysctl.c
@@ -303,9 +303,7 @@ int link_get_ip_forwarding(Link *link, int family) {
return t;
/* If IPMasquerade= is enabled, also enable IP forwarding. */
- if (family == AF_INET && FLAGS_SET(link->network->ip_masquerade, ADDRESS_FAMILY_IPV4))
- return true;
- if (family == AF_INET6 && FLAGS_SET(link->network->ip_masquerade, ADDRESS_FAMILY_IPV6))
+ if (FLAGS_SET(link->network->ip_masquerade, AF_TO_ADDRESS_FAMILY(family)))
return true;
/* If IPv6SendRA= is enabled, also enable IPv6 forwarding. */
@@ -377,7 +375,7 @@ static int link_set_ip_forwarding(Link *link, int family) {
/* When IPMasquerade= is enabled and the global setting is unset, enable _global_ IP forwarding, and
* re-apply per-link setting for all links. */
- if (FLAGS_SET(link->network->ip_masquerade, family == AF_INET ? ADDRESS_FAMILY_IPV4 : ADDRESS_FAMILY_IPV6) &&
+ if (FLAGS_SET(link->network->ip_masquerade, AF_TO_ADDRESS_FAMILY(family)) &&
link->manager->ip_forwarding[family == AF_INET6] < 0) {
link->manager->ip_forwarding[family == AF_INET6] = true;