[stgt] [PATCH 5/5] Call user defined callback program with initiator info
Chandra Seetharaman
sekharan at us.ibm.com
Sat Sep 18 03:02:11 CEST 2010
Add argument passing to callback.
Callback program is called with target name and ipv4 or ipv6 address (as
unsigned int parameters).
For ipv4, initiator address from sin_addr.s_addr is sent as an unsigned
int argument.
For example, when 10.0.0.1 is the initiator, the callback program
"/usr/local/bin/redirect" is called as
/usr/local/bin/redirect targetname 16777226
For ipv6, sin6_addr->s6_addr32[0] thru sin6_addr->s6_addr32[3] are sent
as four unisgned int arguments, as in
/usr/local/bin/redirect targetname 12345 98765 12233 34535
Signed-Off-By: Chandra Seetharaman <sekharan at us.ibm.com>
---
usr/iscsi/target.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 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
@@ -197,9 +197,27 @@ int target_redirected(struct iscsi_targe
socklen_t len;
int ret, rsn;
char *p, *q, *str, *port, *addr;
- char buffer[NI_MAXHOST + NI_MAXSERV + 4];
+ char buffer[NI_MAXHOST + NI_MAXSERV + 4], in_buf[1024];
+
+ len = sizeof(from);
+ ret = conn->tp->ep_getpeername(conn, (struct sockaddr *)&from, &len);
+ if (ret < 0)
+ return 0;
if (target->redirect_info.callback) {
+ p = in_buf;
+ p += sprintf(p, "%s ", target->redirect_info.callback);
+ p += sprintf(p, "%s ", tgt_targetname(target->tid));
+ if (((struct sockaddr *)&from)->sa_family == AF_INET)
+ sprintf(p, " %u", (((struct sockaddr_in *)
+ &from)->sin_addr.s_addr));
+ else {
+ struct in6_addr *a1 = &((struct sockaddr_in6 *)
+ &from)->sin6_addr;
+ sprintf(p, " %u %u %u %u", a1->s6_addr32[0],
+ a1->s6_addr32[1], a1->s6_addr32[2],
+ a1->s6_addr32[3]);
+ }
bzero(buffer, NI_MAXHOST + NI_MAXSERV + 4);
ret = call_program(target->redirect_info.callback,
NULL, NULL, buffer, NI_MAXHOST + NI_MAXSERV + 4, 0);
@@ -241,11 +259,6 @@ process:
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
More information about the stgt
mailing list