Changeset f240823 for lib


Ignore:
Timestamp:
11/29/12 13:20:08 (9 years ago)
Author:
Richard Sanger <rjs51@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
2627439
Parents:
1935565
Message:

Added in a working trace_event handler, Shanes tests showed the default handler was not working for PACKET_MMAP. Also fixed minor calculate_buffers bugs resulting in larger buffer allocation then needed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_linux.c

    r17dc71c rf240823  
    272272        /* Calculate frame size */
    273273        req->tp_frame_size = pagesize;
    274         do {
     274        while(req->tp_frame_size < mtu && req->tp_frame_size < LIBTRACE_PACKET_BUFSIZE){
    275275                req->tp_frame_size <<= 1;
    276         } while(req->tp_frame_size < mtu && req->tp_frame_size < LIBTRACE_PACKET_BUFSIZE);
     276        }
    277277        if(req->tp_frame_size > LIBTRACE_PACKET_BUFSIZE)
    278278                req->tp_frame_size >>= 1;
     
    282282        do{
    283283                req->tp_block_size >>= 1;
    284         } while((CONF_RING_FRAMES * req->tp_frame_size) < req->tp_block_size);
     284        } while((CONF_RING_FRAMES * req->tp_frame_size) <= req->tp_block_size);
    285285        req->tp_block_size <<= 1;
    286286       
     
    295295                        (req->tp_block_size / req->tp_frame_size);
    296296
    297         printf("MaxO 0x%x BS 0x%x BN 0x%x FS 0x%x FN 0x%x\n",
     297        /*printf("MaxO 0x%x BS 0x%x BN 0x%x FS 0x%x FN 0x%x\n",
    298298                max_order,
    299299                req->tp_block_size,
    300300                req->tp_block_nr,
    301301                req->tp_frame_size,
    302                 req->tp_frame_nr);
     302                req->tp_frame_nr);*/
    303303       
    304304        /* In case we have some silly values*/
     
    933933static int linuxring_get_framing_length(const libtrace_packet_t *packet);
    934934
    935 static int linuxring_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) {
    936 
    937         struct tpacket2_hdr *header;
    938         struct pollfd pollset; 
    939         int ret;
    940        
     935/* Release a frame back to the kernel or free() if it's a malloc'd buffer
     936 */
     937inline static void ring_release_frame(libtrace_t *libtrace, libtrace_packet_t *packet ){
    941938        /* Free the old packet */
     939        if(packet->buffer == NULL)
     940                return;
     941
    942942        if(packet->buf_control == TRACE_CTRL_PACKET){
    943943                free(packet->buffer);
     944                packet->buffer = NULL;
    944945        }
    945946        if(packet->buf_control == TRACE_CTRL_EXTERNAL) {
     
    955956                }
    956957        }
     958}
     959
     960static int linuxring_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) {
     961
     962        struct tpacket2_hdr *header;
     963        struct pollfd pollset; 
     964        int ret;
     965       
     966        ring_release_frame(libtrace, packet);
    957967       
    958968        packet->buf_control = TRACE_CTRL_EXTERNAL;
     
    968978         */
    969979        while (!(header->tp_status & TP_STATUS_USER)) {
     980                printf("I shouldn't run if event handler\n");
    970981                pollset.fd = FORMAT(libtrace->format_data)->fd;
    971982                pollset.events = POLLIN;
     
    9941005                                linuxring_get_capture_length(packet);
    9951006
     1007}
     1008
     1009/* Non-blocking read */
     1010static libtrace_eventobj_t linuxring_event(libtrace_t *libtrace, libtrace_packet_t *packet) {
     1011        struct tpacket2_hdr *header;
     1012        libtrace_eventobj_t event = {0,0,0.0,0};
     1013
     1014        /* We must free the old packet, otherwise select() will instantly return
     1015         */
     1016        ring_release_frame(libtrace, packet);
     1017
     1018        /* Fetch the current frame */
     1019        header = GET_CURRENT_BUFFER(libtrace);
     1020        if(header->tp_status & TP_STATUS_USER){
     1021                /* We have a frame waiting */
     1022                event.size = linuxring_read_packet(libtrace, packet);
     1023                event.type = TRACE_EVENT_PACKET;
     1024        } else {
     1025                /* Ok we don't have a packet waiting */
     1026                event.type = TRACE_EVENT_IOWAIT;
     1027                event.fd = FORMAT(libtrace->format_data)->fd;
     1028        }
     1029
     1030        return event;
    9961031}
    9971032
     
    14681503        linuxnative_get_captured_packets,/* get_captured_packets */
    14691504        linuxnative_get_fd,             /* get_fd */
    1470         trace_event_device,             /* trace_event */
     1505        linuxring_event,                /* trace_event */
    14711506        linuxring_help,         /* help */
    14721507        NULL
Note: See TracChangeset for help on using the changeset viewer.