diff options
Diffstat (limited to 'src/settings/plugins/ifcfg-rh/reader.c')
-rw-r--r-- | src/settings/plugins/ifcfg-rh/reader.c | 292 |
1 files changed, 13 insertions, 279 deletions
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index cbaf0aaeb8..27e2df9b7e 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -274,251 +274,6 @@ read_mac_address (shvarFile *ifcfg, const char *key, gsize len, 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); - - /* - * We blocked signals in main(). We need to restore original signal - * mask for iscsiadm here so that it can receive signals. - */ - nm_unblock_posix_signals (NULL); -} - -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) { - PARSE_WARNING ("malformed iscsiadm record: no = in '%s'.", 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; - guint32 ipaddr; - guint32 gateway; - guint32 dns1; - guint32 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, 0, - "%s exited abnormally.", iscsiadm_path); - goto done; - } - - if (WEXITSTATUS (status) != 0) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "%s exited with error %d. Message: '%s'", - iscsiadm_path, WEXITSTATUS (status), err ? err : "(none)"); - goto done; - } - - if (!read_mac_address (ifcfg, "HWADDR", ETH_ALEN, &ifcfg_mac, error)) - goto done; - /* Ensure we got a MAC */ - if (!ifcfg_mac) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 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) { - PARSE_WARNING ("malformed iscsiadm record: already parsing record."); - 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) { - PARSE_WARNING ("malformed iscsiadm record: missing BOOTPROTO."); - goto done; - } - - 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 || !prefix) { - PARSE_WARNING ("malformed iscsiadm record: BOOTPROTO=static " - "but missing IP address or prefix."); - goto done; - } - - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ipaddr); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gateway); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); - - if (dns1) - nm_setting_ip4_config_add_dns (s_ip4, dns1); - if (dns2) - nm_setting_ip4_config_add_dns (s_ip4, dns2); - - // FIXME: DNS search domains? - } - success = TRUE; - goto done; - } - 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))) { - guint8 *ibft_mac[ETH_ALEN]; - - if (!nm_utils_hwaddr_aton (p, ibft_mac, ETH_ALEN)) { - PARSE_WARNING ("malformed iscsiadm record: invalid hwaddress."); - skip = TRUE; - continue; - } - - if (!nm_utils_hwaddr_matches (ibft_mac, ETH_ALEN, ifcfg_mac->data, ifcfg_mac->len)) { - /* 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 { - PARSE_WARNING ("malformed iscsiadm record: unknown BOOTPROTO '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_IPADDR_TAG, &skip))) { - if (inet_pton (AF_INET, p, &ipaddr) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid IP address '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_SUBNET_TAG, &skip))) { - guint32 mask; - - if (inet_pton (AF_INET, p, &mask) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid subnet mask '%s'.", p); - skip = TRUE; - continue; - } - - prefix = nm_utils_ip4_netmask_to_prefix (mask); - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_GATEWAY_TAG, &skip))) { - if (inet_pton (AF_INET, p, &gateway) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid IP gateway '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_DNS1_TAG, &skip))) { - if (inet_pton (AF_INET, p, &dns1) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid DNS1 address '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_DNS2_TAG, &skip))) { - if (inet_pton (AF_INET, p, &dns2) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid DNS2 address '%s'.", 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; -} - /* Returns TRUE on missing address or valid address */ static gboolean read_ip4_address (shvarFile *ifcfg, @@ -1242,7 +997,6 @@ error: static NMSetting * make_ip4_setting (shvarFile *ifcfg, const char *network_file, - const char *iscsiadm_path, GError **error) { NMSettingIP4Config *s_ip4 = NULL; @@ -1294,16 +1048,6 @@ make_ip4_setting (shvarFile *ifcfg, method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; } else if (!g_ascii_strcasecmp (value, "static")) { method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - } else if (!g_ascii_strcasecmp (value, "ibft")) { - g_free (value); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, NULL); - /* 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, @@ -1600,7 +1344,6 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo static NMSetting * make_ip6_setting (shvarFile *ifcfg, const char *network_file, - const char *iscsiadm_path, GError **error) { NMSettingIP6Config *s_ip6 = NULL; @@ -5005,7 +4748,6 @@ NMConnection * connection_from_file (const char *filename, 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 **out_unhandled, char **out_keyfile, char **out_routefile, @@ -5033,9 +4775,6 @@ connection_from_file (const char *filename, if (!network_file) network_file = SYSCONFDIR "/sysconfig/network"; - if (!iscsiadm_path) - iscsiadm_path = "/sbin/iscsiadm"; - ifcfg_name = utils_get_ifcfg_name (filename, TRUE); if (!ifcfg_name) { g_set_error (error, IFCFG_PLUGIN_ERROR, 0, @@ -5056,6 +4795,17 @@ connection_from_file (const char *filename, goto done; } + /* iBFT is handled by the iBFT settings plugin */ + bootproto = svGetValue (parsed, "BOOTPROTO", FALSE); + if (bootproto && !g_ascii_strcasecmp (bootproto, "ibft")) { + if (out_ignore_error) + *out_ignore_error = TRUE; + g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + "Ignoring iBFT configuration"); + g_free (bootproto); + goto done; + } + type = NULL; devtype = svGetValue (parsed, "DEVICETYPE", FALSE); @@ -5150,7 +4900,7 @@ connection_from_file (const char *filename, if (!connection) goto done; - s_ip6 = make_ip6_setting (parsed, network_file, iscsiadm_path, error); + s_ip6 = make_ip6_setting (parsed, network_file, error); if (!s_ip6) { g_object_unref (connection); connection = NULL; @@ -5158,7 +4908,7 @@ connection_from_file (const char *filename, } else nm_connection_add_setting (connection, s_ip6); - s_ip4 = make_ip4_setting (parsed, network_file, iscsiadm_path, error); + s_ip4 = make_ip4_setting (parsed, network_file, error); if (!s_ip4) { g_object_unref (connection); connection = NULL; @@ -5192,22 +4942,6 @@ connection_from_file (const char *filename, if (s_dcb) nm_connection_add_setting (connection, s_dcb); - /* 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 = nm_connection_get_setting_connection (connection); - g_assert (s_con); - - g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_READ_ONLY, TRUE, NULL); - } - g_free (bootproto); - if (!nm_connection_normalize (connection, NULL, NULL, error)) { g_object_unref (connection); connection = NULL; |