summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-dhcp-common.c
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/network/networkd-dhcp-common.c
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/network/networkd-dhcp-common.c')
-rw-r--r--src/network/networkd-dhcp-common.c27
1 files changed, 27 insertions, 0 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,