mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 07:48:10 +02:00
libnm-util: expose nm_setting_bond_validate_option as public API
Co-Authored-By: Jiří Klimeš <jklimes@redhat.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
3f3f2a82d0
commit
df4e159728
3 changed files with 35 additions and 17 deletions
|
|
@ -207,6 +207,7 @@ global:
|
||||||
nm_setting_bond_get_valid_options;
|
nm_setting_bond_get_valid_options;
|
||||||
nm_setting_bond_new;
|
nm_setting_bond_new;
|
||||||
nm_setting_bond_remove_option;
|
nm_setting_bond_remove_option;
|
||||||
|
nm_setting_bond_validate_option;
|
||||||
nm_setting_bridge_error_get_type;
|
nm_setting_bridge_error_get_type;
|
||||||
nm_setting_bridge_error_quark;
|
nm_setting_bridge_error_quark;
|
||||||
nm_setting_bridge_get_ageing_time;
|
nm_setting_bridge_get_ageing_time;
|
||||||
|
|
|
||||||
|
|
@ -271,29 +271,43 @@ validate_ip (const char *name, const char *value)
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If value is NULL, validates name only */
|
/**
|
||||||
static gboolean
|
* nm_setting_bond_validate_option:
|
||||||
validate_option (const char *name, const char *value)
|
* @name: the name of the option to validate
|
||||||
|
* @value: the value of the option to validate
|
||||||
|
*
|
||||||
|
* Checks whether @name is a valid bond option and @value is a valid value for
|
||||||
|
* the @name. If @value is NULL, the function only validates the option name.
|
||||||
|
*
|
||||||
|
* Returns: TRUE, if the @value is valid for the given name.
|
||||||
|
* If the @name is not a valid option, FALSE will be returned.
|
||||||
|
*
|
||||||
|
* Since: 0.9.10
|
||||||
|
**/
|
||||||
|
gboolean
|
||||||
|
nm_setting_bond_validate_option (const char *name,
|
||||||
|
const char *value)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (name != NULL, FALSE);
|
if (!name || !name[0])
|
||||||
g_return_val_if_fail (name[0] != '\0', FALSE);
|
return FALSE;
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
|
for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
|
||||||
if (g_strcmp0 (defaults[i].opt, name) == 0) {
|
if (g_strcmp0 (defaults[i].opt, name) == 0) {
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
else if (defaults[i].opt_type == TYPE_INT)
|
switch (defaults[i].opt_type) {
|
||||||
|
case TYPE_INT:
|
||||||
return validate_int (name, value, &defaults[i]);
|
return validate_int (name, value, &defaults[i]);
|
||||||
else if (defaults[i].opt_type == TYPE_STR)
|
case TYPE_STR:
|
||||||
return validate_list (name, value, &defaults[i]);
|
return validate_list (name, value, &defaults[i]);
|
||||||
else if (defaults[i].opt_type == TYPE_BOTH)
|
case TYPE_BOTH:
|
||||||
return validate_int (name, value, &defaults[i])
|
return validate_int (name, value, &defaults[i])
|
||||||
|| validate_list (name, value, &defaults[i]);
|
|| validate_list (name, value, &defaults[i]);
|
||||||
else if (defaults[i].opt_type == TYPE_IP)
|
case TYPE_IP:
|
||||||
return validate_ip (name, value);
|
return validate_ip (name, value);
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -316,7 +330,7 @@ nm_setting_bond_get_option_by_name (NMSettingBond *setting,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
|
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
|
||||||
g_return_val_if_fail (validate_option (name, NULL), NULL);
|
g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NULL);
|
||||||
|
|
||||||
return g_hash_table_lookup (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
|
return g_hash_table_lookup (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
|
||||||
}
|
}
|
||||||
|
|
@ -342,7 +356,7 @@ gboolean nm_setting_bond_add_option (NMSettingBond *setting,
|
||||||
NMSettingBondPrivate *priv;
|
NMSettingBondPrivate *priv;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
|
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
|
||||||
g_return_val_if_fail (validate_option (name, value), FALSE);
|
g_return_val_if_fail (nm_setting_bond_validate_option (name, value), FALSE);
|
||||||
g_return_val_if_fail (value != NULL, FALSE);
|
g_return_val_if_fail (value != NULL, FALSE);
|
||||||
|
|
||||||
priv = NM_SETTING_BOND_GET_PRIVATE (setting);
|
priv = NM_SETTING_BOND_GET_PRIVATE (setting);
|
||||||
|
|
@ -383,7 +397,7 @@ nm_setting_bond_remove_option (NMSettingBond *setting,
|
||||||
gboolean found;
|
gboolean found;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
|
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
|
||||||
g_return_val_if_fail (validate_option (name, NULL), FALSE);
|
g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), FALSE);
|
||||||
|
|
||||||
found = g_hash_table_remove (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
|
found = g_hash_table_remove (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
|
||||||
if (found)
|
if (found)
|
||||||
|
|
@ -428,13 +442,13 @@ nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
|
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
|
||||||
g_return_val_if_fail (validate_option (name, NULL), NULL);
|
g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NULL);
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
|
for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
|
||||||
if (g_strcmp0 (defaults[i].opt, name) == 0)
|
if (g_strcmp0 (defaults[i].opt, name) == 0)
|
||||||
return defaults[i].val;
|
return defaults[i].val;
|
||||||
}
|
}
|
||||||
/* Any option that passes validate_option() should also be found in defaults */
|
/* Any option that passes nm_setting_bond_validate_option() should also be found in defaults */
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -476,7 +490,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, priv->options);
|
g_hash_table_iter_init (&iter, priv->options);
|
||||||
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
|
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
|
||||||
if (!value[0] || !validate_option (key, value)) {
|
if (!value[0] || !nm_setting_bond_validate_option (key, value)) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
NM_SETTING_BOND_ERROR,
|
NM_SETTING_BOND_ERROR,
|
||||||
NM_SETTING_BOND_ERROR_INVALID_OPTION,
|
NM_SETTING_BOND_ERROR_INVALID_OPTION,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301 USA.
|
* Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* (C) Copyright 2011 - 2012 Red Hat, Inc.
|
* (C) Copyright 2011 - 2013 Red Hat, Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NM_SETTING_BOND_H
|
#ifndef NM_SETTING_BOND_H
|
||||||
|
|
@ -105,6 +105,9 @@ gboolean nm_setting_bond_add_option (NMSettingBond *setting,
|
||||||
gboolean nm_setting_bond_remove_option (NMSettingBond *setting,
|
gboolean nm_setting_bond_remove_option (NMSettingBond *setting,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
|
||||||
|
gboolean nm_setting_bond_validate_option (const char *name,
|
||||||
|
const char *value);
|
||||||
|
|
||||||
const char **nm_setting_bond_get_valid_options (NMSettingBond *setting);
|
const char **nm_setting_bond_get_valid_options (NMSettingBond *setting);
|
||||||
|
|
||||||
const char * nm_setting_bond_get_option_default (NMSettingBond *setting,
|
const char * nm_setting_bond_get_option_default (NMSettingBond *setting,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue