Changeset 17c5749


Ignore:
Timestamp:
07/22/14 12:57:50 (6 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
41148f2
Parents:
54834a1 (diff), a6c77b0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'upsteam/develop' into FixingDPDK

Conflicts:

README
lib/format_linux.c
test/Makefile

Files:
11 added
26 edited

Legend:

Unmodified
Added
Removed
  • README

    rf1015ad r17c5749  
    44Libtrace functions might not function correctly breaking the supplied tools.
    55
    6 libtrace 3.0.19
     6libtrace 3.0.20
    77
    88---------------------------------------------------------------------------
  • configure.in

    rabf01b6 r457bf45  
    44# and in the README
    55
    6 AC_INIT([libtrace],[3.0.19],[contact@wand.net.nz],[libtrace])
     6AC_INIT([libtrace],[3.0.20],[contact@wand.net.nz],[libtrace])
    77
    88LIBTRACE_MAJOR=3
    99LIBTRACE_MID=0
    10 LIBTRACE_MINOR=19
     10LIBTRACE_MINOR=20
    1111
    1212# OpenSolaris hides libraries like libncurses in /usr/gnu/lib, which is not
     
    580580)
    581581
     582AC_ARG_WITH([lzma],
     583        AC_HELP_STRING([--with-lzma], [build with support for lzma compressed files]))
     584
     585AS_IF([test "x$with_lzma" != "xno"],
     586        [
     587        AC_CHECK_HEADER(lzma.h, have_lzma=yes, have_lzma=no)
     588        ], [have_lzma=no])
     589
     590AS_IF([test "x$have_lzma" = "xyes"], [
     591        if test "$ac_cv_lib_lzma_code" != "none required"; then
     592                LIBWANDIO_LIBS="$LIBWANDIO_LIBS -llzma"
     593        fi
     594        AC_DEFINE(HAVE_LIBLZMA, 1, "Compiled with lzma support")
     595        with_lzma=yes],
     596
     597       
     598        [AS_IF([test "x$with_lzma" = "xyes"],
     599                [AC_MSG_ERROR([lzma requested but not found])])
     600        AC_DEFINE(HAVE_LIBLZMA, 0, "Compiled with lzma support")
     601        with_lzma=no]
     602)
    582603
    583604# Define automake conditionals for use in our Makefile.am files
     
    594615AM_CONDITIONAL([HAVE_ZLIB], [test "x$with_zlib" != "xno"])
    595616AM_CONDITIONAL([HAVE_LZO], [ test "x$with_lzo" != "xno"])
     617AM_CONDITIONAL([HAVE_LZMA], [ test "x$with_lzma" != "xno"])
    596618
    597619# Check for miscellaneous programs
     
    648670reportopt "Compiled with compressed trace (bz2) support" $with_bzip2
    649671reportopt "Compiled with compressed trace (lzo write only) support" $with_lzo
     672reportopt "Compiled with compressed trace (lzma) support" $with_lzma
    650673if test x"$libtrace_dag" = xtrue; then
    651674        if test "$libtrace_dag_version" = 24; then
  • lib/format_linux.c

    rbcfe4ea r17c5749  
    11091109        if (check_queue) {
    11101110                // Check for a packet - TODO only Linux has MSG_DONTWAIT should use fctl O_NONBLOCK
    1111                 hdr->wirelen = recvmsg(fd, &msghdr, MSG_DONTWAIT);
     1111                hdr->wirelen = recvmsg(fd, &msghdr, MSG_DONTWAIT | MSG_TRUNC);
    11121112                if ((int) hdr->wirelen == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
    11131113                        // Do message queue check or select
     
    11361136                }
    11371137        } else {
    1138                 hdr->wirelen = recvmsg(fd, &msghdr, 0);
     1138                hdr->wirelen = recvmsg(fd, &msghdr, MSG_TRUNC);
    11391139        }
    11401140       
  • lib/format_pcap.c

    rb13b939 r17c5749  
    578578static libtrace_direction_t pcap_set_direction(libtrace_packet_t *packet,
    579579                libtrace_direction_t dir) {
    580        
     580
     581        /* We only support tagging with IN or OUT return error for any others */
     582        if(!(dir == TRACE_DIR_OUTGOING || dir == TRACE_DIR_INCOMING))
     583                return -1;
     584
    581585        /* PCAP doesn't have a direction field in the header, so we need to
    582586         * promote to Linux SLL to tag it properly */
  • lib/libtrace.h.in

    r50ce607 r17c5749  
    883883        uint8_t ospf_v;         /**< OSPF Version, should be 2 */
    884884        uint8_t type;           /**< OSPF Packet Type */
    885         uint16_t len;           /**< Packet length, including OSPF header */
     885        uint16_t ospf_len;      /**< Packet length, including OSPF header */
    886886        struct in_addr router;  /**< Router ID of the packet source */
    887887        struct in_addr area;    /**< Area the packet belongs to */
     
    12551255        TRACE_OPTION_COMPRESSTYPE_BZ2  = 2, /**< BZip2 Compression */
    12561256        TRACE_OPTION_COMPRESSTYPE_LZO  = 3,  /**< LZO Compression */
     1257        TRACE_OPTION_COMPRESSTYPE_LZMA  = 4,  /**< LZO Compression */
    12571258        TRACE_OPTION_COMPRESSTYPE_LAST
    12581259} trace_option_compresstype_t;
     
    17951796DLLEXPORT uint16_t *trace_checksum_transport(libtrace_packet_t *packet,
    17961797                uint16_t *csum);
     1798
     1799/** Calculates the fragment offset in bytes for an IP packet
     1800 * @param packet        The libtrace packet to calculate the offset for
     1801 * @param[out] more     A boolean flag to indicate whether there are more
     1802 *                      fragments after the current packet.
     1803 * @return The fragment offset for the packet in bytes. If the packet is not
     1804 * an IP packet or the fragment offset is not present in packet, the return
     1805 * value will be 0.
     1806 *
     1807 * @note The value returned is in bytes, not 8-octet units as it is stored
     1808 * in the fragment offset field in the headers. In other words, libtrace
     1809 * automatically does the multiplication for you.
     1810 *
     1811 * The value passed in for 'more' does not matter; it will be overwritten
     1812 * with the value of the More Fragments flag from the IP header.
     1813 *
     1814 * New in libtrace 3.0.20
     1815 */
     1816DLLEXPORT uint16_t trace_get_fragment_offset(const libtrace_packet_t *packet,
     1817                uint8_t *more);
    17971818
    17981819/** Gets a pointer to the transport layer header (if any)
  • lib/protocols_l3.c

    r9ca1fce r7baa948  
    724724}
    725725
     726DLLEXPORT uint16_t trace_get_fragment_offset(const libtrace_packet_t *packet,
     727                uint8_t *more) {
     728
     729        void *l3;
     730        uint16_t ethertype;
     731        uint32_t remaining;
     732
     733        *more = 0;
     734
     735        l3 = trace_get_layer3(packet, &ethertype, &remaining);
     736        if (l3 == NULL)
     737                return 0;
     738
     739        if (ethertype == TRACE_ETHERTYPE_IP) {
     740                libtrace_ip_t *ip = (libtrace_ip_t *)l3;
     741                uint16_t offset = 0;
     742
     743                /* Fragment offset appears in 7th and 8th bytes */
     744                if (remaining < 8)
     745                        return 0;
     746                 
     747                offset = ntohs(ip->ip_off);
     748
     749                if ((offset & 0x2000) != 0)
     750                        *more = 1;
     751                return (offset & 0x1FFF) * 8;
     752        }
     753
     754        if (ethertype == TRACE_ETHERTYPE_IPV6) {
     755                libtrace_ip6_t *ip6 = (libtrace_ip6_t *)l3;
     756                void *payload = ip6++;
     757                uint8_t nxt = ip6->nxt;
     758                uint16_t len;
     759               
     760                /* First task, find a Fragment header if present */
     761                if (remaining < sizeof(libtrace_ip6_t))
     762                        return 0;
     763                remaining -= sizeof(libtrace_ip6_t);
     764
     765                /* Adapted from trace_get_payload_from_ip6 */
     766                while (1) {
     767                        switch (nxt) {
     768                        case 0:
     769                        case TRACE_IPPROTO_ROUTING:
     770                        case TRACE_IPPROTO_AH:
     771                        case TRACE_IPPROTO_DSTOPTS:
     772                        {
     773
     774                                /* Length does not include the first 8 bytes */
     775                                len=((libtrace_ip6_ext_t*)payload)->len * 8;
     776                                len += 8;
     777
     778                                if (remaining < len) {
     779                                        /* Snap too short */
     780                                        return 0;
     781                                }
     782                                remaining-=len;
     783
     784                                nxt=((libtrace_ip6_ext_t*)payload)->nxt;
     785                                continue;
     786                        }
     787                        case TRACE_IPPROTO_FRAGMENT:
     788                        {
     789                                libtrace_ip6_frag_t *frag = (libtrace_ip6_frag_t *)payload;
     790                                uint16_t offset;
     791                                len = sizeof(libtrace_ip6_frag_t);
     792                                if (remaining < len) {
     793                                        /* Snap too short */
     794                                        return 0;
     795                                }
     796                                remaining-=len;
     797
     798                                offset = ntohs(frag->frag_off);
     799                                if ((offset & 0x0001) != 0)
     800                                        *more = 1;
     801
     802                                return ((offset & 0xFFF8) >> 3) * 8;
     803                         }
     804                         default:
     805                                return 0;
     806                         }
     807                }
     808
     809        }
     810        return 0;
     811}
  • lib/protocols_transport.c

    r10f924c re0bea4e5  
    382382        uint32_t remaining;
    383383        uint8_t proto;
    384         const struct ports_t *port =
    385                 (const struct ports_t*)trace_get_transport((libtrace_packet_t*)packet,
     384        struct ports_t *port;
     385        uint16_t fragoff;
     386        uint8_t more;
     387
     388        fragoff = trace_get_fragment_offset(packet, &more);
     389
     390        /* If we're not the first fragment, we're unlikely to be able
     391         * to get any useful port numbers from this packet.
     392         */
     393        if (fragoff != 0)
     394                return 0;
     395       
     396       
     397        port = (struct ports_t*)trace_get_transport(
     398                        (libtrace_packet_t*)packet,
    386399                        &proto, &remaining);
    387400
     
    391404
    392405        /* ICMP *technically* doesn't have ports */
    393         if (proto == TRACE_IPPROTO_ICMP)
     406        if (proto == TRACE_IPPROTO_ICMP || proto == TRACE_IPPROTO_ICMPV6)
    394407                return 0;
    395408
     
    405418        uint32_t remaining;
    406419        uint8_t proto;
    407         struct ports_t *port =
    408                 (struct ports_t*)trace_get_transport((libtrace_packet_t*)packet,
     420        struct ports_t *port;
     421        uint16_t fragoff;
     422        uint8_t more;
     423
     424        fragoff = trace_get_fragment_offset(packet, &more);
     425
     426        /* If we're not the first fragment, we're unlikely to be able
     427         * to get any useful port numbers from this packet.
     428         */
     429        if (fragoff != 0)
     430                return 0;
     431       
     432       
     433        port = (struct ports_t*)trace_get_transport(
     434                        (libtrace_packet_t*)packet,
    409435                        &proto, &remaining);
    410436        /* Snapped too early */
     
    413439       
    414440        /* ICMP *technically* doesn't have ports */
    415         if (proto == TRACE_IPPROTO_ICMP)
     441        if (proto == TRACE_IPPROTO_ICMP || proto == TRACE_IPPROTO_ICMPV6)
    416442                return 0;
    417443
  • libpacketdump/eth_2048.c

    r66ad025 r387d299  
    1010#include <netdb.h>
    1111
    12 #define DISPLAY_EXP(x,fmt,exp) \
    13         if ((unsigned int)len>=((char*)&ip->x-(char*)ip+sizeof(ip->x))) \
    14                 printf(fmt,exp); \
    15         else \
    16                 return;
    17 
    18 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,ip->x)
    19 
    20 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(ip->x))
    21 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&ip->x))
    22 
    2312DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
    2413{
     
    2918        }
    3019        //DISPLAY(ip_tos," TOS %02x")
    31         DISPLAY_EXP(ip_tos," DSCP %02x",ip->ip_tos >> 2)
    32         DISPLAY_EXP(ip_tos," ECN %x",ip->ip_tos & 0x2)
    33         DISPLAYS(ip_len," Total Length %i")
     20        DISPLAY_EXP(ip, ip_tos," DSCP %02x",ip->ip_tos >> 2);
     21        DISPLAY_EXP(ip, ip_tos," ECN %x",ip->ip_tos & 0x2);
     22        DISPLAYS(ip, ip_len," Total Length %i");
    3423        printf("\n IP:");
    35         DISPLAYS(ip_id," Id %u");
     24        DISPLAYS(ip, ip_id," Id %u");
    3625       
    3726        if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) {
     
    4231        }
    4332        //printf("\n IP:");
    44         DISPLAY(ip_ttl,"\n IP: TTL %i");
     33        DISPLAY(ip, ip_ttl,"\n IP: TTL %i");
    4534        if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) {
    4635                struct protoent *ent=getprotobynumber(ip->ip_p);
     
    5544                return;
    5645        }
    57         DISPLAYS(ip_sum," Checksum %i\n");
    58         DISPLAYIP(ip_src," IP: Source %s ");
    59         DISPLAYIP(ip_dst,"Destination %s\n");
     46        DISPLAYS(ip, ip_sum," Checksum %i\n");
     47        DISPLAYIP(ip, ip_src," IP: Source %s ");
     48        DISPLAYIP(ip, ip_dst,"Destination %s\n");
    6049        decode_next(packet+ip->ip_hl*4,len-ip->ip_hl*4,"ip",ip->ip_p);
    6150        return;
  • libpacketdump/ip_1.c

    rec0b927 r387d299  
    33#include <dlfcn.h>
    44#include "libpacketdump.h"
    5 
    6 #define STRUCT icmp
    7 
    8 #define SAFE(x) \
    9         ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))
    10 #define DISPLAY_EXP(x,fmt,exp) \
    11         if (SAFE(x)) \
    12                 printf(fmt,exp); \
    13         else \
    14                 return;
    15 
    16 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)
    17 
    18 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))
    19 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))
    20 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))
    215
    226static char *unreach_types[]={
  • libpacketdump/ip_17.c

    rc7062df r387d299  
    88#include <netdb.h>
    99
    10 #define STRUCT udp
    11 
    12 #define SAFE(x) \
    13         ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))
    14 #define DISPLAY_EXP(x,fmt,exp) \
    15         if (SAFE(x)) \
    16                 printf(fmt,exp); \
    17         else \
    18                 return;
    19 
    20 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)
    21 
    22 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))
    23 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))
    24 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))
    25 
    2610
    2711DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
     
    2913        struct libtrace_udp *udp = (struct libtrace_udp*)packet;
    3014        printf(" UDP:");
    31         if (SAFE(source)) {
     15        if (SAFE(udp, source)) {
    3216                struct servent *ent=getservbyport(udp->source,"udp");
    3317                if(ent) {
     
    4125                return;
    4226        }
    43         if (SAFE(dest)) {
     27        if (SAFE(udp, dest)) {
    4428                struct servent *ent=getservbyport(udp->dest,"udp");
    4529                if(ent) {
     
    5438        }
    5539        printf("\n UDP:");
    56         DISPLAYS(len," Len %u");
    57         DISPLAYS(check," Checksum %u");
     40        DISPLAYS(udp, len," Len %u");
     41        DISPLAYS(udp, check," Checksum %u");
    5842        printf("\n");
    5943        if (htons(udp->source) < htons(udp->dest))
  • libpacketdump/ip_33.c

    rc7062df r387d299  
    66#include <netinet/tcp.h>
    77#include <netinet/in.h>
    8 
    9 #define STRUCT dccp
    10 
    11 #define SAFE(x) \
    12         ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x)))
    13 #define DISPLAY_EXP(x,fmt,exp) \
    14         if (SAFE(x)) \
    15                 printf(fmt,exp); \
    16         else \
    17                 return;
    18 
    19 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x)
    20 
    21 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x))
    22 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x))
    23 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x))
    248
    259struct dccphdr {
     
    5034{
    5135        struct dccphdr *dccp = (struct dccphdr*)packet;
    52         DISPLAYS(source," DCCP: Source %i");
    53         DISPLAYS(dest," Dest %i");
     36        DISPLAYS(dccp, source," DCCP: Source %i");
     37        DISPLAYS(dccp, dest," Dest %i");
    5438        if (len>4) {
    5539                printf("\n DCCP: Type %i",dccp->type);
     
    6953        else
    7054                return;
    71         DISPLAY(doff," DCCP: Dataoff: %i\n");
     55        DISPLAY(dccp, doff," DCCP: Dataoff: %i\n");
    7256        if (len>9)
    7357                printf(" DCCP: NDP %i CsLen: %i\n",dccp->ndp,dccp->cslen);
     
    7559                return;
    7660        }
    77         DISPLAY(check," DCCP: Checksum: %i\n");
     61        /* Should this be byteswapped??? */
     62        DISPLAY(dccp, check," DCCP: Checksum: %i\n");
    7863        if (htons(dccp->source) < htons(dccp->dest))
    7964                decode_next(packet+dccp->doff*4,len-dccp->doff*4,"dccp",htons(dccp->source));
  • libpacketdump/ip_6.c

    r9ca0b29 r387d299  
    55#include <assert.h>
    66#include <netdb.h>
    7 
    8 #define SAFE(x) \
    9         ((unsigned int)len>=((char*)&tcp->x-(char*)tcp+sizeof(tcp->x)))
    10 #define DISPLAY_EXP(x,fmt,exp) \
    11         if (SAFE(x)) \
    12                 printf(fmt,exp); \
    13         else \
    14                 return;
    15 
    16 #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,tcp->x)
    17 
    18 #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(tcp->x))
    19 #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(tcp->x))
    20 #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&tcp->x))
    217
    228DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
     
    2713        libtrace_tcp_t *tcp = (libtrace_tcp_t *)packet;
    2814        printf(" TCP:");
    29         if (SAFE(source)) {
     15        if (SAFE(tcp, source)) {
    3016                struct servent *ent=getservbyport(tcp->source,"tcp");
    3117                if(ent) {
     
    3925                return;
    4026        }
    41         if (SAFE(dest)) {
     27        if (SAFE(tcp, dest)) {
    4228                struct servent *ent=getservbyport(tcp->dest,"tcp");
    4329                if(ent) {
     
    5238        }
    5339        printf("\n TCP:");
    54         DISPLAYL(seq," Seq %u");
     40        DISPLAYL(tcp, seq," Seq %u");
    5541        printf("\n TCP:");
    56         DISPLAYL(ack_seq," Ack %u");
     42        DISPLAYL(tcp, ack_seq," Ack %u");
    5743        if ((char*)&tcp->window-(char *)tcp>len) {
    5844                printf("\n");
     
    7157        if (tcp->ack) printf(" ACK");
    7258        if (tcp->urg) printf(" URG");
    73         DISPLAYS(window," Window %i");
     59        DISPLAYS(tcp, window," Window %i");
    7460        printf("\n TCP:");
    75         DISPLAYS(check," Checksum %i");
    76         DISPLAYS(urg_ptr," Urgent %i");
     61        DISPLAYS(tcp, check," Checksum %i");
     62        DISPLAYS(tcp, urg_ptr," Urgent %i");
    7763        pkt = (unsigned char*)packet+sizeof(*tcp);
    7864        plen = (len-sizeof *tcp) < (tcp->doff*4-sizeof(*tcp))?(len-sizeof(*tcp)):(tcp->doff*4-sizeof *tcp);
  • libpacketdump/ip_89.c

    re224862 r387d299  
    1010static void dump_ospf_v2_header(libtrace_ospf_v2_t *hdr, unsigned len) {
    1111
    12         printf(" OSPF Header: Version %u Type %u ",
    13                         hdr->ospf_v, hdr->type);
     12        DISPLAY(hdr, ospf_v, " OSPF Header: Version %u");
     13        DISPLAY(hdr, type, " Type %u ");
    1414        switch(hdr->type) {
    1515                case TRACE_OSPF_HELLO:
     
    2929                        break;
    3030        }
     31        printf("\n");
    3132
    32         printf("\n OSPF Header: Length %u \n", ntohs(hdr->len));
    33         printf(" OSPF Header: Router Id %s ", inet_ntoa(hdr->router));
    34         printf("Area Id %s\n", inet_ntoa(hdr->area));
    35         printf(" OSPF Header: Checksum %u Auth Type %u\n", ntohs(hdr->sum),
    36                         ntohs(hdr->au_type));
    37 
    38         printf(" OSPF Header: Auth Key ID %u Auth Data Len %u\n",
    39                         hdr->au_key_id, hdr->au_data_len);
    40         printf(" OSPF Header: Auth Crypto Seq %u\n", ntohl(hdr->au_seq_num));
    41 
     33        DISPLAYS(hdr, ospf_len, "OSPF Header: Length %u \n");
     34        DISPLAYIP(hdr, router, " OSPF Header: Router Id %s ");
     35        DISPLAYIP(hdr, area, "Area Id %s\n");
     36        DISPLAYS(hdr, sum, " OSPF Header: Checksum %u ");
     37        DISPLAYS(hdr, au_type, "Auth Type %u\n");
     38        DISPLAY(hdr, au_key_id, " OSPF Header: Auth Key ID %u ");
     39        DISPLAY(hdr, au_data_len, "Auth Data Len %u\n");
     40        DISPLAYL(hdr, au_seq_num, " OSPF Header: Auth Crypto Seq %u\n");
    4241
    4342}
  • libpacketdump/libpacketdump.h

    r66ad025 r387d299  
    66extern "C" {
    77#endif
     8
     9#define SAFE(hdr,x) \
     10        ((unsigned int)len>=((char*)&hdr->x-(char*)hdr+sizeof(hdr->x)))
     11
     12#define DISPLAY_EXP(hdr,x,fmt,exp) \
     13        if (SAFE(hdr, x)) \
     14                printf(fmt,exp); \
     15        else {\
     16                printf("(Truncated)\n"); \
     17                return; \
     18        }
     19
     20#define DISPLAY(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,hdr->x)
     21
     22#define DISPLAYS(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,htons(hdr->x))
     23#define DISPLAYL(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,htonl(hdr->x))
     24#define DISPLAYIP(hdr,x,fmt) DISPLAY_EXP(hdr,x,fmt,inet_ntoa(*(struct in_addr*)&hdr->x))
     25
    826
    927void trace_hexdump_packet(libtrace_packet_t *packet);
  • libwandio/Makefile.am

    rbd119b3 r3b6e0cf  
    2424endif
    2525
     26if HAVE_LZMA
     27LIBTRACEIO_LZMA=ior-lzma.c iow-lzma.c
     28else
     29LIBTRACEIO_LZMA=
     30endif
     31
    2632libwandio_la_SOURCES=wandio.c ior-peek.c ior-stdio.c ior-thread.c \
    2733                iow-stdio.c iow-thread.c wandio.h wandio_internal.h \
    28                 $(LIBTRACEIO_ZLIB) $(LIBTRACEIO_BZLIB) $(LIBTRACEIO_LZO)
     34                $(LIBTRACEIO_ZLIB) $(LIBTRACEIO_BZLIB) $(LIBTRACEIO_LZO) \
     35                $(LIBTRACEIO_LZMA)
    2936
    3037AM_CPPFLAGS = @ADD_INCLS@
    3138libwandio_la_LIBADD = @LIBWANDIO_LIBS@
    32 libwandio_la_LDFLAGS=-version-info 1:0:0 @ADD_LDFLAGS@
     39libwandio_la_LDFLAGS=-version-info 1:1:0 @ADD_LDFLAGS@
    3340
     41bin_PROGRAMS = wandiocat
     42wandiocat_SOURCES = wcat.c
     43wandiocat_CFLAGS = -I"$(top_srcdir)/libwandio"
     44wandiocat_CXXFLAGS = -I"$(top_srcdir)/libwandio"
     45wandiocat_LDFLAGS = -L"$(top_srcdir)/libwandio" -lwandio
  • libwandio/iow-lzo.c

    r2a7047c rfa7faf3  
    274274}
    275275
    276 iow_t *lzo_wopen(iow_t *child, int compress_level UNUSED)
     276iow_t *lzo_wopen(iow_t *child, int compress_level)
    277277{
    278278        const int opt_filter = 0;
     
    290290                return NULL;
    291291        }
     292
     293        /* Compress level is useless for LZO, but getting UNUSED into here
     294         * is more trouble than it is worth so this check will at least
     295         * stop us from getting warnings about it.
     296         */
     297        if (compress_level < 0)
     298                return NULL;
    292299
    293300        iow = malloc(sizeof(iow_t));
  • libwandio/wandio.c

    r10f924c r4b0cd2f  
    4646 */
    4747
    48 struct compression_type compression_type[]  = {
    49         { "GZ",         "gz",   WANDIO_COMPRESS_ZLIB    },
    50         { "BZ2",        "bz2",  WANDIO_COMPRESS_BZ2     },
    51         { "LZO",        "lzo",  WANDIO_COMPRESS_LZO     },
     48struct wandio_compression_type compression_type[]  = {
     49        { "gzip",       "gz",   WANDIO_COMPRESS_ZLIB    },
     50        { "bzip2",      "bz2",  WANDIO_COMPRESS_BZ2     },
     51        { "lzo",        "lzo",  WANDIO_COMPRESS_LZO     },
     52        { "lzma",       "xz",  WANDIO_COMPRESS_LZMA     },
    5253        { "NONE",       "",     WANDIO_COMPRESS_NONE    }
    5354};
     
    141142        DEBUG_PIPELINE("peek");
    142143        io_t *io = peek_open(stdio_open(filename));
    143         char buffer[1024];
     144        unsigned char buffer[1024];
    144145        int len;
    145146        if (!io)
     
    151152
    152153        if (autodetect) {
    153                 if (len>=3 && buffer[0] == '\037' && buffer[1] == '\213' &&
     154                if (len>=3 && buffer[0] == 0x1f && buffer[1] == 0x8b &&
    154155                                buffer[2] == 0x08) {
    155156#if HAVE_LIBZ
     
    162163                }
    163164                /* Auto detect compress(1) compressed data (gzip can read this) */
    164                 if (len>=2 && buffer[0] == '\037' && buffer[1] == '\235') {
     165                if (len>=2 && buffer[0] == 0x1f && buffer[1] == 0x9d) {
    165166#if HAVE_LIBZ
    166167                        DEBUG_PIPELINE("zlib");
     
    182183#endif
    183184                }
     185
     186                if (len >=5 && buffer[0] == 0xfd && buffer[1] == '7' &&
     187                                buffer[2] == 'z' && buffer[3] == 'X' &&
     188                                buffer[4] == 'Z') {
     189#if HAVE_LIBLZMA
     190                        DEBUG_PIPELINE("lzma");
     191                        io = lzma_open(io);
     192#else
     193                        fprintf(stderr, "File %s is lzma compressed but libtrace has not been built with lzma support!\n", filename);
     194                        return NULL;
     195#endif
     196                }
    184197        }       
    185198        /* Now open a threaded, peekable reader using the appropriate module
     
    193206        DEBUG_PIPELINE("peek");
    194207        return peek_open(io);
     208}
     209
     210DLLEXPORT struct wandio_compression_type *wandio_lookup_compression_type(
     211        const char *name) {
     212
     213        struct wandio_compression_type *wct = compression_type;
     214
     215        while (strcmp(wct->name, "NONE") != 0) {
     216                if (strcmp(wct->name, name) == 0)
     217                        return wct;
     218                wct++;
     219        }
     220
     221        return NULL;
    195222}
    196223
     
    291318        }
    292319#endif
     320#if HAVE_LIBLZMA
     321        else if (compression_level != 0 &&
     322            compress_type == WANDIO_COMPRESS_LZMA) {
     323                iow = lzma_wopen(iow,compression_level);
     324        }
     325#endif
    293326        /* Open a threaded writer */
    294327        if (use_threads)
  • libwandio/wandio.h

    rc7021d9 r4b0cd2f  
    6666
    6767/** Structure defining a supported compression method */
    68 struct compression_type {
     68struct wandio_compression_type {
    6969        /** Name of the compression method */
    7070        const char *name;
     
    7777
    7878/** The list of supported compression methods */
    79 extern struct compression_type compression_type[];
     79extern struct wandio_compression_type compression_type[];
    8080
    8181/** Structure defining a libtrace IO reader module */
     
    178178        /** LZO compression */
    179179        WANDIO_COMPRESS_LZO     = 3,
     180        /** LZMA compression */
     181        WANDIO_COMPRESS_LZMA    = 4,
    180182        /** All supported methods - used as a bitmask */
    181183        WANDIO_COMPRESS_MASK    = 7
     
    193195io_t *zlib_open(io_t *parent);
    194196io_t *thread_open(io_t *parent);
     197io_t *lzma_open(io_t *parent);
    195198io_t *peek_open(io_t *parent);
    196199io_t *stdio_open(const char *filename);
     
    199202iow_t *bz_wopen(iow_t *child, int compress_level);
    200203iow_t *lzo_wopen(iow_t *child, int compress_level);
     204iow_t *lzma_wopen(iow_t *child, int compress_level);
    201205iow_t *thread_wopen(iow_t *child);
    202206iow_t *stdio_wopen(const char *filename, int fileflags);
     
    211215 *
    212216 * @{ */
     217
     218/** Given a string describing the compression method, finds the internal
     219  * data structure representing that method. This is mostly useful for
     220  * nicely mapping a method name to the internal libwandio compression
     221  * method enum when configuring an output file.
     222  *
     223  * @param name          The compression method name as a string, e.g. "gzip",
     224  *                      "bzip2", "lzo" or "lzma".
     225  * @return A pointer to the compression_type structure representing the
     226  * compression method or NULL if no match can be found.
     227  *
     228  */
     229struct wandio_compression_type *wandio_lookup_compression_type(const char *name);
    213230
    214231/** Creates a new libtrace IO reader and opens the provided file for reading.
  • test/Makefile

    r59ef093 r17c5749  
    1818
    1919BINS = test-pcap-bpf test-event test-time test-dir test-wireless test-errors \
    20         test-plen test-autodetect $(BINS_DATASTRUCT) $(BINS_PARALLEL)
     20        test-plen test-autodetect test-ports test-fragment test-live test-live-snaplen \
     21        $(BINS_DATASTRUCT) $(BINS_PARALLEL)
    2122
    2223.PHONY: all clean distclean install depend test
  • test/do-tests.sh

    r5692bc4 r95b6218  
    7272echo \* Testing payload length
    7373do_test ./test-plen
     74
     75echo \* Testing port numbers
     76do_test ./test-ports
     77
     78echo \* Testing fragment parsing
     79do_test ./test-fragment
    7480
    7581echo \* Testing event framework
     
    221227echo " * format autodetection - bzip2"
    222228do_test ./test-autodetect traces/5_packets.erf.bz2
     229echo " * format autodetection - lzma"
     230do_test ./test-autodetect traces/5_packets.erf.xz
    223231
    224232echo
  • tools/traceanon/traceanon.1

    rd6dc0f6 r17f954f  
    8686.BI \-\^\-compress-type=method
    8787compress the output trace using the compression algorithm "method". Possible
    88 algorithms are "gzip", "bzip2", "lzo" and "none". Default is "none".
     88algorithms are "gzip", "bzip2", "lzo", "xz" and "none". Default is "none".
    8989
    9090.SH EXAMPLES
  • tools/traceanon/traceanon.c

    rf5b5cca r17f954f  
    219219        } else if (strncmp(compress_type_str, "lzo", 3) == 0) {
    220220                compress_type = TRACE_OPTION_COMPRESSTYPE_LZO;
     221        } else if (strncmp(compress_type_str, "xz", 2) == 0) {
     222                compress_type = TRACE_OPTION_COMPRESSTYPE_LZMA;
    221223        } else if (strncmp(compress_type_str, "no", 2) == 0) {
    222224                compress_type = TRACE_OPTION_COMPRESSTYPE_NONE;
  • tools/tracemerge/tracemerge.1

    rd6dc0f6 r17f954f  
    5353.BI \-\^\-compress-type method
    5454Describes the compression algorithm to be used when writing the output trace.
    55 Possible methods are "gzip", "bzip2", "lzo" and "none". Defaults to "none".
     55Possible methods are "gzip", "bzip2", "lzo", "xz" and "none". Defaults to
     56"none".
    5657
    5758
  • tools/tracemerge/tracemerge.c

    rc0ccccd r17f954f  
    120120        } else if (strncmp(compress_type_str, "lzo", 3) == 0) {
    121121                compress_type = TRACE_OPTION_COMPRESSTYPE_LZO;
     122        } else if (strncmp(compress_type_str, "xz", 2) == 0) {
     123                compress_type = TRACE_OPTION_COMPRESSTYPE_LZMA;
    122124        } else if (strncmp(compress_type_str, "no", 2) == 0) {
    123125                compress_type = TRACE_OPTION_COMPRESSTYPE_NONE;
  • tools/tracesplit/tracesplit.1

    rd6dc0f6 r17f954f  
    6161\fB-Z\fR compression-method
    6262Compress the data using the specified compression algorithm. Accepted methods
    63 are "gzip", "bzip2", "lzo" or "none". Default value is none unless a
     63are "gzip", "bzip2", "lzo", "xz" or "none". Default value is none unless a
    6464compression level is specified, in which case gzip will be used.
    6565
  • tools/tracesplit/tracesplit.c

    r755855a r17f954f  
    316316        } else if (strncmp(compress_type_str, "lzo", 3) == 0) {
    317317                compress_type = TRACE_OPTION_COMPRESSTYPE_LZO;
     318        } else if (strncmp(compress_type_str, "xz", 2) == 0) {
     319                compress_type = TRACE_OPTION_COMPRESSTYPE_LZMA;
    318320        } else if (strncmp(compress_type_str, "no", 2) == 0) {
    319321                compress_type = TRACE_OPTION_COMPRESSTYPE_NONE;
Note: See TracChangeset for help on using the changeset viewer.