File: fcUtils.c

package info (click to toggle)
ntop 3:3.3-11
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,772 kB
  • ctags: 7,534
  • sloc: ansic: 71,427; sh: 16,772; awk: 1,504; perl: 792; makefile: 782; php: 123; python: 23; sql: 13; sed: 11
file content (662 lines) | stat: -rw-r--r-- 17,951 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/**
 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 *
 *                          http://www.ntop.org
 *
 * Copyright (C) 2003 Dinesh G. Dutt <ddutt@cisco.com>
 * Copyright (C) 2003-04 Luca Deri <deri@ntop.org>
 *
 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


#include "ntop.h"
#include <stdarg.h>
#include <assert.h>
#include "fcUtils.h"

/* **************************************** */

int isFlogiAcc (FcAddress *fcAddress, u_int8_t r_ctl, u_int8_t type, u_int8_t cmd)
{
  if (((fcAddress->domain == 0xFF) && (fcAddress->area == 0xFF) && (fcAddress->port == 0xFE)) && 
      ((r_ctl & 0xF0) == FC_RCTL_ELS) && (type == FC_TYPE_ELS) &&
      (cmd == FC_ELS_CMD_ACC)) {
    return (TRUE);
  }
  else {
    return (FALSE);
  }
}

/* **************************************** */

/* Routine to extract WWN from FLOGI frame */
int fillFcHostInfo (const u_char *bp, HostTraffic *srcHost)
{
  assert (bp != NULL);

  srcHost->fcCounters->fcRecvSize = ntohs ((u_short)bp[10] & 0xFFF);
  memcpy (srcHost->fcCounters->pWWN.str, &bp[20], LEN_WWN_ADDRESS);
  memcpy (srcHost->fcCounters->nWWN.str, &bp[28], LEN_WWN_ADDRESS);

  setResolvedName(srcHost, (char*)srcHost->fcCounters->pWWN.str,
		  FLAG_HOST_SYM_ADDR_TYPE_FC_WWN);

  return (0);
}

/* **************************************** */

/* Routine to extract WWN from PLOGI frame */
int isPlogi (u_int8_t r_ctl, u_int8_t type, u_int8_t cmd)
{
  if (((r_ctl & 0xF0) == FC_RCTL_ELS) && (type == FC_TYPE_ELS) &&
      (cmd == FC_ELS_CMD_PLOGI)) {
    return (TRUE);
  }
  else {
    return (FALSE);
  }
}

/* **************************************** */

int isLogout (u_int8_t r_ctl, u_int8_t type, u_int8_t cmd)
{
  if (((r_ctl & 0xF0) == FC_RCTL_ELS) && (type == FC_TYPE_ELS) &&
      (cmd == FC_ELS_CMD_LOGO)) {
    return (TRUE);
  }
  else {
    return (FALSE);
  }
}

/* **************************************** */

int isRscn (u_int8_t r_ctl, u_int8_t type, u_int8_t cmd)
{
  if (((r_ctl & 0xF0) == FC_RCTL_ELS) && (type == FC_TYPE_ELS) &&
      (cmd == FC_ELS_CMD_RSCN)) {
    return (TRUE);
  }
  else {
    return (FALSE);
  }
}

/* **************************************** */

HostTraffic *allocFcScsiCounters(HostTraffic *host) {
  if(host->fcCounters == NULL) {
    host->fcCounters = malloc(sizeof(FcScsiCounters));
    if(host->fcCounters == NULL) 
      return(NULL); /* Out of memory */
    
    memset(host->fcCounters, 0, sizeof(FcScsiCounters));
    host->fcCounters->vsanId = -1;
  }

  return(host);
}

/* **************************************** */

int fillFcpInfo (const u_char *bp, HostTraffic *srcHost, HostTraffic *dstHost)
{
  int offset = 0;
  u_int32_t fcpDl;
    
  assert (bp != NULL);
  assert (srcHost != NULL);
  assert (dstHost != NULL);
    
  if (bp[offset] == 0) {
    /* This is a single-level LUN */
  }

  fcpDl = ntohl (*(u_int32_t *)&bp[offset+28]);

  if(allocFcScsiCounters(srcHost) == NULL) return(0);
  if(allocFcScsiCounters(dstHost) == NULL) return(0);

  if (bp[offset+11] & 0x1) {
    incrementTrafficCounter (&srcHost->fcCounters->scsiWriteBytes, fcpDl);
    incrementTrafficCounter (&dstHost->fcCounters->scsiWriteBytes, fcpDl);
  }
  else if (bp[offset+11] & 0x2) {
    incrementTrafficCounter (&srcHost->fcCounters->scsiReadBytes, fcpDl);
    incrementTrafficCounter (&dstHost->fcCounters->scsiReadBytes, fcpDl);
  }

  return (0);
}

/* **************************************** */

FcFabricElementHash *getFcFabricElementHash (u_short vsanId, int actualDeviceId)
{
  FcFabricElementHash **theHash;
  u_int myIdx = 0, idx;

  idx = vsanId % MAX_ELEMENT_HASH;
  theHash = myGlobals.device[actualDeviceId].vsanHash;    

  while(1) {
    if((theHash[idx] == NULL) || (theHash[idx]->vsanId == vsanId))
      break;

    idx = (idx+1) % MAX_ELEMENT_HASH;
    if(++myIdx == MAX_ELEMENT_HASH) {
      traceEvent(CONST_TRACE_WARNING, "updateElementHash(): hash full!");
      return (NULL);
    }
  }

  if(theHash[idx] == NULL) {
    theHash[idx] = (FcFabricElementHash*) calloc(1, sizeof(FcFabricElementHash));
    theHash[idx]->vsanId = vsanId;
  }

  return (theHash[idx]);
}

/* **************************************** */

int isValidFcNxPort (FcAddress *fcAddress)
{
  if (fcAddress != NULL) {
    if ((fcAddress->domain < MAX_FC_DOMAINS) && (fcAddress->domain))
      return (TRUE);
  }

  return (FALSE);
}

/* **************************************** */

int updateFcFabricElementHash (FcFabricElementHash **theHash, u_short vsanId,
                               const u_char *bp, FcAddress *srcAddr, FcAddress *dstAddr,
                               u_short protocol, u_char r_ctl, u_int32_t pktlen)
{
  u_int myIdx = 0, idx;
  FcFabricElementHash *hash;
  u_int8_t cmd, srcDomain, dstDomain;
  u_short payload_len;
  u_int8_t gs_type, gs_stype;

  idx = vsanId % MAX_ELEMENT_HASH;
    
  while(1) {
    if((theHash[idx] == NULL) || (theHash[idx]->vsanId == vsanId))
      break;

    idx = (idx+1) % MAX_ELEMENT_HASH;
    if(++myIdx == MAX_ELEMENT_HASH) {
      traceEvent(CONST_TRACE_WARNING, "updateElementHash(): hash full!");
      return (1);
    }
  }

  if(theHash[idx] == NULL) {
    theHash[idx] = (FcFabricElementHash*) calloc(1, sizeof(FcFabricElementHash));
    theHash[idx]->vsanId = vsanId;
  }

  /* ************************** */

  hash = theHash[idx];

  incrementTrafficCounter (&hash->totBytes, pktlen);
  incrementTrafficCounter (&hash->totPkts, 1);

#ifdef NOT_YET    
  if (protocol == FC_FTYPE_SWILS) {
    cmd = *bp;

    switch (cmd) {
    case FC_SWILS_ELP:
      incrementTrafficCounter (&hash->pmBytes, pktlen);
      incrementTrafficCounter (&hash->pmPkts, 1);
      hash->fabricConfStartTime = myGlobals.actTime;

      break;
    case FC_SWILS_ESC:
      incrementTrafficCounter (&hash->pmBytes, pktlen);
      incrementTrafficCounter (&hash->pmPkts, 1);
            
      break;
    case FC_SWILS_BF:
      incrementTrafficCounter (&hash->dmBytes, pktlen);
      incrementTrafficCounter (&hash->dmPkts, 1);
      incrementTrafficCounter (&hash->numBF, 1);
      hash->fabricConfStartTime = myGlobals.actTime;

      break;
    case FC_SWILS_RCF:
      incrementTrafficCounter (&hash->dmBytes, pktlen);
      incrementTrafficCounter (&hash->dmPkts, 1);
      incrementTrafficCounter (&hash->numRCF, 1);
      hash->fabricConfStartTime = myGlobals.actTime;
            
      break; 
    case FC_SWILS_EFP:
      incrementTrafficCounter (&hash->dmBytes, pktlen);
      incrementTrafficCounter (&hash->dmPkts, 1);

      /* Copy the latest EFP for the domain list */
      payload_len = ntohs (*(u_short *)&bp[2]);
      memcpy (hash->principalSwitch.str, &bp[8], sizeof (wwn_t));

      payload_len -= 16;
      payload_len = (payload_len > pktlen) ? pktlen : payload_len;
            
      hash->domainList = (FcDomainList *)malloc (payload_len);
      memcpy (hash->domainList, &bp[16], payload_len);

      hash->domainListLen = payload_len;

      break;
    case FC_SWILS_DIA:
      incrementTrafficCounter (&hash->dmBytes, pktlen);
      incrementTrafficCounter (&hash->dmPkts, 1);

      break;
    case FC_SWILS_RDI:
      incrementTrafficCounter (&hash->dmBytes, pktlen);
      incrementTrafficCounter (&hash->dmPkts, 1);
            
      break;
    case FC_SWILS_HLO:
      incrementTrafficCounter (&hash->fspfBytes, pktlen);
      incrementTrafficCounter (&hash->fspfPkts, 1);
      incrementTrafficCounter (&hash->hloPkts, 1);
            
      break;
    case FC_SWILS_LSU:
      incrementTrafficCounter (&hash->fspfBytes, pktlen);
      incrementTrafficCounter (&hash->fspfPkts, 1);
      incrementTrafficCounter (&hash->lsuBytes, pktlen);
      incrementTrafficCounter (&hash->lsuPkts, 1);
            
      break;
    case FC_SWILS_LSA:
      incrementTrafficCounter (&hash->fspfBytes, pktlen);
      incrementTrafficCounter (&hash->fspfPkts, 1);
      incrementTrafficCounter (&hash->lsaBytes, pktlen);
      incrementTrafficCounter (&hash->lsaPkts, 1);

      /* Check if fabric configuration is over */
      if (hash->fabricConfInProgress) {
	flags = bp[23];

	if (flags & 0x2) {
	  /* Compute duration of fabric configuration, avg */
	  confTime = difftime (myGlobals.actTime, hash->fabricConfStartTime);

	  if (hash->maxTimeFabricConf < confTime) {
	    hash->maxTimeFabricConf = confTime;
	  }

	  if (hash->minTimeFabricConf > confTime) {
	    hash->minTimeFabricConf = confTime;
	  }
	}
      }
            
      break;
    case FC_SWILS_RSCN:
      incrementTrafficCounter (&hash->rscnBytes, pktlen);
      incrementTrafficCounter (&hash->rscnPkts, 1);

      break;
    case FC_SWILS_DRLIR:
      break;
    case FC_SWILS_DSCN:
      break;
    case FC_SWILS_LOOPD:
      break;
            
    case FC_SWILS_MR:
      incrementTrafficCounter (&hash->zsBytes, pktlen);
      incrementTrafficCounter (&hash->zsPkts, 1);
            
      break;
    case FC_SWILS_ACA:
      incrementTrafficCounter (&hash->zsBytes, pktlen);
      incrementTrafficCounter (&hash->zsPkts, 1);

      hash->zoneConfStartTime = myGlobals.actTime;
      hash->zoneConfInProgress = TRUE;
            
      break;
    case FC_SWILS_RCA:
      incrementTrafficCounter (&hash->zsBytes, pktlen);
      incrementTrafficCounter (&hash->zsPkts, 1);

      /* We should in reality do this when we see the ACC for RCA */
      if (hash->zoneConfInProgress) {
	hash->zoneConfInProgress = FALSE;

	confTime = difftime (myGlobals.actTime, hash->zoneConfStartTime);
	if (hash->maxTimeZoneConf < confTime) {
	  hash->maxTimeZoneConf = confTime;
	}
                
	if (hash->minTimeZoneConf > confTime) {
	  hash->minTimeZoneConf = confTime;
	}
      }
      break;
    case FC_SWILS_SFC:
      incrementTrafficCounter (&hash->zsBytes, pktlen);
      incrementTrafficCounter (&hash->zsPkts, 1);
      incrementTrafficCounter (&hash->numZoneConf, 1);
            
      break;
    case FC_SWILS_UFC:
      incrementTrafficCounter (&hash->zsBytes, pktlen);
      incrementTrafficCounter (&hash->zsPkts, 1);
            
      break;
    case FC_SWILS_SWACC:
    case FC_SWILS_SWRJT:
      break;
    default:
      traceEvent (CONST_TRACE_ALWAYSDISPLAY, "updateFcFabricElementHash: Unknown SW_ILS command %d\n",
		  cmd);
      break;
    }
  }
  else {
  }
#else        
  if (protocol == FC_FTYPE_SWILS) {
    cmd = *bp;

    switch (cmd) {
    case FC_SWILS_ELP:
    case FC_SWILS_BF:
    case FC_SWILS_RCF:
      hash->fabricConfStartTime = myGlobals.actTime;
      break;
    case FC_SWILS_EFP:
      /* Copy the latest EFP for the domain list */
      payload_len = ntohs (*(u_short *)&bp[2]);
      memcpy (hash->principalSwitch.str, &bp[8], sizeof (wwn_t));

      payload_len -= 16;
      payload_len = (payload_len > pktlen) ? pktlen : payload_len;

      if (hash->domainList != NULL) {
	free (hash->domainList);
	hash->domainList = NULL;
      }
      hash->domainList = (FcDomainList *)malloc (payload_len);
      memcpy (hash->domainList, &bp[16], payload_len);

      hash->domainListLen = payload_len;

      break;
    case FC_SWILS_LSA:
      break;
            
    case FC_SWILS_ACA:
      hash->zoneConfStartTime = myGlobals.actTime;
      break;

    case FC_SWILS_RCA:
      break;
    }
  }
#endif
    
  /* Update Domain Stats */
  srcDomain = srcAddr->domain;
    
  if (srcDomain == FC_ID_SYSTEM_DOMAIN) {
    if (srcAddr->area == FC_ID_DOMCTLR_AREA) {
      srcDomain = srcAddr->port; /* This for addr of type FF.FC.<dom> */ 
    }
  }

  dstDomain = dstAddr->domain;
  if (dstDomain == FC_ID_SYSTEM_DOMAIN) {
    if (dstAddr->area == FC_ID_DOMCTLR_AREA) {
      dstDomain = dstAddr->port; /* This for addr of type FF.FC.<dom> */ 
    }
  }

  if (srcDomain != FC_ID_SYSTEM_DOMAIN) {
    incrementTrafficCounter (&hash->domainStats[srcDomain].sentBytes, pktlen);

    switch (protocol) {
    }
  }
    
  if (dstDomain != FC_ID_SYSTEM_DOMAIN) {
    incrementTrafficCounter (&hash->domainStats[dstDomain].rcvdBytes, pktlen);
        
    switch (protocol) {
    }
  }

  switch (protocol) {
  case FC_FTYPE_SWILS:
    incrementTrafficCounter (&hash->fcSwilsBytes, pktlen);
    break;
  case FC_FTYPE_SCSI:
    incrementTrafficCounter (&hash->fcFcpBytes, pktlen);
    break;
  case FC_FTYPE_SBCCS:
    incrementTrafficCounter (&hash->fcFiconBytes, pktlen);
    break;
  case FC_FTYPE_ELS:
    incrementTrafficCounter (&hash->fcElsBytes, pktlen);
    break;
  case FC_FTYPE_FCCT:
    gs_type = bp[4];
    gs_stype = bp[5];

    if ((gs_type == FCCT_GSTYPE_DIRSVC) && (gs_stype == FCCT_GSSUBTYPE_DNS)) {
      incrementTrafficCounter (&hash->fcDnsBytes, pktlen);
    }
    else {
      incrementTrafficCounter (&hash->otherFcBytes, pktlen);
    }
    break;
  case FC_FTYPE_IP:
    incrementTrafficCounter (&hash->fcIpfcBytes, pktlen);
    break;
        
  default:
    incrementTrafficCounter (&hash->otherFcBytes, pktlen);
    break;
  }

  return (0);
}

/* **************************************** */

void processFcNSCacheFile(char *filename) {
  char *token, *bufptr, *strtokState;
  FcNameServerCacheEntry *entry;
  HostTraffic *el;
  FcAddress fcid;
  u_int32_t vsanId, domain, area, port, tgtType, i, j;
  wwn_t pWWN, nWWN;
  char alias[MAX_LEN_SYM_HOST_NAME];
  FILE *fd;
  int id, hashIdx = 0, entryFound, hex;
  char buffer[256];

  if (filename == NULL) {
    return;
  }

  if (myGlobals.fcnsCacheHash == NULL) {
    /* We cannot use the file if the entry is NULL */
    return;
  }
    
  if ((fd = fopen (filename, "r")) == NULL) {
    traceEvent (CONST_TRACE_WARNING, "Unable to open FC WWN cache file %s"
		"error = %d\n", filename, errno);
    return;
  }

  traceEvent (CONST_TRACE_ALWAYSDISPLAY, "Processing FC NS file %s\n", filename);
  while (!feof (fd) && (fgets(buffer, 256, fd) != NULL)) {
    alias[0] = '\0';
    pWWN.str[0] = '\0';
    nWWN.str[0] = '\0';
        
    /* Ignore lines that start with '#' as comments */
    if (strrchr(buffer, '#') != NULL) {
      continue;
    }

    /*
     * The file is a CSV list of lines with a line format as follows:
     * VSAN, FC_ID, pWWN, nWWN, Alias, Target type
     *
     * FC_ID is specified as a 3-byte hex i.e. 0xFFFFFD
     * pWWN & nWWN are specified as octets separated by ':'
     * Alias is a comma-separated string of max 64 chars
     * Target type is a decimal returned by the INQUIRY command
     *
     * If a field is missing, it is represented by a null string i.e. two
     * consecutive commas.
     */
    id = 0;
    bufptr = buffer;
    token = strtok_r (buffer, ",", &strtokState);
    while (token != NULL) {
      if (token[0]  != '\0') {
	switch (id) {
	case FLAG_FC_NS_CASE_VSAN:
	  if (isxdigit (*token)) {
	    sscanf (token, "%d", &vsanId);
	  }
	  else {
	    /* Invalid input. Skip rest of line */
	    token = NULL;
	    continue;
	  }
	  break;
	case FLAG_FC_NS_CASE_FCID:
	  if (isxdigit (*token)) {
	    if (sscanf (token, "%02hx.%02hx.%02hx", 
			(short unsigned int *)&domain, 
			(short unsigned int *)&area, 
			(short unsigned int *)&port) == 3) {
	      fcid.domain = domain;
	      fcid.area = area;
	      fcid.port = port;
	    }
	    else {
	      /* Invalid input. Skip rest of line */
	      token = NULL;
	      continue;
	    }
	  }
	  else {
	    /* Invalid input. Skip rest of line */
	    token = NULL;
	    continue;
	  }
	  break;
	case FLAG_FC_NS_CASE_PWWN:
	  for (i = 0, j = 0; i < LEN_WWN_ADDRESS; i++) {
	    sscanf (&token[j], "%02x:", &hex);
	    pWWN.str[i] = (char)hex;
	    j += 3;
	  }
	  break;
	case FLAG_FC_NS_CASE_NWWN:
	  for (i = 0, j = 0; i < LEN_WWN_ADDRESS; i++) {
	    sscanf (&token[j], "%02x:", &hex);
	    nWWN.str[i] = (char)hex;
	    j += 3;
	  }
	  break;
	case FLAG_FC_NS_CASE_ALIAS:
	  sscanf (token, "%63s", alias);
	  break;
	case FLAG_FC_NS_CASE_TGTTYPE:
	  if (isxdigit (*token)) {
	    sscanf (token, "%d", &tgtType);
	  }
	  else {
	    /* Invalid input. Skip rest of line */
	    token = NULL;
	    continue;
	  }
	  break;
	default:
	  break;
	}
      }
      id++;

      token = strtok_r (NULL, ",", &strtokState);
    }

    /* Validate inputs */
    if (id < FLAG_FC_NS_CASE_NWWN) {
      continue;
    }

    /* Obtain hash index. We pass -1 for device ID since this file is
     * device-independent.
     */
    hashIdx = hashFcHost (&fcid, vsanId, &el, -1);
    entry = myGlobals.fcnsCacheHash[hashIdx];

    entryFound = 0;
    while (entry != NULL) {
      if (memcmp ((u_int8_t *)&(entry->fcAddress), (u_int8_t *)&fcid,
		  LEN_FC_ADDRESS) == 0) {
	entryFound = 1;
	break;
      }

      entry = entry->next;
    }

    if (!entryFound) {
      if ((entry = malloc (sizeof (FcNameServerCacheEntry))) == NULL) {
	traceEvent (CONST_TRACE_ERROR, "Unable to malloc entry for FcNameServerCache Entry\n");
	return;
      }

      memset (entry, 0, sizeof (FcNameServerCacheEntry));
      entry->hashIdx = hashIdx;
      entry->next = myGlobals.fcnsCacheHash[hashIdx];
      myGlobals.fcnsCacheHash[hashIdx] = entry;
    }

    entry->vsanId = vsanId;
    entry->fcAddress = fcid;
    memcpy (&entry->pWWN.str[0], &pWWN.str[0], LEN_WWN_ADDRESS);
    memcpy (&entry->nWWN.str[0], &nWWN.str[0], LEN_WWN_ADDRESS);
    strncpy (&entry->alias[0], alias, MAX_LEN_SYM_HOST_NAME);
    entry->alias[MAX_LEN_SYM_HOST_NAME] = '\0';
  }
}