summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-10-02 09:09:25 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-10-06 19:50:50 +0200
commit67c311abd3e930e30ff3ff0ef73d159f7360b61f (patch)
treea5fdd551059b809e4581f412657fb13ac4f98c45 /src
parentnetwork: move link_get_xxx_route_table() (diff)
downloadsystemd-67c311abd3e930e30ff3ff0ef73d159f7360b61f.tar.xz
systemd-67c311abd3e930e30ff3ff0ef73d159f7360b61f.zip
network: unify link_dhcp{4,6}_enabled()
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-dhcp-common.c27
-rw-r--r--src/network/networkd-dhcp-common.h10
-rw-r--r--src/network/networkd-link.c39
3 files changed, 37 insertions, 39 deletions
diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c
index ecf9bcea85..3ea3a5a7ba 100644
--- a/src/network/networkd-dhcp-common.c
+++ b/src/network/networkd-dhcp-common.c
@@ -1,15 +1,42 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <netinet/in.h>
+#include <linux/if_arp.h>
+
#include "dhcp-internal.h"
#include "dhcp6-internal.h"
#include "escape.h"
#include "in-addr-util.h"
#include "networkd-dhcp-common.h"
+#include "networkd-link.h"
#include "networkd-network.h"
#include "parse-util.h"
+#include "socket-util.h"
#include "string-table.h"
#include "strv.h"
+bool link_dhcp_enabled(Link *link, int family) {
+ assert(link);
+ assert(IN_SET(family, AF_INET, AF_INET6));
+
+ if (family == AF_INET6 && !socket_ipv6_is_supported())
+ return false;
+
+ if (link->flags & IFF_LOOPBACK)
+ return false;
+
+ if (!link->network)
+ return false;
+
+ if (link->network->bond)
+ return false;
+
+ if (link->iftype == ARPHRD_CAN)
+ return false;
+
+ return link->network->dhcp & (family == AF_INET ? ADDRESS_FAMILY_IPV4 : ADDRESS_FAMILY_IPV6);
+}
+
int config_parse_dhcp(
const char* unit,
const char *filename,
diff --git a/src/network/networkd-dhcp-common.h b/src/network/networkd-dhcp-common.h
index 01400a2385..1032ec2bda 100644
--- a/src/network/networkd-dhcp-common.h
+++ b/src/network/networkd-dhcp-common.h
@@ -7,6 +7,8 @@
#define DHCP_ROUTE_METRIC 1024
+typedef struct Link Link;
+
typedef enum DHCPUseDomains {
DHCP_USE_DOMAINS_NO,
DHCP_USE_DOMAINS_YES,
@@ -35,6 +37,14 @@ typedef struct DUID {
usec_t llt_time;
} DUID;
+bool link_dhcp_enabled(Link *link, int family);
+static inline bool link_dhcp4_enabled(Link *link) {
+ return link_dhcp_enabled(link, AF_INET);
+}
+static inline bool link_dhcp6_enabled(Link *link) {
+ return link_dhcp_enabled(link, AF_INET6);
+}
+
const char* dhcp_use_domains_to_string(DHCPUseDomains p) _const_;
DHCPUseDomains dhcp_use_domains_from_string(const char *s) _pure_;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index c73389e25c..dcdfbe2ac4 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -61,45 +61,6 @@ DUID* link_get_duid(Link *link) {
return &link->manager->duid;
}
-static bool link_dhcp6_enabled(Link *link) {
- assert(link);
-
- if (!socket_ipv6_is_supported())
- return false;
-
- if (link->flags & IFF_LOOPBACK)
- return false;
-
- if (!link->network)
- return false;
-
- if (link->network->bond)
- return false;
-
- if (link->iftype == ARPHRD_CAN)
- return false;
-
- return link->network->dhcp & ADDRESS_FAMILY_IPV6;
-}
-
-static bool link_dhcp4_enabled(Link *link) {
- assert(link);
-
- if (link->flags & IFF_LOOPBACK)
- return false;
-
- if (!link->network)
- return false;
-
- if (link->network->bond)
- return false;
-
- if (link->iftype == ARPHRD_CAN)
- return false;
-
- return link->network->dhcp & ADDRESS_FAMILY_IPV4;
-}
-
static bool link_dhcp4_server_enabled(Link *link) {
assert(link);