mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-21 01:40:33 +01:00
libnm-core, etc: drop type-based hwaddr funcs, port to length-based ones
Drop the arptype-based nm_utils_hwaddr funcs, and rename the length-based ones to no longer have _len in their names. This also switches nm_utils_hwaddr_atoba() to using a length rather than an arptype, and adds a length argument to nm_utils_hwaddr_valid() (making nm_utils_hwaddr_valid() now a replacement for nm_utils_hwaddr_aton() in some places, where we were only using aton() to do validity checking).
This commit is contained in:
parent
86ab915f6a
commit
35f36ba4c3
32 changed files with 140 additions and 182 deletions
|
|
@ -2472,12 +2472,14 @@ check_and_convert_mac (const char *mac,
|
|||
GError **error)
|
||||
{
|
||||
GByteArray *local_mac_array = NULL;
|
||||
|
||||
g_return_val_if_fail (mac_array == NULL || *mac_array == NULL, FALSE);
|
||||
g_return_val_if_fail (type == ARPHRD_ETHER || type == ARPHRD_INFINIBAND, FALSE);
|
||||
|
||||
if (!mac)
|
||||
return TRUE;
|
||||
|
||||
local_mac_array = nm_utils_hwaddr_atoba (mac, type);
|
||||
local_mac_array = nm_utils_hwaddr_atoba (mac, nm_utils_hwaddr_len (type));
|
||||
if (!local_mac_array) {
|
||||
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
_("Error: '%s': '%s' is not a valid %s MAC address."),
|
||||
|
|
@ -4177,7 +4179,7 @@ cleanup_bt:
|
|||
}
|
||||
}
|
||||
|
||||
if ( !(addr_array = nm_utils_hwaddr_atoba (parent, ARPHRD_ETHER))
|
||||
if ( !(addr_array = nm_utils_hwaddr_atoba (parent, ETH_ALEN))
|
||||
&& !nm_utils_is_uuid (parent)
|
||||
&& !nm_utils_iface_valid_name (parent)) {
|
||||
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
|
|
|
|||
|
|
@ -2054,7 +2054,7 @@ find_ap_on_device (NMDevice *device, GByteArray *bssid, const char *ssid)
|
|||
} else if (bssid) {
|
||||
/* Parameter is BSSID */
|
||||
const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap);
|
||||
char *bssid_up = nm_utils_hwaddr_ntoa (bssid->data, ARPHRD_ETHER);
|
||||
char *bssid_up = nm_utils_hwaddr_ntoa (bssid->data, bssid->len);
|
||||
|
||||
/* Compare BSSIDs */
|
||||
if (strcmp (bssid_up, candidate_bssid) == 0) {
|
||||
|
|
@ -2103,7 +2103,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
/* Get the first compulsory argument (SSID or BSSID) */
|
||||
if (argc > 0) {
|
||||
param_user = *argv;
|
||||
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ARPHRD_ETHER);
|
||||
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ETH_ALEN);
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
|
@ -2111,7 +2111,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
if (nmc->ask) {
|
||||
ssid_ask = nmc_readline (_("SSID or BSSID: "));
|
||||
param_user = ssid_ask ? ssid_ask : "";
|
||||
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ARPHRD_ETHER);
|
||||
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ETH_ALEN);
|
||||
}
|
||||
if (!ssid_ask) {
|
||||
g_string_printf (nmc->return_text, _("Error: SSID or BSSID are missing."));
|
||||
|
|
@ -2136,7 +2136,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
goto error;
|
||||
}
|
||||
bssid = *argv;
|
||||
bssid2_arr = nm_utils_hwaddr_atoba (bssid, ARPHRD_ETHER);
|
||||
bssid2_arr = nm_utils_hwaddr_atoba (bssid, ETH_ALEN);
|
||||
if (!bssid2_arr) {
|
||||
g_string_printf (nmc->return_text, _("Error: bssid argument value '%s' is not a valid BSSID."),
|
||||
bssid);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <net/if_arp.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/if_infiniband.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -830,7 +831,7 @@ vpn_data_item (const char *key, const char *value, gpointer user_data)
|
|||
g_object_get_property (G_OBJECT (setting), property_name, &val); \
|
||||
array = g_value_get_boxed (&val); \
|
||||
if (array && array->len) \
|
||||
hwaddr = nm_utils_hwaddr_ntoa_len (array->data, array->len); \
|
||||
hwaddr = nm_utils_hwaddr_ntoa (array->data, array->len); \
|
||||
g_value_unset (&val); \
|
||||
return hwaddr; \
|
||||
}
|
||||
|
|
@ -2080,7 +2081,7 @@ nmc_property_set_mac (NMSetting *setting, const char *prop, const char *val, GEr
|
|||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
array = nm_utils_hwaddr_atoba (val, ARPHRD_ETHER);
|
||||
array = nm_utils_hwaddr_atoba (val, ETH_ALEN);
|
||||
if (!array) {
|
||||
g_set_error (error, 1, 0, _("'%s' is not a valid Ethernet MAC"), val);
|
||||
return FALSE;
|
||||
|
|
@ -2207,7 +2208,7 @@ done:
|
|||
\
|
||||
list = nmc_strsplit_set (val, " \t,", 0); \
|
||||
for (iter = list; iter && *iter; iter++) { \
|
||||
if (!nm_utils_hwaddr_aton (*iter, ARPHRD_ETHER, buf)) { \
|
||||
if (!nm_utils_hwaddr_aton (*iter, buf, ETH_ALEN)) { \
|
||||
g_set_error (error, 1, 0, _("'%s' is not a valid MAC"), *iter); \
|
||||
g_strfreev (list); \
|
||||
g_slist_free (macaddr_blacklist); \
|
||||
|
|
@ -2849,7 +2850,7 @@ nmc_property_ib_set_mac (NMSetting *setting, const char *prop, const char *val,
|
|||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
array = nm_utils_hwaddr_atoba (val, ARPHRD_INFINIBAND);
|
||||
array = nm_utils_hwaddr_atoba (val, INFINIBAND_ALEN);
|
||||
if (!array) {
|
||||
g_set_error (error, 1, 0, _("'%s' is not a valid InfiniBand MAC"), val);
|
||||
return FALSE;
|
||||
|
|
@ -3804,7 +3805,7 @@ _validate_and_remove_wired_mac_blacklist_item (NMSettingWired *setting,
|
|||
gboolean ret;
|
||||
guint8 buf[32];
|
||||
|
||||
if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf)) {
|
||||
if (!nm_utils_hwaddr_aton (mac, buf, ETH_ALEN)) {
|
||||
g_set_error (error, 1, 0, _("'%s' is not a valid MAC address"), mac);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -3972,7 +3973,7 @@ _validate_and_remove_wifi_mac_blacklist_item (NMSettingWireless *setting,
|
|||
gboolean ret;
|
||||
guint8 buf[32];
|
||||
|
||||
if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf)) {
|
||||
if (!nm_utils_hwaddr_aton (mac, buf, ETH_ALEN)) {
|
||||
g_set_error (error, 1, 0, _("'%s' is not a valid MAC address"), mac);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,14 +141,15 @@ device_entry_parse (NmtDeviceEntry *deventry,
|
|||
words[1][len - 2] = '\0';
|
||||
}
|
||||
|
||||
if ( nm_utils_hwaddr_aton (words[0], priv->arptype, buf)
|
||||
len = nm_utils_hwaddr_len (priv->arptype);
|
||||
if ( nm_utils_hwaddr_aton (words[0], buf, len)
|
||||
&& (!words[1] || nm_utils_iface_valid_name (words[1]))) {
|
||||
*mac_address = words[0];
|
||||
*interface_name = NULL;
|
||||
g_free (words);
|
||||
return TRUE;
|
||||
} else if ( nm_utils_iface_valid_name (words[0])
|
||||
&& (!words[1] || nm_utils_hwaddr_aton (words[1], priv->arptype, buf))) {
|
||||
&& (!words[1] || nm_utils_hwaddr_aton (words[1], buf, len))) {
|
||||
*interface_name = words[0];
|
||||
*mac_address = NULL;
|
||||
g_free (words);
|
||||
|
|
@ -258,7 +259,7 @@ update_entry (NmtDeviceEntry *deventry)
|
|||
}
|
||||
|
||||
if (priv->mac_address) {
|
||||
mac = nm_utils_hwaddr_ntoa (priv->mac_address->data, priv->arptype);
|
||||
mac = nm_utils_hwaddr_ntoa (priv->mac_address->data, priv->mac_address->len);
|
||||
mac_device = find_device_by_mac_address (deventry, mac);
|
||||
} else {
|
||||
mac = NULL;
|
||||
|
|
@ -363,7 +364,7 @@ entry_text_changed (GObject *object,
|
|||
if (mac) {
|
||||
GByteArray *mac_address;
|
||||
|
||||
mac_address = nm_utils_hwaddr_atoba (mac, priv->arptype);
|
||||
mac_address = nm_utils_hwaddr_atoba (mac, nm_utils_hwaddr_len (priv->arptype));
|
||||
nmt_device_entry_set_mac_address (deventry, mac_address);
|
||||
g_byte_array_unref (mac_address);
|
||||
g_free (mac);
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ nmt_mac_entry_set_property (GObject *object,
|
|||
case PROP_MAC_ADDRESS:
|
||||
addr = g_value_get_boxed (value);
|
||||
if (addr) {
|
||||
addr_str = nm_utils_hwaddr_ntoa_len (addr->data, addr->len);
|
||||
addr_str = nm_utils_hwaddr_ntoa (addr->data, addr->len);
|
||||
nmt_newt_entry_set_text (NMT_NEWT_ENTRY (object), addr_str);
|
||||
g_free (addr_str);
|
||||
} else
|
||||
|
|
@ -190,7 +190,7 @@ nmt_mac_entry_get_property (GObject *object,
|
|||
g_value_set_int (value, priv->mac_length);
|
||||
break;
|
||||
case PROP_MAC_ADDRESS:
|
||||
addr = nm_utils_hwaddr_atoba (nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object)), ARPHRD_ETHER);
|
||||
addr = nm_utils_hwaddr_atoba (nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object)), ETH_ALEN);
|
||||
g_value_take_boxed (value, addr);
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -271,12 +271,11 @@ nm_setting_wired_add_mac_blacklist_item (NMSettingWired *setting, const char *ma
|
|||
{
|
||||
NMSettingWiredPrivate *priv;
|
||||
GSList *iter;
|
||||
guint8 buf[32];
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
|
||||
g_return_val_if_fail (mac != NULL, FALSE);
|
||||
|
||||
if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
|
||||
if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
|
||||
return FALSE;
|
||||
|
||||
priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
|
||||
|
|
@ -330,12 +329,11 @@ nm_setting_wired_remove_mac_blacklist_item_by_value (NMSettingWired *setting, co
|
|||
{
|
||||
NMSettingWiredPrivate *priv;
|
||||
GSList *iter;
|
||||
guint8 buf[32];
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
|
||||
g_return_val_if_fail (mac != NULL, FALSE);
|
||||
|
||||
if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
|
||||
if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
|
||||
return FALSE;
|
||||
|
||||
priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
|
||||
|
|
|
|||
|
|
@ -507,12 +507,11 @@ nm_setting_wireless_add_mac_blacklist_item (NMSettingWireless *setting, const ch
|
|||
{
|
||||
NMSettingWirelessPrivate *priv;
|
||||
GSList *iter;
|
||||
guint8 buf[32];
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
|
||||
g_return_val_if_fail (mac != NULL, FALSE);
|
||||
|
||||
if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
|
||||
if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
|
||||
return FALSE;
|
||||
|
||||
priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
|
||||
|
|
@ -566,12 +565,11 @@ nm_setting_wireless_remove_mac_blacklist_item_by_value (NMSettingWireless *setti
|
|||
{
|
||||
NMSettingWirelessPrivate *priv;
|
||||
GSList *iter;
|
||||
guint8 buf[32];
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
|
||||
g_return_val_if_fail (mac != NULL, FALSE);
|
||||
|
||||
if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
|
||||
if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
|
||||
return FALSE;
|
||||
|
||||
priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
|
||||
|
|
|
|||
|
|
@ -1930,52 +1930,30 @@ nm_utils_wifi_is_channel_valid (guint32 channel, const char *band)
|
|||
*
|
||||
* Returns the length in octets of a hardware address of type @type.
|
||||
*
|
||||
* Return value: the positive length, or -1 if the type is unknown/unsupported.
|
||||
* It is an error to call this function with any value other than %ARPHRD_ETHER
|
||||
* or %ARPHRD_INFINIBAND.
|
||||
*
|
||||
* Return value: the length.
|
||||
*/
|
||||
int
|
||||
gsize
|
||||
nm_utils_hwaddr_len (int type)
|
||||
{
|
||||
g_return_val_if_fail (type == ARPHRD_ETHER || type == ARPHRD_INFINIBAND, 0);
|
||||
|
||||
if (type == ARPHRD_ETHER)
|
||||
return ETH_ALEN;
|
||||
else if (type == ARPHRD_INFINIBAND)
|
||||
return INFINIBAND_ALEN;
|
||||
else
|
||||
return -1;
|
||||
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
#define HEXVAL(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
|
||||
|
||||
/**
|
||||
* nm_utils_hwaddr_aton:
|
||||
* @asc: the ASCII representation of a hardware address
|
||||
* @type: the type of address; either %ARPHRD_ETHER or %ARPHRD_INFINIBAND
|
||||
* @buffer: buffer to store the result into
|
||||
*
|
||||
* Parses @asc and converts it to binary form in @buffer. See
|
||||
* nm_utils_hwaddr_atoba() if you'd rather have the result in a
|
||||
* #GByteArray.
|
||||
*
|
||||
* See also nm_utils_hwaddr_aton_len(), which takes an output length
|
||||
* instead of a type.
|
||||
*
|
||||
* Return value: @buffer, or %NULL if @asc couldn't be parsed
|
||||
*/
|
||||
guint8 *
|
||||
nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer)
|
||||
{
|
||||
int len = nm_utils_hwaddr_len (type);
|
||||
|
||||
if (len <= 0) {
|
||||
g_return_val_if_reached (NULL);
|
||||
return NULL;
|
||||
}
|
||||
return nm_utils_hwaddr_aton_len (asc, buffer, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_hwaddr_atoba:
|
||||
* @asc: the ASCII representation of a hardware address
|
||||
* @type: the type of address; either %ARPHRD_ETHER or %ARPHRD_INFINIBAND
|
||||
* @length: the expected length in bytes of the result
|
||||
*
|
||||
* Parses @asc and converts it to binary form in a #GByteArray. See
|
||||
* nm_utils_hwaddr_aton() if you don't want a #GByteArray.
|
||||
|
|
@ -1984,19 +1962,16 @@ nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer)
|
|||
* be parsed
|
||||
*/
|
||||
GByteArray *
|
||||
nm_utils_hwaddr_atoba (const char *asc, int type)
|
||||
nm_utils_hwaddr_atoba (const char *asc, gsize length)
|
||||
{
|
||||
GByteArray *ba;
|
||||
int len = nm_utils_hwaddr_len (type);
|
||||
|
||||
if (len <= 0) {
|
||||
g_return_val_if_reached (NULL);
|
||||
return NULL;
|
||||
}
|
||||
g_return_val_if_fail (asc != NULL, NULL);
|
||||
g_return_val_if_fail (length > 0 && length <= NM_UTILS_HWADDR_LEN_MAX, NULL);
|
||||
|
||||
ba = g_byte_array_sized_new (len);
|
||||
g_byte_array_set_size (ba, len);
|
||||
if (!nm_utils_hwaddr_aton_len (asc, ba->data, len)) {
|
||||
ba = g_byte_array_sized_new (length);
|
||||
g_byte_array_set_size (ba, length);
|
||||
if (!nm_utils_hwaddr_aton (asc, ba->data, length)) {
|
||||
g_byte_array_unref (ba);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2005,32 +1980,7 @@ nm_utils_hwaddr_atoba (const char *asc, int type)
|
|||
}
|
||||
|
||||
/**
|
||||
* nm_utils_hwaddr_ntoa:
|
||||
* @addr: a binary hardware address
|
||||
* @type: the type of address; either %ARPHRD_ETHER or %ARPHRD_INFINIBAND
|
||||
*
|
||||
* Converts @addr to textual form.
|
||||
*
|
||||
* See also nm_utils_hwaddr_ntoa_len(), which takes a length instead of
|
||||
* a type.
|
||||
*
|
||||
* Return value: (transfer full): the textual form of @addr
|
||||
*/
|
||||
char *
|
||||
nm_utils_hwaddr_ntoa (gconstpointer addr, int type)
|
||||
{
|
||||
int len = nm_utils_hwaddr_len (type);
|
||||
|
||||
if (len <= 0) {
|
||||
g_return_val_if_reached (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nm_utils_hwaddr_ntoa_len (addr, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_hwaddr_aton_len:
|
||||
* nm_utils_hwaddr_aton:
|
||||
* @asc: the ASCII representation of a hardware address
|
||||
* @buffer: buffer to store the result into
|
||||
* @length: the expected length in bytes of the result and
|
||||
|
|
@ -2043,18 +1993,15 @@ nm_utils_hwaddr_ntoa (gconstpointer addr, int type)
|
|||
* or would be shorter or longer than @length.
|
||||
*/
|
||||
guint8 *
|
||||
nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length)
|
||||
nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize length)
|
||||
{
|
||||
const char *in = asc;
|
||||
guint8 *out = (guint8 *)buffer;
|
||||
char delimiter = '\0';
|
||||
|
||||
if (!asc) {
|
||||
g_return_val_if_reached (NULL);
|
||||
return NULL;
|
||||
}
|
||||
g_return_val_if_fail (buffer, NULL);
|
||||
g_return_val_if_fail (length, NULL);
|
||||
g_return_val_if_fail (asc != NULL, NULL);
|
||||
g_return_val_if_fail (buffer != NULL, NULL);
|
||||
g_return_val_if_fail (length > 0 && length <= NM_UTILS_HWADDR_LEN_MAX, NULL);
|
||||
|
||||
while (length && *in) {
|
||||
guint8 d1 = in[0], d2 = in[1];
|
||||
|
|
@ -2094,7 +2041,7 @@ nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length)
|
|||
}
|
||||
|
||||
/**
|
||||
* nm_utils_hwaddr_ntoa_len:
|
||||
* nm_utils_hwaddr_ntoa:
|
||||
* @addr: a binary hardware address
|
||||
* @length: the length of @addr
|
||||
*
|
||||
|
|
@ -2103,14 +2050,14 @@ nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length)
|
|||
* Return value: (transfer full): the textual form of @addr
|
||||
*/
|
||||
char *
|
||||
nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length)
|
||||
nm_utils_hwaddr_ntoa (gconstpointer addr, gsize length)
|
||||
{
|
||||
const guint8 *in = addr;
|
||||
char *out, *result;
|
||||
const char *LOOKUP = "0123456789ABCDEF";
|
||||
|
||||
g_return_val_if_fail (addr != NULL, g_strdup (""));
|
||||
g_return_val_if_fail (length != 0, g_strdup (""));
|
||||
g_return_val_if_fail (length > 0 && length <= NM_UTILS_HWADDR_LEN_MAX, g_strdup (""));
|
||||
|
||||
result = out = g_malloc (length * 3);
|
||||
for (;;) {
|
||||
|
|
@ -2126,30 +2073,45 @@ nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
hwaddr_binary_len (const char *asc)
|
||||
{
|
||||
int octets = 1;
|
||||
|
||||
for (; *asc; asc++) {
|
||||
if (*asc == ':' || *asc == '-')
|
||||
octets++;
|
||||
}
|
||||
return octets;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_hwaddr_valid:
|
||||
* @asc: the ASCII representation of a hardware address
|
||||
* @length: the length of address that @asc is expected to convert to
|
||||
* (or -1 to accept any length up to %NM_UTILS_HWADDR_LEN_MAX)
|
||||
*
|
||||
* Parses @asc to see if it is a valid hardware address of some type.
|
||||
* Parses @asc to see if it is a valid hardware address of the given
|
||||
* length.
|
||||
*
|
||||
* Return value: %TRUE if @asc appears to be a valid hardware address
|
||||
* of some type, %FALSE if not.
|
||||
* of the indicated length, %FALSE if not.
|
||||
*/
|
||||
gboolean
|
||||
nm_utils_hwaddr_valid (const char *asc)
|
||||
nm_utils_hwaddr_valid (const char *asc, gssize length)
|
||||
{
|
||||
guint8 buf[NM_UTILS_HWADDR_LEN_MAX];
|
||||
gsize in_len, out_len;
|
||||
|
||||
if (!asc || !*asc)
|
||||
return FALSE;
|
||||
in_len = strlen (asc);
|
||||
if ((in_len + 1) % 3 != 0)
|
||||
return FALSE;
|
||||
out_len = (in_len + 1) / 3;
|
||||
if (out_len > NM_UTILS_HWADDR_LEN_MAX)
|
||||
return FALSE;
|
||||
return nm_utils_hwaddr_aton_len (asc, buf, out_len) != NULL;
|
||||
g_return_val_if_fail (asc != NULL, FALSE);
|
||||
g_return_val_if_fail (length == -1 || (length > 0 && length <= NM_UTILS_HWADDR_LEN_MAX), FALSE);
|
||||
|
||||
if (length == -1) {
|
||||
length = hwaddr_binary_len (asc);
|
||||
if (length == 0 || length > NM_UTILS_HWADDR_LEN_MAX)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return nm_utils_hwaddr_aton (asc, buf, length) != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -135,15 +135,13 @@ gboolean nm_utils_wifi_is_channel_valid (guint32 channel, const char *band);
|
|||
*/
|
||||
#define NM_UTILS_HWADDR_LEN_MAX 20 /* INFINIBAND_ALEN */
|
||||
|
||||
int nm_utils_hwaddr_len (int type) G_GNUC_PURE;
|
||||
char *nm_utils_hwaddr_ntoa (gconstpointer addr, int type);
|
||||
GByteArray *nm_utils_hwaddr_atoba (const char *asc, int type);
|
||||
guint8 *nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer);
|
||||
gsize nm_utils_hwaddr_len (int type) G_GNUC_PURE;
|
||||
|
||||
char *nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length);
|
||||
guint8 *nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length);
|
||||
char *nm_utils_hwaddr_ntoa (gconstpointer addr, gsize length);
|
||||
GByteArray *nm_utils_hwaddr_atoba (const char *asc, gsize length);
|
||||
guint8 *nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize length);
|
||||
|
||||
gboolean nm_utils_hwaddr_valid (const char *asc);
|
||||
gboolean nm_utils_hwaddr_valid (const char *asc, gssize length);
|
||||
|
||||
char *nm_utils_bin2hexstr (const char *bytes, int len, int final_len);
|
||||
int nm_utils_hex2byte (const char *hex);
|
||||
|
|
|
|||
|
|
@ -1910,7 +1910,7 @@ test_hwaddr_aton_ether_normal (void)
|
|||
guint8 buf[100];
|
||||
guint8 expected[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
|
||||
|
||||
g_assert (nm_utils_hwaddr_aton ("00:11:22:33:44:55", ARPHRD_ETHER, buf) != NULL);
|
||||
g_assert (nm_utils_hwaddr_aton ("00:11:22:33:44:55", buf, ETH_ALEN) != NULL);
|
||||
g_assert (memcmp (buf, expected, sizeof (expected)) == 0);
|
||||
}
|
||||
|
||||
|
|
@ -1923,7 +1923,7 @@ test_hwaddr_aton_ib_normal (void)
|
|||
0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89,
|
||||
0x90 };
|
||||
|
||||
g_assert (nm_utils_hwaddr_aton (source, ARPHRD_INFINIBAND, buf) != NULL);
|
||||
g_assert (nm_utils_hwaddr_aton (source, buf, INFINIBAND_ALEN) != NULL);
|
||||
g_assert (memcmp (buf, expected, sizeof (expected)) == 0);
|
||||
}
|
||||
|
||||
|
|
@ -1933,7 +1933,7 @@ test_hwaddr_aton_no_leading_zeros (void)
|
|||
guint8 buf[100];
|
||||
guint8 expected[ETH_ALEN] = { 0x00, 0x1A, 0x2B, 0x03, 0x44, 0x05 };
|
||||
|
||||
g_assert (nm_utils_hwaddr_aton ("0:1a:2B:3:44:5", ARPHRD_ETHER, buf) != NULL);
|
||||
g_assert (nm_utils_hwaddr_aton ("0:1a:2B:3:44:5", buf, ETH_ALEN) != NULL);
|
||||
g_assert (memcmp (buf, expected, sizeof (expected)) == 0);
|
||||
}
|
||||
|
||||
|
|
@ -1942,7 +1942,7 @@ test_hwaddr_aton_malformed (void)
|
|||
{
|
||||
guint8 buf[100];
|
||||
|
||||
g_assert (nm_utils_hwaddr_aton ("0:1a:2B:3:a@%%", ARPHRD_ETHER, buf) == NULL);
|
||||
g_assert (nm_utils_hwaddr_aton ("0:1a:2B:3:a@%%", buf, ETH_ALEN) == NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -2658,6 +2658,7 @@ int main (int argc, char **argv)
|
|||
test_hwaddr_aton_ib_normal ();
|
||||
test_hwaddr_aton_no_leading_zeros ();
|
||||
test_hwaddr_aton_malformed ();
|
||||
|
||||
test_ip4_prefix_to_netmask ();
|
||||
test_ip4_netmask_to_prefix ();
|
||||
|
||||
|
|
|
|||
|
|
@ -883,10 +883,8 @@ global:
|
|||
nm_utils_hexstr2bin;
|
||||
nm_utils_hwaddr_atoba;
|
||||
nm_utils_hwaddr_aton;
|
||||
nm_utils_hwaddr_aton_len;
|
||||
nm_utils_hwaddr_len;
|
||||
nm_utils_hwaddr_ntoa;
|
||||
nm_utils_hwaddr_ntoa_len;
|
||||
nm_utils_hwaddr_valid;
|
||||
nm_utils_iface_valid_name;
|
||||
nm_utils_inet4_ntop;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
|
|||
|
||||
hwaddr_str = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device));
|
||||
if (hwaddr_str) {
|
||||
hwaddr = nm_utils_hwaddr_aton (hwaddr_str, ARPHRD_INFINIBAND, hwaddr_buf);
|
||||
hwaddr = nm_utils_hwaddr_aton (hwaddr_str, hwaddr_buf, INFINIBAND_ALEN);
|
||||
if (!hwaddr) {
|
||||
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC,
|
||||
"Invalid device MAC address.");
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
|
|||
else
|
||||
mac_address = NULL;
|
||||
if (mac_address) {
|
||||
mac_address_str = nm_utils_hwaddr_ntoa_len (mac_address->data, mac_address->len);
|
||||
mac_address_str = nm_utils_hwaddr_ntoa (mac_address->data, mac_address->len);
|
||||
if (!g_strcmp0 (mac_address_str, NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address)) {
|
||||
g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_MAC_MISMATCH,
|
||||
"The hardware address of the device and the connection didn't match.");
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@ update_initial_hw_address (NMDevice *dev)
|
|||
memcpy (priv->initial_hw_addr, mac, ETH_ALEN);
|
||||
|
||||
_LOGD (LOGD_DEVICE | LOGD_ETHER, "read initial MAC address %s",
|
||||
(tmp_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ARPHRD_ETHER)));
|
||||
(tmp_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN)));
|
||||
}
|
||||
|
||||
static guint32
|
||||
|
|
@ -1657,7 +1657,7 @@ get_property (GObject *object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_PERM_HW_ADDRESS:
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER));
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ETH_ALEN));
|
||||
break;
|
||||
case PROP_SPEED:
|
||||
g_value_set_uint (value, priv->speed);
|
||||
|
|
|
|||
|
|
@ -316,8 +316,7 @@ spec_match_list (NMDevice *device, const GSList *specs)
|
|||
if (NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->spec_match_list (device, specs))
|
||||
return TRUE;
|
||||
|
||||
hwaddr_str = nm_utils_hwaddr_ntoa (nm_device_get_hw_address (device, NULL),
|
||||
ARPHRD_INFINIBAND);
|
||||
hwaddr_str = nm_utils_hwaddr_ntoa (nm_device_get_hw_address (device, NULL), INFINIBAND_ALEN);
|
||||
|
||||
/* InfiniBand hardware address matches only need to match the last
|
||||
* 8 bytes. In string format, that means we skip the first 36
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ update_initial_hw_address (NMDevice *dev)
|
|||
memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
|
||||
|
||||
_LOGD (LOGD_DEVICE | LOGD_VLAN, "read initial MAC address %s",
|
||||
(mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ARPHRD_ETHER)));
|
||||
(mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN)));
|
||||
}
|
||||
|
||||
static guint32
|
||||
|
|
|
|||
|
|
@ -6927,7 +6927,7 @@ nm_device_update_hw_address (NMDevice *self)
|
|||
memcpy (priv->hw_addr, hwaddr, hwaddrlen);
|
||||
|
||||
_LOGD (LOGD_HW | LOGD_DEVICE, "hardware address now %s",
|
||||
(tmp_str = nm_utils_hwaddr_ntoa_len (hwaddr, hwaddrlen)));
|
||||
(tmp_str = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen)));
|
||||
g_object_notify (G_OBJECT (self), NM_DEVICE_HW_ADDRESS);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -6959,7 +6959,7 @@ nm_device_set_hw_addr (NMDevice *self, const guint8 *addr,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
mac_str = nm_utils_hwaddr_ntoa_len (addr, len);
|
||||
mac_str = nm_utils_hwaddr_ntoa (addr, len);
|
||||
|
||||
/* Can't change MAC address while device is up */
|
||||
nm_device_take_down (self, FALSE);
|
||||
|
|
@ -7030,7 +7030,7 @@ spec_match_list (NMDevice *self, const GSList *specs)
|
|||
return TRUE;
|
||||
|
||||
if (priv->hw_addr_len) {
|
||||
hwaddr_str = nm_utils_hwaddr_ntoa_len (priv->hw_addr, priv->hw_addr_len);
|
||||
hwaddr_str = nm_utils_hwaddr_ntoa (priv->hw_addr, priv->hw_addr_len);
|
||||
matched = nm_match_spec_hwaddr (specs, hwaddr_str);
|
||||
g_free (hwaddr_str);
|
||||
}
|
||||
|
|
@ -7386,7 +7386,7 @@ set_property (GObject *object, guint prop_id,
|
|||
}
|
||||
|
||||
priv->hw_addr_len = count;
|
||||
if (!nm_utils_hwaddr_aton_len (hw_addr, priv->hw_addr, priv->hw_addr_len)) {
|
||||
if (!nm_utils_hwaddr_aton (hw_addr, priv->hw_addr, priv->hw_addr_len)) {
|
||||
g_warning ("Could not parse hw-address '%s'", hw_addr);
|
||||
memset (priv->hw_addr, 0, sizeof (priv->hw_addr));
|
||||
}
|
||||
|
|
@ -7519,7 +7519,7 @@ get_property (GObject *object, guint prop_id,
|
|||
break;
|
||||
case PROP_HW_ADDRESS:
|
||||
if (priv->hw_addr_len)
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa_len (priv->hw_addr, priv->hw_addr_len));
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, priv->hw_addr_len));
|
||||
else
|
||||
g_value_set_string (value, NULL);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -635,13 +635,13 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap)
|
|||
|
||||
if (new_ap) {
|
||||
new_bssid = nm_ap_get_address (new_ap);
|
||||
new_addr = nm_utils_hwaddr_ntoa (new_bssid, ARPHRD_ETHER);
|
||||
new_addr = nm_utils_hwaddr_ntoa (new_bssid, ETH_ALEN);
|
||||
new_ssid = nm_ap_get_ssid (new_ap);
|
||||
}
|
||||
|
||||
if (priv->current_ap) {
|
||||
old_bssid = nm_ap_get_address (priv->current_ap);
|
||||
old_addr = nm_utils_hwaddr_ntoa (old_bssid, ARPHRD_ETHER);
|
||||
old_addr = nm_utils_hwaddr_ntoa (old_bssid, ETH_ALEN);
|
||||
old_ssid = nm_ap_get_ssid (priv->current_ap);
|
||||
}
|
||||
|
||||
|
|
@ -2571,7 +2571,7 @@ update_initial_hw_address (NMDevice *device)
|
|||
memcpy (priv->initial_hw_addr, nm_device_get_hw_address (device, NULL), ETH_ALEN);
|
||||
|
||||
_LOGD (LOGD_DEVICE | LOGD_ETHER, "read initial MAC address %s",
|
||||
(mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ARPHRD_ETHER)));
|
||||
(mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN)));
|
||||
g_free (mac_str);
|
||||
}
|
||||
|
||||
|
|
@ -3268,7 +3268,7 @@ get_property (GObject *object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_PERM_HW_ADDRESS:
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER));
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->perm_hw_addr, ETH_ALEN));
|
||||
break;
|
||||
case PROP_MODE:
|
||||
g_value_set_uint (value, priv->mode);
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ get_property (GObject *object, guint prop_id,
|
|||
g_value_set_uint (value, priv->freq);
|
||||
break;
|
||||
case PROP_HW_ADDRESS:
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->address, ARPHRD_ETHER));
|
||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->address, ETH_ALEN));
|
||||
break;
|
||||
case PROP_MODE:
|
||||
g_value_set_uint (value, priv->mode);
|
||||
|
|
|
|||
|
|
@ -1049,7 +1049,7 @@ set_link_status (NMDeviceWimax *self, WIMAX_API_LINK_STATUS_INFO_EX *link_status
|
|||
conv_rssi = sdk_rssi_to_dbm (link_status->RSSI);
|
||||
conv_cinr = sdk_cinr_to_db (link_status->CINR);
|
||||
conv_tx_pow = sdk_tx_pow_to_dbm (link_status->txPWR);
|
||||
new_bsid = nm_utils_hwaddr_ntoa_len (link_status->bsId, 6);
|
||||
new_bsid = nm_utils_hwaddr_ntoa (link_status->bsId, 6);
|
||||
}
|
||||
|
||||
if (priv->center_freq != center_freq) {
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device)
|
|||
}
|
||||
|
||||
hwaddr = nm_device_get_hw_address (device, &hwaddr_len);
|
||||
hwaddr_str = nm_utils_hwaddr_ntoa_len (hwaddr, hwaddr_len);
|
||||
hwaddr_str = nm_utils_hwaddr_ntoa (hwaddr, hwaddr_len);
|
||||
g_string_append (updated, hwaddr_str);
|
||||
g_free (hwaddr_str);
|
||||
g_string_append_c (updated, '\n');
|
||||
|
|
|
|||
|
|
@ -2516,7 +2516,7 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size
|
|||
rtnl_link_set_addr (change, nladdr);
|
||||
|
||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
|
||||
char *mac = nm_utils_hwaddr_ntoa_len (address, length);
|
||||
char *mac = nm_utils_hwaddr_ntoa (address, length);
|
||||
|
||||
debug ("link: change %d: address %s (%lu bytes)", ifindex, mac, (unsigned long) length);
|
||||
g_free (mac);
|
||||
|
|
|
|||
|
|
@ -1814,7 +1814,7 @@ nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection,
|
|||
return; /* Already in the list */
|
||||
|
||||
/* Add the new BSSID; let the hash take ownership of the allocated BSSID string */
|
||||
bssid_str = nm_utils_hwaddr_ntoa (seen_bssid, ARPHRD_ETHER);
|
||||
bssid_str = nm_utils_hwaddr_ntoa (seen_bssid, ETH_ALEN);
|
||||
g_hash_table_insert (priv->seen_bssids, mac_dup (seen_bssid), bssid_str);
|
||||
|
||||
/* Build up a list of all the BSSIDs in string form */
|
||||
|
|
|
|||
|
|
@ -560,7 +560,7 @@ get_unmanaged_specs (NMSystemConfigInterface *config)
|
|||
ids = g_strsplit (str, ";", -1);
|
||||
for (i = 0; ids[i] != NULL; i++) {
|
||||
/* Verify unmanaged specification and add it to the list */
|
||||
if (!strncmp (ids[i], "mac:", 4) && nm_utils_hwaddr_valid (ids[i] + 4)) {
|
||||
if (!strncmp (ids[i], "mac:", 4) && nm_utils_hwaddr_valid (ids[i] + 4, -1)) {
|
||||
specs = g_slist_append (specs, ids[i]);
|
||||
} else if (!strncmp (ids[i], "interface-name:", 15) && nm_utils_iface_valid_name (ids[i] + 15)) {
|
||||
specs = g_slist_append (specs, ids[i]);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/ether.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_infiniband.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
|
@ -247,7 +247,7 @@ make_connection_setting (const char *file,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
read_mac_address (shvarFile *ifcfg, const char *key, int type,
|
||||
read_mac_address (shvarFile *ifcfg, const char *key, gsize len,
|
||||
GByteArray **array, GError **error)
|
||||
{
|
||||
char *value = NULL;
|
||||
|
|
@ -264,7 +264,7 @@ read_mac_address (shvarFile *ifcfg, const char *key, int type,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
*array = nm_utils_hwaddr_atoba (value, type);
|
||||
*array = nm_utils_hwaddr_atoba (value, len);
|
||||
if (!*array) {
|
||||
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
|
||||
"%s: the MAC address '%s' was invalid.", key, value);
|
||||
|
|
@ -359,7 +359,7 @@ fill_ip4_setting_from_ibft (shvarFile *ifcfg,
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (!read_mac_address (ifcfg, "HWADDR", ARPHRD_ETHER, &ifcfg_mac, error))
|
||||
if (!read_mac_address (ifcfg, "HWADDR", ETH_ALEN, &ifcfg_mac, error))
|
||||
goto done;
|
||||
/* Ensure we got a MAC */
|
||||
if (!ifcfg_mac) {
|
||||
|
|
@ -3546,7 +3546,7 @@ make_wireless_setting (shvarFile *ifcfg,
|
|||
|
||||
s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ());
|
||||
|
||||
if (read_mac_address (ifcfg, "HWADDR", ARPHRD_ETHER, &array, error)) {
|
||||
if (read_mac_address (ifcfg, "HWADDR", ETH_ALEN, &array, error)) {
|
||||
if (array) {
|
||||
g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, array, NULL);
|
||||
g_byte_array_free (array, TRUE);
|
||||
|
|
@ -3557,7 +3557,7 @@ make_wireless_setting (shvarFile *ifcfg,
|
|||
}
|
||||
|
||||
array = NULL;
|
||||
if (read_mac_address (ifcfg, "MACADDR", ARPHRD_ETHER, &array, error)) {
|
||||
if (read_mac_address (ifcfg, "MACADDR", ETH_ALEN, &array, error)) {
|
||||
if (array) {
|
||||
g_object_set (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, array, NULL);
|
||||
g_byte_array_free (array, TRUE);
|
||||
|
|
@ -3678,7 +3678,7 @@ make_wireless_setting (shvarFile *ifcfg,
|
|||
if (value) {
|
||||
GByteArray *bssid;
|
||||
|
||||
bssid = nm_utils_hwaddr_atoba (value, ARPHRD_ETHER);
|
||||
bssid = nm_utils_hwaddr_atoba (value, ETH_ALEN);
|
||||
if (!bssid) {
|
||||
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
|
||||
"Invalid BSSID '%s'", value);
|
||||
|
|
@ -3841,7 +3841,7 @@ make_wired_setting (shvarFile *ifcfg,
|
|||
g_free (value);
|
||||
}
|
||||
|
||||
if (read_mac_address (ifcfg, "HWADDR", ARPHRD_ETHER, &mac, error)) {
|
||||
if (read_mac_address (ifcfg, "HWADDR", ETH_ALEN, &mac, error)) {
|
||||
if (mac) {
|
||||
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
||||
g_byte_array_free (mac, TRUE);
|
||||
|
|
@ -3933,7 +3933,7 @@ make_wired_setting (shvarFile *ifcfg,
|
|||
g_free (value);
|
||||
|
||||
mac = NULL;
|
||||
if (read_mac_address (ifcfg, "MACADDR", ARPHRD_ETHER, &mac, error)) {
|
||||
if (read_mac_address (ifcfg, "MACADDR", ETH_ALEN, &mac, error)) {
|
||||
if (mac) {
|
||||
g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, mac, NULL);
|
||||
g_byte_array_free (mac, TRUE);
|
||||
|
|
@ -4123,7 +4123,7 @@ make_infiniband_setting (shvarFile *ifcfg,
|
|||
g_free (value);
|
||||
}
|
||||
|
||||
if (read_mac_address (ifcfg, "HWADDR", ARPHRD_INFINIBAND, &mac, error)) {
|
||||
if (read_mac_address (ifcfg, "HWADDR", INFINIBAND_ALEN, &mac, error)) {
|
||||
if (mac) {
|
||||
g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL);
|
||||
g_byte_array_free (mac, TRUE);
|
||||
|
|
@ -4525,7 +4525,7 @@ make_bridge_setting (shvarFile *ifcfg,
|
|||
g_object_set (s_bridge, NM_SETTING_BRIDGE_INTERFACE_NAME, value, NULL);
|
||||
g_free (value);
|
||||
|
||||
if (read_mac_address (ifcfg, "MACADDR", ARPHRD_ETHER, &array, error)) {
|
||||
if (read_mac_address (ifcfg, "MACADDR", ETH_ALEN, &array, error)) {
|
||||
if (array) {
|
||||
g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, array, NULL);
|
||||
g_byte_array_free (array, TRUE);
|
||||
|
|
|
|||
|
|
@ -826,14 +826,14 @@ write_wireless_setting (NMConnection *connection,
|
|||
device_mac = nm_setting_wireless_get_mac_address (s_wireless);
|
||||
if (device_mac) {
|
||||
svSetValue_free (ifcfg, "HWADDR",
|
||||
nm_utils_hwaddr_ntoa_len (device_mac->data, device_mac->len), FALSE);
|
||||
nm_utils_hwaddr_ntoa (device_mac->data, device_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "MACADDR", NULL, FALSE);
|
||||
cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless);
|
||||
if (cloned_mac) {
|
||||
svSetValue_free (ifcfg, "MACADDR",
|
||||
nm_utils_hwaddr_ntoa_len (cloned_mac->data, cloned_mac->len), FALSE);
|
||||
nm_utils_hwaddr_ntoa (cloned_mac->data, cloned_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE);
|
||||
|
|
@ -936,7 +936,7 @@ write_wireless_setting (NMConnection *connection,
|
|||
bssid = nm_setting_wireless_get_bssid (s_wireless);
|
||||
if (bssid) {
|
||||
svSetValue_free (ifcfg, "BSSID",
|
||||
nm_utils_hwaddr_ntoa_len (bssid->data, bssid->len), FALSE);
|
||||
nm_utils_hwaddr_ntoa (bssid->data, bssid->len), FALSE);
|
||||
}
|
||||
|
||||
/* Ensure DEFAULTKEY and SECURITYMODE are cleared unless there's security;
|
||||
|
|
@ -1010,7 +1010,7 @@ write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **e
|
|||
svSetValue (ifcfg, "HWADDR", NULL, FALSE);
|
||||
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
|
||||
if (mac) {
|
||||
tmp = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_INFINIBAND);
|
||||
tmp = nm_utils_hwaddr_ntoa (mac->data, mac->len);
|
||||
svSetValue (ifcfg, "HWADDR", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
@ -1068,14 +1068,14 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
device_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (device_mac) {
|
||||
svSetValue_free (ifcfg, "HWADDR",
|
||||
nm_utils_hwaddr_ntoa_len (device_mac->data, device_mac->len), FALSE);
|
||||
nm_utils_hwaddr_ntoa (device_mac->data, device_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "MACADDR", NULL, FALSE);
|
||||
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
|
||||
if (cloned_mac) {
|
||||
svSetValue_free (ifcfg, "MACADDR",
|
||||
nm_utils_hwaddr_ntoa_len (cloned_mac->data, cloned_mac->len), FALSE);
|
||||
nm_utils_hwaddr_ntoa (cloned_mac->data, cloned_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE);
|
||||
|
|
@ -1253,14 +1253,14 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired,
|
|||
|
||||
device_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (device_mac) {
|
||||
tmp = nm_utils_hwaddr_ntoa (device_mac->data, ARPHRD_ETHER);
|
||||
tmp = nm_utils_hwaddr_ntoa (device_mac->data, device_mac->len);
|
||||
svSetValue (ifcfg, "HWADDR", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
|
||||
if (cloned_mac) {
|
||||
tmp = nm_utils_hwaddr_ntoa (cloned_mac->data, ARPHRD_ETHER);
|
||||
tmp = nm_utils_hwaddr_ntoa (cloned_mac->data, device_mac->len);
|
||||
svSetValue (ifcfg, "MACADDR", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
@ -1403,7 +1403,7 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error
|
|||
|
||||
mac = nm_setting_bridge_get_mac_address (s_bridge);
|
||||
if (mac)
|
||||
svSetValue_free (ifcfg, "MACADDR", nm_utils_hwaddr_ntoa_len (mac->data, mac->len), FALSE);
|
||||
svSetValue_free (ifcfg, "MACADDR", nm_utils_hwaddr_ntoa (mac->data, mac->len), FALSE);
|
||||
|
||||
/* Bridge options */
|
||||
opts = g_string_sized_new (32);
|
||||
|
|
|
|||
|
|
@ -506,7 +506,7 @@ read_mac_address (const char *conn_name, GByteArray **array, GError **error)
|
|||
if (!value || !strlen (value))
|
||||
return TRUE;
|
||||
|
||||
*array = nm_utils_hwaddr_atoba (value, ARPHRD_ETHER);
|
||||
*array = nm_utils_hwaddr_atoba (value, ETH_ALEN);
|
||||
if (!*array) {
|
||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||
"The MAC address '%s' was invalid.", value);
|
||||
|
|
@ -982,7 +982,7 @@ make_wireless_connection_setting (const char *conn_name,
|
|||
if (value) {
|
||||
GByteArray *bssid;
|
||||
|
||||
bssid = nm_utils_hwaddr_atoba (value, ARPHRD_ETHER);
|
||||
bssid = nm_utils_hwaddr_atoba (value, ETH_ALEN);
|
||||
if (!bssid) {
|
||||
g_set_error (error, ifnet_plugin_error_quark (), 0,
|
||||
"Invalid BSSID '%s'", value);
|
||||
|
|
@ -2293,7 +2293,7 @@ write_wireless_setting (NMConnection *connection,
|
|||
ifnet_set_data (ssid_str, "mac", NULL);
|
||||
mac = nm_setting_wireless_get_mac_address (s_wireless);
|
||||
if (mac) {
|
||||
tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len);
|
||||
tmp = nm_utils_hwaddr_ntoa (mac->data, mac->len);
|
||||
ifnet_set_data (ssid_str, "mac", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
@ -2322,7 +2322,7 @@ write_wireless_setting (NMConnection *connection,
|
|||
wpa_set_data (ssid_str, "bssid", NULL);
|
||||
bssid = nm_setting_wireless_get_bssid (s_wireless);
|
||||
if (bssid) {
|
||||
tmp = nm_utils_hwaddr_ntoa_len (bssid->data, bssid->len);
|
||||
tmp = nm_utils_hwaddr_ntoa (bssid->data, bssid->len);
|
||||
wpa_set_data (ssid_str, "bssid", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
@ -2361,7 +2361,7 @@ write_wired_setting (NMConnection *connection,
|
|||
ifnet_set_data (conn_name, "mac", NULL);
|
||||
mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (mac) {
|
||||
tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len);
|
||||
tmp = nm_utils_hwaddr_ntoa (mac->data, mac->len);
|
||||
ifnet_set_data (conn_name, "mac", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ bind_device_to_connection (SCPluginIfupdown *self,
|
|||
return;
|
||||
}
|
||||
|
||||
mac_address = nm_utils_hwaddr_atoba (address, ARPHRD_ETHER);
|
||||
mac_address = nm_utils_hwaddr_atoba (address, ETH_ALEN);
|
||||
if (!mac_address) {
|
||||
nm_log_warn (LOGD_SETTINGS, "failed to parse MAC address '%s' for %s",
|
||||
address, iface);
|
||||
|
|
|
|||
|
|
@ -501,7 +501,7 @@ get_unmanaged_specs (NMSystemConfigInterface *config)
|
|||
|
||||
for (i = 0; udis[i] != NULL; i++) {
|
||||
/* Verify unmanaged specification and add it to the list */
|
||||
if (!strncmp (udis[i], "mac:", 4) && nm_utils_hwaddr_valid (udis[i] + 4)) {
|
||||
if (!strncmp (udis[i], "mac:", 4) && nm_utils_hwaddr_valid (udis[i] + 4, -1)) {
|
||||
specs = g_slist_append (specs, udis[i]);
|
||||
} else if (!strncmp (udis[i], "interface-name:", 15) && nm_utils_iface_valid_name (udis[i] + 15)) {
|
||||
specs = g_slist_append (specs, udis[i]);
|
||||
|
|
|
|||
|
|
@ -557,7 +557,7 @@ mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, cons
|
|||
/* If we found enough it's probably a string-format MAC address */
|
||||
array = g_byte_array_sized_new (i+1);
|
||||
g_byte_array_set_size (array, i+1);
|
||||
if (!nm_utils_hwaddr_aton_len (tmp_string, array->data, array->len)) {
|
||||
if (!nm_utils_hwaddr_aton (tmp_string, array->data, array->len)) {
|
||||
g_byte_array_unref (array);
|
||||
array = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ mac_address_writer (GKeyFile *file,
|
|||
if (!array || !array->len)
|
||||
return;
|
||||
|
||||
mac = nm_utils_hwaddr_ntoa_len (array->data, array->len);
|
||||
mac = nm_utils_hwaddr_ntoa (array->data, array->len);
|
||||
nm_keyfile_plugin_kf_set_string (file, setting_name, key, mac);
|
||||
g_free (mac);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -494,7 +494,7 @@ test_connection_match_wired (void)
|
|||
copy = nm_connection_duplicate (orig);
|
||||
connections = g_slist_append (connections, copy);
|
||||
|
||||
mac = nm_utils_hwaddr_atoba ("52:54:00:ab:db:23", ARPHRD_ETHER);
|
||||
mac = nm_utils_hwaddr_atoba ("52:54:00:ab:db:23", ETH_ALEN);
|
||||
s_wired = nm_connection_get_setting_wired (orig);
|
||||
g_assert (s_wired);
|
||||
g_object_set (G_OBJECT (s_wired),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue