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

Chandra Seetharaman sekharan at us.ibm.com
Tue Sep 21 03:34:57 CEST 2010


On Sat, 2010-09-18 at 17:42 +0900, FUJITA Tomonori wrote:
> On Fri, 17 Sep 2010 18:02:11 -0700
> Chandra Seetharaman <sekharan at us.ibm.com> wrote:
> 
> > 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]);
> 
> The above means we get different arguments on big and little endian
> boxes?
> 
> Passing an address string is simpler like the following?
> 
> ipv4 -> 192.168.10.1:3260
> ipv6 -> [2001:2c0:418:1::2]:3260

Good catch again. Fixed it. Will send a patch in a few minutes.

--
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