Changeset bad6a93


Ignore:
Timestamp:
09/20/06 16:42:52 (14 years ago)
Author:
Shane Alcock <salcock@…>
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:
e86124e
Parents:
d0aa87c
Message:

trace_get_vlan_payload_from_ethernet is now available to libtrace users.
Fixed error where erf wire length was having padding subtracted from it - wire length doesn't include padding.
erf can also attach padding to the end of packets - get_capture_length now returns the minimum of the record length - padding and the wire length.
Added support for RT_LOSTCONN - also other zero sized rt packets shouldn't cause TRACE_EVENT_TERMINATE anymore
rt header information is no longer stored statically when doing a non-blocking read
The packet->buffer for rt packets is now regarded as external, so now trace_destroy_packet shouldn't cause a segfault

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • examples/skeleton/event.c

    r0eef5d4 rbad6a93  
    138138                /* Got a packet - let's do something with it */
    139139                per_packet(packet);
    140                
    141140        }
    142141        free(uri);
  • examples/skeleton/trivial.c

    r34ee7eb rbad6a93  
    1010#include "libtrace.h"
    1111#include <stdio.h>
     12#include <assert.h>
    1213
    1314void per_packet(libtrace_packet_t *packet)
  • lib/format_erf.c

    r959f88f rbad6a93  
    996996                /* loss counter. Can't do this */
    997997                erfhdr.lctr = 0;
    998                 /* Wire length, may contain the padding */
    999                 erfhdr.wlen = htons(trace_get_wire_length(packet)+pad);
     998                /* Wire length, does not include padding! */
     999                erfhdr.wlen = htons(trace_get_wire_length(packet));
    10001000
    10011001                /* Write it out */
     
    10351035static int erf_get_capture_length(const libtrace_packet_t *packet) {
    10361036        dag_record_t *erfptr = 0;
     1037        int caplen;
    10371038        if (packet->payload == NULL)
    10381039                return 0;
    10391040       
    10401041        erfptr = (dag_record_t *)packet->header;
     1042        caplen = ntohs(erfptr->rlen) - erf_get_framing_length(packet);
     1043        if (ntohs(erfptr->wlen) < caplen)
     1044                return ntohs(erfptr->wlen);
     1045
    10411046        return (ntohs(erfptr->rlen) - erf_get_framing_length(packet));
    10421047}
     
    10451050        dag_record_t *erfptr = 0;
    10461051        erfptr = (dag_record_t *)packet->header;
    1047         return ntohs(erfptr->wlen) - erf_get_padding(packet);
     1052        return ntohs(erfptr->wlen);
    10481053}
    10491054
  • lib/format_rt.c

    re502f76 rbad6a93  
    8383        char *buf_current;
    8484        int buf_filled;
    85 
     85        rt_header_t rt_hdr;
     86       
    8687        libtrace_t *dummy_duck;
    8788        libtrace_t *dummy_erf;
     
    485486static int rt_read_packet_versatile(libtrace_t *libtrace,
    486487                libtrace_packet_t *packet,int blocking) {
    487         static rt_header_t rt_hdr;
    488488        static rt_header_t *pkt_hdr = 0;
    489489       
     
    491491                /* first time through */
    492492                pkt_hdr = malloc(sizeof(rt_header_t));
    493                 rt_hdr.type = RT_LAST;
    494         }
    495        
     493                RT_INFO->rt_hdr.type = RT_LAST;
     494        }
     495
     496        /*
    496497        if (packet->buf_control == TRACE_CTRL_EXTERNAL || !packet->buffer) {
    497498                packet->buf_control = TRACE_CTRL_PACKET;
    498499                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
    499500        }
     501        */
     502        if (packet->buf_control == TRACE_CTRL_PACKET) {
     503                packet->buf_control = TRACE_CTRL_EXTERNAL;
     504                free(packet->buffer);
     505                packet->buffer = NULL;
     506        }
    500507
    501508        /* RT_LAST means that the next bytes received should be a
    502509         * rt header - I know it's hax and maybe I'll fix it later on */
    503         if (rt_hdr.type == RT_LAST) {
     510        if (RT_INFO->rt_hdr.type == RT_LAST) {
    504511       
    505512                /* FIXME: Better error handling required */
     
    512519                /* Need to salvage these in case the next rt_read overwrites
    513520                 * the buffer they came from! */
    514                 rt_hdr.type = pkt_hdr->type;
    515                 rt_hdr.length = pkt_hdr->length;
    516                 rt_hdr.sequence = pkt_hdr->sequence;
    517         }
    518         packet->type = rt_hdr.type;
    519         packet->size = rt_hdr.length;
     521                RT_INFO->rt_hdr.type = pkt_hdr->type;
     522                RT_INFO->rt_hdr.length = pkt_hdr->length;
     523                RT_INFO->rt_hdr.sequence = pkt_hdr->sequence;
     524        }
     525        packet->type = RT_INFO->rt_hdr.type;
     526        packet->size = RT_INFO->rt_hdr.length;
    520527
    521528        if (packet->type >= RT_DATA_SIMPLE) {
    522                 if (rt_read(libtrace, &packet->buffer, rt_hdr.length,blocking) != rt_hdr.length) {
     529                if (rt_read(libtrace, &packet->buffer, RT_INFO->rt_hdr.length,blocking) != RT_INFO->rt_hdr.length) {
    523530                        return -1;
    524531                }
     
    526533               
    527534                if (RT_INFO->reliable > 0) {
    528                         if (rt_send_ack(libtrace, rt_hdr.sequence)
     535                        if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence)
    529536                                        == -1)
    530537                        {
     
    535542                       
    536543                if (rt_set_format(libtrace, packet) < 0) {
    537                         return -1;
     544                        return -1;
    538545                }
    539546                rt_set_payload(packet);
     
    542549                        case RT_STATUS:
    543550                                if (rt_read(libtrace, &packet->buffer,
    544                                         rt_hdr.length, blocking) !=
    545                                                 rt_hdr.length) {
     551                                        RT_INFO->rt_hdr.length, blocking) !=
     552                                                RT_INFO->rt_hdr.length) {
    546553                                        return -1;
    547554                                }
     
    552559                        case RT_DUCK_2_5:
    553560                                if (rt_read(libtrace, &packet->buffer,
    554                                         rt_hdr.length, blocking) !=
    555                                                 rt_hdr.length) {
     561                                        RT_INFO->rt_hdr.length, blocking) !=
     562                                                RT_INFO->rt_hdr.length) {
    556563                                        return -1;
    557564                                }
     
    563570                                break;
    564571                        case RT_END_DATA:
    565                                 return 0;
     572                                break;
    566573                        case RT_PAUSE_ACK:
    567574                                /* FIXME: Do something useful */
     
    581588        }
    582589        /* Return the number of bytes read from the stream */
    583         rt_hdr.type = RT_LAST;
     590        RT_INFO->rt_hdr.type = RT_LAST;
    584591        return packet->size;
    585592}
     
    615622                case RT_KEYCHANGE:
    616623                        return 0;
     624                case RT_LOSTCONN:
     625                        return 0;
    617626        }
    618627        printf("Unknown type: %d\n", packet->type);
     
    656665                }
    657666        } else if (event.size == 0) {
    658                 event.type = TRACE_EVENT_TERMINATE;
     667                if (packet->type == RT_END_DATA)
     668                        event.type = TRACE_EVENT_TERMINATE;
     669                else
     670                        event.type = TRACE_EVENT_PACKET;
    659671               
    660672        }       
  • lib/libtrace.h.in

    r755e794 rbad6a93  
    872872                uint16_t *type, uint32_t *remaining);
    873873
     874/** Skips over any 802.1q headers, if present.
     875 * @param ethernet      A pointer to the payload following an ethernet header -usually the result of calling trace_get_payload_from_link
     876 * @param[in,out] type  The ethernet type, replaced with the vlan ether type
     877 * @param[in,out] remaining Updated with the number of bytes remaining
     878 *
     879 * @return a pointer to the header beyond the vlan header, if present.
     880 * Otherwise, returns the ethernet payload that was passed in
     881 *
     882 * Remaining may be NULL. If Remaining is not NULL it must point to the number
     883 * of bytes captured past (but not including) the link layer. It will be
     884 * updated after this function to the number of bytes remaining after the
     885 * vlan header. If it is unchanged then no vlan header exists.
     886 *
     887 * Type must point to the value of the ethernet type. Libtrace will assert
     888 * fail if type is NULL.
     889 *
     890 */
     891DLLEXPORT void *trace_get_vlan_payload_from_ethernet_payload(
     892                void *ethernet_payload, uint16_t *type, uint32_t *remaining);
     893
    874894/** Gets a pointer to the payload given a pointer to a tcp header
    875895 * @param tcp           The tcp Header
  • lib/protocols.c

    re5222e1 rbad6a93  
    4646 * type is input/output
    4747 */
    48 static void *trace_get_vlan_payload_from_ethernet_payload(void *ethernet, uint16_t *type,
     48void *trace_get_vlan_payload_from_ethernet_payload(void *ethernet, uint16_t *type,
    4949                uint32_t *remaining)
    5050{
  • lib/trace.c

    re502f76 rbad6a93  
    402402                trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT,
    403403                                "Unknown format (%s)",scan);
    404                 return 0;
    405404        }
    406405
Note: See TracChangeset for help on using the changeset viewer.