diff options
Diffstat (limited to 'src/dnsmasq-manager/nm-dnsmasq-manager.c')
-rw-r--r-- | src/dnsmasq-manager/nm-dnsmasq-manager.c | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/src/dnsmasq-manager/nm-dnsmasq-manager.c b/src/dnsmasq-manager/nm-dnsmasq-manager.c index 083fb5339..21bbd23a5 100644 --- a/src/dnsmasq-manager/nm-dnsmasq-manager.c +++ b/src/dnsmasq-manager/nm-dnsmasq-manager.c @@ -28,9 +28,11 @@ #include <stdlib.h> #include "nm-dnsmasq-manager.h" +#include "nm-dnsmasq-utils.h" #include "nm-logging.h" #include "nm-glib-compat.h" #include "nm-posix-signals.h" +#include "nm-utils.h" typedef struct { char *iface; @@ -53,6 +55,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; typedef enum { NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, + NM_DNSMASQ_MANAGER_ERROR_INVALID_IP_RANGE, } NMDnsMasqManagerError; GQuark @@ -112,8 +115,6 @@ nm_dnsmasq_manager_new (const char *iface) NMDnsMasqManagerPrivate *priv; manager = (NMDnsMasqManager *) g_object_new (NM_TYPE_DNSMASQ_MANAGER, NULL); - if (!manager) - return NULL; priv = NM_DNSMASQ_MANAGER_GET_PRIVATE (manager); priv->iface = g_strdup (iface); @@ -251,10 +252,11 @@ create_dm_cmd_line (const char *iface, const char *dm_binary; NMCmdLine *cmd; GString *s; - NMIP4Address *tmp; - struct in_addr addr; - char buf[INET_ADDRSTRLEN + 15]; - char localaddr[INET_ADDRSTRLEN + 1]; + const NMPlatformIP4Address *tmp; + char first[INET_ADDRSTRLEN]; + char last[INET_ADDRSTRLEN]; + char localaddr[INET_ADDRSTRLEN]; + char *error_desc = NULL; dm_binary = nm_find_dnsmasq (); if (!dm_binary) { @@ -296,48 +298,23 @@ create_dm_cmd_line (const char *iface, nm_cmd_line_add_string (cmd, "--strict-order"); s = g_string_new ("--listen-address="); - addr.s_addr = nm_ip4_address_get_address (tmp); - if (!inet_ntop (AF_INET, &addr, &localaddr[0], INET_ADDRSTRLEN)) { - char *err_msg = g_strdup_printf ("error converting IP4 address 0x%X", - ntohl (addr.s_addr)); - g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, err_msg); - nm_log_warn (LOGD_SHARING, "%s", err_msg); - g_free (err_msg); - goto error; - } + nm_utils_inet4_ntop (tmp->address, localaddr); g_string_append (s, localaddr); nm_cmd_line_add_string (cmd, s->str); g_string_free (s, TRUE); - s = g_string_new ("--dhcp-range="); - - /* Add start of address range */ - addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (9); - if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) { - char *err_msg = g_strdup_printf ("error converting IP4 address 0x%X", - ntohl (addr.s_addr)); - g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, err_msg); - nm_log_warn (LOGD_SHARING, "%s", err_msg); - g_free (err_msg); - goto error; - } - g_string_append (s, buf); - - g_string_append_c (s, ','); - - /* Add end of address range */ - addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (99); - if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) { - char *err_msg = g_strdup_printf ("error converting IP4 address 0x%X", - ntohl (addr.s_addr)); - g_set_error_literal (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, err_msg); - nm_log_warn (LOGD_SHARING, "%s", err_msg); - g_free (err_msg); + if (!nm_dnsmasq_utils_get_range (tmp, first, last, &error_desc)) { + g_set_error_literal (error, + NM_DNSMASQ_MANAGER_ERROR, + NM_DNSMASQ_MANAGER_ERROR_INVALID_IP_RANGE, + error_desc); + nm_log_warn (LOGD_SHARING, "Failed to find DHCP address ranges: %s", error_desc); + g_free (error_desc); goto error; } - g_string_append (s, buf); - g_string_append (s, ",60m"); + s = g_string_new ("--dhcp-range="); + g_string_append_printf (s, "%s,%s,60m", first, last); nm_cmd_line_add_string (cmd, s->str); g_string_free (s, TRUE); |