Changeset 1598c46


Ignore:
Timestamp:
11/02/15 14:02:11 (6 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
pfring
Children:
4c365fa
Parents:
f72e13d
Message:

Fix some pfring bugs found in initial testing

  • Fixed bug where I'd forgotten to set packet->header.
  • Fixed 32 vs 64 bit timeval problems
  • Fixed uses of ntohl when I really mean htonl
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pfring.c

    rf72e13d r1598c46  
    136136};
    137137
     138struct local_pfring_header {
     139        struct timeval ts;
     140        uint32_t caplen;
     141        uint32_t wlen;
     142        struct libtrace_pfring_extend ext;     
     143       
     144};
     145
     146
    138147struct libtrace_pfring_header {
    139148        struct {
    140                 uint32_t tv_sec;
    141                 uint32_t tv_usec;
     149                uint64_t tv_sec;
     150                uint64_t tv_usec;
    142151        } ts;
    143152        uint32_t caplen;
     
    334343        struct pfring_per_stream_t *stream = FORMAT_DATA_FIRST;
    335344        struct libtrace_pfring_header *hdr;
     345        struct local_pfring_header local;
    336346        int rc;
    337347
     
    347357        hdr = (struct libtrace_pfring_header *)packet->buffer;
    348358        if ((rc = pfring_recv(stream->pd, (u_char **)&packet->payload,
    349                         0, (struct pfring_pkthdr *)hdr, 1)) == -1)
     359                        0, (struct pfring_pkthdr *)&local, 1)) == -1)
    350360        {
    351361                trace_set_err(libtrace, errno, "Failed to read packet from pfring:");
     
    354364
    355365        /* Convert the header fields to network byte order so we can
    356          * export them over RT safely */
    357 
    358         /* TODO: Deal with 32 vs 64 bit timestamps */
    359         hdr->caplen = ntohl(hdr->caplen);
    360         hdr->wlen = ntohl(hdr->wlen);
    361         hdr->ts.tv_sec = ntohl(hdr->ts.tv_sec);
    362         hdr->ts.tv_usec = ntohl(hdr->ts.tv_usec);
    363         hdr->ext.ts_ns = bswap_host_to_le64(hdr->ext.ts_ns);
    364         hdr->ext.flags = ntohl(hdr->ext.flags);
    365         hdr->ext.if_index = ntohl(hdr->ext.if_index);
    366         hdr->ext.hash = ntohl(hdr->ext.hash);
    367         hdr->ext.tx.bounce_iface = ntohl(hdr->ext.tx.bounce_iface);
    368         hdr->ext.parsed_hdr_len = ntohs(hdr->ext.parsed_hdr_len);
     366         * export them over RT safely. Also deal with 32 vs 64 bit
     367         * timevals! */
     368        hdr->ts.tv_sec = bswap_host_to_le64((uint64_t)local.ts.tv_sec);
     369        hdr->ts.tv_usec = bswap_host_to_le64((uint64_t)local.ts.tv_usec);
     370        hdr->caplen = htonl(local.caplen);
     371        hdr->wlen = htonl(local.wlen);
     372        hdr->ts.tv_sec = htonl(local.ts.tv_sec);
     373        hdr->ts.tv_usec = htonl(local.ts.tv_usec);
     374        hdr->ext.ts_ns = bswap_host_to_le64(local.ext.ts_ns);
     375        hdr->ext.flags = htonl(local.ext.flags);
     376        hdr->ext.if_index = htonl(local.ext.if_index);
     377        hdr->ext.hash = htonl(local.ext.hash);
     378        hdr->ext.tx.bounce_iface = htonl(local.ext.tx.bounce_iface);
     379        hdr->ext.parsed_hdr_len = htons(local.ext.parsed_hdr_len);
     380        hdr->ext.direction = local.ext.direction;
    369381
    370382        /* I think we can ignore parsed as it will only be populated if
     
    374386        packet->trace = libtrace;
    375387        packet->type = TRACE_RT_DATA_PFRING;
    376        
     388        packet->header = packet->buffer;
     389
    377390        return pfring_get_capture_length(packet) +
    378391                        pfring_get_framing_length(packet);
Note: See TracChangeset for help on using the changeset viewer.