mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 14:00:11 +01:00
ifcfg-rh: read iBFT config and convert to NM IPv4 config
This commit is contained in:
parent
869e57524c
commit
1d5a68db74
17 changed files with 958 additions and 46 deletions
|
|
@ -32,7 +32,8 @@ libifcfg_rh_io_la_CPPFLAGS = \
|
|||
$(DBUS_CFLAGS) \
|
||||
$(NSS_CFLAGS) \
|
||||
-DG_DISABLE_DEPRECATED \
|
||||
-DSYSCONFDIR=\"$(sysconfdir)\"
|
||||
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||
-DSBINDIR=\"$(sbindir)\"
|
||||
|
||||
libifcfg_rh_io_la_LIBADD = $(GLIB_LIBS) $(NSS_LIBS)
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ nm_ifcfg_connection_new (const char *filename,
|
|||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
|
||||
wrapped = connection_from_file (filename, NULL, NULL, &unmanaged, &keyfile, error, ignore_error);
|
||||
wrapped = connection_from_file (filename, NULL, NULL, NULL, &unmanaged, &keyfile, error, ignore_error);
|
||||
if (!wrapped)
|
||||
return NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/wait.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <errno.h>
|
||||
|
|
@ -183,6 +184,284 @@ make_connection_setting (const char *file,
|
|||
return NM_SETTING (s_con);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
read_mac_address (shvarFile *ifcfg, GByteArray **array, GError **error)
|
||||
{
|
||||
char *value = NULL;
|
||||
struct ether_addr *mac;
|
||||
|
||||
g_return_val_if_fail (ifcfg != NULL, FALSE);
|
||||
g_return_val_if_fail (array != NULL, FALSE);
|
||||
g_return_val_if_fail (*array == NULL, FALSE);
|
||||
g_return_val_if_fail (error != NULL, FALSE);
|
||||
g_return_val_if_fail (*error == NULL, FALSE);
|
||||
|
||||
value = svGetValue (ifcfg, "HWADDR", FALSE);
|
||||
if (!value || !strlen (value)) {
|
||||
g_free (value);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
mac = ether_aton (value);
|
||||
if (!mac) {
|
||||
g_free (value);
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"The MAC address '%s' was invalid.", value);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_free (value);
|
||||
*array = g_byte_array_sized_new (ETH_ALEN);
|
||||
g_byte_array_append (*array, (guint8 *) mac->ether_addr_octet, ETH_ALEN);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
iscsiadm_child_setup (gpointer user_data G_GNUC_UNUSED)
|
||||
{
|
||||
/* We are in the child process here; set a different process group to
|
||||
* ensure signal isolation between child and parent.
|
||||
*/
|
||||
pid_t pid = getpid ();
|
||||
setpgid (pid, pid);
|
||||
}
|
||||
|
||||
static char *
|
||||
match_iscsiadm_tag (const char *line, const char *tag, gboolean *skip)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (g_ascii_strncasecmp (line, tag, strlen (tag)))
|
||||
return NULL;
|
||||
|
||||
p = strchr (line, '=');
|
||||
if (!p) {
|
||||
g_warning ("%s: malformed iscsiadm record: no = in '%s'.",
|
||||
__func__, line);
|
||||
*skip = TRUE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p++; /* advance past = */
|
||||
return g_strstrip (p);
|
||||
}
|
||||
|
||||
#define ISCSI_HWADDR_TAG "iface.hwaddress"
|
||||
#define ISCSI_BOOTPROTO_TAG "iface.bootproto"
|
||||
#define ISCSI_IPADDR_TAG "iface.ipaddress"
|
||||
#define ISCSI_SUBNET_TAG "iface.subnet_mask"
|
||||
#define ISCSI_GATEWAY_TAG "iface.gateway"
|
||||
#define ISCSI_DNS1_TAG "iface.primary_dns"
|
||||
#define ISCSI_DNS2_TAG "iface.secondary_dns"
|
||||
|
||||
static gboolean
|
||||
fill_ip4_setting_from_ibft (shvarFile *ifcfg,
|
||||
NMSettingIP4Config *s_ip4,
|
||||
const char *iscsiadm_path,
|
||||
GError **error)
|
||||
{
|
||||
const char *argv[4] = { iscsiadm_path, "-m", "fw", NULL };
|
||||
const char *envp[1] = { NULL };
|
||||
gboolean success = FALSE, in_record = FALSE, hwaddr_matched = FALSE, skip = FALSE;
|
||||
char *out = NULL, *err = NULL;
|
||||
gint status = 0;
|
||||
GByteArray *ifcfg_mac = NULL;
|
||||
char **lines = NULL, **iter;
|
||||
const char *method = NULL;
|
||||
struct in_addr ipaddr;
|
||||
struct in_addr gateway;
|
||||
struct in_addr dns1;
|
||||
struct in_addr dns2;
|
||||
guint32 prefix = 0;
|
||||
|
||||
g_return_val_if_fail (s_ip4 != NULL, FALSE);
|
||||
g_return_val_if_fail (iscsiadm_path != NULL, FALSE);
|
||||
|
||||
if (!g_spawn_sync ("/", (char **) argv, (char **) envp, 0,
|
||||
iscsiadm_child_setup, NULL, &out, &err, &status, error))
|
||||
return FALSE;
|
||||
|
||||
if (!WIFEXITED (status)) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"%s exited abnormally.", iscsiadm_path);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (WEXITSTATUS (status) != 0) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"%s exited with error %d. Message: '%s'",
|
||||
iscsiadm_path, WEXITSTATUS (status), err ? err : "(none)");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!read_mac_address (ifcfg, &ifcfg_mac, error))
|
||||
goto done;
|
||||
/* Ensure we got a MAC */
|
||||
if (!ifcfg_mac) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"Missing device MAC address (no HWADDR tag present).");
|
||||
goto done;
|
||||
}
|
||||
|
||||
memset (&ipaddr, 0, sizeof (ipaddr));
|
||||
memset (&gateway, 0, sizeof (gateway));
|
||||
memset (&dns1, 0, sizeof (dns1));
|
||||
memset (&dns2, 0, sizeof (dns2));
|
||||
|
||||
/* Success, lets parse the output */
|
||||
lines = g_strsplit_set (out, "\n\r", -1);
|
||||
for (iter = lines; iter && *iter; iter++) {
|
||||
char *p;
|
||||
|
||||
if (!g_ascii_strcasecmp (*iter, "# BEGIN RECORD")) {
|
||||
if (in_record) {
|
||||
g_warning ("%s: malformed iscsiadm record: already parsing record.", __func__);
|
||||
skip = TRUE;
|
||||
}
|
||||
} else if (!g_ascii_strcasecmp (*iter, "# END RECORD")) {
|
||||
if (!skip && hwaddr_matched) {
|
||||
/* Record is good; fill IP4 config with its info */
|
||||
if (!method) {
|
||||
g_warning ("%s: malformed iscsiadm record: missing BOOTPROTO.", __func__);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, method, NULL);
|
||||
|
||||
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
|
||||
NMIP4Address *addr;
|
||||
|
||||
if (!ipaddr.s_addr || !prefix) {
|
||||
g_warning ("%s: malformed iscsiadm record: BOOTPROTO=static "
|
||||
"but missing IP address or prefix.", __func__);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
addr = nm_ip4_address_new ();
|
||||
nm_ip4_address_set_address (addr, ipaddr.s_addr);
|
||||
nm_ip4_address_set_prefix (addr, prefix);
|
||||
nm_ip4_address_set_gateway (addr, gateway.s_addr);
|
||||
nm_setting_ip4_config_add_address (s_ip4, addr);
|
||||
nm_ip4_address_unref (addr);
|
||||
|
||||
if (dns1.s_addr)
|
||||
nm_setting_ip4_config_add_dns (s_ip4, dns1.s_addr);
|
||||
if (dns2.s_addr)
|
||||
nm_setting_ip4_config_add_dns (s_ip4, dns2.s_addr);
|
||||
|
||||
// FIXME: DNS search domains?
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
skip = FALSE;
|
||||
hwaddr_matched = FALSE;
|
||||
memset (&ipaddr, 0, sizeof (ipaddr));
|
||||
memset (&gateway, 0, sizeof (gateway));
|
||||
memset (&dns1, 0, sizeof (dns1));
|
||||
memset (&dns2, 0, sizeof (dns2));
|
||||
prefix = 0;
|
||||
method = NULL;
|
||||
}
|
||||
|
||||
if (skip)
|
||||
continue;
|
||||
|
||||
/* HWADDR */
|
||||
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_HWADDR_TAG, &skip))) {
|
||||
struct ether_addr *ibft_mac;
|
||||
|
||||
ibft_mac = ether_aton (p);
|
||||
if (!ibft_mac) {
|
||||
g_warning ("%s: malformed iscsiadm record: invalid hwaddress.", __func__);
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (memcmp (ifcfg_mac->data, (guint8 *) ibft_mac->ether_addr_octet, ETH_ALEN)) {
|
||||
/* This record isn't for the current device, ignore it */
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Success, this record is for this device */
|
||||
hwaddr_matched = TRUE;
|
||||
}
|
||||
|
||||
/* BOOTPROTO */
|
||||
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_BOOTPROTO_TAG, &skip))) {
|
||||
if (!g_ascii_strcasecmp (p, "dhcp"))
|
||||
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
||||
else if (!g_ascii_strcasecmp (p, "static"))
|
||||
method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
|
||||
else {
|
||||
g_warning ("%s: malformed iscsiadm record: unknown BOOTPROTO '%s'.",
|
||||
__func__, p);
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_IPADDR_TAG, &skip))) {
|
||||
if (inet_pton (AF_INET, p, &ipaddr) < 1) {
|
||||
g_warning ("%s: malformed iscsiadm record: invalid IP address '%s'.",
|
||||
__func__, p);
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_SUBNET_TAG, &skip))) {
|
||||
struct in_addr mask;
|
||||
|
||||
if (inet_pton (AF_INET, p, &mask) < 1) {
|
||||
g_warning ("%s: malformed iscsiadm record: invalid subnet mask '%s'.",
|
||||
__func__, p);
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
prefix = nm_utils_ip4_netmask_to_prefix (mask.s_addr);
|
||||
}
|
||||
|
||||
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_GATEWAY_TAG, &skip))) {
|
||||
if (inet_pton (AF_INET, p, &gateway) < 1) {
|
||||
g_warning ("%s: malformed iscsiadm record: invalid IP gateway '%s'.",
|
||||
__func__, p);
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_DNS1_TAG, &skip))) {
|
||||
if (inet_pton (AF_INET, p, &dns1) < 1) {
|
||||
g_warning ("%s: malformed iscsiadm record: invalid DNS1 address '%s'.",
|
||||
__func__, p);
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_DNS2_TAG, &skip))) {
|
||||
if (inet_pton (AF_INET, p, &dns2) < 1) {
|
||||
g_warning ("%s: malformed iscsiadm record: invalid DNS2 address '%s'.",
|
||||
__func__, p);
|
||||
skip = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
success = TRUE;
|
||||
|
||||
done:
|
||||
if (ifcfg_mac)
|
||||
g_byte_array_free (ifcfg_mac, TRUE);
|
||||
g_strfreev (lines);
|
||||
g_free (out);
|
||||
g_free (err);
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
read_ip4_address (shvarFile *ifcfg,
|
||||
const char *tag,
|
||||
|
|
@ -325,7 +604,10 @@ error:
|
|||
}
|
||||
|
||||
static NMSetting *
|
||||
make_ip4_setting (shvarFile *ifcfg, const char *network_file, GError **error)
|
||||
make_ip4_setting (shvarFile *ifcfg,
|
||||
const char *network_file,
|
||||
const char *iscsiadm_path,
|
||||
GError **error)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4 = NULL;
|
||||
char *value = NULL;
|
||||
|
|
@ -364,7 +646,15 @@ make_ip4_setting (shvarFile *ifcfg, const char *network_file, GError **error)
|
|||
if (value) {
|
||||
if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp"))
|
||||
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
||||
else if (!g_ascii_strcasecmp (value, "autoip")) {
|
||||
else if (!g_ascii_strcasecmp (value, "ibft")) {
|
||||
/* iSCSI Boot Firmware Table: need to read values from the iSCSI
|
||||
* firmware for this device and create the IP4 setting using those.
|
||||
*/
|
||||
if (fill_ip4_setting_from_ibft (ifcfg, s_ip4, iscsiadm_path, error))
|
||||
return NM_SETTING (s_ip4);
|
||||
g_object_unref (s_ip4);
|
||||
return NULL;
|
||||
} else if (!g_ascii_strcasecmp (value, "autoip")) {
|
||||
g_free (value);
|
||||
g_object_set (s_ip4,
|
||||
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
|
||||
|
|
@ -498,38 +788,6 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
read_mac_address (shvarFile *ifcfg, GByteArray **array, GError **error)
|
||||
{
|
||||
char *value = NULL;
|
||||
struct ether_addr *mac;
|
||||
|
||||
g_return_val_if_fail (ifcfg != NULL, FALSE);
|
||||
g_return_val_if_fail (array != NULL, FALSE);
|
||||
g_return_val_if_fail (*array == NULL, FALSE);
|
||||
g_return_val_if_fail (error != NULL, FALSE);
|
||||
g_return_val_if_fail (*error == NULL, FALSE);
|
||||
|
||||
value = svGetValue (ifcfg, "HWADDR", FALSE);
|
||||
if (!value || !strlen (value)) {
|
||||
g_free (value);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
mac = ether_aton (value);
|
||||
if (!mac) {
|
||||
g_free (value);
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"The MAC address '%s' was invalid.", value);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_free (value);
|
||||
*array = g_byte_array_sized_new (ETH_ALEN);
|
||||
g_byte_array_append (*array, (guint8 *) mac->ether_addr_octet, ETH_ALEN);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_one_wep_key (shvarFile *ifcfg,
|
||||
const char *shvar_key,
|
||||
|
|
@ -2032,8 +2290,9 @@ is_wireless_device (const char *iface)
|
|||
|
||||
NMConnection *
|
||||
connection_from_file (const char *filename,
|
||||
const char *network_file,
|
||||
const char *test_type, /* for unit tests only */
|
||||
const char *network_file, /* for unit tests only */
|
||||
const char *test_type, /* for unit tests only */
|
||||
const char *iscsiadm_path, /* for unit tests only */
|
||||
char **unmanaged,
|
||||
char **keyfile,
|
||||
GError **error,
|
||||
|
|
@ -2041,7 +2300,7 @@ connection_from_file (const char *filename,
|
|||
{
|
||||
NMConnection *connection = NULL;
|
||||
shvarFile *parsed;
|
||||
char *type, *nmc = NULL;
|
||||
char *type, *nmc = NULL, *bootproto;
|
||||
NMSetting *s_ip4;
|
||||
char *ifcfg_name = NULL;
|
||||
gboolean nm_controlled = TRUE;
|
||||
|
|
@ -2056,6 +2315,9 @@ connection_from_file (const char *filename,
|
|||
if (!network_file)
|
||||
network_file = SYSCONFDIR "/sysconfig/network";
|
||||
|
||||
if (!iscsiadm_path)
|
||||
iscsiadm_path = SBINDIR "/iscsiadm";
|
||||
|
||||
ifcfg_name = utils_get_ifcfg_name (filename);
|
||||
if (!ifcfg_name) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
|
|
@ -2142,7 +2404,7 @@ connection_from_file (const char *filename,
|
|||
if (!connection || *unmanaged)
|
||||
goto done;
|
||||
|
||||
s_ip4 = make_ip4_setting (parsed, network_file, error);
|
||||
s_ip4 = make_ip4_setting (parsed, network_file, iscsiadm_path, error);
|
||||
if (*error) {
|
||||
g_object_unref (connection);
|
||||
connection = NULL;
|
||||
|
|
@ -2151,6 +2413,21 @@ connection_from_file (const char *filename,
|
|||
nm_connection_add_setting (connection, s_ip4);
|
||||
}
|
||||
|
||||
/* iSCSI / ibft connections are read-only since their settings are
|
||||
* stored in NVRAM and can only be changed in BIOS.
|
||||
*/
|
||||
bootproto = svGetValue (parsed, "BOOTPROTO", FALSE);
|
||||
if ( bootproto
|
||||
&& connection
|
||||
&& !g_ascii_strcasecmp (bootproto, "ibft")) {
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||
g_assert (s_con);
|
||||
|
||||
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_READ_ONLY, TRUE, NULL);
|
||||
}
|
||||
|
||||
if (!nm_connection_verify (connection, error)) {
|
||||
g_object_unref (connection);
|
||||
connection = NULL;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@
|
|||
#include "shvar.h"
|
||||
|
||||
NMConnection *connection_from_file (const char *filename,
|
||||
const char *network_file,
|
||||
const char *test_type,
|
||||
const char *network_file, /* for unit tests only */
|
||||
const char *test_type, /* for unit tests only */
|
||||
const char *iscsiadm_path, /* for unit tests only */
|
||||
char **unmanaged,
|
||||
char **keyfile,
|
||||
GError **error,
|
||||
|
|
|
|||
|
|
@ -30,3 +30,12 @@ check-local: test-ifcfg-rh
|
|||
|
||||
endif
|
||||
|
||||
EXTRA_DIST = \
|
||||
iscsiadm-test-dhcp \
|
||||
iscsiadm-test-static \
|
||||
iscsiadm-test-malformed \
|
||||
iscsiadm-test-bad-ipaddr \
|
||||
iscsiadm-test-bad-gateway \
|
||||
iscsiadm-test-bad-dns1 \
|
||||
iscsiadm-test-bad-dns2
|
||||
|
||||
|
|
|
|||
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1
Executable file
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = STATIC
|
||||
iface.ipaddress = 192.168.32.72
|
||||
iface.subnet_mask = 255.255.252.0
|
||||
iface.gateway = 192.168.35.254
|
||||
iface.primary_dns = 10000.500.250.1
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
EOF
|
||||
|
||||
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2
Executable file
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = STATIC
|
||||
iface.ipaddress = 192.168.32.72
|
||||
iface.subnet_mask = 255.255.252.0
|
||||
iface.gateway = 192.168.35.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = blah.foo.bar.baz
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
EOF
|
||||
|
||||
35
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry
Executable file
35
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = STATIC
|
||||
iface.ipaddress 192.168.32.72
|
||||
iface.subnet_mask = 255.255.252.0
|
||||
iface.gateway = 192.168.35.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f1
|
||||
iface.bootproto = DHCP
|
||||
iface.gateway = 10.16.52.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth1
|
||||
node.name = iqn.1.2008-11.com.blahblah:iscsi1
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
EOF
|
||||
|
||||
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-gateway
Executable file
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-gateway
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = STATIC
|
||||
iface.ipaddress = aa.bb.cc.dd
|
||||
iface.subnet_mask = 255.255.252.0
|
||||
iface.gateway = 192.168.35.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
EOF
|
||||
|
||||
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr
Executable file
21
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = STATIC
|
||||
iface.ipaddress = 192.168.32.72
|
||||
iface.subnet_mask = 255.255.252.0
|
||||
iface.gateway = bb.cc.dd.ee
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
EOF
|
||||
|
||||
18
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record
Executable file
18
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = DHCP
|
||||
iface.gateway = 10.16.52.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
EOF
|
||||
|
||||
33
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp
Executable file
33
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = DHCP
|
||||
iface.gateway = 10.16.52.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f1
|
||||
iface.bootproto = DHCP
|
||||
iface.gateway = 10.16.52.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth1
|
||||
node.name = iqn.1.2008-11.com.blahblah:iscsi1
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
EOF
|
||||
|
||||
35
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-static
Executable file
35
system-settings/plugins/ifcfg-rh/tests/iscsiadm-test-static
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat << EOF
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f0
|
||||
iface.bootproto = STATIC
|
||||
iface.ipaddress = 192.168.32.72
|
||||
iface.subnet_mask = 255.255.252.0
|
||||
iface.gateway = 192.168.35.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth0
|
||||
node.name = iqn.0.2008-11.com.blahblah:iscsi0
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
# BEGIN RECORD
|
||||
iface.initiatorname = iqn.pjones6
|
||||
iface.hwaddress = 00:33:21:98:b9:f1
|
||||
iface.bootproto = DHCP
|
||||
iface.gateway = 10.16.52.254
|
||||
iface.primary_dns = 10.16.255.2
|
||||
iface.secondary_dns = 10.16.255.3
|
||||
iface.vlan = 0
|
||||
iface.net_ifacename = eth1
|
||||
node.name = iqn.1.2008-11.com.blahblah:iscsi1
|
||||
node.conn[0].address = 10.16.52.16
|
||||
node.conn[0].port = 3260
|
||||
node.boot_lun = 00000000
|
||||
# END RECORD
|
||||
EOF
|
||||
|
||||
|
|
@ -35,7 +35,9 @@ EXTRA_DIST = \
|
|||
ifcfg-test-wifi-wpa-eap-ttls-tls \
|
||||
keys-test-wifi-wpa-eap-ttls-tls \
|
||||
test_ca_cert.pem \
|
||||
test1_key_and_cert.pem
|
||||
test1_key_and_cert.pem \
|
||||
ifcfg-test-ibft-dhcp \
|
||||
ifcfg-test-ibft-static
|
||||
|
||||
check-local:
|
||||
@for f in $(EXTRA_DIST); do \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
|
||||
DEVICE=eth0
|
||||
HWADDR=00:33:21:98:b9:f1
|
||||
BOOTPROTO=ibft
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
|
||||
DEVICE=eth0
|
||||
HWADDR=00:33:21:98:b9:f0
|
||||
BOOTPROTO=ibft
|
||||
|
|
@ -176,6 +176,7 @@ test_read_minimal (void)
|
|||
connection = connection_from_file (TEST_IFCFG_MINIMAL,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -299,6 +300,7 @@ test_read_unmanaged (void)
|
|||
connection = connection_from_file (TEST_IFCFG_UNMANAGED,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -417,6 +419,7 @@ test_read_wired_static (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIRED_STATIC,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -557,7 +560,7 @@ test_read_wired_static (void)
|
|||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
||||
ASSERT (nm_ip4_address_get_prefix (ip4_addr) == 24,
|
||||
"wired-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1 gateway",
|
||||
"wired-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1 prefix",
|
||||
TEST_IFCFG_WIRED_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
|
@ -612,6 +615,7 @@ test_read_wired_dhcp (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIRED_DHCP,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -777,6 +781,7 @@ test_read_wired_global_gateway (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIRED_GLOBAL_GATEWAY,
|
||||
TEST_NETWORK_WIRED_GLOBAL_GATEWAY,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -844,7 +849,7 @@ test_read_wired_global_gateway (void)
|
|||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
||||
ASSERT (nm_ip4_address_get_prefix (ip4_addr) == 24,
|
||||
"wired-global-gateway-verify-ip4", "failed to verify %s: unexpected IP4 address #1 gateway",
|
||||
"wired-global-gateway-verify-ip4", "failed to verify %s: unexpected IP4 address #1 prefix",
|
||||
TEST_IFCFG_WIRED_GLOBAL_GATEWAY,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
|
@ -894,6 +899,7 @@ test_read_wired_never_default (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIRED_NEVER_DEFAULT,
|
||||
TEST_NETWORK_WIRED_NEVER_DEFAULT,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -983,6 +989,7 @@ test_read_onboot_no (void)
|
|||
connection = connection_from_file (TEST_IFCFG_ONBOOT_NO,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -1039,6 +1046,7 @@ test_read_wired_8021x_peap_mschapv2 (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -1226,6 +1234,7 @@ test_read_wifi_open (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_OPEN,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -1394,6 +1403,7 @@ test_read_wifi_open_ssid_hex (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_SSID_HEX,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -1463,7 +1473,14 @@ test_read_wifi_open_ssid_bad (const char *file, const char *test)
|
|||
gboolean ignore_error = FALSE;
|
||||
GError *error = NULL;
|
||||
|
||||
connection = connection_from_file (file, NULL, TYPE_WIRELESS, &unmanaged, &keyfile, &error, &ignore_error);
|
||||
connection = connection_from_file (file,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
&ignore_error);
|
||||
ASSERT (connection == NULL, test, "unexpected success reading %s", file);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
|
@ -1488,6 +1505,7 @@ test_read_wifi_open_ssid_quoted (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_SSID_QUOTED,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -1575,6 +1593,7 @@ test_read_wifi_wep (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WEP,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -1835,6 +1854,7 @@ test_read_wifi_wep_adhoc (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WEP_ADHOC,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -2088,6 +2108,7 @@ test_read_wifi_leap (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_LEAP,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -2235,6 +2256,7 @@ test_read_wifi_wpa_psk (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -2533,6 +2555,7 @@ test_read_wifi_wpa_psk_adhoc (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK_ADHOC,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -2715,6 +2738,7 @@ test_read_wifi_wpa_psk_hex (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK_HEX,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -2861,6 +2885,7 @@ test_read_wifi_wpa_eap_tls (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WPA_EAP_TLS,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -2995,6 +3020,7 @@ test_read_wifi_wpa_eap_ttls_tls (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WPA_EAP_TTLS_TLS,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -3152,6 +3178,7 @@ test_read_wifi_wep_eap_ttls_chap (void)
|
|||
connection = connection_from_file (TEST_IFCFG_WIFI_WEP_EAP_TTLS_CHAP,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -3402,6 +3429,7 @@ test_write_wired_static (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -3500,6 +3528,7 @@ test_write_wired_dhcp (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -3618,6 +3647,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -3742,6 +3772,7 @@ test_write_wifi_open (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -3846,6 +3877,7 @@ test_write_wifi_open_hex_ssid (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -3970,6 +4002,7 @@ test_write_wifi_wep (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -4114,6 +4147,7 @@ test_write_wifi_wep_adhoc (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -4263,6 +4297,7 @@ test_write_wifi_wpa_psk (const char *name,
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -4407,6 +4442,7 @@ test_write_wifi_wpa_psk_adhoc (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -4566,6 +4602,7 @@ test_write_wifi_wpa_eap_tls (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -4742,6 +4779,7 @@ test_write_wifi_wpa_eap_ttls_tls (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -4893,6 +4931,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void)
|
|||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
|
|
@ -4917,6 +4956,366 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void)
|
|||
g_object_unref (reread);
|
||||
}
|
||||
|
||||
#define TEST_IFCFG_IBFT_DHCP TEST_IFCFG_DIR"/network-scripts/ifcfg-test-ibft-dhcp"
|
||||
|
||||
static void
|
||||
test_read_ibft_dhcp (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWired *s_wired;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GError *error = NULL;
|
||||
const char *tmp;
|
||||
const GByteArray *array;
|
||||
char expected_mac_address[ETH_ALEN] = { 0x00, 0x33, 0x21, 0x98, 0xb9, 0xf1 };
|
||||
const char *expected_id = "System test-ibft-dhcp";
|
||||
guint64 expected_timestamp = 0;
|
||||
|
||||
connection = connection_from_file (TEST_IFCFG_IBFT_DHCP,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
TEST_IFCFG_DIR "/iscsiadm-test-dhcp",
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
&ignore_error);
|
||||
ASSERT (connection != NULL,
|
||||
"ibft-dhcp-read", "failed to read %s: %s", TEST_IFCFG_IBFT_DHCP, error->message);
|
||||
|
||||
ASSERT (nm_connection_verify (connection, &error),
|
||||
"ibft-dhcp-verify", "failed to verify %s: %s", TEST_IFCFG_IBFT_DHCP, error->message);
|
||||
|
||||
/* ===== CONNECTION SETTING ===== */
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
ASSERT (s_con != NULL,
|
||||
"ibft-dhcp-verify-connection", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
|
||||
/* ID */
|
||||
tmp = nm_setting_connection_get_id (s_con);
|
||||
ASSERT (tmp != NULL,
|
||||
"ibft-dhcp-verify-connection", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_ID);
|
||||
ASSERT (strcmp (tmp, expected_id) == 0,
|
||||
"ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_ID);
|
||||
|
||||
/* UUID can't be tested if the ifcfg does not contain the UUID key, because
|
||||
* the UUID is generated on the full path of the ifcfg file, which can change
|
||||
* depending on where the tests are run.
|
||||
*/
|
||||
|
||||
/* Timestamp */
|
||||
ASSERT (nm_setting_connection_get_timestamp (s_con) == expected_timestamp,
|
||||
"ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s /%s key value",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_TIMESTAMP);
|
||||
|
||||
/* Autoconnect */
|
||||
ASSERT (nm_setting_connection_get_autoconnect (s_con) == TRUE,
|
||||
"ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s /%s key value",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT);
|
||||
|
||||
/* Read-only */
|
||||
ASSERT (nm_setting_connection_get_read_only (s_con) == TRUE,
|
||||
"ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s /%s key value",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_READ_ONLY);
|
||||
|
||||
/* ===== WIRED SETTING ===== */
|
||||
|
||||
s_wired = NM_SETTING_WIRED (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED));
|
||||
ASSERT (s_wired != NULL,
|
||||
"ibft-dhcp-verify-wired", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_WIRED_SETTING_NAME);
|
||||
|
||||
/* MAC address */
|
||||
array = nm_setting_wired_get_mac_address (s_wired);
|
||||
ASSERT (array != NULL,
|
||||
"ibft-dhcp-verify-wired", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MAC_ADDRESS);
|
||||
ASSERT (array->len == ETH_ALEN,
|
||||
"ibft-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value length",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MAC_ADDRESS);
|
||||
ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0,
|
||||
"ibft-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MAC_ADDRESS);
|
||||
|
||||
ASSERT (nm_setting_wired_get_mtu (s_wired) == 0,
|
||||
"ibft-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MTU);
|
||||
|
||||
/* ===== IPv4 SETTING ===== */
|
||||
|
||||
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
|
||||
ASSERT (s_ip4 != NULL,
|
||||
"ibft-dhcp-verify-ip4", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME);
|
||||
|
||||
/* Method */
|
||||
tmp = nm_setting_ip4_config_get_method (s_ip4);
|
||||
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
|
||||
"ibft-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_DHCP,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_METHOD);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
#define TEST_IFCFG_IBFT_STATIC TEST_IFCFG_DIR"/network-scripts/ifcfg-test-ibft-static"
|
||||
|
||||
static void
|
||||
test_read_ibft_static (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWired *s_wired;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GError *error = NULL;
|
||||
const char *tmp;
|
||||
const GByteArray *array;
|
||||
char expected_mac_address[ETH_ALEN] = { 0x00, 0x33, 0x21, 0x98, 0xb9, 0xf0 };
|
||||
const char *expected_id = "System test-ibft-static";
|
||||
guint64 expected_timestamp = 0;
|
||||
const char *expected_dns1 = "10.16.255.2";
|
||||
const char *expected_dns2 = "10.16.255.3";
|
||||
struct in_addr addr;
|
||||
const char *expected_address1 = "192.168.32.72";
|
||||
const char *expected_address1_gw = "192.168.35.254";
|
||||
NMIP4Address *ip4_addr;
|
||||
|
||||
connection = connection_from_file (TEST_IFCFG_IBFT_STATIC,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
TEST_IFCFG_DIR "/iscsiadm-test-static",
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
&ignore_error);
|
||||
ASSERT (connection != NULL,
|
||||
"ibft-static-read", "failed to read %s: %s", TEST_IFCFG_IBFT_STATIC, error->message);
|
||||
|
||||
ASSERT (nm_connection_verify (connection, &error),
|
||||
"ibft-static-verify", "failed to verify %s: %s", TEST_IFCFG_IBFT_STATIC, error->message);
|
||||
|
||||
/* ===== CONNECTION SETTING ===== */
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
ASSERT (s_con != NULL,
|
||||
"ibft-static-verify-connection", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
|
||||
/* ID */
|
||||
tmp = nm_setting_connection_get_id (s_con);
|
||||
ASSERT (tmp != NULL,
|
||||
"ibft-static-verify-connection", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_ID);
|
||||
ASSERT (strcmp (tmp, expected_id) == 0,
|
||||
"ibft-static-verify-connection", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_ID);
|
||||
|
||||
/* UUID can't be tested if the ifcfg does not contain the UUID key, because
|
||||
* the UUID is generated on the full path of the ifcfg file, which can change
|
||||
* depending on where the tests are run.
|
||||
*/
|
||||
|
||||
/* Timestamp */
|
||||
ASSERT (nm_setting_connection_get_timestamp (s_con) == expected_timestamp,
|
||||
"ibft-static-verify-connection", "failed to verify %s: unexpected %s /%s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_TIMESTAMP);
|
||||
|
||||
/* Autoconnect */
|
||||
ASSERT (nm_setting_connection_get_autoconnect (s_con) == TRUE,
|
||||
"ibft-static-verify-connection", "failed to verify %s: unexpected %s /%s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT);
|
||||
|
||||
/* Read-only */
|
||||
ASSERT (nm_setting_connection_get_read_only (s_con) == TRUE,
|
||||
"ibft-static-verify-connection", "failed to verify %s: unexpected %s /%s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME,
|
||||
NM_SETTING_CONNECTION_READ_ONLY);
|
||||
|
||||
/* ===== WIRED SETTING ===== */
|
||||
|
||||
s_wired = NM_SETTING_WIRED (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED));
|
||||
ASSERT (s_wired != NULL,
|
||||
"ibft-static-verify-wired", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME);
|
||||
|
||||
/* MAC address */
|
||||
array = nm_setting_wired_get_mac_address (s_wired);
|
||||
ASSERT (array != NULL,
|
||||
"ibft-static-verify-wired", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MAC_ADDRESS);
|
||||
ASSERT (array->len == ETH_ALEN,
|
||||
"ibft-static-verify-wired", "failed to verify %s: unexpected %s / %s key value length",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MAC_ADDRESS);
|
||||
ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0,
|
||||
"ibft-static-verify-wired", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MAC_ADDRESS);
|
||||
|
||||
ASSERT (nm_setting_wired_get_mtu (s_wired) == 0,
|
||||
"ibft-static-verify-wired", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_MTU);
|
||||
|
||||
/* ===== IPv4 SETTING ===== */
|
||||
|
||||
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
|
||||
ASSERT (s_ip4 != NULL,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME);
|
||||
|
||||
/* Method */
|
||||
tmp = nm_setting_ip4_config_get_method (s_ip4);
|
||||
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_METHOD);
|
||||
|
||||
/* DNS Addresses */
|
||||
ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_DNS);
|
||||
|
||||
ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #1",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_DNS);
|
||||
ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr.s_addr,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_DNS);
|
||||
|
||||
ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #2",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_DNS);
|
||||
ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr.s_addr,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_DNS);
|
||||
|
||||
ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_DNS);
|
||||
|
||||
/* Address #1 */
|
||||
ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0);
|
||||
ASSERT (ip4_addr,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: missing IP4 address #1",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
||||
ASSERT (nm_ip4_address_get_prefix (ip4_addr) == 22,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1 prefix",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
||||
ASSERT (inet_pton (AF_INET, expected_address1, &addr) > 0,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: couldn't convert IP address #1",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_DNS);
|
||||
ASSERT (nm_ip4_address_get_address (ip4_addr) == addr.s_addr,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
||||
ASSERT (inet_pton (AF_INET, expected_address1_gw, &addr) > 0,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: couldn't convert IP address #1 gateway",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
ASSERT (nm_ip4_address_get_gateway (ip4_addr) == addr.s_addr,
|
||||
"ibft-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1 gateway",
|
||||
TEST_IFCFG_IBFT_STATIC,
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME,
|
||||
NM_SETTING_IP4_CONFIG_ADDRESSES);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_ibft_malformed (const char *name, const char *iscsiadm_path)
|
||||
{
|
||||
NMConnection *connection;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GError *error = NULL;
|
||||
|
||||
connection = connection_from_file (TEST_IFCFG_IBFT_STATIC,
|
||||
NULL,
|
||||
TYPE_ETHERNET,
|
||||
iscsiadm_path,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&error,
|
||||
&ignore_error);
|
||||
ASSERT (connection == NULL,
|
||||
name, "unexpectedly able to read %s", TEST_IFCFG_IBFT_STATIC);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_wired_pppoe (void)
|
||||
{
|
||||
|
|
@ -5236,6 +5635,16 @@ int main (int argc, char **argv)
|
|||
test_write_wifi_wpa_eap_ttls_tls ();
|
||||
test_write_wifi_wpa_eap_ttls_mschapv2 ();
|
||||
|
||||
/* iSCSI / ibft */
|
||||
test_read_ibft_dhcp ();
|
||||
test_read_ibft_static ();
|
||||
test_read_ibft_malformed ("ibft-bad-record-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-record");
|
||||
test_read_ibft_malformed ("ibft-bad-entry-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-entry");
|
||||
test_read_ibft_malformed ("ibft-bad-ipaddr-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-ipaddr");
|
||||
test_read_ibft_malformed ("ibft-bad-gateway-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-gateway");
|
||||
test_read_ibft_malformed ("ibft-bad-dns1-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-dns1");
|
||||
test_read_ibft_malformed ("ibft-bad-dns2-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-dns2");
|
||||
|
||||
/* Stuff we expect to fail for now */
|
||||
test_write_wired_pppoe ();
|
||||
test_write_vpn ();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue