Changeset 0277ab8
- Timestamp:
- 08/05/15 13:50:02 (6 years ago)
- 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:
- d280f48
- Parents:
- 84d137d
- Location:
- lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtrace.h.in
r7428ab2 r0277ab8 1603 1603 void *trace_get_link(const libtrace_packet_t *packet); 1604 1604 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. 1614 1606 * @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 together1617 * to create the full mask. A mask of zero will strip all strippable headers.1618 1607 * 1619 1608 * @return The packet with the requested headers removed (if they were … … 1636 1625 * the original packet being returned unmodified. 1637 1626 * 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 */ 1628 DLLEXPORT libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet); 1645 1629 1646 1630 /** Get a pointer to the IPv4 header (if any) for a given packet -
lib/protocols_l2.c
r84d137d r0277ab8 101 101 } 102 102 103 libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet, 104 int stripopts) { 103 libtrace_packet_t *trace_strip_packet(libtrace_packet_t *packet) { 105 104 106 105 libtrace_ether_t *ethernet; … … 108 107 uint16_t ethertype; 109 108 uint32_t remaining; 110 libtrace_packet_t *copy; 111 char *payload; 109 char *nextpayload; 112 110 uint16_t finalethertype = 0; 113 111 uint16_t caplen, removed = 0; … … 130 128 } 131 129 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? 135 145 */ 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 = (char *)trace_get_layer3(packet, ðertype, &remaining);148 caplen = trace_get_capture_length(packet);149 dest = ((char *)ethernet) + sizeof(libtrace_ether_t);150 151 if (payload == NULL || remaining == 0)152 return packet;153 154 if (payload == dest)155 return packet;156 157 ethernet->ether_type = ntohs(ethertype);158 trace_set_capture_length(packet, caplen - (payload - dest));159 memmove(payload - (dest - (char *)packet->payload), packet->payload,160 (dest - (char *)packet->payload));161 packet->payload = payload - (dest - (char *)packet->payload);162 packet->l2_header = NULL;163 packet->l3_header = NULL;164 packet->l4_header = NULL;165 166 /*167 payload = trace_get_payload_from_layer2(ethernet, linktype,168 ðertype, &remaining);169 170 146 while (!done) { 171 147 172 if ( payload == NULL || remaining == 0)148 if (nextpayload == NULL || remaining == 0) 173 149 break; 174 150 … … 177 153 178 154 case TRACE_ETHERTYPE_8021Q: 179 payload = (void *)trace_get_payload_from_vlan(payload, 155 nextpayload = (char *)trace_get_payload_from_vlan( 156 nextpayload, 180 157 ðertype, &remaining); 181 if (stripopts == 0 || (stripopts & TRACE_STRIP_VLAN)) 182 { 183 removed += (oldrem - remaining); 184 //memmove(dest, payload, remaining); 185 //payload = dest; 186 187 } else { 188 if (finalethertype == 0) { 189 finalethertype = TRACE_ETHERTYPE_8021Q; 190 } 191 //dest = payload; 192 } 158 removed += (oldrem - remaining); 193 159 break; 194 160 195 161 case TRACE_ETHERTYPE_MPLS: 196 payload = (void *)trace_get_payload_from_mpls(payload, 162 nextpayload = (char *)trace_get_payload_from_mpls( 163 nextpayload, 197 164 ðertype, &remaining); 198 if (stripopts == 0 || (stripopts & TRACE_STRIP_MPLS)) 199 { 200 removed += (oldrem - remaining); 201 //memmove(dest, payload, remaining); 202 //payload = dest; 203 204 } else { 205 if (finalethertype == 0) { 206 finalethertype = TRACE_ETHERTYPE_MPLS; 207 } 208 //dest = payload; 209 } 165 removed += (oldrem - remaining); 166 break; 167 case TRACE_ETHERTYPE_PPP_SES: 168 nextpayload = (char *)trace_get_payload_from_pppoe( 169 nextpayload, 170 ðertype, &remaining); 171 removed += (oldrem - remaining); 210 172 break; 211 173 … … 219 181 } 220 182 } 221 */ 222 /* Update the preceding headers to match the new packet contents */ 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 packet->link_type = finalethertype; 194 } 195 223 196 return packet; 224 197 -
lib/protocols_l3.c
r7baa948 r0277ab8 245 245 } 246 246 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 } 248 254 iphdr = trace_get_payload_from_layer2( 249 255 link,
Note: See TracChangeset
for help on using the changeset viewer.