diff options
| author | Sebastien Bacher <seb128@ubuntu.com> | 2021-07-05 20:36:07 +0200 |
|---|---|---|
| committer | Sebastien Bacher <seb128@ubuntu.com> | 2021-07-05 20:36:07 +0200 |
| commit | 5d67593e4f1329fc32a36adc5dbc445e7c606bd1 (patch) | |
| tree | 5f470f020ca8f1240ddc29b11912fee174f5d68c /src/core/dhcp | |
| parent | 9996e637dc976a77c36f07c6debb737f9a5df0b7 (diff) | |
| parent | 35779c6675728fa6f0fd0a21cefb904408509c23 (diff) | |
Update upstream source from tag 'upstream/1.32.2'
Update to upstream version '1.32.2' with Debian dir db5d9d9657d75d750d835860e38c6af24cc54472
Diffstat (limited to 'src/core/dhcp')
| -rw-r--r-- | src/core/dhcp/meson.build | 7 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-client.c | 167 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-client.h | 31 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-dhclient-utils.c | 13 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-dhclient.c | 56 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-dhcpcanon.c | 5 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-dhcpcd.c | 49 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-helper.c | 10 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-listener.c | 2 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-manager.c | 107 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-manager.h | 7 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-nettools.c | 60 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-options.c | 2 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-systemd.c | 130 | ||||
| -rw-r--r-- | src/core/dhcp/nm-dhcp-utils.c | 16 | ||||
| -rw-r--r-- | src/core/dhcp/tests/test-dhcp-dhclient.c | 4 | ||||
| -rw-r--r-- | src/core/dhcp/tests/test-dhcp-utils.c | 4 |
17 files changed, 369 insertions, 301 deletions
diff --git a/src/core/dhcp/meson.build b/src/core/dhcp/meson.build index 1bb004cd..ddaa32fb 100644 --- a/src/core/dhcp/meson.build +++ b/src/core/dhcp/meson.build @@ -3,10 +3,11 @@ executable( 'nm-dhcp-helper', 'nm-dhcp-helper.c', - dependencies: glib_nm_default_dep, - c_args: [ - '-DG_LOG_DOMAIN="nm-dhcp-helper"', + include_directories: [ + src_inc, + top_inc, ], + dependencies: glib_dep, link_args: ldflags_linker_script_binary, link_depends: linker_script_binary, install: true, diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index c38c814e..ab8243d0 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -13,15 +13,16 @@ #include <stdio.h> #include <stdlib.h> #include <linux/rtnetlink.h> +#include <linux/if_ether.h> -#include "nm-glib-aux/nm-dedup-multi.h" -#include "nm-glib-aux/nm-random-utils.h" +#include "libnm-glib-aux/nm-dedup-multi.h" +#include "libnm-glib-aux/nm-random-utils.h" #include "NetworkManagerUtils.h" #include "nm-utils.h" #include "nm-dhcp-utils.h" #include "nm-dhcp-options.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" @@ -33,6 +34,7 @@ static guint signals[LAST_SIGNAL] = {0}; NM_GOBJECT_PROPERTIES_DEFINE(NMDhcpClient, PROP_ADDR_FAMILY, + PROP_ANYCAST_ADDRESS, PROP_FLAGS, PROP_HWADDR, PROP_BROADCAST_HWADDR, @@ -61,6 +63,7 @@ typedef struct _NMDhcpClientPrivate { char * hostname; const char ** reject_servers; char * mud_url; + char * anycast_address; GBytes * vendor_class_identifier; pid_t pid; guint timeout_id; @@ -73,8 +76,7 @@ typedef struct _NMDhcpClientPrivate { guint32 iaid; NMDhcpState state; NMDhcpHostnameFlags hostname_flags; - bool info_only : 1; - bool use_fqdn : 1; + NMDhcpClientFlags client_flags; bool iaid_explicit : 1; } NMDhcpClientPrivate; @@ -84,6 +86,11 @@ G_DEFINE_ABSTRACT_TYPE(NMDhcpClient, nm_dhcp_client, G_TYPE_OBJECT) /*****************************************************************************/ +/* we use pid=-1 for invalid PIDs. Ensure that pid_t can hold negative values. */ +G_STATIC_ASSERT(!(((pid_t) -1) > 0)); + +/*****************************************************************************/ + pid_t nm_dhcp_client_get_pid(NMDhcpClient *self) { @@ -277,6 +284,14 @@ nm_dhcp_client_set_client_id_bin(NMDhcpClient *self, } const char * +nm_dhcp_client_get_anycast_address(NMDhcpClient *self) +{ + g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); + + return NM_DHCP_CLIENT_GET_PRIVATE(self)->anycast_address; +} + +const char * nm_dhcp_client_get_hostname(NMDhcpClient *self) { g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NULL); @@ -292,20 +307,12 @@ nm_dhcp_client_get_hostname_flags(NMDhcpClient *self) return NM_DHCP_CLIENT_GET_PRIVATE(self)->hostname_flags; } -gboolean -nm_dhcp_client_get_info_only(NMDhcpClient *self) +NMDhcpClientFlags +nm_dhcp_client_get_client_flags(NMDhcpClient *self) { - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE); + g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), NM_DHCP_CLIENT_FLAGS_NONE); - return NM_DHCP_CLIENT_GET_PRIVATE(self)->info_only; -} - -gboolean -nm_dhcp_client_get_use_fqdn(NMDhcpClient *self) -{ - g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE); - - return NM_DHCP_CLIENT_GET_PRIVATE(self)->use_fqdn; + return NM_DHCP_CLIENT_GET_PRIVATE(self)->client_flags; } const char * @@ -334,29 +341,25 @@ nm_dhcp_client_get_reject_servers(NMDhcpClient *self) /*****************************************************************************/ -static const char *state_table[NM_DHCP_STATE_MAX + 1] = { - [NM_DHCP_STATE_UNKNOWN] = "unknown", - [NM_DHCP_STATE_BOUND] = "bound", - [NM_DHCP_STATE_EXTENDED] = "extended", - [NM_DHCP_STATE_TIMEOUT] = "timeout", - [NM_DHCP_STATE_EXPIRE] = "expire", - [NM_DHCP_STATE_DONE] = "done", - [NM_DHCP_STATE_FAIL] = "fail", - [NM_DHCP_STATE_TERMINATED] = "terminated", -}; - -static const char * -state_to_string(NMDhcpState state) -{ - if ((gsize) state < G_N_ELEMENTS(state_table)) - return state_table[state]; - return NULL; -} +NM_UTILS_LOOKUP_STR_DEFINE(nm_dhcp_state_to_string, + NMDhcpState, + NM_UTILS_LOOKUP_DEFAULT(NULL), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_BOUND, "bound"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_DONE, "done"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_EXPIRE, "expire"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_EXTENDED, "extended"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_FAIL, "fail"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_NOOP, "noop"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_TERMINATED, "terminated"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_TIMEOUT, "timeout"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_UNKNOWN, "unknown"), + NM_UTILS_LOOKUP_ITEM_IGNORE(__NM_DHCP_STATE_MAX), ); static NMDhcpState reason_to_state(NMDhcpClient *self, const char *iface, const char *reason) { - if (g_ascii_strcasecmp(reason, "bound") == 0 || g_ascii_strcasecmp(reason, "bound6") == 0) + if (g_ascii_strcasecmp(reason, "bound") == 0 || g_ascii_strcasecmp(reason, "bound6") == 0 + || g_ascii_strcasecmp(reason, "static") == 0) return NM_DHCP_STATE_BOUND; else if (g_ascii_strcasecmp(reason, "renew") == 0 || g_ascii_strcasecmp(reason, "renew6") == 0 || g_ascii_strcasecmp(reason, "reboot") == 0 @@ -488,8 +491,8 @@ nm_dhcp_client_set_state(NMDhcpClient *self, const char *addr = nm_g_hash_table_lookup(options, req_str); _LOGI("state changed %s -> %s%s%s%s", - state_to_string(priv->state), - state_to_string(new_state), + nm_dhcp_state_to_string(priv->state), + nm_dhcp_state_to_string(new_state), NM_PRINT_FMT_QUOTED(addr, ", address=", addr, "", "")); } @@ -514,20 +517,12 @@ daemon_watch_cb(GPid pid, int status, gpointer user_data) { NMDhcpClient * self = NM_DHCP_CLIENT(user_data); NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + gs_free char * desc = NULL; g_return_if_fail(priv->watch_id); priv->watch_id = 0; - if (WIFEXITED(status)) - _LOGI("client pid %d exited with status %d", pid, WEXITSTATUS(status)); - else if (WIFSIGNALED(status)) - _LOGI("client pid %d killed by signal %d", pid, WTERMSIG(status)); - else if (WIFSTOPPED(status)) - _LOGI("client pid %d stopped by signal %d", pid, WSTOPSIG(status)); - else if (WIFCONTINUED(status)) - _LOGI("client pid %d resumed (by SIGCONT)", pid); - else - _LOGW("client died abnormally"); + _LOGI("client pid %d %s", pid, (desc = nm_utils_get_process_exit_status_desc(status))); priv->pid = -1; @@ -578,7 +573,6 @@ nm_dhcp_client_stop_watch_child(NMDhcpClient *self, pid_t pid) gboolean nm_dhcp_client_start_ip4(NMDhcpClient *self, GBytes * client_id, - const char * dhcp_anycast_addr, const char * last_ip4_address, GError ** error) { @@ -598,10 +592,7 @@ nm_dhcp_client_start_ip4(NMDhcpClient *self, nm_dhcp_client_set_client_id(self, client_id); - return NM_DHCP_CLIENT_GET_CLASS(self)->ip4_start(self, - dhcp_anycast_addr, - last_ip4_address, - error); + return NM_DHCP_CLIENT_GET_CLASS(self)->ip4_start(self, last_ip4_address, error); } gboolean @@ -638,7 +629,6 @@ gboolean nm_dhcp_client_start_ip6(NMDhcpClient * self, GBytes * client_id, gboolean enforce_duid, - const char * dhcp_anycast_addr, const struct in6_addr * ll_addr, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes, @@ -667,8 +657,11 @@ nm_dhcp_client_start_ip6(NMDhcpClient * self, else _LOGI("activation: beginning transaction (timeout in %u seconds)", (guint) priv->timeout); - return NM_DHCP_CLIENT_GET_CLASS(self) - ->ip6_start(self, dhcp_anycast_addr, ll_addr, privacy, needed_prefixes, error); + return NM_DHCP_CLIENT_GET_CLASS(self)->ip6_start(self, + ll_addr, + privacy, + needed_prefixes, + error); } void @@ -749,7 +742,7 @@ nm_dhcp_client_stop(NMDhcpClient *self, gboolean release) _LOGI("canceled DHCP transaction"); nm_assert(priv->pid == -1); - nm_dhcp_client_set_state(self, NM_DHCP_STATE_DONE, NULL, NULL); + nm_dhcp_client_set_state(self, NM_DHCP_STATE_TERMINATED, NULL, NULL); } /*****************************************************************************/ @@ -898,8 +891,8 @@ nm_dhcp_client_handle_event(gpointer unused, old_state = priv->state; new_state = reason_to_state(self, priv->iface, reason); _LOGD("DHCP state '%s' -> '%s' (reason: '%s')", - state_to_string(old_state), - state_to_string(new_state), + nm_dhcp_state_to_string(old_state), + nm_dhcp_state_to_string(new_state), reason); if (new_state == NM_DHCP_STATE_NOOP) @@ -930,12 +923,12 @@ nm_dhcp_client_handle_event(gpointer unused, priv->route_metric)); } else { prefix = nm_dhcp_utils_ip6_prefix_from_options(str_options); - ip_config = NM_IP_CONFIG_CAST( - nm_dhcp_utils_ip6_config_from_options(nm_dhcp_client_get_multi_idx(self), - priv->ifindex, - priv->iface, - str_options, - priv->info_only)); + ip_config = NM_IP_CONFIG_CAST(nm_dhcp_utils_ip6_config_from_options( + nm_dhcp_client_get_multi_idx(self), + priv->ifindex, + priv->iface, + str_options, + NM_FLAGS_HAS(priv->client_flags, NM_DHCP_CLIENT_FLAGS_INFO_ONLY))); } } else g_warn_if_reached(); @@ -1052,11 +1045,8 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps case PROP_FLAGS: /* construct-only */ flags = g_value_get_uint(value); - nm_assert( - (flags & ~((guint)(NM_DHCP_CLIENT_FLAGS_INFO_ONLY | NM_DHCP_CLIENT_FLAGS_USE_FQDN))) - == 0); - priv->info_only = NM_FLAGS_HAS(flags, NM_DHCP_CLIENT_FLAGS_INFO_ONLY); - priv->use_fqdn = NM_FLAGS_HAS(flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN); + nm_assert(!NM_FLAGS_ANY(flags, ~((guint) NM_DHCP_CLIENT_FLAGS_ALL))); + priv->client_flags = flags; break; case PROP_MULTI_IDX: /* construct-only */ @@ -1080,6 +1070,10 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps /* construct-only */ priv->hwaddr = g_value_dup_boxed(value); break; + case PROP_ANYCAST_ADDRESS: + /* construct-only */ + priv->anycast_address = g_value_dup_string(value); + break; case PROP_BROADCAST_HWADDR: /* construct-only */ priv->bcast_hwaddr = g_value_dup_boxed(value); @@ -1153,6 +1147,28 @@ nm_dhcp_client_init(NMDhcpClient *self) priv->pid = -1; } +#if NM_MORE_ASSERTS +static void +constructed(GObject *object) +{ + NMDhcpClient * self = NM_DHCP_CLIENT(object); + NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self); + + /* certain flags only make sense with certain address family. Assert + * for that. */ + if (NM_IS_IPv4(priv->addr_family)) + nm_assert(!NM_FLAGS_ANY(priv->client_flags, NM_DHCP_CLIENT_FLAGS_INFO_ONLY)); + else { + nm_assert(NM_FLAGS_HAS(priv->client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN)); + nm_assert(!NM_FLAGS_ANY(priv->client_flags, NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)); + } + + nm_assert(!priv->anycast_address || nm_utils_hwaddr_valid(priv->anycast_address, ETH_ALEN)); + + G_OBJECT_CLASS(nm_dhcp_client_parent_class)->constructed(object); +} +#endif + static void dispose(GObject *object) { @@ -1172,6 +1188,7 @@ dispose(GObject *object) nm_clear_g_free(&priv->iface); nm_clear_g_free(&priv->hostname); nm_clear_g_free(&priv->uuid); + nm_clear_g_free(&priv->anycast_address); nm_clear_g_free(&priv->mud_url); nm_clear_g_free(&priv->reject_servers); nm_clear_pointer(&priv->client_id, g_bytes_unref); @@ -1191,6 +1208,9 @@ nm_dhcp_client_class_init(NMDhcpClientClass *client_class) g_type_class_add_private(client_class, sizeof(NMDhcpClientPrivate)); +#if NM_MORE_ASSERTS + object_class->constructed = constructed; +#endif object_class->dispose = dispose; object_class->get_property = get_property; object_class->set_property = set_property; @@ -1243,6 +1263,13 @@ nm_dhcp_client_class_init(NMDhcpClientClass *client_class) AF_UNSPEC, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_ANYCAST_ADDRESS] = + g_param_spec_string(NM_DHCP_CLIENT_ANYCAST_ADDRESS, + "", + "", + NULL, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_UUID] = g_param_spec_string(NM_DHCP_CLIENT_UUID, "", diff --git a/src/core/dhcp/nm-dhcp-client.h b/src/core/dhcp/nm-dhcp-client.h index 72ab477d..3fe1b34e 100644 --- a/src/core/dhcp/nm-dhcp-client.h +++ b/src/core/dhcp/nm-dhcp-client.h @@ -25,6 +25,7 @@ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClientClass)) #define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family" +#define NM_DHCP_CLIENT_ANYCAST_ADDRESS "anycast-address" #define NM_DHCP_CLIENT_FLAGS "flags" #define NM_DHCP_CLIENT_HWADDR "hwaddr" #define NM_DHCP_CLIENT_BROADCAST_HWADDR "broadcast-hwaddr" @@ -51,7 +52,7 @@ typedef enum { NM_DHCP_STATE_BOUND, /* new lease */ NM_DHCP_STATE_EXTENDED, /* lease extended */ NM_DHCP_STATE_TIMEOUT, /* timed out contacting server */ - NM_DHCP_STATE_DONE, /* client quit or stopped */ + NM_DHCP_STATE_DONE, /* client reported it's stopping */ NM_DHCP_STATE_EXPIRE, /* lease expired or NAKed */ NM_DHCP_STATE_FAIL, /* failed for some reason */ NM_DHCP_STATE_TERMINATED, /* client is no longer running */ @@ -60,6 +61,8 @@ typedef enum { NM_DHCP_STATE_MAX = __NM_DHCP_STATE_MAX - 1, } NMDhcpState; +const char *nm_dhcp_state_to_string(NMDhcpState state); + struct _NMDhcpClientPrivate; typedef struct { @@ -68,25 +71,27 @@ typedef struct { CList dhcp_client_lst; } NMDhcpClient; -typedef enum { - NM_DHCP_CLIENT_FLAGS_INFO_ONLY = (1LL << 0), - NM_DHCP_CLIENT_FLAGS_USE_FQDN = (1LL << 1), +typedef enum _nm_packed { + NM_DHCP_CLIENT_FLAGS_NONE = 0, + + NM_DHCP_CLIENT_FLAGS_INFO_ONLY = (1LL << 0), + NM_DHCP_CLIENT_FLAGS_USE_FQDN = (1LL << 1), + NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST = (1LL << 2), + + _NM_DHCP_CLIENT_FLAGS_LAST, + NM_DHCP_CLIENT_FLAGS_ALL = ((_NM_DHCP_CLIENT_FLAGS_LAST - 1) << 1) - 1, } NMDhcpClientFlags; typedef struct { GObjectClass parent; - gboolean (*ip4_start)(NMDhcpClient *self, - const char * anycast_addr, - const char * last_ip4_address, - GError ** error); + gboolean (*ip4_start)(NMDhcpClient *self, const char *last_ip4_address, GError **error); gboolean (*accept)(NMDhcpClient *self, GError **error); gboolean (*decline)(NMDhcpClient *self, const char *error_message, GError **error); gboolean (*ip6_start)(NMDhcpClient * self, - const char * anycast_addr, const struct in6_addr * ll_addr, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes, @@ -126,6 +131,8 @@ GBytes *nm_dhcp_client_get_hw_addr(NMDhcpClient *self); GBytes *nm_dhcp_client_get_broadcast_hw_addr(NMDhcpClient *self); +const char *nm_dhcp_client_get_anycast_address(NMDhcpClient *self); + guint32 nm_dhcp_client_get_route_table(NMDhcpClient *self); void nm_dhcp_client_set_route_table(NMDhcpClient *self, guint32 route_table); @@ -148,22 +155,18 @@ const char *const *nm_dhcp_client_get_reject_servers(NMDhcpClient *self); NMDhcpHostnameFlags nm_dhcp_client_get_hostname_flags(NMDhcpClient *self); -gboolean nm_dhcp_client_get_info_only(NMDhcpClient *self); - -gboolean nm_dhcp_client_get_use_fqdn(NMDhcpClient *self); +NMDhcpClientFlags nm_dhcp_client_get_client_flags(NMDhcpClient *self); GBytes *nm_dhcp_client_get_vendor_class_identifier(NMDhcpClient *self); gboolean nm_dhcp_client_start_ip4(NMDhcpClient *self, GBytes * client_id, - const char * dhcp_anycast_addr, const char * last_ip4_address, GError ** error); gboolean nm_dhcp_client_start_ip6(NMDhcpClient * self, GBytes * client_id, gboolean enforce_duid, - const char * dhcp_anycast_addr, const struct in6_addr * ll_addr, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes, diff --git a/src/core/dhcp/nm-dhcp-dhclient-utils.c b/src/core/dhcp/nm-dhcp-dhclient-utils.c index ad1e097f..4284a852 100644 --- a/src/core/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/core/dhcp/nm-dhcp-dhclient-utils.c @@ -12,12 +12,12 @@ #include <net/if.h> #include <linux/if_ether.h> -#include "nm-glib-aux/nm-dedup-multi.h" +#include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-dhcp-utils.h" #include "nm-ip4-config.h" #include "nm-utils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "NetworkManagerUtils.h" #define TIMEOUT_TAG "timeout " @@ -291,7 +291,7 @@ char * nm_dhcp_dhclient_create_config(const char * interface, int addr_family, GBytes * client_id, - const char * anycast_addr, + const char * anycast_address, const char * hostname, guint32 timeout, gboolean use_fqdn, @@ -308,7 +308,8 @@ nm_dhcp_dhclient_create_config(const char * interface, gboolean reset_reqlist = FALSE; int i; - g_return_val_if_fail(!anycast_addr || nm_utils_hwaddr_valid(anycast_addr, ETH_ALEN), NULL); + g_return_val_if_fail(!anycast_address || nm_utils_hwaddr_valid(anycast_address, ETH_ALEN), + NULL); g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), NULL); g_return_val_if_fail(!reject_servers || addr_family == AF_INET, NULL); nm_assert(!out_new_client_id || !*out_new_client_id); @@ -508,14 +509,14 @@ nm_dhcp_dhclient_create_config(const char * interface, g_string_append_c(new_contents, '\n'); - if (anycast_addr) { + if (anycast_address) { g_string_append_printf(new_contents, "interface \"%s\" {\n" " initial-interval 1; \n" " anycast-mac ethernet %s;\n" "}\n", interface, - anycast_addr); + anycast_address); } return g_string_free(g_steal_pointer(&new_contents), FALSE); diff --git a/src/core/dhcp/nm-dhcp-dhclient.c b/src/core/dhcp/nm-dhcp-dhclient.c index c42a0ba5..4a11250f 100644 --- a/src/core/dhcp/nm-dhcp-dhclient.c +++ b/src/core/dhcp/nm-dhcp-dhclient.c @@ -21,7 +21,7 @@ #include <arpa/inet.h> #include <ctype.h> - #include "nm-glib-aux/nm-dedup-multi.h" + #include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-utils.h" #include "nm-dhcp-dhclient-utils.h" @@ -151,7 +151,7 @@ merge_dhclient_config(NMDhcpDhclient * self, const char * iface, const char * conf_file, GBytes * client_id, - const char * anycast_addr, + const char * anycast_address, const char * hostname, guint32 timeout, gboolean use_fqdn, @@ -180,7 +180,7 @@ merge_dhclient_config(NMDhcpDhclient * self, new = nm_dhcp_dhclient_create_config(iface, addr_family, client_id, - anycast_addr, + anycast_address, hostname, timeout, use_fqdn, @@ -280,7 +280,7 @@ create_dhclient_config(NMDhcpDhclient * self, const char * iface, const char * uuid, GBytes * client_id, - const char * dhcp_anycast_addr, + const char * anycast_address, const char * hostname, guint32 timeout, gboolean use_fqdn, @@ -312,7 +312,7 @@ create_dhclient_config(NMDhcpDhclient * self, iface, new, client_id, - dhcp_anycast_addr, + anycast_address, hostname, timeout, use_fqdn, @@ -435,6 +435,12 @@ dhclient_start(NMDhcpClient *client, if (release) g_ptr_array_add(argv, (gpointer) "-r"); + if (!release + && NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), + NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)) { + g_ptr_array_add(argv, (gpointer) "-B"); + } + if (addr_family == AF_INET6) { g_ptr_array_add(argv, (gpointer) "-6"); @@ -508,10 +514,7 @@ dhclient_start(NMDhcpClient *client, } static gboolean -ip4_start(NMDhcpClient *client, - const char * dhcp_anycast_addr, - const char * last_ip4_address, - GError ** error) +ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) { NMDhcpDhclient * self = NM_DHCP_DHCLIENT(client); NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE(self); @@ -520,19 +523,20 @@ ip4_start(NMDhcpClient *client, client_id = nm_dhcp_client_get_client_id(client); - priv->conf_file = create_dhclient_config(self, - AF_INET, - nm_dhcp_client_get_iface(client), - nm_dhcp_client_get_uuid(client), - client_id, - dhcp_anycast_addr, - nm_dhcp_client_get_hostname(client), - nm_dhcp_client_get_timeout(client), - nm_dhcp_client_get_use_fqdn(client), - nm_dhcp_client_get_hostname_flags(client), - nm_dhcp_client_get_mud_url(client), - nm_dhcp_client_get_reject_servers(client), - &new_client_id); + priv->conf_file = create_dhclient_config( + self, + AF_INET, + nm_dhcp_client_get_iface(client), + nm_dhcp_client_get_uuid(client), + client_id, + nm_dhcp_client_get_anycast_address(client), + nm_dhcp_client_get_hostname(client), + nm_dhcp_client_get_timeout(client), + NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_USE_FQDN), + nm_dhcp_client_get_hostname_flags(client), + nm_dhcp_client_get_mud_url(client), + nm_dhcp_client_get_reject_servers(client), + &new_client_id); if (!priv->conf_file) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_UNKNOWN, @@ -549,7 +553,6 @@ ip4_start(NMDhcpClient *client, static gboolean ip6_start(NMDhcpClient * client, - const char * dhcp_anycast_addr, const struct in6_addr * ll_addr, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes, @@ -566,7 +569,7 @@ ip6_start(NMDhcpClient * client, nm_dhcp_client_get_iface(client), nm_dhcp_client_get_uuid(client), NULL, - dhcp_anycast_addr, + nm_dhcp_client_get_anycast_address(client), nm_dhcp_client_get_hostname(client), nm_dhcp_client_get_timeout(client), TRUE, @@ -582,7 +585,10 @@ ip6_start(NMDhcpClient * client, } return dhclient_start(client, - nm_dhcp_client_get_info_only(NM_DHCP_CLIENT(self)) ? "-S" : "-N", + NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), + NM_DHCP_CLIENT_FLAGS_INFO_ONLY) + ? "-S" + : "-N", FALSE, NULL, needed_prefixes, diff --git a/src/core/dhcp/nm-dhcp-dhcpcanon.c b/src/core/dhcp/nm-dhcp-dhcpcanon.c index 3504a048..f3a52ea9 100644 --- a/src/core/dhcp/nm-dhcp-dhcpcanon.c +++ b/src/core/dhcp/nm-dhcp-dhcpcanon.c @@ -161,10 +161,7 @@ dhcpcanon_start(NMDhcpClient *client, } static gboolean -ip4_start(NMDhcpClient *client, - const char * dhcp_anycast_addr, - const char * last_ip4_address, - GError ** error) +ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) { return dhcpcanon_start(client, NULL, NULL, FALSE, NULL, 0, error); } diff --git a/src/core/dhcp/nm-dhcp-dhcpcd.c b/src/core/dhcp/nm-dhcp-dhcpcd.c index cf9fe5c2..605fb84d 100644 --- a/src/core/dhcp/nm-dhcp-dhcpcd.c +++ b/src/core/dhcp/nm-dhcp-dhcpcd.c @@ -65,10 +65,7 @@ nm_dhcp_dhcpcd_get_path(void) } static gboolean -ip4_start(NMDhcpClient *client, - const char * dhcp_anycast_addr, - const char * last_ip4_address, - GError ** error) +ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) { NMDhcpDhcpcd * self = NM_DHCP_DHCPCD(client); gs_unref_ptrarray GPtrArray *argv = NULL; @@ -122,7 +119,7 @@ ip4_start(NMDhcpClient *client, hostname = nm_dhcp_client_get_hostname(client); if (hostname) { - if (nm_dhcp_client_get_use_fqdn(client)) { + if (NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_USE_FQDN)) { g_ptr_array_add(argv, (gpointer) "-h"); g_ptr_array_add(argv, (gpointer) hostname); g_ptr_array_add(argv, (gpointer) "-F"); @@ -169,27 +166,29 @@ stop(NMDhcpClient *client, gboolean release) int sig, errsv; pid = nm_dhcp_client_get_pid(client); - sig = release ? SIGALRM : SIGTERM; - _LOGD("sending %s to dhcpcd pid %d", sig == SIGALRM ? "SIGALRM" : "SIGTERM", pid); - - /* dhcpcd-9.x features privilege separation. - * It's not our job to track all these processes so we rely on dhcpcd - * to always cleanup after itself. - * Because it also re-parents itself to PID 1, the process cannot be - * reaped or waited for. - * As such, just send the correct signal. - */ - if (kill(pid, sig) == -1) { - errsv = errno; - _LOGE("failed to kill dhcpcd %d:%s", errsv, strerror(errsv)); - } + if (pid > 1) { + sig = release ? SIGALRM : SIGTERM; + _LOGD("sending %s to dhcpcd pid %d", sig == SIGALRM ? "SIGALRM" : "SIGTERM", pid); + + /* dhcpcd-9.x features privilege separation. + * It's not our job to track all these processes so we rely on dhcpcd + * to always cleanup after itself. + * Because it also re-parents itself to PID 1, the process cannot be + * reaped or waited for. + * As such, just send the correct signal. + */ + if (kill(pid, sig) == -1) { + errsv = errno; + _LOGE("failed to kill dhcpcd %d:%s", errsv, strerror(errsv)); + } - /* When this function exits NM expects the PID to be -1. - * This means we also need to stop watching the pid. - * If we need to know the exit status then we need to refactor NM - * to allow a non -1 to mean we're waiting to exit still. - */ - nm_dhcp_client_stop_watch_child(client, pid); + /* When this function exits NM expects the PID to be -1. + * This means we also need to stop watching the pid. + * If we need to know the exit status then we need to refactor NM + * to allow a non -1 to mean we're waiting to exit still. + */ + nm_dhcp_client_stop_watch_child(client, pid); + } } /*****************************************************************************/ diff --git a/src/core/dhcp/nm-dhcp-helper.c b/src/core/dhcp/nm-dhcp-helper.c index 0f98add1..56d20101 100644 --- a/src/core/dhcp/nm-dhcp-helper.c +++ b/src/core/dhcp/nm-dhcp-helper.c @@ -3,13 +3,13 @@ * Copyright (C) 2007 - 2013 Red Hat, Inc. */ -#include "nm-glib-aux/nm-default-glib.h" +#include "libnm-glib-aux/nm-default-glib.h" #include <unistd.h> #include <stdlib.h> #include <signal.h> -#include "nm-utils/nm-vpn-plugin-macros.h" +#include "libnm-glib-aux/nm-logging-syslog.h" #include "nm-dhcp-helper-api.h" @@ -92,7 +92,7 @@ build_signal_parameters(void) g_variant_builder_add(&builder, "{sv}", name, - g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, val, strlen(val), 1)); + nm_g_variant_new_ay((const guint8 *) val, strlen(val))); next:; } @@ -154,7 +154,7 @@ do_connect: error->message, try_count, (long long) (time_end - time_remaining - time_start) / 1000); - interval = NM_CLAMP((gint64)(100L * (1L << NM_MIN(try_count, 31))), 5000, 100000); + interval = NM_CLAMP((gint64) (100L * (1L << NM_MIN(try_count, 31))), 5000, 100000); g_usleep(NM_MIN(interval, time_remaining)); g_clear_error(&error); goto do_connect; @@ -199,7 +199,7 @@ do_notify: * do some retry. */ if (remaining_time > 0) { _LOGi("failure to call notify: %s (retry %u)", error->message, try_count); - interval = NM_CLAMP((gint64)(100L * (1L << NM_MIN(try_count, 31))), 5000, 25000); + interval = NM_CLAMP((gint64) (100L * (1L << NM_MIN(try_count, 31))), 5000, 25000); g_usleep(NM_MIN(interval, remaining_time)); g_clear_error(&error); goto do_notify; diff --git a/src/core/dhcp/nm-dhcp-listener.c b/src/core/dhcp/nm-dhcp-listener.c index 1673bbb7..b8bb3c33 100644 --- a/src/core/dhcp/nm-dhcp-listener.c +++ b/src/core/dhcp/nm-dhcp-listener.c @@ -16,7 +16,7 @@ #include "nm-dhcp-helper-api.h" #include "nm-dhcp-client.h" #include "nm-dhcp-manager.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" #include "nm-dbus-manager.h" #include "NetworkManagerUtils.h" diff --git a/src/core/dhcp/nm-dhcp-manager.c b/src/core/dhcp/nm-dhcp-manager.c index bc114ad8..44b8ede2 100644 --- a/src/core/dhcp/nm-dhcp-manager.c +++ b/src/core/dhcp/nm-dhcp-manager.c @@ -16,8 +16,8 @@ #include <fcntl.h> #include <stdio.h> -#include "nm-glib-aux/nm-dedup-multi.h" -#include "systemd/nm-sd-utils-shared.h" +#include "libnm-glib-aux/nm-dedup-multi.h" +#include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "nm-config.h" #include "NetworkManagerUtils.h" @@ -213,12 +213,11 @@ client_start(NMDhcpManager * self, guint32 iaid, gboolean iaid_explicit, guint32 timeout, - const char * dhcp_anycast_addr, + NMDhcpClientFlags client_flags, + const char * anycast_address, const char * hostname, - gboolean hostname_use_fqdn, NMDhcpHostnameFlags hostname_flags, const char * mud_url, - gboolean info_only, NMSettingIP6ConfigPrivacy privacy, const char * last_ip4_address, guint needed_prefixes, @@ -241,6 +240,7 @@ client_start(NMDhcpManager * self, || g_bytes_get_size(vendor_class_identifier) <= 255, NULL); g_return_val_if_fail(!error || !*error, NULL); + nm_assert(!NM_FLAGS_ANY(client_flags, ~NM_DHCP_CLIENT_FLAGS_ALL)); if (addr_family == AF_INET) { if (!hwaddr || !bcast_hwaddr) { @@ -252,7 +252,7 @@ client_start(NMDhcpManager * self, } hwaddr_len = g_bytes_get_size(hwaddr); - if (hwaddr_len == 0 || hwaddr_len > NM_UTILS_HWADDR_LEN_MAX) { + if (hwaddr_len == 0 || hwaddr_len > _NM_UTILS_HWADDR_LEN_MAX) { nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "invalid MAC address"); g_return_val_if_reached(NULL); } @@ -263,12 +263,14 @@ client_start(NMDhcpManager * self, } if (hostname) { - if ((hostname_use_fqdn && !nm_sd_dns_name_is_valid(hostname)) - || (!hostname_use_fqdn && !nm_sd_hostname_is_valid(hostname, FALSE))) { + gboolean use_fqdn = NM_FLAGS_HAS(client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN); + + if ((use_fqdn && !nm_sd_dns_name_is_valid(hostname)) + || (!use_fqdn && !nm_sd_hostname_is_valid(hostname, FALSE))) { nm_log_warn(LOGD_DHCP, "dhcp%c: %s '%s' is invalid, will be ignored", nm_utils_addr_family_to_char(addr_family), - hostname_use_fqdn ? "FQDN" : "hostname", + use_fqdn ? "FQDN" : "hostname", hostname); hostname = NULL; } @@ -334,8 +336,9 @@ client_start(NMDhcpManager * self, NM_DHCP_CLIENT_REJECT_SERVERS, reject_servers, NM_DHCP_CLIENT_FLAGS, - (guint)(0 | (hostname_use_fqdn ? NM_DHCP_CLIENT_FLAGS_USE_FQDN : 0) - | (info_only ? NM_DHCP_CLIENT_FLAGS_INFO_ONLY : 0)), + (guint) client_flags, + NM_DHCP_CLIENT_ANYCAST_ADDRESS, + anycast_address, NULL); nm_assert(client && c_list_is_empty(&client->dhcp_client_lst)); c_list_link_tail(&priv->dhcp_client_lst_head, &client->dhcp_client_lst); @@ -371,16 +374,11 @@ client_start(NMDhcpManager * self, */ if (addr_family == AF_INET) { - success = nm_dhcp_client_start_ip4(client, - dhcp_client_id, - dhcp_anycast_addr, - last_ip4_address, - error); + success = nm_dhcp_client_start_ip4(client, dhcp_client_id, last_ip4_address, error); } else { success = nm_dhcp_client_start_ip6(client, dhcp_client_id, enforce_duid, - dhcp_anycast_addr, ipv6_ll_addr, privacy, needed_prefixes, @@ -406,6 +404,7 @@ nm_dhcp_manager_start_ip4(NMDhcpManager * self, const char * uuid, guint32 route_table, guint32 route_metric, + NMDhcpClientFlags client_flags, gboolean send_hostname, const char * dhcp_hostname, const char * dhcp_fqdn, @@ -413,7 +412,7 @@ nm_dhcp_manager_start_ip4(NMDhcpManager * self, const char * mud_url, GBytes * dhcp_client_id, guint32 timeout, - const char * dhcp_anycast_addr, + const char * anycast_address, const char * last_ip_address, GBytes * vendor_class_identifier, const char *const * reject_servers, @@ -425,6 +424,10 @@ nm_dhcp_manager_start_ip4(NMDhcpManager * self, gboolean use_fqdn = FALSE; char * dot; + /* these flags are set automatically/prohibited, and not free to set to the caller. */ + nm_assert(!NM_FLAGS_ANY(client_flags, + NM_DHCP_CLIENT_FLAGS_USE_FQDN | NM_DHCP_CLIENT_FLAGS_INFO_ONLY)); + g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL); priv = NM_DHCP_MANAGER_GET_PRIVATE(self); @@ -451,34 +454,34 @@ nm_dhcp_manager_start_ip4(NMDhcpManager * self, } } - return client_start(self, - AF_INET, - multi_idx, - iface, - ifindex, - hwaddr, - bcast_hwaddr, - uuid, - route_table, - route_metric, - NULL, - dhcp_client_id, - FALSE, - 0, - FALSE, - timeout, - dhcp_anycast_addr, - hostname, - use_fqdn, - hostname_flags, - mud_url, - FALSE, - 0, - last_ip_address, - 0, - vendor_class_identifier, - reject_servers, - error); + return client_start( + self, + AF_INET, + multi_idx, + iface, + ifindex, + hwaddr, + bcast_hwaddr, + uuid, + route_table, + route_metric, + NULL, + dhcp_client_id, + FALSE, + 0, + FALSE, + timeout, + client_flags | (use_fqdn ? NM_DHCP_CLIENT_FLAGS_USE_FQDN : NM_DHCP_CLIENT_FLAGS_NONE), + anycast_address, + hostname, + hostname_flags, + mud_url, + 0, + last_ip_address, + 0, + vendor_class_identifier, + reject_servers, + error); } /* Caller owns a reference to the NMDhcpClient on return */ @@ -491,6 +494,7 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self, const char * uuid, guint32 route_table, guint32 route_metric, + NMDhcpClientFlags client_flags, gboolean send_hostname, const char * dhcp_hostname, NMDhcpHostnameFlags hostname_flags, @@ -500,8 +504,7 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self, guint32 iaid, gboolean iaid_explicit, guint32 timeout, - const char * dhcp_anycast_addr, - gboolean info_only, + const char * anycast_address, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes, GError ** error) @@ -509,6 +512,9 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self, NMDhcpManagerPrivate *priv; const char * hostname = NULL; + /* this flag is set automatically, and not free to set to the caller. */ + nm_assert(!NM_FLAGS_ANY(client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN)); + g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL); priv = NM_DHCP_MANAGER_GET_PRIVATE(self); @@ -532,12 +538,11 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self, iaid, iaid_explicit, timeout, - dhcp_anycast_addr, + client_flags | NM_DHCP_CLIENT_FLAGS_USE_FQDN, + anycast_address, hostname, - TRUE, hostname_flags, mud_url, - info_only, privacy, NULL, needed_prefixes, diff --git a/src/core/dhcp/nm-dhcp-manager.h b/src/core/dhcp/nm-dhcp-manager.h index f7aba8a0..ce160437 100644 --- a/src/core/dhcp/nm-dhcp-manager.h +++ b/src/core/dhcp/nm-dhcp-manager.h @@ -41,6 +41,7 @@ NMDhcpClient *nm_dhcp_manager_start_ip4(NMDhcpManager * manager, const char * uuid, guint32 route_table, guint32 route_metric, + NMDhcpClientFlags client_flags, gboolean send_hostname, const char * dhcp_hostname, const char * dhcp_fqdn, @@ -48,7 +49,7 @@ NMDhcpClient *nm_dhcp_manager_start_ip4(NMDhcpManager * manager, const char * mud_url, GBytes * dhcp_client_id, guint32 timeout, - const char * dhcp_anycast_addr, + const char * anycast_address, const char * last_ip_address, GBytes * vendor_class_identifier, const char *const * reject_servers, @@ -62,6 +63,7 @@ NMDhcpClient *nm_dhcp_manager_start_ip6(NMDhcpManager * manager, const char * uuid, guint32 route_table, guint32 route_metric, + NMDhcpClientFlags client_flags, gboolean send_hostname, const char * dhcp_hostname, NMDhcpHostnameFlags hostname_flags, @@ -71,8 +73,7 @@ NMDhcpClient *nm_dhcp_manager_start_ip6(NMDhcpManager * manager, guint32 iaid, gboolean iaid_explicit, guint32 timeout, - const char * dhcp_anycast_addr, - gboolean info_only, + const char * anycast_address, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes, GError ** error); diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c index 116e1bdb..fe71f587 100644 --- a/src/core/dhcp/nm-dhcp-nettools.c +++ b/src/core/dhcp/nm-dhcp-nettools.c @@ -13,9 +13,9 @@ #include <ctype.h> #include <net/if_arp.h> -#include "nm-glib-aux/nm-dedup-multi.h" -#include "nm-std-aux/unaligned.h" -#include "nm-glib-aux/nm-str-buf.h" +#include "libnm-glib-aux/nm-dedup-multi.h" +#include "libnm-std-aux/unaligned.h" +#include "libnm-glib-aux/nm-str-buf.h" #include "nm-utils.h" #include "nm-config.h" @@ -23,11 +23,11 @@ #include "nm-dhcp-options.h" #include "nm-core-utils.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" #include "n-dhcp4/src/n-dhcp4.h" -#include "systemd/nm-sd-utils-shared.h" -#include "systemd/nm-sd-utils-dhcp.h" +#include "libnm-systemd-shared/nm-sd-utils-shared.h" +#include "libnm-systemd-core/nm-sd-utils-dhcp.h" /*****************************************************************************/ @@ -342,16 +342,16 @@ lease_parse_routes(NDhcp4ClientLease *lease, const guint8 *l_data; gsize l_data_len; int r; + guint i; - r = _client_lease_query(lease, - NM_DHCP_OPTION_DHCP4_CLASSLESS_STATIC_ROUTE, - &l_data, - &l_data_len); - if (r == 0) { - nm_str_buf_reset(sbuf); + for (i = 0; i < 2; i++) { + const guint8 option_code = (i == 0) ? NM_DHCP_OPTION_DHCP4_CLASSLESS_STATIC_ROUTE + : NM_DHCP_OPTION_DHCP4_PRIVATE_CLASSLESS_STATIC_ROUTE; - has_classless = TRUE; + if (_client_lease_query(lease, option_code, &l_data, &l_data_len) != 0) + continue; + nm_str_buf_reset(sbuf); while (lease_option_consume_route(&l_data, &l_data_len, TRUE, &dest, &plen, &gateway)) { _nm_utils_inet4_ntop(dest, dest_str); _nm_utils_inet4_ntop(gateway, gateway_str); @@ -359,6 +359,11 @@ lease_parse_routes(NDhcp4ClientLease *lease, nm_str_buf_append_required_delimiter(sbuf, ' '); nm_str_buf_append_printf(sbuf, "%s/%d %s", dest_str, (int) plen, gateway_str); + if (has_classless) { + /* Ignore private option if the standard one is present */ + continue; + } + if (plen == 0) { /* if there are multiple default routes, we add them with differing * metrics. */ @@ -384,10 +389,8 @@ lease_parse_routes(NDhcp4ClientLease *lease, NULL); } - nm_dhcp_option_add_option(options, - AF_INET, - NM_DHCP_OPTION_DHCP4_CLASSLESS_STATIC_ROUTE, - nm_str_buf_get_str(sbuf)); + has_classless = TRUE; + nm_dhcp_option_add_option(options, AF_INET, option_code, nm_str_buf_get_str(sbuf)); } r = _client_lease_query(lease, NM_DHCP_OPTION_DHCP4_STATIC_ROUTE, &l_data, &l_data_len); @@ -693,8 +696,8 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, v_str = nm_utils_buf_utf8safe_escape((char *) l_data, l_data_len, 0, &to_free); - nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_NIS_DOMAIN, v_str); - nm_ip4_config_set_nis_domain(ip4_config, v_str); + nm_dhcp_option_add_option(options, AF_INET, NM_DHCP_OPTION_DHCP4_NIS_DOMAIN, v_str ?: ""); + nm_ip4_config_set_nis_domain(ip4_config, v_str ?: ""); } lease_parse_address_list(lease, ip4_config, NM_DHCP_OPTION_DHCP4_NIS_SERVERS, options, &sbuf); @@ -871,7 +874,7 @@ dhcp4_event_cb(int fd, GIOCondition condition, gpointer user_data) } static gboolean -nettools_create(NMDhcpNettools *self, const char *dhcp_anycast_addr, GError **error) +nettools_create(NMDhcpNettools *self, GError **error) { NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); nm_auto(n_dhcp4_client_config_freep) NDhcp4ClientConfig *config = NULL; @@ -890,6 +893,8 @@ nettools_create(NMDhcpNettools *self, const char *dhcp_anycast_addr, GError **er g_return_val_if_fail(!priv->client, FALSE); + /* TODO: honor nm_dhcp_client_get_anycast_address() */ + hwaddr = nm_dhcp_client_get_hw_addr(NM_DHCP_CLIENT(self)); if (!hwaddr || !(hwaddr_arr = g_bytes_get_data(hwaddr, &hwaddr_len)) || (arp_type = nm_utils_arp_type_detect_from_hwaddrlen(hwaddr_len)) < 0) { @@ -938,9 +943,13 @@ nettools_create(NMDhcpNettools *self, const char *dhcp_anycast_addr, GError **er n_dhcp4_client_config_set_transport(config, transport); n_dhcp4_client_config_set_mac(config, hwaddr_arr, hwaddr_len); n_dhcp4_client_config_set_broadcast_mac(config, bcast_hwaddr_arr, bcast_hwaddr_len); + n_dhcp4_client_config_set_request_broadcast( + config, + NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), + NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)); r = n_dhcp4_client_config_set_client_id(config, client_id_arr, - NM_MIN(client_id_len, 1 + _NM_SD_MAX_CLIENT_ID_LEN)); + NM_MIN(client_id_len, 1 + _NM_MAX_CLIENT_ID_LEN)); if (r) { set_error_nettools(error, r, "failed to set client-id"); return FALSE; @@ -1028,10 +1037,7 @@ fqdn_flags_to_wire(NMDhcpHostnameFlags flags) } static gboolean -ip4_start(NMDhcpClient *client, - const char * dhcp_anycast_addr, - const char * last_ip4_address, - GError ** error) +ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) { nm_auto(n_dhcp4_client_probe_config_freep) NDhcp4ClientProbeConfig *config = NULL; NMDhcpNettools * self = NM_DHCP_NETTOOLS(client); @@ -1045,7 +1051,7 @@ ip4_start(NMDhcpClient *client, g_return_val_if_fail(!priv->probe, FALSE); - if (!nettools_create(self, dhcp_anycast_addr, error)) + if (!nettools_create(self, error)) return FALSE; r = n_dhcp4_client_probe_config_new(&config); @@ -1110,7 +1116,7 @@ ip4_start(NMDhcpClient *client, } hostname = nm_dhcp_client_get_hostname(client); if (hostname) { - if (nm_dhcp_client_get_use_fqdn(client)) { + if (NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_USE_FQDN)) { uint8_t buffer[255]; NMDhcpHostnameFlags flags; size_t fqdn_len; diff --git a/src/core/dhcp/nm-dhcp-options.c b/src/core/dhcp/nm-dhcp-options.c index 3537cd14..8f0d7408 100644 --- a/src/core/dhcp/nm-dhcp-options.c +++ b/src/core/dhcp/nm-dhcp-options.c @@ -7,7 +7,7 @@ #include "nm-dhcp-options.h" -#include "nm-glib-aux/nm-str-buf.h" +#include "libnm-glib-aux/nm-str-buf.h" /*****************************************************************************/ diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c index b92a9073..c789aaee 100644 --- a/src/core/dhcp/nm-dhcp-systemd.c +++ b/src/core/dhcp/nm-dhcp-systemd.c @@ -13,18 +13,18 @@ #include <ctype.h> #include <net/if_arp.h> -#include "nm-glib-aux/nm-dedup-multi.h" -#include "nm-std-aux/unaligned.h" +#include "libnm-glib-aux/nm-dedup-multi.h" +#include "libnm-std-aux/unaligned.h" #include "nm-utils.h" #include "nm-dhcp-utils.h" #include "nm-dhcp-options.h" #include "nm-core-utils.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" -#include "systemd/nm-sd.h" -#include "systemd/nm-sd-utils-dhcp.h" +#include "libnm-systemd-core/nm-sd.h" +#include "libnm-systemd-core/nm-sd-utils-dhcp.h" /*****************************************************************************/ @@ -85,29 +85,29 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, const struct in_addr * addr_list; char addr_str[NM_UTILS_INET_ADDRSTRLEN]; const char * s; - nm_auto_free_gstring GString *str = NULL; - gs_free sd_dhcp_route **routes = NULL; - const char *const * search_domains = NULL; - guint16 mtu; - int i, num; - const void * data; - gsize data_len; - gboolean metered = FALSE; - gboolean has_router_from_classless = FALSE; - gboolean has_classless_route = FALSE; - gboolean has_static_route = FALSE; - const gint32 ts = nm_utils_get_monotonic_timestamp_sec(); - gint64 ts_time = time(NULL); - struct in_addr a_address; - struct in_addr a_netmask; - struct in_addr a_next_server; - struct in_addr server_id; - struct in_addr broadcast; - const struct in_addr * a_router; - guint32 a_plen; - guint32 a_lifetime; - guint32 renewal; - guint32 rebinding; + nm_auto_free_gstring GString *str = NULL; + nm_auto_free sd_dhcp_route **routes = NULL; + const char *const * search_domains = NULL; + guint16 mtu; + int i, num; + const void * data; + gsize data_len; + gboolean metered = FALSE; + gboolean has_router_from_classless = FALSE; + gboolean has_classless_route = FALSE; + gboolean has_static_route = FALSE; + const gint32 ts = nm_utils_get_monotonic_timestamp_sec(); + gint64 ts_time = time(NULL); + struct in_addr a_address; + struct in_addr a_netmask; + struct in_addr a_next_server; + struct in_addr server_id; + struct in_addr broadcast; + const struct in_addr * a_router; + guint32 a_plen; + guint32 a_lifetime; + guint32 renewal; + guint32 rebinding; gs_free nm_sd_dhcp_option *private_options = NULL; nm_assert(lease != NULL); @@ -153,7 +153,7 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, nm_dhcp_option_add_option_u64(options, AF_INET, NM_DHCP_OPTION_DHCP4_NM_EXPIRY, - (guint64)(ts_time + a_lifetime)); + (guint64) (ts_time + a_lifetime)); if (sd_dhcp_lease_get_next_server(lease, &a_next_server) == 0) { _nm_utils_inet4_ntop(a_next_server.s_addr, addr_str); @@ -429,18 +429,33 @@ lease_to_ip4_config(NMDedupMultiIndex *multi_idx, num = nm_sd_dhcp_lease_get_private_options(lease, &private_options); if (num > 0) { for (i = 0; i < num; i++) { - char *option_string; - - option_string = nm_utils_bin2hexstr_full(private_options[i].data, - private_options[i].data_len, - ':', - FALSE, - NULL); - if (!options) { - g_free(option_string); + guint8 code = private_options[i].code; + const guint8 *l_data = private_options[i].data; + gsize l_data_len = private_options[i].data_len; + char * option_string; + + if (code == NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY) { + if (nm_dhcp_lease_data_parse_cstr(l_data, l_data_len, &l_data_len)) { + nm_dhcp_option_add_option_utf8safe_escape( + options, + AF_INET, + NM_DHCP_OPTION_DHCP4_PRIVATE_PROXY_AUTODISCOVERY, + l_data, + l_data_len); + } continue; } - nm_dhcp_option_take_option(options, AF_INET, private_options[i].code, option_string); + if (code == NM_DHCP_OPTION_DHCP4_PRIVATE_CLASSLESS_STATIC_ROUTE) { + /* nettools and dhclient parse option 249 (Microsoft Classless Static Route) + * as fallback for routes and ignores them from private options. + * + * The systemd plugin does not, and for consistency with nettools we + * also don't expose it as private option either. */ + continue; + } + + option_string = nm_utils_bin2hexstr_full(l_data, l_data_len, ':', FALSE, NULL); + nm_dhcp_option_take_option(options, AF_INET, code, option_string); } } NM_SET_OUT(out_options, g_steal_pointer(&options)); @@ -543,10 +558,7 @@ dhcp_event_cb(sd_dhcp_client *client, int event, gpointer user_data) } static gboolean -ip4_start(NMDhcpClient *client, - const char * dhcp_anycast_addr, - const char * last_ip4_address, - GError ** error) +ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error) { nm_auto(sd_dhcp_client_unrefp) sd_dhcp_client *sd_client = NULL; NMDhcpSystemd * self = NM_DHCP_SYSTEMD(client); @@ -572,6 +584,8 @@ ip4_start(NMDhcpClient *client, g_return_val_if_fail(!priv->client4, FALSE); g_return_val_if_fail(!priv->client6, FALSE); + /* TODO: honor nm_dhcp_client_get_anycast_address() */ + r = sd_dhcp_client_new(&sd_client, FALSE); if (r < 0) { nm_utils_error_set_errno(error, r, "failed to create dhcp-client: %s"); @@ -632,6 +646,11 @@ ip4_start(NMDhcpClient *client, sd_dhcp_lease_get_address(lease, &last_addr); } + r = sd_dhcp_client_set_request_broadcast(sd_client, + NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), + NM_DHCP_CLIENT_FLAGS_REQUEST_BROADCAST)); + nm_assert(r >= 0); + if (last_addr.s_addr) { r = sd_dhcp_client_set_request_address(sd_client, &last_addr); if (r < 0) { @@ -659,7 +678,7 @@ ip4_start(NMDhcpClient *client, r = sd_dhcp_client_set_client_id(sd_client, client_id_arr[0], client_id_arr + 1, - NM_MIN(client_id_len - 1, _NM_SD_MAX_CLIENT_ID_LEN)); + NM_MIN(client_id_len - 1, _NM_MAX_CLIENT_ID_LEN)); if (r < 0) { nm_utils_error_set_errno(error, r, "failed to set IPv4 client-id: %s"); return FALSE; @@ -844,14 +863,16 @@ bound6_handle(NMDhcpSystemd *self) _LOGD("lease available"); - ip6_config = lease_to_ip6_config(nm_dhcp_client_get_multi_idx(NM_DHCP_CLIENT(self)), - iface, - nm_dhcp_client_get_ifindex(NM_DHCP_CLIENT(self)), - lease, - nm_dhcp_client_get_info_only(NM_DHCP_CLIENT(self)), - &options, - ts, - &error); + ip6_config = + lease_to_ip6_config(nm_dhcp_client_get_multi_idx(NM_DHCP_CLIENT(self)), + iface, + nm_dhcp_client_get_ifindex(NM_DHCP_CLIENT(self)), + lease, + NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(NM_DHCP_CLIENT(self)), + NM_DHCP_CLIENT_FLAGS_INFO_ONLY), + &options, + ts, + &error); if (!ip6_config) { _LOGW("%s", error->message); @@ -905,7 +926,6 @@ dhcp6_event_cb(sd_dhcp6_client *client, int event, gpointer user_data) static gboolean ip6_start(NMDhcpClient * client, - const char * dhcp_anycast_addr, const struct in6_addr * ll_addr, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes, @@ -924,6 +944,8 @@ ip6_start(NMDhcpClient * client, g_return_val_if_fail(!priv->client4, FALSE); g_return_val_if_fail(!priv->client6, FALSE); + /* TODO: honor nm_dhcp_client_get_anycast_address() */ + if (!(duid = nm_dhcp_client_get_client_id(client)) || !(duid_arr = g_bytes_get_data(duid, &duid_len)) || duid_len < 2) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_UNKNOWN, "missing DUID"); @@ -938,7 +960,7 @@ ip6_start(NMDhcpClient * client, _LOGT("dhcp-client6: set %p", sd_client); - if (nm_dhcp_client_get_info_only(client)) { + if (NM_FLAGS_HAS(nm_dhcp_client_get_client_flags(client), NM_DHCP_CLIENT_FLAGS_INFO_ONLY)) { sd_dhcp6_client_set_address_request(sd_client, 0); if (needed_prefixes == 0) sd_dhcp6_client_set_information_request(sd_client, 1); diff --git a/src/core/dhcp/nm-dhcp-utils.c b/src/core/dhcp/nm-dhcp-utils.c index 646411e2..7fd18b0a 100644 --- a/src/core/dhcp/nm-dhcp-utils.c +++ b/src/core/dhcp/nm-dhcp-utils.c @@ -8,18 +8,18 @@ #include <unistd.h> #include <arpa/inet.h> -#include "nm-std-aux/unaligned.h" -#include "nm-glib-aux/nm-dedup-multi.h" -#include "nm-glib-aux/nm-str-buf.h" -#include "systemd/nm-sd-utils-shared.h" +#include "libnm-std-aux/unaligned.h" +#include "libnm-glib-aux/nm-dedup-multi.h" +#include "libnm-glib-aux/nm-str-buf.h" +#include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "nm-dhcp-utils.h" #include "nm-utils.h" #include "nm-config.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" -#include "nm-core-internal.h" +#include "libnm-core-intern/nm-core-internal.h" /*****************************************************************************/ @@ -880,7 +880,7 @@ nm_dhcp_lease_data_parse_cstr(const guint8 *data, gsize n_data, gsize *out_new_l n_data--; if (n_data > 0) { - if (memchr(data, n_data, '\0')) { + if (memchr(data, '\0', n_data)) { /* we accept trailing NUL, but none in between. * * https://tools.ietf.org/html/rfc2132#section-2 @@ -989,7 +989,7 @@ lease_option_print_label(NMStrBuf *sbuf, size_t n_label, const uint8_t **datap, break; case '.': case '\\': - nm_str_buf_append_c2(sbuf, '\\', c); + nm_str_buf_append_c(sbuf, '\\', c); break; default: nm_str_buf_append_printf(sbuf, "\\%3d", c); diff --git a/src/core/dhcp/tests/test-dhcp-dhclient.c b/src/core/dhcp/tests/test-dhcp-dhclient.c index 77626f69..e9a62096 100644 --- a/src/core/dhcp/tests/test-dhcp-dhclient.c +++ b/src/core/dhcp/tests/test-dhcp-dhclient.c @@ -9,14 +9,14 @@ #include <arpa/inet.h> #include <linux/rtnetlink.h> -#include "nm-glib-aux/nm-dedup-multi.h" +#include "libnm-glib-aux/nm-dedup-multi.h" #include "NetworkManagerUtils.h" #include "dhcp/nm-dhcp-dhclient-utils.h" #include "dhcp/nm-dhcp-utils.h" #include "nm-utils.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/dhcp/tests/test-dhcp-utils.c b/src/core/dhcp/tests/test-dhcp-utils.c index 9b54e2cd..4d47e7e2 100644 --- a/src/core/dhcp/tests/test-dhcp-utils.c +++ b/src/core/dhcp/tests/test-dhcp-utils.c @@ -9,12 +9,12 @@ #include <arpa/inet.h> #include <linux/rtnetlink.h> -#include "nm-glib-aux/nm-dedup-multi.h" +#include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-utils.h" #include "dhcp/nm-dhcp-utils.h" #include "dhcp/nm-dhcp-options.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-test-utils-core.h" |