summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-10-02 09:35:54 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-10-06 19:50:50 +0200
commit5ae0fb7fb75efeea1a965cda1ff9181f0bcd47d2 (patch)
tree1b20e1c630690854e37f3f44d5b5452125a15378
parentnetwork: move link_ipv6_accept_ra_enabled() (diff)
downloadsystemd-5ae0fb7fb75efeea1a965cda1ff9181f0bcd47d2.tar.xz
systemd-5ae0fb7fb75efeea1a965cda1ff9181f0bcd47d2.zip
network: move link_dhcp4_server_enabled()
-rw-r--r--src/network/networkd-dhcp-server.c42
-rw-r--r--src/network/networkd-link.c41
2 files changed, 47 insertions, 36 deletions
diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c
index a0ef756df8..0155ab2de2 100644
--- a/src/network/networkd-dhcp-server.c
+++ b/src/network/networkd-dhcp-server.c
@@ -1,5 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <netinet/in.h>
+#include <linux/if_arp.h>
+#include <linux/if.h>
+
#include "sd-dhcp-server.h"
#include "fd-util.h"
@@ -15,6 +19,24 @@
#include "string-util.h"
#include "strv.h"
+static bool link_dhcp4_server_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_server;
+}
+
static Address* link_find_dhcp_server_address(Link *link) {
Address *address;
@@ -231,6 +253,24 @@ int dhcp4_server_configure(Link *link) {
Address *address;
int r;
+ assert(link);
+
+ if (!link_dhcp4_server_enabled(link))
+ return 0;
+
+ if (!(link->flags & IFF_UP))
+ return 0;
+
+ if (!link->dhcp_server) {
+ r = sd_dhcp_server_new(&link->dhcp_server, link->ifindex);
+ if (r < 0)
+ return r;
+
+ r = sd_dhcp_server_attach_event(link->dhcp_server, link->manager->event, 0);
+ if (r < 0)
+ return r;
+ }
+
address = link_find_dhcp_server_address(link);
if (!address)
return log_link_error_errno(link, SYNTHETIC_ERRNO(EBUSY),
@@ -342,6 +382,8 @@ int dhcp4_server_configure(Link *link) {
r = sd_dhcp_server_start(link->dhcp_server);
if (r < 0)
return log_link_error_errno(link, r, "Could not start DHCPv4 server instance: %m");
+
+ log_link_debug(link, "Offering DHCPv4 leases");
}
return 0;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 357848ee57..0610af16d5 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -61,24 +61,6 @@ DUID* link_get_duid(Link *link) {
return &link->manager->duid;
}
-static bool link_dhcp4_server_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_server;
-}
-
bool link_ipv4ll_enabled(Link *link, AddressFamily mask) {
assert(link);
assert((mask & ~(ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4)) == 0);
@@ -974,12 +956,9 @@ static int link_set_static_configs(Link *link) {
return r;
/* now that we can figure out a default address for the dhcp server, start it */
- if (link_dhcp4_server_enabled(link) && (link->flags & IFF_UP)) {
- r = dhcp4_server_configure(link);
- if (r < 0)
- return r;
- log_link_debug(link, "Offering DHCPv4 leases");
- }
+ r = dhcp4_server_configure(link);
+ if (r < 0)
+ return r;
return 0;
}
@@ -2414,16 +2393,6 @@ static int link_configure(Link *link) {
return r;
}
- if (link_dhcp4_server_enabled(link)) {
- r = sd_dhcp_server_new(&link->dhcp_server, link->ifindex);
- if (r < 0)
- return r;
-
- r = sd_dhcp_server_attach_event(link->dhcp_server, NULL, 0);
- if (r < 0)
- return r;
- }
-
if (link_dhcp6_enabled(link) ||
link_ipv6_accept_ra_enabled(link)) {
r = dhcp6_configure(link);
@@ -2684,7 +2653,7 @@ static int link_reconfigure_internal(Link *link, sd_netlink_message *m, bool for
if (r < 0)
return r;
- if (link_dhcp4_server_enabled(link))
+ if (link->dhcp_server)
(void) sd_dhcp_server_stop(link->dhcp_server);
r = link_drop_config(link);
@@ -3174,7 +3143,7 @@ static int link_carrier_lost(Link *link) {
return r;
}
- if (link_dhcp4_server_enabled(link))
+ if (link->dhcp_server)
(void) sd_dhcp_server_stop(link->dhcp_server);
r = link_drop_config(link);