Subject: Re: bin/34578 (iscsi_target rejects Windows iscsi initiator.)
To: None <agc@NetBSD.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,>
From: nakamoto <hiroshi-n@iname.com>
List: netbsd-bugs
Date: 11/26/2006 14:55:02
The following reply was made to PR bin/34578; it has been noted by GNATS.

From: nakamoto <hiroshi-n@iname.com>
To: gnats-bugs@NetBSD.org
Cc: agc@NetBSD.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: bin/34578 (iscsi_target rejects Windows iscsi initiator.)
Date: Sun, 26 Nov 2006 22:38:24 +0900

 I checked the source file from 4.0_BETA and I noticed allow_netmask()
 (netmask.c) had a bug.
 (I did it a while ago, but I did not know how to report the fix.)
 It works with any netmasks other than "0.0.0.0/0" ( "any", "all" ).
 When it meets "0.0.0.0/0", it executes some strange code to avoid
 shifting 32 bits,
 
 After I modified the function as the following, the bug disappeared.
 If you do not see the problem, it might already have been fixed.
 
 Hiroshi Nakamoto
 ------------
 int
 allow_netmask(const char *netmaskarg, const char *addr)
 {
 struct in_addr a;
 struct in_addr m;
 const char *netmask;
 magic_t *mp;
 char maskaddr[NETMASK_BUFFER_SIZE];
 char *cp;
 int slash;
 int i;
 
 /* firstly check for any magic values in the netmask */
 netmask = netmaskarg;
 for (mp = magics ; mp->magic ; mp++) {
 if (strcmp(netmask, mp->magic) == 0) {
 netmask = mp->xform;
 break;
 }
 }
 
 /* find out if slash notation has been used */
 (void) memset(&a, 0x0, sizeof(a));
 if ((cp = strchr(netmask, '/')) == NULL) {
 (void) strlcpy(maskaddr, netmask, sizeof(maskaddr));
 slash = 32;
 } else {
 (void) strlcpy(maskaddr, netmask, MIN(sizeof(maskaddr), (int)(cp -
 netmask) + 1));
 slash = atoi(cp + 1);
 }
 
 /* canonicalise IPv4 address to dotted quad */
 for (i = 0, cp = maskaddr ; *cp ; cp++) {
 if (*cp == '.') {
 i += 1;
 }
 }
 for ( ; i < 3 ; i++) {
 (void) strlcat(maskaddr, ".0", sizeof(maskaddr));
 }
 
 /* translate netmask to in_addr */
 if (!inet_aton(maskaddr, &m)) {
 (void) fprintf(stderr, "allow_netmask: can't interpret mask `%s' as an
 IPv4 address\n", maskaddr);
 return 0;
 }
 
 /* translate address to in_addr */
 if (!inet_aton(addr, &a)) {
 (void) fprintf(stderr, "allow_netmask: can't interpret address `%s' as
 an IPv4 address\n", addr);
 return 0;
 }
 
 #ifdef ALLOW_NETMASK_DEBUG
 printf("addr %s %u, mask %s %u, slash %d\n", addr,
 (ISCSI_HTONL(a.s_addr) >> (32 - slash)), maskaddr,
 (ISCSI_HTONL(m.s_addr) >> (32 - slash)), slash);
 #endif
 if (slash == 0) {
 return 1;
 }
 
 /* and return 1 if address is in netmask */
 return ((ISCSI_HTONL(a.s_addr) >> (32 - slash)) ==
 (ISCSI_HTONL(m.s_addr) >> (32 - slash))) ? 1 : 0;
 }
 ---------------
 
 > Synopsis: iscsi_target rejects Windows iscsi initiator.
 >
 > Responsible-Changed-From-To: bin-bug-people->agc
 > Responsible-Changed-By: agc@netbsd.org
 > Responsible-Changed-When: Sun, 26 Nov 2006 10:56:06 +0000
 > Responsible-Changed-Why:
 > agc looks after the NetBSD iSCSI target
 >
 >
 > State-Changed-From-To: open->analyzed
 > State-Changed-By: agc@netbsd.org
 > State-Changed-When: Sun, 26 Nov 2006 10:56:06 +0000
 > State-Changed-Why:
 > I've analyzed the problem, and can't reproduce it in my set up.
 >
 > I have a target exported to 0/0, and made up the slides/snapshots of
 > the target serving up storage to the Microsoft v2 initiator, running
 > on a Windows XP laptop. Target is from 4.99.1 (when the snapshots
 > were made).
 >
 > I haven't tried this on an amd64 box (ENOHARDWARE).
 >
 > Can you give me a few more details of the environments involved, please?
 >
 > Thanks.
 >
 >
 >
 >
 >