It would seem that the sflowPlugin.c code was based on a rather old
version of inMon's sflowtool, from the days before anyone used an
enterprise ID other than 0 and while it still had a slight bug in
skipTLVrecord where it would advance through the sample when it
shouldn't.  This patch then cribs a bit of the changes in a later
sflowtool to avoid getting confused while trying to parse PDUs with
unknown enterprise IDs.

Quickly tested against a captured sample of such PDUs and no error
messages appear any longer.  

Signed-off-by: Rick Jones <[email protected]>


*** sflowPlugin.c.orig  2011-04-14 15:51:10.736141958 -0700
--- sflowPlugin.c       2011-04-18 11:07:57.230769702 -0700
***************
*** 1905,1919 ****
    return buf;
  }
  
! static u_int32_t skipTLVRecord(SFSample *sample, u_int32_t tag, char 
*description, int deviceId) {
    char buf[51];
!   u_int32_t len;
!   if(SFLOW_DEBUG(deviceId)) traceEvent(CONST_TRACE_INFO, "skipping unknown 
%s: %s\n", description, printTag(tag, buf, 50, deviceId));
!   len = getData32(sample, deviceId);
!   // sanity check
    if(len > sample->rawSampleLen) SFABORT(sample, SF_ABORT_EOS);
    else skipBytes(sample, len);
!   return len;
  }
  
  /*_________________---------------------------__________________
--- 1905,1917 ----
    return buf;
  }
  
! static void skipTLVRecord(SFSample *sample, u_int32_t tag, u_int32_t len, 
char *description, int deviceId) {
    char buf[51];
!   if(SFLOW_DEBUG(deviceId)) traceEvent(CONST_TRACE_INFO, "skipping unknown 
%s: %s length %d\n", description, printTag(tag, buf, 50, deviceId),len);
!   // sanity check left in even though later sflowtool doesn't have it
    if(len > sample->rawSampleLen) SFABORT(sample, SF_ABORT_EOS);
    else skipBytes(sample, len);
! 
  }
  
  /*_________________---------------------------__________________
***************
*** 2632,2640 ****
        case SFLFLOW_EX_MPLS_FTN:     readExtendedMplsFTN(sample, deviceId); 
break;
        case SFLFLOW_EX_MPLS_LDP_FEC: readExtendedMplsLDP_FEC(sample, 
deviceId); break;
        case SFLFLOW_EX_VLAN_TUNNEL:  readExtendedVlanTunnel(sample, deviceId); 
break;
!       default: skipTLVRecord(sample, tag, "flow_sample_element", deviceId); 
break;
        }
!       lengthCheck(sample, "flow_sample_element", start, length);
      }
    }
  
--- 2630,2638 ----
        case SFLFLOW_EX_MPLS_FTN:     readExtendedMplsFTN(sample, deviceId); 
break;
        case SFLFLOW_EX_MPLS_LDP_FEC: readExtendedMplsLDP_FEC(sample, 
deviceId); break;
        case SFLFLOW_EX_VLAN_TUNNEL:  readExtendedVlanTunnel(sample, deviceId); 
break;
!       default: skipTLVRecord(sample, tag, length, "flow_sample_element 1", 
deviceId); break;
        }
!       lengthCheck(sample, "flow_sample_element 2", start, length);
      }
    }
  
***************
*** 2869,2875 ****
        case SFLCOUNTERS_TOKENRING:readCounters_tokenring(sample, deviceId); 
break;
        case SFLCOUNTERS_VG: readCounters_vg(sample, deviceId); break;
        case SFLCOUNTERS_VLAN: readCounters_vlan(sample, deviceId); break;
!       default: skipTLVRecord(sample, tag, "counters_sample_element", 
deviceId); break;
        }
        
        lengthCheck(sample, "counters_sample_element", (u_char*)start, length);
--- 2867,2873 ----
        case SFLCOUNTERS_TOKENRING:readCounters_tokenring(sample, deviceId); 
break;
        case SFLCOUNTERS_VG: readCounters_vg(sample, deviceId); break;
        case SFLCOUNTERS_VLAN: readCounters_vlan(sample, deviceId); break;
!       default: skipTLVRecord(sample, tag, length, "counters_sample_element", 
deviceId); break;
        }
        
        lengthCheck(sample, "counters_sample_element", (u_char*)start, length);
***************
*** 2955,2961 ****
        case SFLCOUNTERS_SAMPLE: readCountersSample(sample, NO, deviceId); 
break;
        case SFLFLOW_SAMPLE_EXPANDED: readFlowSample(sample, YES, deviceId); 
break;
        case SFLCOUNTERS_SAMPLE_EXPANDED: readCountersSample(sample, YES, 
deviceId); break;
!       default: skipTLVRecord(sample, sample->sampleType, "sample", deviceId); 
break;
        }
        } else {
        switch(sample->sampleType) {
--- 2953,2959 ----
        case SFLCOUNTERS_SAMPLE: readCountersSample(sample, NO, deviceId); 
break;
        case SFLFLOW_SAMPLE_EXPANDED: readFlowSample(sample, YES, deviceId); 
break;
        case SFLCOUNTERS_SAMPLE_EXPANDED: readCountersSample(sample, YES, 
deviceId); break;
!       default: skipTLVRecord(sample, sample->sampleType, getData32(sample, 
deviceId), "sample", deviceId); break;
        }
        } else {
        switch(sample->sampleType) {
_______________________________________________
Ntop-dev mailing list
[email protected]
http://listgateway.unipi.it/mailman/listinfo/ntop-dev

Reply via email to