[stgt] [PATCH 5/5] Call user defined callback program with initiator info

Chandra Seetharaman sekharan at us.ibm.com
Thu Sep 2 02:46:15 CEST 2010


Add argument passing to callback.

Callback program is called with 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 16777226

For ipv6, sin6_addr->s6_addr32[0] thru sin6_addr->s6_addr32[3] are sent
as four unisgned int arguments.

Signed-Off-By: Chandra Seetharaman <sekharan at us.ibm.com>
---
 usr/iscsi/target.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 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,12 +197,28 @@ 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);
+		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,
-				buffer, NI_MAXHOST + NI_MAXSERV + 4);
+		ret = call_program(in_buf, buffer, NI_MAXHOST + NI_MAXSERV + 4);
 		if (ret)
 			goto predefined;
 
@@ -241,11 +257,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