Add argument passing to callback. Callback program is called with target name and ipv4 or ipv6 address. If the callback program is /usr/local/bin/redirect, it is called as under: example, ipv4: /usr/local/bin/redirect targetname 10.0.0.1 example, ipv6: /usr/local/bin/redirect targetname fe80::214:5eff:ef3b:c600 Signed-Off-By: Chandra Seetharaman <sekharan at us.ibm.com> --- usr/iscsi/target.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) Index: tgt-1.0.8/usr/iscsi/target.c =================================================================== --- tgt-1.0.8.orig/usr/iscsi/target.c +++ tgt-1.0.8/usr/iscsi/target.c @@ -239,14 +239,31 @@ int target_redirected(struct iscsi_targe struct sockaddr_storage from; struct addrinfo hints, *res; socklen_t len; - int ret = 1, rsn; + int ret, rsn; char *p, *q, *str, *port, *addr; char buffer[NI_MAXHOST + NI_MAXSERV + 4]; + char dst[INET6_ADDRSTRLEN], in_buf[1024]; - if (target->redirect_info.callback) - ret = get_redirect_address(target->redirect_info.callback, - buffer, sizeof(buffer), &addr, &port, &rsn); + len = sizeof(from); + ret = conn->tp->ep_getpeername(conn, (struct sockaddr *)&from, &len); + if (ret < 0) + return 0; + ret = 1; + if (target->redirect_info.callback) { + p = in_buf; + p += sprintf(p, "%s ", target->redirect_info.callback); + p += sprintf(p, "%s ", tgt_targetname(target->tid)); + ret = getnameinfo((struct sockaddr *)&from, sizeof(from), dst, + sizeof(dst), NULL, 0, NI_NUMERICHOST); + if (ret) + goto predefined; + sprintf(p, "%s", dst); + ret = get_redirect_address(in_buf, buffer, + sizeof(buffer), &addr, &port, &rsn); + } + +predefined: if (ret) { if (!strlen(target->redirect_info.addr)) return 0; @@ -260,11 +277,6 @@ int target_redirected(struct iscsi_targe rsn != ISCSI_LOGIN_STATUS_TGT_MOVED_PERM) return 0; - len = sizeof(from); - ret = conn->tp->ep_getpeername(conn, (struct sockaddr *)&from, &len); - if (ret < 0) - return 0; - p = strdup(addr); if (!p) return 0; -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html |