Changeset d280f48


Ignore:
Timestamp:
08/05/15 13:51:33 (5 years ago)
Author:
Shane Alcock <salcock@…>
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:
3a333e2, fc0325e
Parents:
7428ab2 (diff), 0277ab8 (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 branch 'faststrip' into develop

Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h.in

    r7428ab2 r0277ab8  
    16031603void *trace_get_link(const libtrace_packet_t *packet);
    16041604
    1605 /**
    1606  * Supported masks for stripping headers from packets.
    1607  */
    1608 enum {
    1609         TRACE_STRIP_VLAN = 0x01, /**< Strip 802.1Q (VLAN tag) headers */
    1610         TRACE_STRIP_MPLS = 0x02  /**< Strip MPLS headers */
    1611 };
    1612 
    1613 /** Strips certain headers from a given packet.
     1605/** Strips layer 2.5 headers from a given packet.
    16141606 * @param packet        The packet to strip headers from.
    1615  * @param stripopts     A mask to indicate which headers should be stripped.
    1616  * If multiple header types are to be stripped, these should be ORed together
    1617  * to create the full mask. A mask of zero will strip all strippable headers.
    16181607 *
    16191608 * @return The packet with the requested headers removed (if they were
     
    16361625 * the original packet being returned unmodified.
    16371626 *
    1638  * @note Depending on the input source, this function may need to copy the
    1639  * original packet to be able to safely modify the contents. This may have
    1640  * a major impact on performance so avoid stripping packets unless absolutely
    1641  * necessary.
    1642  */
    1643 DLLEXPORT libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet,
    1644                 int stripopts);
     1627 */
     1628DLLEXPORT libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet);
    16451629
    16461630/** Get a pointer to the IPv4 header (if any) for a given packet
  • lib/protocols_l2.c

    r7428ab2 r0277ab8  
    101101}
    102102
    103 libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet,
    104                 int stripopts) {
     103libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet) {
    105104
    106105        libtrace_ether_t *ethernet;
     
    108107        uint16_t ethertype;
    109108        uint32_t remaining;
    110         libtrace_packet_t *copy;
    111         void *payload;
     109        char *nextpayload;
    112110        uint16_t finalethertype = 0;
    113111        uint16_t caplen, removed = 0;
     
    130128        }
    131129
    132         /* Copy the packet as we need to be sure that the packet
    133          * payload is contiguous. This won't be guaranteed for live
    134          * formats, for instance.
     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?
    135145         */
    136         if (packet->buf_control == TRACE_CTRL_EXTERNAL) {
    137                 copy = trace_copy_packet(packet);
    138                 trace_destroy_packet(packet);
    139                 packet = copy;
    140 
    141                 /* Re-grab the ethernet header from the copy */
    142                 ethernet = (libtrace_ether_t *)trace_get_layer2(packet,
    143                         &linktype, &remaining);
    144 
    145         }
    146 
    147         payload = trace_get_payload_from_layer2(ethernet, linktype,
    148                         &ethertype, &remaining);
    149 
    150         dest = ((char *)ethernet) + sizeof(libtrace_ether_t);
    151         caplen = trace_get_capture_length(packet);
    152146        while (!done) {
    153147
    154                 if (payload == NULL || remaining == 0)
     148                if (nextpayload == NULL || remaining == 0)
    155149                        break;
    156150
     
    159153
    160154                case TRACE_ETHERTYPE_8021Q:
    161                         payload = (void *)trace_get_payload_from_vlan(payload,
     155                        nextpayload = (char *)trace_get_payload_from_vlan(
     156                                        nextpayload,
    162157                                        &ethertype, &remaining);
    163                         if (stripopts == 0 || (stripopts & TRACE_STRIP_VLAN))
    164                         {
    165                                 removed += (oldrem - remaining);
    166                                 memmove(dest, payload, remaining);
    167                                 payload = dest;
    168 
    169                         } else {
    170                                 if (finalethertype == 0) {
    171                                         finalethertype = TRACE_ETHERTYPE_8021Q;
    172                                 }
    173                                 dest = payload;
    174                         }
     158                        removed += (oldrem - remaining);
    175159                        break;
    176160
    177161                case TRACE_ETHERTYPE_MPLS:
    178                         payload = (void *)trace_get_payload_from_mpls(payload,
     162                        nextpayload = (char *)trace_get_payload_from_mpls(
     163                                        nextpayload,
    179164                                        &ethertype, &remaining);
    180                         if (stripopts == 0 || (stripopts & TRACE_STRIP_MPLS))
    181                         {
    182                                 removed += (oldrem - remaining);
    183                                 memmove(dest, payload, remaining);
    184                                 payload = dest;
    185 
    186                         } else {
    187                                 if (finalethertype == 0) {
    188                                         finalethertype = TRACE_ETHERTYPE_MPLS;
    189                                 }
    190                                 dest = payload;
    191                         }
     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);
    192172                        break;
    193173
     
    202182        }
    203183
    204         /* Update the preceding headers to match the new packet contents */
    205         ethernet->ether_type = ntohs(finalethertype);
    206         trace_set_capture_length(packet, caplen - removed);
     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                packet->link_type = finalethertype;
     194        }
     195       
    207196        return packet;
    208197
  • 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.