Commit 9d92848a authored by Thomas Haller's avatar Thomas Haller

libnm: rename MDns flag UNKNOWN to DEFAULT

"UNKNOWN" is not a good name. If you don't set the property
in the connection explicitly, it should be "DEFAULT".

Also, make "DEFAULT" -1. For one, that ensures that the enum's
underlying integer type is signed. Otherwise, it's cumbersome
to test "if (mdns >= DEFAULT)" because in case of unsigned types,
the compiler will warn about the check always being true.
Also, it allows for "NO" to be zero. These are no strong reasons,
but I tend to think this is better.

Also, don't make the property of NMSettingConnection a CONSTRUCT property.
Initialize the default manually in the init function.

Also, order the numeric values so that DEFAULT < NO < RESOLVE < YES with
YES being largest because it enables *the most*.
parent eec907b3
......@@ -876,7 +876,7 @@ NMSettingConnectionMdns
nm_setting_connection_get_mdns (NMSettingConnection *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting),
NM_SETTING_CONNECTION_MDNS_UNKNOWN);
NM_SETTING_CONNECTION_MDNS_DEFAULT);
return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->mdns;
}
......@@ -1076,7 +1076,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if ( priv->mdns < NM_SETTING_CONNECTION_MDNS_UNKNOWN
if ( priv->mdns < NM_SETTING_CONNECTION_MDNS_DEFAULT
|| priv->mdns > NM_SETTING_CONNECTION_MDNS_RESOLVE) {
g_set_error (error,
NM_CONNECTION_ERROR,
......@@ -1244,6 +1244,9 @@ compare_property (NMSetting *setting,
static void
nm_setting_connection_init (NMSettingConnection *setting)
{
NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
priv->mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT;
}
static void
......@@ -2048,8 +2051,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
(object_class, PROP_MDNS,
g_param_spec_int (NM_SETTING_CONNECTION_MDNS, "", "",
G_MININT32, G_MAXINT32,
NM_SETTING_CONNECTION_MDNS_UNKNOWN,
NM_SETTING_CONNECTION_MDNS_DEFAULT,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
}
......@@ -100,20 +100,20 @@ typedef enum {
/**
* NMSettingConnectionMdns:
* @NM_SETTING_CONNECTION_MDNS_UNKNOWN: default value
* @NM_SETTING_CONNECTION_MDNS_YES: disable mDNS
* @NM_SETTING_CONNECTION_MDNS_NO: enable mDNS
* @NM_SETTING_CONNECTION_MDNS_DEFAULT: default value
* @NM_SETTING_CONNECTION_MDNS_NO: disable mDNS
* @NM_SETTING_CONNECTION_MDNS_RESOLVE: support only resolving, do not register hostname
* @NM_SETTING_CONNECTION_MDNS_YES: enable mDNS
*
* #NMSettingConnectionMdns values indicate whether mDNS should be enabled.
*
* Since: 1.12
*/
typedef enum {
NM_SETTING_CONNECTION_MDNS_UNKNOWN = 0,
NM_SETTING_CONNECTION_MDNS_YES = 1,
NM_SETTING_CONNECTION_MDNS_NO = 2,
NM_SETTING_CONNECTION_MDNS_RESOLVE = 3,
NM_SETTING_CONNECTION_MDNS_DEFAULT = -1,
NM_SETTING_CONNECTION_MDNS_NO = 0,
NM_SETTING_CONNECTION_MDNS_RESOLVE = 1,
NM_SETTING_CONNECTION_MDNS_YES = 2,
} NMSettingConnectionMdns;
/**
......
......@@ -1445,7 +1445,10 @@ nm_dns_manager_add_connection_config (NMDnsManager *self,
g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE);
g_return_val_if_fail (ifindex > 0, FALSE);
g_return_val_if_fail (iface != NULL && iface[0], FALSE);
g_return_val_if_fail (mdns != NM_SETTING_CONNECTION_MDNS_UNKNOWN, FALSE);
g_return_val_if_fail (NM_IN_SET (mdns,
NM_SETTING_CONNECTION_MDNS_NO,
NM_SETTING_CONNECTION_MDNS_YES,
NM_SETTING_CONNECTION_MDNS_RESOLVE), FALSE);
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
plugin = priv->plugin;
......
......@@ -1072,11 +1072,12 @@ add_connection_dns (NMPolicy *self, NMConnection *connection, const char *iface,
if (s_con) {
NMSettingConnectionMdns mdns = nm_setting_connection_get_mdns (s_con);
if (mdns != NM_SETTING_CONNECTION_MDNS_UNKNOWN)
if (mdns != NM_SETTING_CONNECTION_MDNS_DEFAULT) {
nm_dns_manager_add_connection_config (NM_POLICY_GET_PRIVATE (self)->dns_manager,
iface,
ifindex,
mdns);
iface,
ifindex,
mdns);
}
}
}
......@@ -2163,9 +2164,9 @@ vpn_connection_deactivated (NMPolicy *self, NMVpnConnection *vpn)
nm_dns_manager_end_updates (priv->dns_manager, __func__);
remove_connection_dns(self,
nm_vpn_connection_get_ip_iface (vpn, TRUE),
nm_vpn_connection_get_ip_ifindex (vpn, TRUE));
remove_connection_dns (self,
nm_vpn_connection_get_ip_iface (vpn, TRUE),
nm_vpn_connection_get_ip_ifindex (vpn, TRUE));
}
static void
......
......@@ -231,4 +231,6 @@ typedef struct _NMSettingsConnection NMSettingsConnection;
/* utils */
typedef struct _NMUtilsIPv6IfaceId NMUtilsIPv6IfaceId;
#define NM_SETTING_CONNECTION_MDNS_UNKNOWN ((NMSettingConnectionMdns) -42)
#endif /* NM_TYPES_H */
......@@ -321,11 +321,11 @@ make_connection_setting (const char *file,
vint64 = svGetValueInt64 (ifcfg, "AUTH_RETRIES", 10, -1, G_MAXINT32, -1);
g_object_set (s_con, NM_SETTING_CONNECTION_AUTH_RETRIES, (gint) vint64, NULL);
i_val = NM_SETTING_CONNECTION_MDNS_UNKNOWN;
i_val = NM_SETTING_CONNECTION_MDNS_DEFAULT;
if (!svGetValueEnum (ifcfg, "MDNS",
nm_setting_connection_mdns_get_type (),
&i_val, NULL)) {
}
&i_val, NULL))
PARSE_WARNING ("invalid MDNS setting");
g_object_set (s_con, NM_SETTING_CONNECTION_MDNS, i_val, NULL);
return NM_SETTING (s_con);
......
......@@ -1727,7 +1727,8 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg)
guint32 n, i;
GString *str;
const char *master, *master_iface = NULL, *type;
gint vint, i_val;
gint vint;
NMSettingConnectionMdns mdns;
guint32 vuint32;
const char *tmp;
......@@ -1883,10 +1884,10 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg)
vint = nm_setting_connection_get_auth_retries (s_con);
svSetValueInt64_cond (ifcfg, "AUTH_RETRIES", vint >= 0, vint);
i_val = nm_setting_connection_get_mdns (s_con);
if (i_val != NM_SETTING_CONNECTION_MDNS_UNKNOWN) {
mdns = nm_setting_connection_get_mdns (s_con);
if (mdns != NM_SETTING_CONNECTION_MDNS_DEFAULT) {
svSetValueEnum (ifcfg, "MDNS", nm_setting_connection_mdns_get_type (),
i_val);
mdns);
} else {
svUnsetValue (ifcfg, "MDNS");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment