Hello community, here is the log from the commit of package target-isns for openSUSE:Factory checked in at 2020-02-13 10:12:41 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/target-isns (Old) and /work/SRC/openSUSE:Factory/.target-isns.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "target-isns" Thu Feb 13 10:12:41 2020 rev:9 rq:773969 version:0.6.7 Changes: -------- --- /work/SRC/openSUSE:Factory/target-isns/target-isns.changes 2018-11-10 16:55:45.824018932 +0100 +++ /work/SRC/openSUSE:Factory/.target-isns.new.26092/target-isns.changes 2020-02-13 10:12:48.956385221 +0100 @@ -1,0 +2,31 @@ +Tue Feb 11 18:44:51 UTC 2020 - [email protected] + +- Update to version 0.6.7 from 0.6.5: + * Update the changelog for release 0.6.7 + * Bump version to 0.6.7 + * Add Yuya Murai to THANKS.md + * Remove email addresses from THANKS.md + * Document IPv6 address support in README.md + * Do not shadow the portal_ref variable in configfs_tpg_update() + * Remove unused struct member isns_portals_cache::nr_portals + * Add a couple of assertions to help clang-tidy + * Use strncpy() instead of strcpy() to fix a warning from clang-tidy + * Upgrade CMake minimum version to 3.1 + * Give example of an IP6 address for the "isns_server" parameter + * Fix the address length passed to getsockname() and getnameinfo() + * Replace HOST_NAME_MAX with NI_MAXHOST + * Fix connection with IPv6 servers + * Add some hints for getaddrinfo() + * Remove the state change notification (SCN) service + * Make the protocol family more apparent in the logs + * Do not use IP:port in the logs because IPv6 addresses contain ":" + * Add MostlyBrian to THANKS + * When iterating over targets, use the alias of each target. + * Update the changelog for release 0.6.6 + * Bump version to 0.6.6 + * Register the iSCSI alias attribute + * Add Hao Wu to THANKS + * Fix bug #44, Can't update "Device Attr" to window 2008 iSNS server. + Replacing target-isns-0.6.5.tar.xz with target-isns-0.6.7.tar.xz. + +------------------------------------------------------------------- Old: ---- target-isns-0.6.5.tar.xz New: ---- target-isns-0.6.7.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ target-isns.spec ++++++ --- /var/tmp/diff_new_pack.e4aaH1/_old 2020-02-13 10:12:50.236385963 +0100 +++ /var/tmp/diff_new_pack.e4aaH1/_new 2020-02-13 10:12:50.240385966 +0100 @@ -1,7 +1,7 @@ # # spec file for package target-isns # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,7 +12,7 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # @@ -20,10 +20,10 @@ Summary: Supplies iSNS support for Linux kernel target License: GPL-2.0-or-later Group: System/Kernel -Version: 0.6.5 +Version: 0.6.7 Release: 0 Source: %{name}-%{version}.tar.xz -Url: https://github.com/open-iscsi/target-isns +URL: https://github.com/open-iscsi/target-isns BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: cmake BuildRequires: flex ++++++ _service ++++++ --- /var/tmp/diff_new_pack.e4aaH1/_old 2020-02-13 10:12:50.264385980 +0100 +++ /var/tmp/diff_new_pack.e4aaH1/_new 2020-02-13 10:12:50.264385980 +0100 @@ -4,8 +4,8 @@ <param name="url">https://github.com/open-iscsi/target-isns.git</param> <param name="subdir"></param> <param name="filename">target-isns</param> - <param name="versionformat">0.6.5</param> - <param name="revision">v0.6.5</param> + <param name="versionformat">0.6.7</param> + <param name="revision">v0.6.7</param> <param name="changesgenerate">enable</param> </service> <service name="recompress" mode="disabled"> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.e4aaH1/_old 2020-02-13 10:12:50.284385991 +0100 +++ /var/tmp/diff_new_pack.e4aaH1/_new 2020-02-13 10:12:50.288385994 +0100 @@ -1,4 +1,4 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/open-iscsi/target-isns.git</param> - <param name="changesrevision">a6e0d6c09f1ec7aafd9a2db5f08880b5cfa28e6d</param></service></servicedata> \ No newline at end of file + <param name="changesrevision">b22a20d597ec409130d0ffd94bc3389a75e71715</param></service></servicedata> \ No newline at end of file ++++++ target-isns-0.6.5.tar.xz -> target-isns-0.6.7.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/CHANGELOG.md new/target-isns-0.6.7/CHANGELOG.md --- old/target-isns-0.6.5/CHANGELOG.md 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/CHANGELOG.md 2020-01-31 22:29:39.000000000 +0100 @@ -6,6 +6,18 @@ ## [Unreleased] +## [0.6.7] - 2020-01-31 +### Fixed +- Register the correct alias when multiple iSCSI targets exist. + Contributed by MostlyBrian. +- Fix multiple bugs with IPv6 (issue #51). Reported by Yuya Murai. + +## [0.6.6] - 2019-05-22 +### Fixed +- Register the iSCSI alias attribute (issue #48). +- Fix registration error with the Microsoft iSNS server when a portal + is removed (issue #44). Contributed by Hao Wu. + ## [0.6.5] - 2018-06-20 ### Fixed - Fix registration of new targets after all existing targets are diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/CMakeLists.txt new/target-isns-0.6.7/CMakeLists.txt --- old/target-isns-0.6.5/CMakeLists.txt 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/CMakeLists.txt 2020-01-31 22:29:39.000000000 +0100 @@ -6,13 +6,10 @@ # project(target-isns "C") -set(TARGET_ISNS_VERSION "0.6.5") +set(TARGET_ISNS_VERSION "0.6.7") -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") -if(CMAKE_VERSION VERSION_LESS "3.1") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") -endif() option(SUPPORT_SYSTEMD "Support service control via systemd" OFF) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/README.md new/target-isns-0.6.7/README.md --- old/target-isns-0.6.5/README.md 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/README.md 2020-01-31 22:29:39.000000000 +0100 @@ -48,9 +48,14 @@ ------------- Edit the configuration file located at `/etc/target-isns.conf` and -adjust the `isns_server` variable to the IP address of your iSNS server: +adjust the `isns_server` variable to the hostname or IP address of +your iSNS server: - isns_server = 192.168.0.1 + isns_server = 192.0.2.1 + +IPv6 addresses are supported too: + + isns_server = 2001:db8::1 The iSNS server address can also be passed on the command line with the `--isns-server` option. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/THANKS new/target-isns-0.6.7/THANKS --- old/target-isns-0.6.5/THANKS 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/THANKS 2020-01-31 22:29:39.000000000 +0100 @@ -1,8 +1,11 @@ -Alexey Tulia <alexey.tulia at gmail.com> -Andy Grover <agrover at redhat.com> -Christophe Vu-Brugier <cvubrugier at fastmail.fm> -Dan Walkes <danwalkes at trellis-logic.com> -Kyle Fortin <kyle.fortin at oracle.com> -Lee Duncan <lduncan at suse.com> -Olaf Kirch <okir at suse.com> -Victor Dodon <dodonvictor at gmail.com> +Alexey Tulia +Andy Grover +Christophe Vu-Brugier +Dan Walkes +Hao Wu +Kyle Fortin +Lee Duncan +MostlyBrian +Olaf Kirch +Victor Dodon +Yuya Murai diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/documentation/testing.md new/target-isns-0.6.7/documentation/testing.md --- old/target-isns-0.6.5/documentation/testing.md 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/documentation/testing.md 2020-01-31 22:29:39.000000000 +0100 @@ -40,9 +40,11 @@ $ mkdir -p fake-iscsi-path/iqn.2018-01.org.example:disk1 $ mkdir -p fake-iscsi-path/iqn.2018-01.org.example:disk1/tpgt_1 + $ echo 1 > fake-iscsi-path/iqn.2018-01.org.example:disk1/tpgt_1/enable $ mkdir -p fake-iscsi-path/iqn.2018-01.org.example:disk1/tpgt_1/np $ mkdir -p fake-iscsi-path/iqn.2018-01.org.example:disk1/tpgt_1/np/0.0.0.0:3260 - $ echo 1 > fake-iscsi-path/iqn.2018-01.org.example:disk1/tpgt_1/enable + $ mkdir -p fake-iscsi-path/iqn.2018-01.org.example:disk1/tpgt_1/param + $ echo 'LIO Target' > fake-iscsi-path/iqn.2018-01.org.example:disk1/tpgt_1/param/TargetAlias Then, you can start target-isns with the `--configfs-iscsi-path` option pointing to the fake configfs hierarchy: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/src/configfs.c new/target-isns-0.6.7/src/configfs.c --- old/target-isns-0.6.5/src/configfs.c 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/src/configfs.c 2020-01-31 22:29:39.000000000 +0100 @@ -25,7 +25,7 @@ * | | +-- np W | | | * | | | +-- $IP:$PORT | | +-- portal 1 * | | | +-- $IP:$PORT | | +-- portal 2 - * | | +-- param | | + * | | +-- param W | | * | | +-- TargetAlias | | * | +-- tpgt_N W | +-- tpg N * +-- $IQN N W +-- target N @@ -58,7 +58,7 @@ LIST_HEAD(targets); LIST_HEAD(portals); static int inotify_fd = -1; - +static const char LIO_TARGET_ALIAS[] = "LIO Target"; bool configfs_iscsi_path_exists(void) { @@ -82,6 +82,19 @@ return NULL; } +char *target_get_alias(const struct target *tgt) +{ + struct tpg *tpg; + + list_for_each(&tgt->tpgs, tpg, node) { + if (tpg->alias[0] == '\0' || + streq(tpg->alias, LIO_TARGET_ALIAS)) + continue; + return tpg->alias; + } + return (char *) LIO_TARGET_ALIAS; +} + static struct tpg *tpg_find_by_tag(const struct target *tgt, uint16_t tpg_tag) { struct tpg *tpg; @@ -98,8 +111,9 @@ struct tpg *tpg; list_for_each(&tgt->tpgs, tpg, node) { - if (tpg->watch_fd == watch_fd || - tpg->np_watch_fd == watch_fd) + if (watch_fd == tpg->watch_fd || + watch_fd == tpg->np_watch_fd || + watch_fd == tpg->param_watch_fd) return tpg; } return NULL; @@ -131,7 +145,7 @@ static bool configfs_tpg_enabled(const struct target *tgt, uint16_t tpg_tag) { - int fd = -1; + int fd; ssize_t nr; char buf[8]; char *path; @@ -153,11 +167,37 @@ return enabled; } +static void configfs_tpg_set_alias(const struct target *tgt, struct tpg *tpg) +{ + int fd; + ssize_t nr; + char *path; + + memset(tpg->alias, 0, ISCSI_ALIAS_SIZE); + + if (asprintf(&path, "%s/%s/tpgt_%hu/param/TargetAlias", + config.configfs_iscsi_path, tgt->name, tpg->tag) < 0) { + return; + } + if ((fd = open(path, O_RDONLY)) == -1) { + free(path); + return; + } + free(path); + if ((nr = read(fd, tpg->alias, ISCSI_ALIAS_SIZE)) != -1) { + /* Remove trailing new line character. */ + if (nr >= 1) + tpg->alias[nr - 1] = '\0'; + } + close(fd); +} + static struct tpg *configfs_tpg_init(struct target *tgt, uint16_t tpg_tag) { struct tpg *tpg; char *path; char *np_path; + char *param_path; if ((tpg = malloc(sizeof(struct tpg))) == NULL) return NULL; @@ -171,16 +211,28 @@ free(tpg); return NULL; } + /* inotify reports no event when the "TargetAlias" file is watched. + * Watch the parent "param" directory instead. + */ + if (asprintf(¶m_path, "%s/param", path) < 0) { + free(np_path); + free(path); + free(tpg); + return NULL; + } tpg->watch_fd = inotify_add_watch(inotify_fd, path, INOTIFY_MASK); tpg->np_watch_fd = inotify_add_watch(inotify_fd, np_path, INOTIFY_MASK); + tpg->param_watch_fd = inotify_add_watch(inotify_fd, param_path, IN_CLOSE_WRITE); tpg->tag = tpg_tag; tpg->enabled = configfs_tpg_enabled(tgt, tpg_tag); + configfs_tpg_set_alias(tgt, tpg); tpg->exists = false; list_head_init(&tpg->portals); list_add(&tgt->tpgs, &tpg->node); free(path); free(np_path); + free(param_path); return tpg; } @@ -273,6 +325,7 @@ return -ENOENT; tpg->enabled = configfs_tpg_enabled(tgt, tpg->tag); + configfs_tpg_set_alias(tgt, tpg); list_for_each(&tpg->portals, portal_ref, node) { portal_ref->exists = false; @@ -294,7 +347,7 @@ assert(portal); } - struct portal_ref *portal_ref = configfs_portal_ref_find(tpg, portal); + portal_ref = configfs_portal_ref_find(tpg, portal); if (!portal_ref) { portal_ref = configfs_portal_ref_init(tpg, portal); assert(portal_ref); @@ -437,6 +490,7 @@ list_del(&tpg->node); inotify_rm_watch(inotify_fd, tpg->watch_fd); inotify_rm_watch(inotify_fd, tpg->np_watch_fd); + inotify_rm_watch(inotify_fd, tpg->param_watch_fd); free(tpg); } list_del(&tgt->node); @@ -459,7 +513,8 @@ struct portal_ref *portal_ref; list_for_each(&targets, tgt, node) { - log_print(LOG_DEBUG, "target: name = %s", tgt->name); + log_print(LOG_DEBUG, "target: name = %s, alias = %s", + tgt->name, target_get_alias(tgt)); list_for_each(&tgt->tpgs, tpg, node) { log_print(LOG_DEBUG, " tpg: tag = %hu, enabled = %d", tpg->tag, tpg->enabled); @@ -481,6 +536,8 @@ return 'D'; else if (event->mask & IN_MODIFY) return 'M'; + else if (event->mask & IN_CLOSE_WRITE) + return 'W'; else return '?'; } @@ -558,6 +615,7 @@ list_del(&tpg->node); inotify_rm_watch(inotify_fd, tpg->watch_fd); inotify_rm_watch(inotify_fd, tpg->np_watch_fd); + inotify_rm_watch(inotify_fd, tpg->param_watch_fd); free(tpg); } @@ -566,6 +624,25 @@ inotify_event_str(event), tgt->name, tpg_tag, event->name); } +static void configfs_param_alias_handle(const struct inotify_event *event) +{ + struct target *tgt; + struct tpg *tpg = NULL; + + list_for_each(&targets, tgt, node) { + tpg = tpg_find_by_watch(tgt, event->wd); + if (tpg) + break; + } + if (!tpg) + return; + + configfs_tpg_set_alias(tgt, tpg); + isns_target_register_later(tgt); + log_print(LOG_DEBUG, "inotify[%c] %s/tpg%hu/param/TargetAlias", + inotify_event_str(event), tgt->name, tpg->tag); +} + void configfs_inotify_events_handle(void) { ssize_t nr; @@ -601,8 +678,10 @@ else if (streq(event->name, "enable") || get_portal(event->name, &af, ip_addr, &port) == 0) configfs_tpg_subtree_handle(event); + else if (streq(event->name, "TargetAlias")) + configfs_param_alias_handle(event); else - log_print(LOG_DEBUG, "inotify[%c] %s unsupported", + log_print(LOG_DEBUG, "inotify[%c] %s ignored", inotify_event_str(event), event->name); p += sizeof(struct inotify_event) + event->len; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/src/configfs.h new/target-isns-0.6.7/src/configfs.h --- old/target-isns-0.6.5/src/configfs.h 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/src/configfs.h 2020-01-31 22:29:39.000000000 +0100 @@ -27,11 +27,13 @@ struct tpg { struct list_node node; /* Member of a target->tpgs list */ uint16_t tag; + char alias[ISCSI_ALIAS_SIZE]; bool enabled; bool exists; struct list_head portals; int watch_fd; int np_watch_fd; + int param_watch_fd; }; struct portal { @@ -62,6 +64,8 @@ struct target *target_find(const char *target_name); +char *target_get_alias(const struct target *tgt); + struct portal *portal_find(int af, const char *ip_addr, uint16_t port); bool tpg_has_portal(const struct tpg *tpg, const struct portal *portal); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/src/isns.c new/target-isns-0.6.7/src/isns.c --- old/target-isns-0.6.5/src/isns.c 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/src/isns.c 2020-01-31 22:29:39.000000000 +0100 @@ -8,8 +8,7 @@ * SPDX-License-Identifier: GPL-2.0+ */ -#define _POSIX_SOURCE -#define _POSIX_C_SOURCE 200112L +#define _GNU_SOURCE #include <errno.h> #include <inttypes.h> #include <limits.h> @@ -32,7 +31,7 @@ #include "itimer.h" #include "log.h" -extern void isns_set_fd(int isns, int scn_listen, int scn); +extern void isns_set_fd(int isns); extern struct list_head targets; extern struct list_head portals; @@ -54,7 +53,6 @@ }; struct isns_portals_cache { - size_t nr_portals; struct { uint8_t ip_addr[16]; uint32_t port; @@ -62,16 +60,13 @@ }; static LIST_HEAD(query_list); -static uint16_t scn_listen_port; int isns_fd = -1; -static int scn_listen_fd = -1; -static int scn_fd = -1; static int registration_timer_fd = -1; -static struct isns_io isns_rx, scn_rx; +static struct isns_io isns_rx; static char *rxbuf; static uint16_t transaction; static uint32_t registration_period = DEFAULT_REGISTRATION_PERIOD; -static char eid[HOST_NAME_MAX]; +static char eid[NI_MAXHOST]; static uint8_t ip[16]; static struct sockaddr_storage ss; @@ -85,7 +80,7 @@ struct sockaddr_in s4; struct sockaddr_in6 s6; } l; - socklen_t slen = sizeof(l.s); + socklen_t slen = sizeof(l.ss); err = getsockname(fd, &l.s, &slen); if (err) { @@ -93,14 +88,14 @@ return err; } - err = getnameinfo(&l.s, sizeof(l.s), + err = getnameinfo(&l.s, slen, eid, sizeof(eid), NULL, 0, 0); if (err) { log_print(LOG_ERR, "getnameinfo error %s!", gai_strerror(err)); return err; } if (streq(eid, "localhost.localdomain")) - getnameinfo(&l.s, sizeof(l.s), + getnameinfo(&l.s, slen, eid, sizeof(eid), NULL, 0, NI_NUMERICHOST); switch (l.ss.ss_family) { @@ -128,6 +123,7 @@ } else if (source_attribute[0] == '\0' || !target_find(source_attribute)) { target = list_top(&targets, struct target, node); + assert(target); strncpy(source_attribute, target->name, ISCSI_NAME_SIZE); source_attribute[ISCSI_NAME_SIZE - 1] = '\0'; log_print(LOG_DEBUG, "source attribute set to %s", @@ -183,15 +179,15 @@ fd = socket(ss.ss_family, SOCK_STREAM, IPPROTO_TCP); if (fd < 0) { - log_print(LOG_ERR, "unable to create (%s) %d!", strerror(errno), - ss.ss_family); + log_print(LOG_ERR, "unable to create socket: %s, protocol family: %d", + strerror(errno), ss.ss_family); return -1; } err = connect(fd, (struct sockaddr *) &ss, sizeof(ss)); if (err < 0) { - log_print(LOG_ERR, "unable to connect (%s) %d!", strerror(errno), - ss.ss_family); + log_print(LOG_ERR, "unable to connect: %s, protocol family: %d", + strerror(errno), ss.ss_family); close(fd); return -1; } @@ -207,7 +203,7 @@ } isns_fd = fd; - isns_set_fd(fd, scn_listen_fd, scn_fd); + isns_set_fd(fd); return fd; } @@ -251,96 +247,6 @@ return isns_tlv_set(tlv, tag, strlen(str) + 1, str); } -/* - * FIXME: State Change Notification is currently disabled. - */ -#define SCN_ENABLED 0 -#if SCN_ENABLED -static int isns_scn_deregister(char *name) -{ - int err; - uint16_t flags, length = 0; - char buf[2048]; - struct isns_hdr *hdr = (struct isns_hdr *) buf; - struct isns_tlv *tlv; - - if (isns_fd == -1 && isns_connect() < 0) - return 0; - - memset(buf, 0, sizeof(buf)); - tlv = (struct isns_tlv *) hdr->pdu; - - length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_NAME, name); - length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_NAME, name); - - flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU; - isns_hdr_init(hdr, ISNS_FUNC_SCN_DEREG, length, flags, - ++transaction, 0); - - err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); - if (err < 0) - log_print(LOG_ERR, "%s %d: %s", __func__, __LINE__, strerror(errno)); - - return 0; -} -#endif - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define set_scn_flag(x) \ -{ \ - x = (x & 0x55555555) << 1 | (x & 0xaaaaaaaa) >> 1; \ - x = (x & 0x33333333) << 2 | (x & 0xcccccccc) >> 2; \ - x = (x & 0x0f0f0f0f) << 4 | (x & 0xf0f0f0f0) >> 4; \ - x = (x & 0x00ff00ff) << 8 | (x & 0xff00ff00) >> 8; \ - x = (x & 0x0000ffff) << 16 | (x & 0xffff0000) >> 16; \ -} -#else -#define set_scn_flag(x) -#endif - -static int isns_scn_register(void) -{ - int err; - uint16_t flags, length = 0; - uint32_t scn_flags; - char buf[4096]; - struct isns_hdr *hdr = (struct isns_hdr *) buf; - struct isns_tlv *tlv; - struct target *target; - - if (list_empty(&targets)) - return 0; - - if (isns_fd == -1 && isns_connect() < 0) - return 0; - - memset(buf, 0, sizeof(buf)); - tlv = (struct isns_tlv *) hdr->pdu; - - target = list_top(&targets, struct target, node); - - length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_NAME, target->name); - length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_NAME, target->name); - length += isns_tlv_set(&tlv, 0, 0, 0); - - scn_flags = ISNS_SCN_FLAG_INITIATOR | ISNS_SCN_FLAG_OBJECT_REMOVE | - ISNS_SCN_FLAG_OBJECT_ADDED | ISNS_SCN_FLAG_OBJECT_UPDATED; - set_scn_flag(scn_flags); - scn_flags = htonl(scn_flags); - - length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_SCN_BITMAP, - sizeof(scn_flags), &scn_flags); - - flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU; - isns_hdr_init(hdr, ISNS_FUNC_SCN_REG, length, flags, ++transaction, 0); - - err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); - if (err < 0) - log_print(LOG_ERR, "%s %d: %s", __func__, __LINE__, strerror(errno)); - - return 0; -} - static int isns_eid_attr_query(void) { int err; @@ -380,48 +286,6 @@ return 0; } -static int isns_attr_query(char *name) -{ - int err; - uint16_t flags, length = 0; - char buf[4096]; - struct isns_hdr *hdr = (struct isns_hdr *) buf; - struct isns_tlv *tlv; - uint32_t node = htonl(ISNS_NODE_INITIATOR); - struct isns_query *query; - - if (list_empty(&targets)) - return 0; - - if (isns_fd == -1 && isns_connect() < 0) - return 0; - - memset(buf, 0, sizeof(buf)); - tlv = (struct isns_tlv *) hdr->pdu; - - query = isns_query_init(name, ++transaction); - if (!query) - return 0; - - length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_NAME, name); - length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NODE_TYPE, - sizeof(node), &node); - length += isns_tlv_set(&tlv, 0, 0, 0); - length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, 0, 0); - length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NODE_TYPE, 0, 0); - length += isns_tlv_set(&tlv, ISNS_ATTR_PORTAL_IP_ADDRESS, 0, 0); - - flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU; - isns_hdr_init(hdr, ISNS_FUNC_DEV_ATTR_QRY, length, flags, - transaction, 0); - - err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); - if (err < 0) - log_print(LOG_ERR, "%s %d: %s", __func__, __LINE__, strerror(errno)); - - return 0; -} - static void isns_ip_addr_set(const struct portal *portal, uint8_t *ip_addr) { memset(ip_addr, 0, 16); @@ -448,23 +312,6 @@ target->registered = true; } -static bool portal_is_solely_used(const struct portal *portal, - const struct target *target) -{ - struct target *tgt; - - assert(target_has_portal(target, portal)); - - list_for_each(&targets, tgt, node) { - if (tgt == target) - continue; - if (tgt->registered && target_has_portal(tgt, portal)) - return false; - } - - return true; -} - #define TGT_REG_BUFSIZE 8192 #define TGT_REG_BUFTHRESH (TGT_REG_BUFSIZE - 256) /* @@ -537,6 +384,7 @@ if (list_empty(&targets)) return 0; target = list_top(&targets, struct target, node); + assert(target); } if (isns_fd == -1 && isns_connect() < 0) @@ -568,17 +416,6 @@ if (!target_has_portal(target, portal) && !all_targets) continue; - /* - * The Microsoft iSNS server returns an "invalid - * update" error if "an object specified in a - * DevAttrReg request to update an Entity already - * exists in another Entity". - * - * https://docs.microsoft.com/en-us/previous-versions/windows/hardware/design/dn653564(v=vs.85)#invalid-update-status-code-14 - */ - if (!portal_is_solely_used(portal, target)) - continue; - uint32_t port = htonl(portal->port); uint8_t ip_addr[16]; isns_ip_addr_set(portal, ip_addr); @@ -591,12 +428,11 @@ } list_for_each(&targets, tgt, node) { - if (tgt != target && !all_targets) - continue; - /* Register the iSCSI target. */ length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_NAME, tgt->name); + length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_ALIAS, + target_get_alias(tgt)); length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NODE_TYPE, sizeof(node), &node); isns_target_register_flush(&tlv, &buf[0], sizeof(buf), @@ -648,9 +484,6 @@ if (err < 0) log_print(LOG_ERR, "%s %d: %s", __func__, __LINE__, strerror(errno)); - if (scn_listen_port) - isns_scn_register(); - return 0; } @@ -691,10 +524,6 @@ all_targets ? "(all)" : target->name, last ? "(last)" : ""); -#if SCN_ENABLED - isns_scn_deregister(target->name); -#endif - memset(buf, 0, sizeof(buf)); tlv = (struct isns_tlv *) hdr->pdu; @@ -809,55 +638,6 @@ function, length, flags, transaction, sequence); \ } -static char *print_scn_pdu(const struct isns_hdr *hdr) -{ - struct isns_tlv *tlv = (struct isns_tlv *) hdr->pdu; - uint16_t length = ntohs(hdr->length); - char *name = NULL; - - while (length) { - uint32_t vlen = ntohl(tlv->length); - - if (vlen + sizeof(*tlv) > length) - vlen = length - sizeof(*tlv); - - switch (ntohl(tlv->tag)) { - case ISNS_ATTR_ISCSI_NAME: - if (vlen) { - size_t slen = vlen - 1; - - if (slen >= ISCSI_NAME_SIZE) - slen = ISCSI_NAME_SIZE - 1; - - *((char *) tlv->value + slen) = 0; - - log_print(LOG_ERR, "scn name: %u, %s", vlen, - (char *) tlv->value); - - if (!name) - name = (char *) tlv->value; - } - break; - case ISNS_ATTR_TIMESTAMP: -/* if (vlen == 8) - log_print(LOG_ERR, "%u : %u : %" PRIx64, ntohl(tlv->tag), - vlen, *((uint64_t *) tlv->value)); -*/ - break; - case ISNS_ATTR_ISCSI_SCN_BITMAP: - if (vlen == 4) - log_print(LOG_ERR, "scn bitmap : %x", - *((uint32_t *) tlv->value)); - break; - } - - length -= (sizeof(*tlv) + vlen); - tlv = (struct isns_tlv *) ((char *) tlv->value + vlen); - } - - return name; -} - static void isns_registration_set_period(uint32_t period); static void isns_rsp_handle(const struct isns_hdr *hdr) @@ -999,7 +779,7 @@ if (err == -EAGAIN) return err; log_print(LOG_DEBUG, "iSNS connection closed (fd = %d)", isns_fd); - isns_set_fd(-1, scn_listen_fd, scn_fd); + isns_set_fd(-1); isns_fd = -1; return err; } @@ -1011,158 +791,6 @@ return 0; } -static int scn_accept_connection(void) -{ - struct sockaddr_storage from; - socklen_t slen; - int fd, err, opt = 1; - - slen = sizeof(from); - fd = accept(scn_listen_fd, (struct sockaddr *) &from, &slen); - if (fd < 0) { - log_print(LOG_ERR, "%s %d: accept error %s", __func__, __LINE__, - strerror(errno)); - return -errno; - } - log_print(LOG_ERR, "Accept scn connection %d", fd); - - err = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); - if (err) - log_print(LOG_ERR, "%s %d: %s\n", __func__, __LINE__, - strerror(errno)); - /* not critical, so ignore. */ - - scn_fd = fd; - isns_set_fd(isns_fd, scn_listen_fd, scn_fd); - - return 0; -} - -static void send_scn_rsp(char *name, uint16_t transaction) -{ - char buf[1024]; - struct isns_hdr *hdr = (struct isns_hdr *) buf; - struct isns_tlv *tlv; - uint16_t flags, length = 0; - int err; - - memset(buf, 0, sizeof(buf)); - *((uint32_t *) hdr->pdu) = 0; - tlv = (struct isns_tlv *) ((char *) hdr->pdu + 4); - length +=4; - - length += isns_tlv_set_string(&tlv, ISNS_ATTR_ISCSI_NAME, name); - - flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU; - isns_hdr_init(hdr, ISNS_FUNC_SCN_RSP, length, flags, transaction, 0); - - err = write(scn_fd, buf, length + sizeof(struct isns_hdr)); - if (err < 0) - log_print(LOG_ERR, "%s %d: %s", __func__, __LINE__, strerror(errno)); -} - -int isns_scn_handle(bool is_accept) -{ - int err; - struct isns_io *rx = &scn_rx; - struct isns_hdr *hdr = (struct isns_hdr *) rx->buf; - uint16_t function, transaction; - char *name = NULL; - - log_print(LOG_ERR, "%s %d: %d", __func__, __LINE__, is_accept); - - if (is_accept) - return scn_accept_connection(); - - err = recv_pdu(scn_fd, rx, hdr); - if (err) { - if (err == -EAGAIN) - return err; - log_print(LOG_DEBUG, "%s %d: close connection %d", __func__, __LINE__, - scn_fd); - isns_set_fd(isns_fd, scn_listen_fd, -1); - scn_fd = -1; - return err; - } - - function = ntohs(hdr->function); - transaction = ntohs(hdr->transaction); - - switch (function) { - case ISNS_FUNC_SCN: - name = print_scn_pdu(hdr); - break; - default: - print_unknown_pdu(hdr); - } - - if (name) { - send_scn_rsp(name, transaction); - isns_attr_query(name); - } - - return 0; -} - -#if SCN_ENABLED -static int scn_init(char *addr __attribute__ ((unused))) -{ - int fd, opt, err; - union { - struct sockaddr s; - struct sockaddr_storage ss; - struct sockaddr_in s4; - struct sockaddr_in6 s6; - } l; - socklen_t slen; - - fd = socket(ss.ss_family, SOCK_STREAM, IPPROTO_TCP); - if (fd < 0) { - log_print(LOG_ERR, "%s %d: %s\n", __func__, __LINE__, strerror(errno)); - return -errno; - } - - opt = 1; - if (ss.ss_family == AF_INET6) { - err = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)); - if (err) - log_print(LOG_ERR, "%s %d: %s\n", __func__, __LINE__, - strerror(errno)); - goto out; - } - - err = listen(fd, 5); - if (err) { - log_print(LOG_ERR, "%s %d: %s\n", __func__, __LINE__, strerror(errno)); - goto out; - } - - slen = sizeof(l.s); - err = getsockname(fd, &l.s, &slen); - if (err) { - log_print(LOG_ERR, "%s %d: %s\n", __func__, __LINE__, strerror(errno)); - goto out; - } - - /* protocol independent way ? */ - if (l.ss.ss_family == AF_INET6) - scn_listen_port = ntohs((&l.s6)->sin6_port); - else - scn_listen_port = ntohs((&l.s4)->sin_port); - - log_print(LOG_DEBUG, "SCN listen port is %hu", scn_listen_port); -out: - if (err) - close(fd); - else { - scn_listen_fd = fd; - isns_set_fd(isns_fd, scn_listen_fd, scn_fd); - } - - return err; -} -#endif - int isns_registration_timer_init(void) { registration_timer_fd = itimer_create(); @@ -1218,17 +846,19 @@ return -1; } - log_print(LOG_INFO, "iSNS server is %s:%hu", addr, isns_port); + log_print(LOG_INFO, "iSNS server address: %s, port: %hu", addr, isns_port); snprintf(port, sizeof(port), "%hu", isns_port); memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_NUMERICSERV; err = getaddrinfo(addr, (char *) &port, &hints, &res); if (err) { log_print(LOG_ERR, "getaddrinfo error %s, %s", gai_strerror(err), addr); return -1; } - memcpy(&ss, res->ai_addr, sizeof(*res->ai_addr)); + memcpy(&ss, res->ai_addr, res->ai_addrlen); freeaddrinfo(res); rxbuf = calloc(2, BUFSIZE); @@ -1237,14 +867,8 @@ return -1; } -#if SCN_ENABLED - scn_init(addr); -#endif - isns_rx.buf = rxbuf; isns_rx.offset = 0; - scn_rx.buf = rxbuf + BUFSIZE; - scn_rx.offset = 0; return 0; } @@ -1262,7 +886,7 @@ void isns_exit(void) { /* We can't receive events any more. */ - isns_set_fd(-1, -1, -1); + isns_set_fd(-1); free(rxbuf); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/src/isns.h new/target-isns-0.6.7/src/isns.h --- old/target-isns-0.6.5/src/isns.h 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/src/isns.h 2020-01-31 22:29:39.000000000 +0100 @@ -17,8 +17,6 @@ int isns_handle(void); -int isns_scn_handle(bool is_accept); - int isns_init(const char *addr, uint16_t isns_port); void isns_start(void); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/src/isns_proto.h new/target-isns-0.6.7/src/isns_proto.h --- old/target-isns-0.6.5/src/isns_proto.h 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/src/isns_proto.h 2020-01-31 22:29:39.000000000 +0100 @@ -12,9 +12,10 @@ #include <inttypes.h> -#define ISCSI_NAME_SIZE 224 -#define ISNS_PORT 3205 -#define ISNS_ALIGN 4 +#define ISCSI_NAME_SIZE 224 +#define ISCSI_ALIAS_SIZE 256 +#define ISNS_PORT 3205 +#define ISNS_ALIGN 4 struct isns_hdr { uint16_t version; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/src/target-isns.c new/target-isns-0.6.7/src/target-isns.c --- old/target-isns-0.6.5/src/target-isns.c 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/src/target-isns.c 2020-01-31 22:29:39.000000000 +0100 @@ -31,8 +31,6 @@ EPOLL_INOTIFY = 0, /* config FS notifications */ EPOLL_SIGNAL, /* signal handling */ EPOLL_ISNS, /* iSNS (de)register commands */ - EPOLL_SCN_LISTEN, /* SCN connection */ - EPOLL_SCN, /* SCN notifications */ EPOLL_REGISTRATION_TIMER, /* iSNS registration timer */ EPOLL_MAX_FD } epoll_id; @@ -44,8 +42,8 @@ static void print_usage(void) { printf("Usage: " PROGNAME " [OPTIONS]\n" - " -i, --isns-server Set the IP address of the iSNS server.\n" - " -p, --isns-port Set the remote port for iSNS server.\n" + " -i, --isns-server Set the hostname or IP address of the iSNS server.\n" + " -p, --isns-port Set the port number of the iSNS server.\n" " -d, --debug Increase the debugging level (implies -f).\n" " -f, --foreground Run in the foreground.\n" " -s, --configfs-iscsi-path Use alternate sys configfs iscsi path.\n" @@ -80,11 +78,9 @@ epoll_set[epoll_id] = fd; } -void isns_set_fd(int isns, int scn_listen, int scn) +void isns_set_fd(int isns) { epoll_set_fd(EPOLL_ISNS, isns); - epoll_set_fd(EPOLL_SCN_LISTEN, scn_listen); - epoll_set_fd(EPOLL_SCN, scn); } static int signal_init(void) @@ -237,10 +233,6 @@ isns_registration_refresh(); else if (fd == epoll_set[EPOLL_ISNS]) isns_handle(); - else if (fd == epoll_set[EPOLL_SCN_LISTEN]) - isns_scn_handle(true); - else if (fd == epoll_set[EPOLL_SCN]) - isns_scn_handle(false); } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/src/util.c new/target-isns-0.6.7/src/util.c --- old/target-isns-0.6.5/src/util.c 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/src/util.c 2020-01-31 22:29:39.000000000 +0100 @@ -43,7 +43,9 @@ memset(&config, 0, sizeof(config)); config.log_level = LOG_INFO; config.isns_port = ISNS_PORT; - strcpy(config.configfs_iscsi_path, CONFIGFS_ISCSI_PATH); + const size_t sz = sizeof(config.configfs_iscsi_path); + strncpy(config.configfs_iscsi_path, CONFIGFS_ISCSI_PATH, sz); + config.configfs_iscsi_path[sz - 1] = '\0'; if ((file = fopen(CONFFILE, "r")) == NULL) { log_print(LOG_ERR, "Could not read " CONFFILE); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/target-isns.8 new/target-isns-0.6.7/target-isns.8 --- old/target-isns-0.6.5/target-isns.8 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/target-isns.8 2020-01-31 22:29:39.000000000 +0100 @@ -16,7 +16,7 @@ .SH OPTIONS .TP \fB\-i\fR, \fB\-\-isns-server\fR=\fI\/HOSTNAME\/\fR -set the hostname of the iSNS server +set the hostname or IP address of the iSNS server .TP \fB\-p\fR, \fB\-\-isns-port\fR=\fI\/PORT\/\fR set the port number of the iSNS server (default iSNS port number is 3205) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/target-isns.conf new/target-isns-0.6.7/target-isns.conf --- old/target-isns-0.6.5/target-isns.conf 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/target-isns.conf 2020-01-31 22:29:39.000000000 +0100 @@ -1,10 +1,12 @@ # Sample configuration file for target-isns. -# IP address of the iSNS server. +# Hostname or IP address of the iSNS server. +# IPv4 and IPv6 are supported. # This parameter is required. -# isns_server = 192.168.0.1 +# isns_server = 2001:db8::1 +# isns_server = 192.0.2.1 -# Remote port of iSNS server. +# Port number of the iSNS server. # This parameter is optional. # isns_port = 3205 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/target-isns-0.6.5/tests/test-isns-fuzzing.c new/target-isns-0.6.7/tests/test-isns-fuzzing.c --- old/target-isns-0.6.5/tests/test-isns-fuzzing.c 2018-06-20 08:26:56.000000000 +0200 +++ new/target-isns-0.6.7/tests/test-isns-fuzzing.c 2020-01-31 22:29:39.000000000 +0100 @@ -24,9 +24,7 @@ extern int isns_fd; -void isns_set_fd(int isns __attribute__((unused)), - int scn_listen __attribute__((unused)), - int scn __attribute__((unused))) +void isns_set_fd(int isns __attribute__((unused))) { }
