summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README7
-rw-r--r--doc/iscsiadm.810
-rw-r--r--usr/iscsi_util.c61
3 files changed, 74 insertions, 4 deletions
diff --git a/README b/README
index 9a44f3c..ee69002 100644
--- a/README
+++ b/README
@@ -651,6 +651,9 @@ To now log into targets it is the same as with sofware iscsi. See section
If a record does not exist, it will be created using the iscsid.conf
discovery settings.
+ The argument to -p may also be a hostname instead of an address.
+ ./iscsiadm -m discoverydb -t st -p smoehost --discover
+
For the ifaces, iscsiadm will first search /etc/iscsi/ifaces for
interfaces using software iscsi. If any are found then nodes found
during discovery will be setup so that they can logged in through
@@ -775,6 +778,10 @@ To now log into targets it is the same as with sofware iscsi. See section
./iscsiadm -m node -T iqn.2005-03.com.max \
-p [2001:c90::211:9ff:feb8:a9e9]:3260 -l
+ To specify a hostname the following can be used:
+
+ ./iscsiadm -m node -T iqn.2005-03.com.max -p somehost -l
+
- iSCSI Login to a specific portal through the NIC setup as iface0:
./iscsiadm -m node -T iqn.2005-03.com.max -p 192.168.0.4:3260 \
diff --git a/doc/iscsiadm.8 b/doc/iscsiadm.8
index 177d3cd..53900a9 100644
--- a/doc/iscsiadm.8
+++ b/doc/iscsiadm.8
@@ -171,8 +171,14 @@ sid is passed in.
.TP
\fB\-p\fR, \fB\-\-portal=\fIip[:port]\fR
-Use target portal with ip-address \fIip\fR and \fIport\fR, the default
-\fIport\fR value is 3260.
+Use target portal with ip-address \fIip\fR and \fIport\fR. If port is not passed
+in the default \fIport\fR value is 3260.
+.IP
+IPv6 addresses can bs specified as [ddd.ddd.ddd.ddd]:port or
+ddd.ddd.ddd.ddd.
+.IP
+Hostnames can also be used for the ip argument.
+
.IP
This option is only valid for discovery, or for node operations with
the \fInew\fR operator.
diff --git a/usr/iscsi_util.c b/usr/iscsi_util.c
index 63cef8f..978d3ed 100644
--- a/usr/iscsi_util.c
+++ b/usr/iscsi_util.c
@@ -217,6 +217,64 @@ char *cfg_get_string_param(char *pathname, const char *key)
return value;
}
+/**
+ * iscsi_addr_match - check if the addrs are to the same ip
+ * @address1: pattern
+ * @address2: address to check
+ *
+ * If address1 is blank then it matches any string passed in.
+ */
+static int iscsi_addr_match(char *address1, char *address2)
+{
+ struct addrinfo hints1, hints2, *res1, *res2;
+ int rc;
+
+ if (!strlen(address1))
+ return 1;
+
+ if (!strcmp(address1, address2))
+ return 1;
+
+ memset(&hints1, 0, sizeof(struct addrinfo));
+ hints1.ai_family = AF_UNSPEC;
+ hints1.ai_socktype = SOCK_STREAM;
+
+ memset(&hints2, 0, sizeof(struct addrinfo));
+ hints2.ai_family = AF_UNSPEC;
+ hints2.ai_socktype = SOCK_STREAM;
+
+ /*
+ * didn't match so we have to resolve to see if one is a dnsname
+ * that matches a ip address.
+ */
+ rc = getaddrinfo(address1, NULL, &hints1, &res1);
+ if (rc) {
+ log_debug(1, "Match error. Could not resolve %s: %s", address1,
+ gai_strerror(rc));
+ return 0;
+
+ }
+
+ rc = getaddrinfo(address2, NULL, &hints2, &res2);
+ if (rc) {
+ log_debug(1, "Match error. Could not resolve %s: %s", address2,
+ gai_strerror(rc));
+ rc = 0;
+ goto free_res1;
+ }
+
+ if ((res1->ai_addrlen != res2->ai_addrlen) ||
+ memcmp(res1->ai_addr, res2->ai_addr, res2->ai_addrlen))
+ rc = 0;
+ else
+ rc = 1;
+
+ freeaddrinfo(res2);
+free_res1:
+ freeaddrinfo(res1);
+ return rc;
+}
+
int __iscsi_match_session(node_rec_t *rec, char *targetname,
char *address, int port, struct iface_rec *iface)
{
@@ -240,8 +298,7 @@ int __iscsi_match_session(node_rec_t *rec, char *targetname,
if (strlen(rec->name) && strcmp(rec->name, targetname))
return 0;
- if (strlen(rec->conn[0].address) &&
- strcmp(rec->conn[0].address, address))
+ if (!iscsi_addr_match(rec->conn[0].address, address))
return 0;
if (rec->conn[0].port != -1 && port != rec->conn[0].port)