summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-dhcp/sd-dhcp-client.c15
-rw-r--r--src/network/networkd-link.c10
-rw-r--r--src/shared/net-util.c15
-rw-r--r--src/shared/net-util.h3
-rw-r--r--src/systemd/sd-dhcp-client.h1
5 files changed, 21 insertions, 23 deletions
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 3b7b9f4ccd..7e5c36a857 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -240,21 +240,6 @@ int sd_dhcp_client_get_hostname(sd_dhcp_client *client, const char **hostname) {
return 0;
}
-int sd_dhcp_client_prefixlen(const struct in_addr *addr) {
- int len = 0;
- uint32_t mask;
-
- assert_return(addr, -EADDRNOTAVAIL);
-
- mask = be32toh(addr->s_addr);
- while (mask) {
- len++;
- mask = mask << 1;
- }
-
- return len;
-}
-
int sd_dhcp_client_get_router(sd_dhcp_client *client, struct in_addr *addr) {
assert_return(client, -EINVAL);
assert_return(addr, -EINVAL);
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index dec33e88ee..f021918311 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -26,6 +26,7 @@
#include "libudev-private.h"
#include "util.h"
#include "bus-util.h"
+#include "net-util.h"
int link_new(Manager *manager, struct udev_device *device, Link **ret) {
_cleanup_link_free_ Link *link = NULL;
@@ -422,7 +423,7 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
struct in_addr address;
struct in_addr netmask;
struct in_addr gateway;
- int prefixlen;
+ unsigned prefixlen;
int r;
assert(link);
@@ -496,12 +497,7 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
return;
}
- prefixlen = sd_dhcp_client_prefixlen(&netmask);
- if (prefixlen < 0) {
- log_warning_link(link, "DHCP error: no prefixlen");
- link_enter_failed(link);
- return;
- }
+ prefixlen = net_netmask_to_prefixlen(&netmask);
r = sd_dhcp_client_get_router(client, &gateway);
if (r < 0) {
diff --git a/src/shared/net-util.c b/src/shared/net-util.c
index 887dae5125..630be18e56 100644
--- a/src/shared/net-util.c
+++ b/src/shared/net-util.c
@@ -58,6 +58,21 @@ bool net_match_config(const struct ether_addr *match_mac,
return 1;
}
+unsigned net_netmask_to_prefixlen(const struct in_addr *addr) {
+ unsigned len = 0;
+ uint32_t mask;
+
+ assert(addr);
+
+ mask = be32toh(addr->s_addr);
+ while (mask) {
+ len++;
+ mask = mask << 1;
+ }
+
+ return len;
+}
+
int config_parse_ifname(const char *unit,
const char *filename,
unsigned line,
diff --git a/src/shared/net-util.h b/src/shared/net-util.h
index c7edfb96f0..0ec04db87e 100644
--- a/src/shared/net-util.h
+++ b/src/shared/net-util.h
@@ -22,6 +22,7 @@
#pragma once
#include <netinet/ether.h>
+#include <netinet/in.h>
#include <stdbool.h>
bool net_match_config(const struct ether_addr *match_mac,
@@ -35,6 +36,8 @@ bool net_match_config(const struct ether_addr *match_mac,
const char *dev_type,
const char *dev_name);
+unsigned net_netmask_to_prefixlen(const struct in_addr *netmask);
+
int config_parse_hwaddr(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index 0f16e99617..e66361193f 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -52,7 +52,6 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client,
int sd_dhcp_client_get_address(sd_dhcp_client *client, struct in_addr *addr);
int sd_dhcp_client_get_netmask(sd_dhcp_client *client, struct in_addr *addr);
-int sd_dhcp_client_prefixlen(const struct in_addr *addr);
int sd_dhcp_client_get_router(sd_dhcp_client *client, struct in_addr *addr);
int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr **addr, size_t *addr_size);
int sd_dhcp_client_get_mtu(sd_dhcp_client *client, uint16_t *mtu);