Changeset 853


Ignore:
Timestamp:
06/06/06 17:32:24 (7 years ago)
Author:
perry
Message:

Add demotion of packets from LINUX_SLL to ethernet when writing ERF packets.
We don't need the extra header to store the direction information, and erf
doesn't have a type for linux-sll /anyway/.

This also adds a test which takes a packet, promotes it and demotes it again
which should catch direction related bugs

Closes: #21

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/format_erf.c

    r850 r853  
    861861 
    862862static int erf_dump_packet(libtrace_out_t *libtrace, 
    863                 dag_record_t *erfptr, int pad, void *buffer, size_t size) { 
     863                dag_record_t *erfptr, int pad, void *buffer) { 
    864864        int numbytes = 0; 
    865         assert(size<=65536); 
     865        int size; 
    866866 
    867867        if ((numbytes = libtrace_io_write(OUTPUT.file, erfptr, dag_record_size + pad)) != dag_record_size+pad) { 
     
    871871        } 
    872872 
    873         if ((numbytes=libtrace_io_write(OUTPUT.file, buffer, size)) != (int)size) { 
     873        size=ntohs(erfptr->rlen)-(dag_record_size+pad); 
     874 
     875        numbytes=libtrace_io_write(OUTPUT.file, buffer, size); 
     876        if (numbytes != size) { 
    874877                trace_set_err_out(libtrace,errno, 
    875878                                "write(%s)",libtrace->uridata); 
     
    926929                                (dag_record_t *)packet->header, 
    927930                                pad, 
    928                                 payload, 
    929                                 trace_get_capture_length(packet) 
     931                                payload 
    930932                                ); 
    931933        } else { 
     
    935937                /* Timestamp */ 
    936938                erfhdr.ts = trace_get_erf_timestamp(packet); 
    937                 type=libtrace_to_erf_type(trace_get_link_type(packet)); 
     939                /* Keep trying to simplify the packet until we can find  
     940                 * something we can do with it */ 
     941                do { 
     942                        type=libtrace_to_erf_type(trace_get_link_type(packet)); 
     943                } while(type==(char)-1 && demote_packet(packet)); 
     944                /* We just don't support this link type sorry */ 
    938945                if (type==(char)-1) { 
    939                         trace_set_err_out(libtrace,TRACE_ERR_NO_CONVERSION, 
     946                        trace_set_err_out(libtrace, 
     947                                        TRACE_ERR_NO_CONVERSION, 
    940948                                        "No erf type for packet"); 
    941949                        return -1; 
     
    946954                if (trace_get_direction(packet)!=-1) 
    947955                        erfhdr.flags.iface = trace_get_direction(packet); 
     956 
    948957                /* Packet length (rlen includes format overhead) */ 
     958                assert(trace_get_capture_length(packet)>0  
     959                                && trace_get_capture_length(packet)<=65536); 
     960                assert(erf_get_framing_length(packet)>0  
     961                                && trace_get_framing_length(packet)<=65536); 
     962                assert( 
     963                        trace_get_capture_length(packet)+erf_get_framing_length(packet)>0 
     964                      &&trace_get_capture_length(packet)+erf_get_framing_length(packet)<=65536); 
    949965                erfhdr.rlen = htons(trace_get_capture_length(packet)  
    950966                        + erf_get_framing_length(packet)); 
     
    958974                                &erfhdr, 
    959975                                pad, 
    960                                 payload, 
    961                                 trace_get_capture_length(packet)); 
     976                                payload); 
    962977        } 
    963978        return numbytes; 
  • trunk/lib/libtrace_int.h

    r808 r853  
    357357 
    358358void promote_packet(libtrace_packet_t *packet); 
     359bool demote_packet(libtrace_packet_t *packet); 
    359360 
    360361#if HAVE_BPF 
  • trunk/lib/linktypes.c

    r795 r853  
    154154        } 
    155155} 
     156 
     157/* Try and simplify the packet one step, kinda the opposite to promote_packet 
     158 * 
     159 * returns true if demotion was possible, false if not. 
     160 */ 
     161bool demote_packet(libtrace_packet_t *packet) 
     162{ 
     163        switch(trace_get_link_type(packet)) { 
     164                case TRACE_TYPE_LINUX_SLL: 
     165                        switch(((libtrace_sll_header_t*)packet->payload) 
     166                                        ->hatype) { 
     167                                case ARPHRD_PPP: 
     168                                        packet->type=pcap_dlt_to_rt(DLT_NULL); 
     169                                        break; 
     170                                case ARPHRD_ETHER: 
     171                                        packet->type=pcap_dlt_to_rt(DLT_EN10MB); 
     172                                        break; 
     173                                default: 
     174                                        /* Dunno how to demote this packet */ 
     175                                        return false; 
     176                        } 
     177                        packet->payload=(void*)((char*)packet->payload 
     178                                        +sizeof(libtrace_sll_header_t)); 
     179                        trace_set_capture_length(packet, 
     180                                trace_get_capture_length(packet) 
     181                                        -sizeof(libtrace_sll_header_t)); 
     182                        break; 
     183                default: 
     184                        return false; 
     185        } 
     186} 
  • trunk/test/Makefile

    r824 r853  
    1010LDLIBS = -L$(libdir) -ltrace 
    1111 
    12 BINS = test-pcap-bpf test-event test-time #test-seek  
     12BINS = test-pcap-bpf test-event test-time test-dir #test-seek  
    1313 
    1414.PHONY: all clean distclean install depend test 
     
    1919        @for i in $(BINS); do                                   \ 
    2020                echo \* $$i;                                    \ 
     21                rm -f traces/*.out.*;                           \ 
    2122                LD_LIBRARY_PATH=$(libdir)                       \ 
    2223                 ./$$i || exit $$?;                             \ 
     
    2526 
    2627test-format-all: test-format 
    27         @for i in erf pcap wtf pcapfile duck; do                        \ 
     28        @for i in erf pcap wtf pcapfile duck; do                \ 
    2829                echo \* $$i;                                    \ 
     30                rm -f traces/*.out.*;                           \ 
    2931                LD_LIBRARY_PATH=$(libdir)                       \ 
    3032                ./test-format $$i || exit $$?;                  \ 
     
    3638        @echo \* Conversions 
    3739        @echo " * erf -> erf" 
     40        @rm -f traces/*.out.* 
    3841        @LD_LIBRARY_PATH=$(libdir) ./test-convert erf erf 
    3942        @echo " * erf -> pcap" 
    4043        @LD_LIBRARY_PATH=$(libdir) ./test-convert erf pcap 
    4144        @echo " * pcap -> erf" 
     45        @rm -f traces/*.out.* 
    4246        @LD_LIBRARY_PATH=$(libdir) ./test-convert pcap erf 
    4347        @echo " * pcapfile -> erf" 
     48        @rm -f traces/*.out.* 
    4449        @LD_LIBRARY_PATH=$(libdir) ./test-convert pcapfile erf 
    4550        @#LD_LIBRARY_PATH=$(libdir) ./test-convert rtclient erf 
    4651        @#LD_LIBRARY_PATH=$(libdir) ./test-convert rtclient pcap 
    4752        @echo " * wtf -> pcap" 
     53        @rm -f traces/*.out.* 
    4854        @LD_LIBRARY_PATH=$(libdir) ./test-convert wtf pcap 
    4955        @echo " * wtf -> wtf" 
     56        @rm -f traces/*.out.* 
    5057        @LD_LIBRARY_PATH=$(libdir) ./test-convert wtf wtf 
    5158        @echo " * duck -> duck" 
     59        @rm -f traces/*.out.* 
    5260        @LD_LIBRARY_PATH=$(libdir) ./test-convert duck duck 
    5361  
Note: See TracChangeset for help on using the changeset viewer.