mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-21 05:10:40 +01:00
ifcfg-rh: refactor parse_full_ip6_address() to use nm_utils_parse_inaddr_prefix_bin()
We already have code that parses exactly this kinds of string: nm_utils_parse_inaddr_prefix_bin(). Use it. Also, it doesn't use g_strsplit_set() to separate a string at the first '/'. Total overkill.
This commit is contained in:
parent
0d3bf9729a
commit
7887909564
2 changed files with 23 additions and 35 deletions
|
|
@ -205,7 +205,8 @@ struct NMIPAddress {
|
|||
**/
|
||||
NMIPAddress *
|
||||
nm_ip_address_new (int family,
|
||||
const char *addr, guint prefix,
|
||||
const char *addr,
|
||||
guint prefix,
|
||||
GError **error)
|
||||
{
|
||||
NMIPAddress *address;
|
||||
|
|
@ -243,7 +244,8 @@ nm_ip_address_new (int family,
|
|||
**/
|
||||
NMIPAddress *
|
||||
nm_ip_address_new_binary (int family,
|
||||
gconstpointer addr, guint prefix,
|
||||
gconstpointer addr,
|
||||
guint prefix,
|
||||
GError **error)
|
||||
{
|
||||
NMIPAddress *address;
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ _cert_get_cert_bytes (const char *ifcfg_path,
|
|||
{
|
||||
gs_free char *path = NULL;
|
||||
|
||||
if (g_str_has_prefix (value, "pkcs11:"))
|
||||
if (NM_STR_HAS_PREFIX (value, "pkcs11:"))
|
||||
return _nm_setting_802_1x_cert_value_to_bytes (NM_SETTING_802_1X_CK_SCHEME_PKCS11, (guint8 *) value, -1, error);
|
||||
|
||||
path = get_full_file_path (ifcfg_path, value);
|
||||
|
|
@ -560,7 +560,6 @@ make_connection_setting (const char *file,
|
|||
return NM_SETTING (s_con);
|
||||
}
|
||||
|
||||
/* Returns TRUE on missing address or valid address */
|
||||
static gboolean
|
||||
read_ip4_address (shvarFile *ifcfg,
|
||||
const char *tag,
|
||||
|
|
@ -570,7 +569,7 @@ read_ip4_address (shvarFile *ifcfg,
|
|||
{
|
||||
gs_free char *value_to_free = NULL;
|
||||
const char *value;
|
||||
guint32 a;
|
||||
in_addr_t a;
|
||||
|
||||
nm_assert (ifcfg);
|
||||
nm_assert (tag);
|
||||
|
|
@ -1341,46 +1340,33 @@ parse_full_ip6_address (shvarFile *ifcfg,
|
|||
NMIPAddress **out_address,
|
||||
GError **error)
|
||||
{
|
||||
char **list;
|
||||
char *ip_val, *prefix_val;
|
||||
NMIPAddress *addr;
|
||||
NMIPAddr addr_bin;
|
||||
int prefix;
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_return_val_if_fail (addr_str != NULL, FALSE);
|
||||
g_return_val_if_fail (out_address != NULL, FALSE);
|
||||
g_return_val_if_fail (*out_address == NULL, FALSE);
|
||||
g_return_val_if_fail (!error || !*error, FALSE);
|
||||
nm_assert (addr_str);
|
||||
nm_assert (out_address && !*out_address);
|
||||
nm_assert (!error || !*error);
|
||||
|
||||
/* Split the address and prefix */
|
||||
list = g_strsplit_set (addr_str, "/", 2);
|
||||
if (g_strv_length (list) < 1) {
|
||||
if (!nm_utils_parse_inaddr_prefix_bin (AF_INET6,
|
||||
addr_str,
|
||||
NULL,
|
||||
&addr_bin,
|
||||
&prefix)) {
|
||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||
"Invalid IP6 address '%s'", addr_str);
|
||||
goto error;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ip_val = list[0];
|
||||
|
||||
prefix_val = list[1];
|
||||
if (prefix_val) {
|
||||
prefix = _nm_utils_ascii_str_to_int64 (prefix_val, 10, 0, 128, -1);
|
||||
if (prefix < 0) {
|
||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||
"Invalid IP6 prefix '%s'", prefix_val);
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
/* Missing prefix is treated as prefix of 64 */
|
||||
if (prefix < 0)
|
||||
prefix = 64;
|
||||
}
|
||||
|
||||
*out_address = nm_ip_address_new (AF_INET6, ip_val, prefix, error);
|
||||
if (*out_address)
|
||||
success = TRUE;
|
||||
addr = nm_ip_address_new_binary (AF_INET6, &addr_bin, prefix, error);
|
||||
if (!addr)
|
||||
return FALSE;
|
||||
|
||||
error:
|
||||
g_strfreev (list);
|
||||
return success;
|
||||
*out_address = addr;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static NMSetting *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue