Changeset 341c38f for lib


Ignore:
Timestamp:
08/25/15 14:48:04 (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:
03aca91
Parents:
54cf135 (diff), 84cdb05 (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 'upstream/develop' into develop

Location:
lib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lib/Makefile.am

    r7c95027 r341c38f  
    6969endif
    7070
    71 AM_CPPFLAGS= @ADD_INCLS@ -I../libwandio
     71AM_CPPFLAGS= @ADD_INCLS@
    7272libtrace_la_LIBADD = @LIBTRACE_LIBS@ @LTLIBOBJS@ $(DPDKLIBS)
    7373libtrace_la_LDFLAGS=-version-info @LIBTRACE_MAJOR@:@LIBTRACE_MINOR@:@LIBTRACE_MID@ @ADD_LDFLAGS@
  • lib/format_dag25.c

    r6b98325 r341c38f  
    299299
    300300        dag_close(dev->fd);
    301         if (dev->dev_name)
    302                 free(dev->dev_name);
    303301        free(dev);
    304302}
  • lib/format_erf.c

    r5ab626a r341c38f  
    4949#include <string.h>
    5050#include <stdlib.h>
     51
    5152
    5253#ifdef WIN32
     
    135136        if (packet->trace->format->type==TRACE_FORMAT_ERF) {
    136137                dag_record_t *erfptr = (dag_record_t *)packet->header;
    137                 switch(erfptr->type) {
     138                switch((erfptr->type & 0x7f)) {
    138139                        case TYPE_ETH:         
    139140                        case TYPE_DSM_COLOR_ETH:
     
    152153int erf_get_framing_length(const libtrace_packet_t *packet)
    153154{
    154         return dag_record_size + erf_get_padding(packet);
     155        uint16_t extsize = 0;
     156        dag_record_t *erfptr = NULL;
     157        uint64_t *exthdr = NULL;
     158       
     159        erfptr = (dag_record_t *)packet->header;
     160        if ((erfptr->type & 0x80) == 0x80) {
     161                /* Extension headers are present */
     162                exthdr = (uint64_t *)((char *)packet->header + dag_record_size);
     163                extsize += 8;
     164
     165                while (*exthdr < (1UL << 31)) {
     166                        extsize += 8;
     167                        exthdr ++;
     168                        assert(extsize <= ntohs(erfptr->rlen));
     169                }
     170        }
     171       
     172
     173        return dag_record_size + extsize + erf_get_padding(packet);
    155174}
    156175
     
    186205        }
    187206        /* Is this a proper typed packet */
    188         if (erf->type > TYPE_AAL2) {
     207        if ((erf->type & 0x7f) > TYPE_AAL2) {
    189208                return 0;
    190209        }
     
    448467
    449468        /* Check for loss */
    450         if (erfptr->type == TYPE_DSM_COLOR_ETH) {
     469        if ((erfptr->type & 0x7f) == TYPE_DSM_COLOR_ETH) {
    451470                /* No idea how we get this yet */
    452471
     
    505524
    506525        /* Unknown/corrupt */
    507         if (((dag_record_t *)packet->buffer)->type >= TYPE_RAW_LINK) {
     526        if ((((dag_record_t *)packet->buffer)->type & 0x7f) >= TYPE_RAW_LINK) {
    508527                trace_set_err(libtrace, TRACE_ERR_BAD_PACKET,
    509528                                "Corrupt or Unknown ERF type");
     
    684703        dag_record_t *erfptr = 0;
    685704        erfptr = (dag_record_t *)packet->header;
    686         if (erfptr->type != TYPE_LEGACY)
    687                 return erf_type_to_libtrace(erfptr->type);
     705        uint8_t type = (erfptr->type & 0x7f);
     706        if (type != TYPE_LEGACY) {
     707                /* The top-most bit is now used to indicate the presence of
     708                 * extension headers :/ */
     709                return erf_type_to_libtrace(type);
     710        }
    688711        else {
    689712                /* Sigh, lets start wildly guessing */
  • lib/libtrace.h.in

    r652d720 r341c38f  
    18731873void *trace_get_link(const libtrace_packet_t *packet);
    18741874
     1875/** Strips layer 2.5 headers from a given packet.
     1876 * @param packet        The packet to strip headers from.
     1877 *
     1878 * @return The packet with the requested headers removed (if they were
     1879 * present).
     1880 *
     1881 * This function is intended for removing those pesky layer 2.5 headers
     1882 * that are not supported by other packet analysis applications, e.g. VLAN
     1883 * and MPLS headers. If successful, the resulting packet will be a simple
     1884 * Ethernet-IP-Transport packet that just about anything should be able to
     1885 * parse without difficulty.
     1886 *
     1887 * If this function encounters a layer 2 or 2.5 header that it does not
     1888 * support, stripping will cease and the packet returning will be stripped
     1889 * up to but not including the unsupported header.
     1890 *
     1891 * New in libtrace 4.0.0
     1892 *
     1893 * @note This function only supports stripping headers from Ethernet packets
     1894 * for now. Passing in packets of other link types will simply result in
     1895 * the original packet being returned unmodified.
     1896 *
     1897 */
     1898DLLEXPORT libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet);
     1899
    18751900/** Get a pointer to the IPv4 header (if any) for a given packet
    18761901 * @param packet        The packet to get the IPv4 header for
  • lib/protocols_l2.c

    rf7bcbfb r84cdb05  
    3737#include <assert.h>
    3838#include <stdlib.h>
     39#include <string.h>
    3940
    4041
     
    9798
    9899        return (void*)((char *)ethernet + sizeof(*vlanhdr));
     100
     101}
     102
     103libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet) {
     104
     105        libtrace_ether_t *ethernet;
     106        libtrace_linktype_t linktype;
     107        uint16_t ethertype;
     108        uint32_t remaining;
     109        char *nextpayload;
     110        uint16_t finalethertype = 0;
     111        uint16_t caplen, removed = 0;
     112        char *dest;
     113        uint8_t done = 0;
     114        uint32_t oldrem;
     115
     116        /* For now, this will just work for Ethernet packets. */
     117        ethernet = (libtrace_ether_t *)trace_get_layer2(packet,
     118                        &linktype, &remaining);
     119
     120        if (linktype != TRACE_TYPE_ETH) {
     121                return packet;
     122        }
     123
     124        /* No headers to strip, return the original packet */
     125        if (ethernet->ether_type == TRACE_ETHERTYPE_IP ||
     126                        ethernet->ether_type == TRACE_ETHERTYPE_IPV6) {
     127                return packet;
     128        }
     129
     130        if (remaining <= sizeof(libtrace_ether_t))
     131                return packet;
     132
     133        caplen = trace_get_capture_length(packet);
     134        ethertype = ntohs(ethernet->ether_type);
     135        dest = ((char *)ethernet) + sizeof(libtrace_ether_t);
     136        nextpayload = dest;
     137        remaining -= sizeof(libtrace_ether_t);
     138
     139        /* I'd normally use trace_get_layer3 here, but it works out faster
     140         * to do it this way (mostly less function call overhead).
     141         *
     142         * XXX This approach is going to just strip everything between the
     143         * Ethernet and IP headers -- is there a use case where someone
     144         * might want to selectively strip headers?
     145         */
     146        while (!done) {
     147
     148                if (nextpayload == NULL || remaining == 0)
     149                        break;
     150
     151                oldrem = remaining;
     152                switch (ethertype) {
     153
     154                case TRACE_ETHERTYPE_8021Q:
     155                        nextpayload = (char *)trace_get_payload_from_vlan(
     156                                        nextpayload,
     157                                        &ethertype, &remaining);
     158                        removed += (oldrem - remaining);
     159                        break;
     160
     161                case TRACE_ETHERTYPE_MPLS:
     162                        nextpayload = (char *)trace_get_payload_from_mpls(
     163                                        nextpayload,
     164                                        &ethertype, &remaining);
     165                        removed += (oldrem - remaining);
     166                        break;
     167                case TRACE_ETHERTYPE_PPP_SES:
     168                        nextpayload = (char *)trace_get_payload_from_pppoe(
     169                                        nextpayload,
     170                                        &ethertype, &remaining);
     171                        removed += (oldrem - remaining);
     172                        break;
     173
     174                case TRACE_ETHERTYPE_IP:
     175                case TRACE_ETHERTYPE_IPV6:
     176                default:
     177                        if (finalethertype == 0)
     178                                finalethertype = ethertype;
     179                        done = true;
     180                        break;
     181                }
     182        }
     183
     184        if (nextpayload != NULL) {
     185
     186                ethernet->ether_type = ntohs(finalethertype);
     187                trace_set_capture_length(packet, caplen - removed);
     188                memmove(nextpayload - (dest - (char *)packet->payload),
     189                        packet->payload,
     190                        (dest - (char *)packet->payload));
     191                packet->payload = nextpayload - (dest - (char *)packet->payload);
     192                packet->l2_header = NULL;
     193        }
     194       
     195        return packet;
    99196
    100197}
  • lib/protocols_l3.c

    r7baa948 r0277ab8  
    245245        }
    246246
    247         link = trace_get_layer2(packet,&linktype,remaining);
     247        if (packet->l2_header) {
     248                link = packet->l2_header;
     249                linktype = packet->link_type;
     250                *remaining = packet->l2_remaining;
     251        } else {
     252                link = trace_get_layer2(packet,&linktype,remaining);
     253        }
    248254        iphdr = trace_get_payload_from_layer2(
    249255                        link,
Note: See TracChangeset for help on using the changeset viewer.