summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/iscsi_if.h7
-rw-r--r--usr/iface.c35
-rw-r--r--usr/iface.h2
3 files changed, 28 insertions, 16 deletions
diff --git a/include/iscsi_if.h b/include/iscsi_if.h
index 5a1c614..22b7c09 100644
--- a/include/iscsi_if.h
+++ b/include/iscsi_if.h
@@ -393,8 +393,11 @@ struct iscsi_path {
#define ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE 0x01
#define ISCSI_IPV6_ROUTER_AUTOCFG_DISABLE 0x02
-#define ISCSI_IFACE_TYPE_IPV4 0x01
-#define ISCSI_IFACE_TYPE_IPV6 0x02
+/* Interface IP Type */
+enum iscsi_iface_type {
+ ISCSI_IFACE_TYPE_IPV4 = 1,
+ ISCSI_IFACE_TYPE_IPV6,
+};
#define ISCSI_MAX_VLAN_ID 4095
#define ISCSI_MAX_VLAN_PRIORITY 7
diff --git a/usr/iface.c b/usr/iface.c
index 21d52b3..30f4ae0 100644
--- a/usr/iface.c
+++ b/usr/iface.c
@@ -445,25 +445,34 @@ int iface_get_by_net_binding(struct iface_rec *pattern,
return ISCSI_ERR_NO_OBJS_FOUND;
}
-int iface_get_iptype(struct iface_rec *iface)
+/*
+ * detect IPv4 vs IPv4 IP address
+ */
+enum iscsi_iface_type iface_get_iptype(struct iface_rec *iface)
{
+ enum iscsi_iface_type res = ISCSI_IFACE_TYPE_IPV4;
+
/* address might not be set if user config with another tool */
if (!strlen(iface->ipaddress) ||
!strcmp(UNKNOWN_VALUE, iface->ipaddress)) {
- /* try to figure out by name */
- if (strstr(iface->name, "ipv4"))
- return ISCSI_IFACE_TYPE_IPV4;
- else if (strstr(iface->name, "ipv6"))
- return ISCSI_IFACE_TYPE_IPV6;
- else /* assume ipv4 by default */
- return ISCSI_IFACE_TYPE_IPV4;
+ /* unknown or empty IP address: try to figure out by name */
+ if (strstr(iface->name, "ipv6"))
+ res = ISCSI_IFACE_TYPE_IPV6;
} else {
+ /* figure out what type of IP address string we have */
if (strcmp(iface->bootproto, "dhcp") &&
- !strstr(iface->ipaddress, "."))
- return ISCSI_IFACE_TYPE_IPV6;
- else
- return ISCSI_IFACE_TYPE_IPV4;
+ !strchr(iface->ipaddress, '.')) {
+ /* bootproto is NOT "dhcp", IP addr does NOT have a dot in it */
+ res = ISCSI_IFACE_TYPE_IPV6;
+ }
}
+
+ log_debug(8, "iface: ipaddr=\"%s\" name=\"%s\" bootproto=\"%s\" -> %s",
+ iface->ipaddress, iface->name,
+ iface->bootproto,
+ res == ISCSI_IFACE_TYPE_IPV4 ? "IPv4" : "IPv6");
+
+ return res;
}
static int iface_setup_binding_from_kern_iface(void *data,
@@ -1211,7 +1220,7 @@ static void iface_get_common_param_count(struct iface_rec *iface, int *count)
static int __iface_get_param_count(void *data, struct iface_rec *iface)
{
struct iface_param_count *iface_params = data;
- int iptype = ISCSI_IFACE_TYPE_IPV4;
+ enum iscsi_iface_type iptype;
int count = 0;
if (strcmp(iface_params->primary->hwaddress, iface->hwaddress))
diff --git a/usr/iface.h b/usr/iface.h
index 6c06f7f..095772e 100644
--- a/usr/iface.h
+++ b/usr/iface.h
@@ -59,7 +59,7 @@ extern int iface_get_param_count(struct iface_rec *iface_primary,
int iface_all);
extern int iface_build_net_config(struct iface_rec *iface_primary,
int iface_all, struct iovec *iovs);
-extern int iface_get_iptype(struct iface_rec *iface);
+extern enum iscsi_iface_type iface_get_iptype(struct iface_rec *iface);
#define iface_fmt "[hw=%s,ip=%s,net_if=%s,iscsi_if=%s]"
#define iface_str(_iface) \