mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 04:10:18 +01:00
dhcp: initialize use_fqdn and info_only paramters in constructor
The two boolean properties do not need to be ever reset. It's nice to initialize such properties in the constructor and don't mutate them afterwards. Instead of adding two boolean GObject properties, add a new flags property that can encode these two values. In the end, properties are too cumbersome, let's combine them.
This commit is contained in:
parent
8ff962d9e4
commit
167a1d5f19
3 changed files with 39 additions and 21 deletions
|
|
@ -52,15 +52,16 @@ enum {
|
|||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
|
||||
PROP_MULTI_IDX,
|
||||
PROP_ADDR_FAMILY,
|
||||
PROP_FLAGS,
|
||||
PROP_HWADDR,
|
||||
PROP_IFACE,
|
||||
PROP_IFINDEX,
|
||||
PROP_HWADDR,
|
||||
PROP_UUID,
|
||||
PROP_ROUTE_TABLE,
|
||||
PROP_MULTI_IDX,
|
||||
PROP_ROUTE_METRIC,
|
||||
PROP_ROUTE_TABLE,
|
||||
PROP_TIMEOUT,
|
||||
PROP_UUID,
|
||||
);
|
||||
|
||||
typedef struct _NMDhcpClientPrivate {
|
||||
|
|
@ -502,7 +503,6 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
|
|||
const char *dhcp_client_id,
|
||||
const char *dhcp_anycast_addr,
|
||||
const char *hostname,
|
||||
gboolean use_fqdn,
|
||||
const char *last_ip4_address)
|
||||
{
|
||||
NMDhcpClientPrivate *priv;
|
||||
|
|
@ -523,7 +523,6 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
|
|||
|
||||
g_clear_pointer (&priv->hostname, g_free);
|
||||
priv->hostname = g_strdup (hostname);
|
||||
priv->use_fqdn = use_fqdn;
|
||||
|
||||
return NM_DHCP_CLIENT_GET_CLASS (self)->ip4_start (self, dhcp_anycast_addr, last_ip4_address);
|
||||
}
|
||||
|
|
@ -598,7 +597,6 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
|
|||
const char *dhcp_anycast_addr,
|
||||
const struct in6_addr *ll_addr,
|
||||
const char *hostname,
|
||||
gboolean info_only,
|
||||
NMSettingIP6ConfigPrivacy privacy,
|
||||
guint needed_prefixes)
|
||||
{
|
||||
|
|
@ -623,8 +621,6 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
|
|||
g_clear_pointer (&priv->hostname, g_free);
|
||||
priv->hostname = g_strdup (hostname);
|
||||
|
||||
priv->info_only = info_only;
|
||||
|
||||
if (priv->timeout == NM_DHCP_TIMEOUT_INFINITY)
|
||||
_LOGI ("activation: beginning transaction (no timeout)");
|
||||
else
|
||||
|
|
@ -929,8 +925,16 @@ set_property (GObject *object, guint prop_id,
|
|||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE ((NMDhcpClient *) object);
|
||||
guint flags;
|
||||
|
||||
switch (prop_id) {
|
||||
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);
|
||||
break;
|
||||
case PROP_MULTI_IDX:
|
||||
/* construct-only */
|
||||
priv->multi_idx = g_value_get_pointer (value);
|
||||
|
|
@ -1098,6 +1102,12 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
|
|||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
obj_properties[PROP_FLAGS] =
|
||||
g_param_spec_uint (NM_DHCP_CLIENT_FLAGS, "", "",
|
||||
0, G_MAXUINT32, 0,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
|
||||
signals[SIGNAL_STATE_CHANGED] =
|
||||
|
|
|
|||
|
|
@ -34,15 +34,16 @@
|
|||
#define NM_IS_DHCP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_CLIENT))
|
||||
#define NM_DHCP_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClientClass))
|
||||
|
||||
#define NM_DHCP_CLIENT_INTERFACE "iface"
|
||||
#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family"
|
||||
#define NM_DHCP_CLIENT_IFINDEX "ifindex"
|
||||
#define NM_DHCP_CLIENT_HWADDR "hwaddr"
|
||||
#define NM_DHCP_CLIENT_UUID "uuid"
|
||||
#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table"
|
||||
#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family"
|
||||
#define NM_DHCP_CLIENT_FLAGS "flags"
|
||||
#define NM_DHCP_CLIENT_HWADDR "hwaddr"
|
||||
#define NM_DHCP_CLIENT_IFINDEX "ifindex"
|
||||
#define NM_DHCP_CLIENT_INTERFACE "iface"
|
||||
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
|
||||
#define NM_DHCP_CLIENT_ROUTE_METRIC "route-metric"
|
||||
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
|
||||
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
|
||||
#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table"
|
||||
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
|
||||
#define NM_DHCP_CLIENT_UUID "uuid"
|
||||
|
||||
#define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed"
|
||||
#define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated"
|
||||
|
|
@ -67,6 +68,11 @@ 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),
|
||||
} NMDhcpClientFlags;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent;
|
||||
|
||||
|
|
@ -141,14 +147,12 @@ gboolean nm_dhcp_client_start_ip4 (NMDhcpClient *self,
|
|||
const char *dhcp_client_id,
|
||||
const char *dhcp_anycast_addr,
|
||||
const char *hostname,
|
||||
gboolean use_fqdn,
|
||||
const char *last_ip4_address);
|
||||
|
||||
gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self,
|
||||
const char *dhcp_anycast_addr,
|
||||
const struct in6_addr *ll_addr,
|
||||
const char *hostname,
|
||||
gboolean info_only,
|
||||
NMSettingIP6ConfigPrivacy privacy,
|
||||
guint needed_prefixes);
|
||||
|
||||
|
|
|
|||
|
|
@ -205,15 +205,19 @@ client_start (NMDhcpManager *self,
|
|||
NM_DHCP_CLIENT_ROUTE_TABLE, (guint) route_table,
|
||||
NM_DHCP_CLIENT_ROUTE_METRIC, (guint) route_metric,
|
||||
NM_DHCP_CLIENT_TIMEOUT, (guint) timeout,
|
||||
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)
|
||||
),
|
||||
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);
|
||||
g_signal_connect (client, NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED, G_CALLBACK (client_state_changed), self);
|
||||
|
||||
if (addr_family == AF_INET)
|
||||
success = nm_dhcp_client_start_ip4 (client, dhcp_client_id, dhcp_anycast_addr, hostname, hostname_use_fqdn, last_ip4_address);
|
||||
success = nm_dhcp_client_start_ip4 (client, dhcp_client_id, dhcp_anycast_addr, hostname, last_ip4_address);
|
||||
else
|
||||
success = nm_dhcp_client_start_ip6 (client, dhcp_anycast_addr, ipv6_ll_addr, hostname, info_only, privacy, needed_prefixes);
|
||||
success = nm_dhcp_client_start_ip6 (client, dhcp_anycast_addr, ipv6_ll_addr, hostname, privacy, needed_prefixes);
|
||||
|
||||
if (!success) {
|
||||
remove_client_unref (self, client);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue