summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorLee Duncan <lduncan@suse.com>2021-09-01 12:21:18 -0700
committerLee Duncan <lduncan@suse.com>2021-09-01 12:37:11 -0700
commit76350316de38abcd42afd3276249d577a0a66bec (patch)
treebb226ed2f58ad959113472c77e7680383f14af73 /usr
parentcb39fb559a4046284925eb3a7457ed00b1e7b6fe (diff)
downloadopen-iscsi-76350316de38abcd42afd3276249d577a0a66bec.tar.gz
Handle IPv6 interfaces correctly.
For IPv6 interface files (in iscsi/ifaces), assume the interface uses IPv4 unless it has "ipv6" in the name. Also, when creating interface files, name them ending with "ipv6.N" or "ipv4.N", where "N" is the interface number (normally zero). This was being done in one place, and this commit makes sure all places that create interface files use this convention. Note that iscsiadm cannot determine if the interface file is IPv6 vs IPv4 from the contents because of the way it processes those files: it creates a template of "legal" values, then processes the file. But it needs to know IPv4 vs IPv6 when creating the template.
Diffstat (limited to 'usr')
-rw-r--r--usr/iface.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/usr/iface.c b/usr/iface.c
index 30f4ae0..9db73c3 100644
--- a/usr/iface.c
+++ b/usr/iface.c
@@ -995,6 +995,30 @@ void iface_link_ifaces(struct list_head *ifaces)
iface_for_each_iface(ifaces, 1, &nr_found, iface_link);
}
+/*
+ * ipv6 address strings will have at least two colons
+ *
+ * NOTE: does NOT validate the IP address
+ */
+static bool ipaddr_is_ipv6(char *ipaddr)
+{
+ char *first_colon, *second_colon;
+ bool res = false;
+
+ if (ipaddr) {
+ first_colon = strchr(ipaddr, ':');
+ if (first_colon) {
+ second_colon = strchr(first_colon+1, ':');
+ if (second_colon &&
+ (second_colon != first_colon))
+ res = true;
+ }
+ }
+ log_debug(8, "%s(%s) -> %u",
+ __FUNCTION__, ipaddr, res);
+ return res;
+}
+
/**
* iface_setup_from_boot_context - setup iface from boot context info
* @iface: iface t setup
@@ -1068,9 +1092,6 @@ int iface_setup_from_boot_context(struct iface_rec *iface,
}
strcpy(iface->transport_name, t->name);
- memset(iface->name, 0, sizeof(iface->name));
- snprintf(iface->name, sizeof(iface->name), "%s.%s",
- iface->transport_name, context->mac);
strlcpy(iface->hwaddress, context->mac,
sizeof(iface->hwaddress));
strlcpy(iface->ipaddress, context->ipaddr,
@@ -1080,6 +1101,11 @@ int iface_setup_from_boot_context(struct iface_rec *iface,
sizeof(iface->subnet_mask));
strlcpy(iface->gateway, context->gateway,
sizeof(iface->gateway));
+ snprintf(iface->name, sizeof(iface->name), "%s.%s.%s.%u",
+ iface->transport_name, context->mac,
+ ipaddr_is_ipv6(iface->ipaddress) ? "ipv6" : "ipv4",
+ iface->iface_num);
+
log_debug(1, "iface " iface_fmt "", iface_str(iface));
return 1;
}