Changeset 9cc1266
- Timestamp:
- 02/22/11 10:01:08 (10 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, 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:
- e4e94c38
- Parents:
- ae76c14
- Location:
- lib
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r7b29593 r9cc1266 1 1 lib_LTLIBRARIES = libtrace.la 2 include_HEADERS = libtrace.h dagformat.h lt_inttypes.h daglegacy.h rt_protocol.h erftypes.h wandio.h 2 include_HEADERS = libtrace.h dagformat.h lt_inttypes.h daglegacy.h rt_protocol.h erftypes.h wandio.h 3 3 4 4 AM_CFLAGS=@LIBCFLAGS@ … … 68 68 ior-peek.c ior-stdio.c ior-thread.c \ 69 69 iow-stdio.c iow-thread.c wandio.c \ 70 wandio.h 70 wandio.h arphrd.h 71 71 72 72 if DAG2_4 -
lib/format_helper.c
rb5af22c r9cc1266 143 143 144 144 if (!trace->event.packet) { 145 trace->event.packet = trace_create_packet(); 146 } 147 148 if (!trace->event.waiting) { 145 149 /* There is no packet event waiting for us, so create a new 146 150 * libtrace packet in the event structure and read the next … … 151 155 * function is called. */ 152 156 153 trace->event.packet = trace_create_packet();154 157 trace->event.psize= 155 158 trace_read_packet(trace,trace->event.packet); … … 195 198 trace->event.trace_last_ts; 196 199 event.type = TRACE_EVENT_SLEEP; 200 trace->event.waiting = true; 197 201 return event; 198 202 } … … 214 218 /* We do a lot of freeing and creating of packet buffers with this 215 219 * method, but at least it works unlike what was here previously */ 216 if (packet->buf_control == TRACE_CTRL_PACKET) {217 free(packet->buffer);218 }220 //if (packet->buf_control == TRACE_CTRL_PACKET) { 221 // free(packet->buffer); 222 //} 219 223 220 224 /* The packet that we had read earlier is now ready to be returned … … 228 232 packet->buf_control = trace->event.packet->buf_control; 229 233 230 trace->event.packet->buffer = NULL;231 trace->event.packet->buf_control = TRACE_CTRL_EXTERNAL;232 233 trace_destroy_packet(trace->event.packet);234 trace->event.packet = NULL;234 //trace->event.packet->buffer = NULL; 235 //trace->event.packet->buf_control = TRACE_CTRL_EXTERNAL; 236 237 //trace_destroy_packet(trace->event.packet); 238 //trace->event.packet = NULL; 235 239 236 240 event.type = TRACE_EVENT_PACKET; 237 241 238 242 trace->event.trace_last_ts = ts; 243 trace->event.waiting = false; 239 244 240 245 return event; -
lib/libtrace.h.in
rc259635 r9cc1266 420 420 buf_control_t buf_control; /**< Describes memory ownership */ 421 421 int capture_length; /**< Cached capture length */ 422 int payload_length; /**< Cached payload length */ 422 423 void *l3_header; /**< Cached l3 header */ 423 424 uint16_t l3_ethertype; /**< Cached l3 ethertype */ 425 void *l4_header; /**< Cached transport header */ 426 uint8_t transport_proto; /**< Cached transport protocol */ 424 427 } libtrace_packet_t; 425 428 -
lib/libtrace_int.h
rae3779b r9cc1266 160 160 /** The size of the current PACKET event */ 161 161 int psize; 162 /** Whether there is a packet stored in *packet above waiting for an 163 * event to occur */ 164 bool waiting; 162 165 }; 163 166 … … 226 229 PRINTF(3,4); 227 230 231 /** Clears the cached values for a libtrace packet 232 * 233 * @param packet The libtrace packet that requires a cache reset 234 */ 235 void trace_clear_cache(libtrace_packet_t *packet); 228 236 229 237 /** Converts the data provided in buffer into a valid libtrace packet … … 857 865 * 858 866 * @param link A pointer to the Linux SLL header to be skipped 859 * @param[out] type The ethertype of the next header 867 * @param[out] arphrd_type The arp hardware type of the packet 868 * @param[out] next_header The ethertype of the next header 860 869 * @param[in,out] remaining Updated with the number of captured bytes 861 870 * remaining … … 874 883 * calling this function. 875 884 */ 876 void *trace_get_payload_from_linux_sll(const void *link, uint16_t *type, 885 void *trace_get_payload_from_linux_sll(const void *link, 886 uint16_t *arphrd_type, 887 uint16_t *next_header, 877 888 uint32_t *remaining); 878 889 -
lib/link_wireless.c
r1326d5f r9cc1266 188 188 } else break; 189 189 case TRACE_TYPE_LINUX_SLL: 190 l = trace_get_payload_from_linux_sll(link, &type, NULL );190 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL ); 191 191 return trace_get_wireless_tsft(l, arphrd_type_to_libtrace(type), tsft); 192 192 … … 223 223 } else break; 224 224 case TRACE_TYPE_LINUX_SLL: 225 l = trace_get_payload_from_linux_sll(link, &type, NULL );225 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 226 226 return trace_get_wireless_flags(l, arphrd_type_to_libtrace(type), flags); 227 227 default: … … 247 247 } else break; 248 248 case TRACE_TYPE_LINUX_SLL: 249 l = trace_get_payload_from_linux_sll(link, &type, NULL );249 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 250 250 return trace_get_wireless_rate(l, arphrd_type_to_libtrace(type), rate); 251 251 default: … … 275 275 } else break; 276 276 case TRACE_TYPE_LINUX_SLL: 277 l = trace_get_payload_from_linux_sll(link, &type, NULL );277 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 278 278 return trace_get_wireless_freq(l, arphrd_type_to_libtrace(type), freq); 279 279 default: … … 311 311 } else break; 312 312 case TRACE_TYPE_LINUX_SLL: 313 l = trace_get_payload_from_linux_sll(link, &type, NULL );313 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 314 314 return trace_get_wireless_channel_flags(l, arphrd_type_to_libtrace(type), flags); 315 315 default: … … 342 342 } else break; 343 343 case TRACE_TYPE_LINUX_SLL: 344 l = trace_get_payload_from_linux_sll(link, &type, NULL );344 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 345 345 return trace_get_wireless_fhss_hopset(l, arphrd_type_to_libtrace(type), hopset); 346 346 default: … … 369 369 } else break; 370 370 case TRACE_TYPE_LINUX_SLL: 371 l = trace_get_payload_from_linux_sll(link, &type, NULL );371 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 372 372 return trace_get_wireless_fhss_hoppattern(l, arphrd_type_to_libtrace(type), hoppattern); 373 373 default: … … 395 395 } else break; 396 396 case TRACE_TYPE_LINUX_SLL: 397 l = trace_get_payload_from_linux_sll(link, &type, NULL );397 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 398 398 return trace_get_wireless_signal_strength_dbm(l, arphrd_type_to_libtrace(type), strength); 399 399 default: … … 419 419 } else break; 420 420 case TRACE_TYPE_LINUX_SLL: 421 l = trace_get_payload_from_linux_sll(link, &type, NULL );421 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 422 422 return trace_get_wireless_noise_strength_dbm(l, arphrd_type_to_libtrace(type), strength); 423 423 default: … … 443 443 } else break; 444 444 case TRACE_TYPE_LINUX_SLL: 445 l = trace_get_payload_from_linux_sll(link, &type, NULL );445 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 446 446 return trace_get_wireless_signal_strength_db(l, arphrd_type_to_libtrace(type), strength); 447 447 default: … … 467 467 } else break; 468 468 case TRACE_TYPE_LINUX_SLL: 469 l = trace_get_payload_from_linux_sll(link, &type, NULL );469 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 470 470 return trace_get_wireless_noise_strength_db(l, arphrd_type_to_libtrace(type), strength); 471 471 default: … … 497 497 } else break; 498 498 case TRACE_TYPE_LINUX_SLL: 499 l = trace_get_payload_from_linux_sll(link, &type, NULL );499 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 500 500 return trace_get_wireless_lock_quality(l, arphrd_type_to_libtrace(type), quality); 501 501 default: … … 523 523 } else break; 524 524 case TRACE_TYPE_LINUX_SLL: 525 l = trace_get_payload_from_linux_sll(link, &type, NULL );525 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 526 526 return trace_get_wireless_tx_attenuation(l, arphrd_type_to_libtrace(type), attenuation); 527 527 default: … … 547 547 } else break; 548 548 case TRACE_TYPE_LINUX_SLL: 549 l = trace_get_payload_from_linux_sll(link, &type, NULL );549 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 550 550 return trace_get_wireless_tx_attenuation_db(l, arphrd_type_to_libtrace(type), attenuation); 551 551 default: … … 571 571 } else break; 572 572 case TRACE_TYPE_LINUX_SLL: 573 l = trace_get_payload_from_linux_sll(link, &type, NULL );573 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 574 574 return trace_get_wireless_tx_power_dbm(l, arphrd_type_to_libtrace(type), txpower); 575 575 default: … … 596 596 } else break; 597 597 case TRACE_TYPE_LINUX_SLL: 598 l = trace_get_payload_from_linux_sll(link, &type, NULL );598 l = trace_get_payload_from_linux_sll(link, &type, NULL, NULL); 599 599 return trace_get_wireless_antenna(l, arphrd_type_to_libtrace(type), antenna); 600 600 default: -
lib/linktypes.c
r1326d5f r9cc1266 41 41 #include <string.h> 42 42 43 #ifndef WIN32 44 #include <net/if_arp.h> 45 #endif 46 47 #ifndef ARPHRD_ETHER 48 #define ARPHRD_ETHER 1 /* Ethernet 10/100Mbps. */ 49 #endif 50 51 #ifndef ARPHRD_EETHER 52 #define ARPHRD_EETHER 2 /* Experimental Ethernet 10/100Mbps. */ 53 #endif 54 55 #ifndef ARPHRD_PPP 56 #define ARPHRD_PPP 512 57 #endif 58 59 #ifndef ARPHRD_IEEE80211 60 #define ARPHRD_IEEE80211 801 61 #endif 62 63 #ifndef ARPHRD_NONE 64 #define ARPHRD_NONE 0xFFFE 65 #endif 43 #include "arphrd.h" 66 44 67 45 … … 209 187 case ARPHRD_80211_RADIOTAP: return TRACE_TYPE_80211_RADIO; 210 188 case ARPHRD_PPP: return TRACE_TYPE_NONE; 189 case ARPHRD_LOOPBACK: return TRACE_TYPE_NONE; 211 190 case ARPHRD_NONE: return TRACE_TYPE_NONE; 212 191 } … … 351 330 352 331 /* Invalidate caches */ 353 packet->l3_header = NULL; 354 packet->capture_length = -1; 355 332 trace_clear_cache(packet); 356 333 return true; 357 334 … … 377 354 378 355 /* Invalidate caches */ 379 packet->l3_header = NULL; 380 packet->capture_length = -1; 356 trace_clear_cache(packet); 381 357 break; 382 358 default: … … 385 361 386 362 /* Invalidate caches */ 387 packet->l3_header = NULL; 388 packet->capture_length = -1; 363 trace_clear_cache(packet); 389 364 return true; 390 365 } -
lib/protocols_l2.c
r1326d5f r9cc1266 37 37 #include <assert.h> 38 38 #include <stdlib.h> 39 39 40 40 41 /* This file contains all the protocol decoding functions for layer 2 … … 398 399 { 399 400 void *l; 401 400 402 if (linktype == ~0U) { 401 403 fprintf(stderr, "Unable to determine linktype for packet\n"); -
lib/protocols_pktmeta.c
r1326d5f r9cc1266 61 61 /* NB: type is returned as an ARPHRD_ type for SLL*/ 62 62 void *trace_get_payload_from_linux_sll(const void *link, 63 uint16_t *type, uint32_t *remaining) 63 uint16_t *arphrd_type, uint16_t *next, 64 uint32_t *remaining) 64 65 { 65 66 libtrace_sll_header_t *sll; … … 75 76 } 76 77 77 if (type) *type = ntohs(sll->hatype); 78 /* The SLL header is actually in place of a link layer header, so 79 * we want to use the protocol field to tell our caller what the 80 * next header is going to be */ 81 if (next) *next = (libtrace_linktype_t)(ntohs(sll->protocol)); 82 if (arphrd_type) *arphrd_type = ntohs(sll->hatype); 78 83 79 84 return (void*)((char*)sll+sizeof(*sll)); … … 189 194 case TRACE_TYPE_LINUX_SLL: 190 195 nexthdr = trace_get_payload_from_linux_sll(meta, 191 &arphrd, remaining); 192 *linktype = arphrd_type_to_libtrace(arphrd); 196 &arphrd, NULL, remaining); 197 198 /* Ethernet header is usually absent in SLL captures, 199 * so we don't want to skip it just yet */ 200 if (arphrd_type_to_libtrace(arphrd) == TRACE_TYPE_ETH) 201 *linktype = TRACE_TYPE_NONE; 202 else 203 *linktype = arphrd_type_to_libtrace(arphrd); 193 204 return nexthdr; 194 205 case TRACE_TYPE_80211_RADIO: -
lib/protocols_transport.c
r3038cd2 r9cc1266 68 68 size_t len = 0; 69 69 70 71 70 /* Just use the cached length if we can */ 71 if (packet->payload_length != -1) 72 return packet->payload_length; 73 74 /* Set to zero so that we can return early without having to 75 * worry about forgetting to update the cached value */ 76 ((libtrace_packet_t *)packet)->payload_length = 0; 72 77 layer = trace_get_layer3(packet, ðertype, &rem); 73 74 78 if (!layer) 75 79 return 0; … … 122 126 } 123 127 128 129 ((libtrace_packet_t *)packet)->payload_length = len; 124 130 return len; 125 131 … … 139 145 140 146 if (!remaining) remaining=&dummy_remaining; 147 148 if (packet->l4_header) { 149 void *link; 150 libtrace_linktype_t linktype; 151 link = trace_get_packet_buffer(packet, &linktype, remaining); 152 if (!link) 153 return NULL; 154 *proto = packet->transport_proto; 155 *remaining -= (packet->l4_header - link); 156 return packet->l4_header; 157 } 141 158 142 159 transport = trace_get_layer3(packet,ðertype,remaining); … … 154 171 (libtrace_ip6_t*)transport, proto,remaining); 155 172 } 156 return transport;173 break; 157 174 case TRACE_ETHERTYPE_IPV6: /* IPv6 */ 158 returntrace_get_payload_from_ip6(175 transport = trace_get_payload_from_ip6( 159 176 (libtrace_ip6_t*)transport, proto, remaining); 177 break; 178 default: 179 *proto = 0; 180 transport = NULL; 181 break; 160 182 161 183 } 162 184 163 *proto=0; 164 return NULL; 185 ((libtrace_packet_t *)packet)->transport_proto = *proto; 186 ((libtrace_packet_t *)packet)->l4_header = transport; 187 188 189 return transport; 165 190 } 166 191 -
lib/trace.c
rdfbdd796 r9cc1266 243 243 libtrace->event.psize = 0; 244 244 libtrace->event.trace_last_ts = 0.0; 245 libtrace->event.waiting = false; 245 246 libtrace->filter = NULL; 246 247 libtrace->snaplen = 0; … … 590 591 if (libtrace->uridata) 591 592 free(libtrace->uridata); 593 if (libtrace->event.packet) 594 trace_destroy_packet(libtrace->event.packet); 592 595 free(libtrace); 593 596 } … … 624 627 625 628 packet->buf_control=TRACE_CTRL_PACKET; 626 packet->capture_length=-1;629 trace_clear_cache(packet); 627 630 return packet; 628 631 } … … 648 651 /* Reset the cache - better to recalculate than try to convert 649 652 * the values over to the new packet */ 650 dest->capture_length = -1; 651 dest->l3_header = NULL; 652 dest->l3_ethertype = 0; 653 653 trace_clear_cache(dest); 654 654 /* Ooooh nasty memcpys! This is why we want to avoid copying packets 655 655 * as much as possible */ … … 712 712 size_t ret; 713 713 /* Clear the packet cache */ 714 packet->capture_length = -1; 715 packet->l3_header = NULL; 716 packet->l3_ethertype = 0; 717 714 trace_clear_cache(packet); 718 715 ret=libtrace->format->read_packet(libtrace,packet); 719 716 if (ret==(size_t)-1 || ret==0) { … … 777 774 778 775 /* Clear packet cache */ 779 packet->capture_length = -1; 780 packet->l3_header = NULL; 781 packet->l3_ethertype = 0; 776 trace_clear_cache(packet); 782 777 783 778 if (trace->format->prepare_packet) { … … 1099 1094 1100 1095 /* Clear the packet cache */ 1101 packet->capture_length = -1; 1102 packet->l3_header = NULL; 1103 packet->l3_ethertype = 0; 1096 trace_clear_cache(packet); 1104 1097 1105 1098 /* Store the trace we are reading from into the packet opaque … … 1818 1811 assert(trace); 1819 1812 return trace->accepted_packets; 1813 } 1814 1815 void trace_clear_cache(libtrace_packet_t *packet) { 1816 1817 packet->l3_header = NULL; 1818 packet->l4_header = NULL; 1819 packet->l3_ethertype = 0; 1820 packet->transport_proto = 0; 1821 packet->capture_length = -1; 1822 packet->payload_length = -1; 1823 1820 1824 } 1821 1825
Note: See TracChangeset
for help on using the changeset viewer.