mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-04 16:50:17 +01:00
keyfile: add support for Infiniband connections
This commit is contained in:
parent
1f8090fb58
commit
8a16af2bd8
5 changed files with 188 additions and 30 deletions
|
|
@ -37,6 +37,7 @@
|
|||
#include <nm-utils.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/ether.h>
|
||||
#include <linux/if_infiniband.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
|
@ -655,7 +656,7 @@ mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, cons
|
|||
gint *tmp_list;
|
||||
GByteArray *array = NULL;
|
||||
gsize length;
|
||||
int i;
|
||||
int i, type;
|
||||
|
||||
p = tmp_string = g_key_file_get_string (keyfile, setting_name, key, NULL);
|
||||
if (tmp_string) {
|
||||
|
|
@ -666,41 +667,45 @@ mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, cons
|
|||
i++;
|
||||
p++;
|
||||
}
|
||||
if (i == 5) {
|
||||
/* parse as a MAC address */
|
||||
array = nm_utils_hwaddr_atoba (tmp_string, ARPHRD_ETHER);
|
||||
if (array) {
|
||||
g_free (tmp_string);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we found enough it's probably a string-format MAC address */
|
||||
type = nm_utils_hwaddr_type (i + 1);
|
||||
if (type > 0)
|
||||
array = nm_utils_hwaddr_atoba (tmp_string, type);
|
||||
}
|
||||
g_free (tmp_string);
|
||||
|
||||
/* Old format; list of ints */
|
||||
tmp_list = g_key_file_get_integer_list (keyfile, setting_name, key, &length, NULL);
|
||||
array = g_byte_array_sized_new (length);
|
||||
for (i = 0; i < length; i++) {
|
||||
int val = tmp_list[i];
|
||||
unsigned char v = (unsigned char) (val & 0xFF);
|
||||
if (array == NULL) {
|
||||
/* Old format; list of ints */
|
||||
tmp_list = g_key_file_get_integer_list (keyfile, setting_name, key, &length, NULL);
|
||||
type = nm_utils_hwaddr_type (length);
|
||||
if (type < 0) {
|
||||
array = g_byte_array_sized_new (length);
|
||||
for (i = 0; i < length; i++) {
|
||||
int val = tmp_list[i];
|
||||
const guint8 v = (guint8) (val & 0xFF);
|
||||
|
||||
if (val < 0 || val > 255) {
|
||||
g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
|
||||
" between 0 and 255 inclusive)", __func__, setting_name,
|
||||
key, val);
|
||||
} else
|
||||
g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
|
||||
if (val < 0 || val > 255) {
|
||||
g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
|
||||
" between 0 and 255 inclusive)", __func__, setting_name,
|
||||
key, val);
|
||||
g_byte_array_free (array, TRUE);
|
||||
array = NULL;
|
||||
break;
|
||||
}
|
||||
g_byte_array_append (array, &v, 1);
|
||||
}
|
||||
}
|
||||
g_free (tmp_list);
|
||||
}
|
||||
g_free (tmp_list);
|
||||
|
||||
done:
|
||||
if (array->len == ETH_ALEN) {
|
||||
if (array) {
|
||||
g_object_set (setting, key, array, NULL);
|
||||
g_byte_array_free (array, TRUE);
|
||||
} else {
|
||||
g_warning ("%s: ignoring invalid MAC address for %s / %s",
|
||||
__func__, setting_name, key);
|
||||
}
|
||||
g_byte_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1033,6 +1038,10 @@ static KeyParser key_parsers[] = {
|
|||
NM_SETTING_BLUETOOTH_BDADDR,
|
||||
TRUE,
|
||||
mac_address_parser },
|
||||
{ NM_SETTING_INFINIBAND_SETTING_NAME,
|
||||
NM_SETTING_INFINIBAND_MAC_ADDRESS,
|
||||
TRUE,
|
||||
mac_address_parser },
|
||||
{ NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SSID,
|
||||
TRUE,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ KEYFILES = \
|
|||
Test_Wired_TLS_Old \
|
||||
Test_Wired_TLS_New \
|
||||
Test_Wired_TLS_Blob \
|
||||
Test_Wired_TLS_Path_Missing
|
||||
Test_Wired_TLS_Path_Missing \
|
||||
Test_Infiniband_Connection
|
||||
|
||||
CERTS = \
|
||||
test-ca-cert.pem \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
[connection]
|
||||
id=Test Infiniband Connection
|
||||
uuid=4e80a56d-c99f-4aad-a6dd-b449bc398c57
|
||||
type=infiniband
|
||||
|
||||
[infiniband]
|
||||
mac-address=00:11:22:33:44:55:66:77:88:99:01:12:23:34:45:56:67:78:89:90
|
||||
mtu=1400
|
||||
|
||||
[ipv4]
|
||||
method=auto
|
||||
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/if_infiniband.h>
|
||||
|
||||
#include <nm-utils.h>
|
||||
#include <nm-setting-connection.h>
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
#include <nm-setting-ppp.h>
|
||||
#include <nm-setting-gsm.h>
|
||||
#include <nm-setting-8021x.h>
|
||||
#include <nm-setting-infiniband.h>
|
||||
|
||||
#include "nm-test-helpers.h"
|
||||
|
||||
|
|
@ -2828,6 +2830,133 @@ test_write_wired_8021x_tls_connection_blob (void)
|
|||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
#define TEST_INFINIBAND_FILE TEST_KEYFILES_DIR"/Test_Infiniband_Connection"
|
||||
|
||||
static void
|
||||
test_read_infiniband_connection (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingInfiniband *s_ib;
|
||||
GError *error = NULL;
|
||||
const GByteArray *array;
|
||||
guint8 expected_mac[INFINIBAND_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
|
||||
0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89,
|
||||
0x90 };
|
||||
const char *expected_id = "Test Infiniband Connection";
|
||||
const char *expected_uuid = "4e80a56d-c99f-4aad-a6dd-b449bc398c57";
|
||||
gboolean success;
|
||||
|
||||
connection = nm_keyfile_plugin_connection_from_file (TEST_INFINIBAND_FILE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection);
|
||||
success = nm_connection_verify (connection, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
/* Connection setting */
|
||||
s_con = nm_connection_get_setting_connection (connection);
|
||||
g_assert (s_con);
|
||||
g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, expected_id);
|
||||
g_assert_cmpstr (nm_setting_connection_get_uuid (s_con), ==, expected_uuid);
|
||||
|
||||
/* Infiniband setting */
|
||||
s_ib = nm_connection_get_setting_infiniband (connection);
|
||||
g_assert (s_ib);
|
||||
|
||||
array = nm_setting_infiniband_get_mac_address (s_ib);
|
||||
g_assert (array);
|
||||
g_assert_cmpint (array->len, ==, INFINIBAND_ALEN);
|
||||
g_assert_cmpint (memcmp (array->data, expected_mac, sizeof (expected_mac)), ==, 0);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_infiniband_connection (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingInfiniband *s_ib;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
char *uuid;
|
||||
GByteArray *mac;
|
||||
guint8 tmpmac[] = { 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0xab, 0xbc,
|
||||
0xcd, 0xde, 0xef, 0xf0, 0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f, 0x6f, 0xba
|
||||
};
|
||||
gboolean success;
|
||||
NMConnection *reread;
|
||||
char *testfile = NULL;
|
||||
GError *error = NULL;
|
||||
pid_t owner_grp;
|
||||
uid_t owner_uid;
|
||||
|
||||
connection = nm_connection_new ();
|
||||
g_assert (connection);
|
||||
|
||||
/* Connection setting */
|
||||
|
||||
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
||||
g_assert (s_con);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_ID, "Work Infiniband",
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME,
|
||||
NULL);
|
||||
g_free (uuid);
|
||||
|
||||
/* Infiniband setting */
|
||||
s_ib = (NMSettingInfiniband *) nm_setting_infiniband_new ();
|
||||
g_assert (s_ib);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ib));
|
||||
|
||||
mac = g_byte_array_sized_new (sizeof (tmpmac));
|
||||
g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac));
|
||||
g_object_set (s_ib,
|
||||
NM_SETTING_INFINIBAND_MAC_ADDRESS, mac,
|
||||
NM_SETTING_INFINIBAND_MTU, 900,
|
||||
NULL);
|
||||
g_byte_array_free (mac, TRUE);
|
||||
|
||||
/* IP4 setting */
|
||||
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
|
||||
g_assert (s_ip4);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
|
||||
|
||||
/* IP6 setting */
|
||||
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
|
||||
g_assert (s_ip6);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
|
||||
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
|
||||
|
||||
/* Write out the connection */
|
||||
owner_uid = geteuid ();
|
||||
owner_grp = getegid ();
|
||||
success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
g_assert (testfile);
|
||||
|
||||
/* Read the connection back in and compare it to the one we just wrote out */
|
||||
reread = nm_keyfile_plugin_connection_from_file (testfile, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (reread);
|
||||
|
||||
g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT));
|
||||
|
||||
unlink (testfile);
|
||||
g_free (testfile);
|
||||
|
||||
g_object_unref (reread);
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
|
@ -2876,6 +3005,9 @@ int main (int argc, char **argv)
|
|||
test_write_wired_8021x_tls_connection_path ();
|
||||
test_write_wired_8021x_tls_connection_blob ();
|
||||
|
||||
test_read_infiniband_connection ();
|
||||
test_write_infiniband_connection ();
|
||||
|
||||
base = g_path_get_basename (argv[0]);
|
||||
fprintf (stdout, "%s: SUCCESS\n", base);
|
||||
g_free (base);
|
||||
|
|
|
|||
|
|
@ -416,7 +416,7 @@ mac_address_writer (GKeyFile *file,
|
|||
GByteArray *array;
|
||||
const char *setting_name = nm_setting_get_name (setting);
|
||||
char *mac;
|
||||
struct ether_addr tmp;
|
||||
int type;
|
||||
|
||||
g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY));
|
||||
|
||||
|
|
@ -424,15 +424,16 @@ mac_address_writer (GKeyFile *file,
|
|||
if (!array)
|
||||
return;
|
||||
|
||||
if (array->len != ETH_ALEN) {
|
||||
type = nm_utils_hwaddr_type (array->len);
|
||||
if (type < 0) {
|
||||
g_warning ("%s: invalid %s / %s MAC address length %d",
|
||||
__func__, setting_name, key, array->len);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy (tmp.ether_addr_octet, array->data, ETH_ALEN);
|
||||
mac = ether_ntoa (&tmp);
|
||||
mac = nm_utils_hwaddr_ntoa (array->data, type);
|
||||
g_key_file_set_string (file, setting_name, key, mac);
|
||||
g_free (mac);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -812,6 +813,9 @@ static KeyWriter key_writers[] = {
|
|||
{ NM_SETTING_BLUETOOTH_SETTING_NAME,
|
||||
NM_SETTING_BLUETOOTH_BDADDR,
|
||||
mac_address_writer },
|
||||
{ NM_SETTING_INFINIBAND_SETTING_NAME,
|
||||
NM_SETTING_INFINIBAND_MAC_ADDRESS,
|
||||
mac_address_writer },
|
||||
{ NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SSID,
|
||||
ssid_writer },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue