- Timestamp:
- 07/20/16 16:01:58 (5 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 000726a
- Parents:
- 733c8b4 (diff), 2b0eae9 (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. - Location:
- lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_bpf.c
rd8b05b7 ra984307 430 430 ptr = ((struct local_bpf_hdr *)(packet->header)); 431 431 replace = ((struct libtrace_bpf_hdr *)(packet->header)); 432 orig = *ptr;432 memcpy(&orig, ptr, sizeof(struct local_bpf_hdr)); 433 433 434 434 replace->bh_tstamp.tv_sec = (uint32_t) (orig.bh_tstamp.tv_sec & 0xffffffff); -
lib/format_dpdk.c
rd8b05b7 ra984307 142 142 #else 143 143 # define DPDK_USE_LOG_LEVEL 0 144 #endif 145 146 /* 1.8.0-rc2 147 * rx/tx_conf thresholds can be set to NULL in rte_eth_rx/tx_queue_setup 148 * this uses the default values, which are better tuned per device 149 * See issue #26 150 */ 151 #if RTE_VERSION >= RTE_VERSION_NUM(1, 8, 0, 2) 152 # define DPDK_USE_NULL_QUEUE_CONFIG 1 153 #else 154 # define DPDK_USE_NULL_QUEUE_CONFIG 0 144 155 #endif 145 156 … … 1342 1353 format_data->nb_tx_buf, 1343 1354 SOCKET_ID_ANY, 1344 &tx_conf);1355 DPDK_USE_NULL_QUEUE_CONFIG ? NULL : &tx_conf); 1345 1356 if (ret < 0) { 1346 1357 snprintf(err, errlen, "Intel DPDK - Cannot configure TX queue" … … 1390 1401 format_data->nb_rx_buf, 1391 1402 format_data->nic_numa_node, 1392 &rx_conf,1403 DPDK_USE_NULL_QUEUE_CONFIG ? NULL: &rx_conf, 1393 1404 stream->mempool); 1394 1405 if (ret < 0) { -
lib/format_rt.c
rd8b05b7 ra984307 159 159 return -1; 160 160 } 161 161 162 162 if (connect_msg.magic != LIBTRACE_RT_MAGIC) { 163 163 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, -
lib/libtrace.h.in
rd391ce0 ra984307 1713 1713 /** Create a new packet object 1714 1714 * 1715 * @return A pointer to an initialised libtrace_packet_t object 1715 * @return A pointer to an initialised libtrace_packet_t object, or NULL if 1716 * libtrace is unable to allocate space for a new packet. 1716 1717 */ 1717 1718 DLLEXPORT libtrace_packet_t *trace_create_packet(void); -
lib/trace.c
rf0cb0d4 ra984307 5 5 * New Zealand. 6 6 * 7 * Authors: Daniel Lawson 7 * Authors: Daniel Lawson 8 8 * Perry Lorier 9 * Shane Alcock 10 * 9 * Shane Alcock 10 * 11 11 * All rights reserved. 12 12 * 13 * This code has been developed by the University of Waikato WAND 13 * This code has been developed by the University of Waikato WAND 14 14 * research group. For further information please see http://www.wand.net.nz/ 15 15 * … … 120 120 dest[n]='\0'; 121 121 } 122 122 123 123 static char *xstrndup(const char *src,size_t n) 124 { 124 { 125 125 char *ret=(char*)malloc(n+1); 126 126 if (ret==NULL) { … … 163 163 } 164 164 165 /* Prints help information for libtrace 165 /* Prints help information for libtrace 166 166 * 167 167 * Function prints out some basic help information regarding libtrace, … … 186 186 { 187 187 struct libtrace_format_t *tmp; 188 188 189 189 /* Try and guess based on filename */ 190 190 for(tmp = formats_list; tmp; tmp=tmp->next) { … … 208 208 } 209 209 } 210 210 211 211 /* No formats matched -- make sure we clean up the IO object we 212 212 * used to probe the file magic */ … … 223 223 * erf:/path/to/erf/file 224 224 * erf:/path/to/erf/file.gz 225 * erf:- 225 * erf:- (stdin) 226 226 * dag:/dev/dagcard 227 * pcapint:pcapinterface 227 * pcapint:pcapinterface (eg: pcapint:eth0) 228 228 * pcapfile:/path/to/pcap/file 229 229 * pcapfile:- … … 236 236 */ 237 237 DLLEXPORT libtrace_t *trace_create(const char *uri) { 238 libtrace_t *libtrace = 238 libtrace_t *libtrace = 239 239 (libtrace_t *)malloc(sizeof(libtrace_t)); 240 240 char *scan = 0; 241 const char *uridata = 0; 241 const char *uridata = 0; 242 242 243 243 trace_init(); … … 249 249 return NULL; 250 250 } 251 251 252 252 libtrace->err.err_num = TRACE_ERR_NOERROR; 253 253 libtrace->format=NULL; 254 254 255 255 libtrace->event.tdelta = 0.0; 256 256 libtrace->event.packet = NULL; … … 327 327 * libtrace->uridata contains the appropriate data for this 328 328 */ 329 330 /* Call the init_input function for the matching capture format */ 329 330 /* Call the init_input function for the matching capture format */ 331 331 if (libtrace->format->init_input) { 332 332 int err=libtrace->format->init_input(libtrace); 333 333 assert (err==-1 || err==0); 334 334 if (err==-1) { 335 /* init_input should call trace_set_err to set 336 * theerror message335 /* init_input should call trace_set_err to set the 336 * error message 337 337 */ 338 338 return libtrace; … … 343 343 return libtrace; 344 344 } 345 345 346 346 if (scan) 347 347 free(scan); … … 366 366 367 367 trace_init(); 368 368 369 369 libtrace->err.err_num = TRACE_ERR_NOERROR; 370 370 … … 374 374 xstrncpy(scan,uri, (size_t)(uridata - uri)); 375 375 } 376 376 377 377 libtrace->err.err_num = TRACE_ERR_NOERROR; 378 378 libtrace->format=NULL; 379 379 380 380 libtrace->event.tdelta = 0.0; 381 381 libtrace->event.packet = NULL; … … 413 413 libtrace->perpkt_cbs = NULL; 414 414 libtrace->reporter_cbs = NULL; 415 416 415 for(tmp=formats_list;tmp;tmp=tmp->next) { 417 416 if (strlen(scan) == strlen(tmp->name) && … … 434 433 } 435 434 436 /* Creates an output trace from a URI. 435 /* Creates an output trace from a URI. 437 436 * 438 437 * @param uri the uri string describing the output format and destination 439 * @returns opaque pointer to a libtrace_output_t 438 * @returns opaque pointer to a libtrace_output_t 440 439 * 441 440 * If an error occured when attempting to open the output trace, NULL is 442 * returned and trace_errno is set. 443 */ 444 441 * returned and trace_errno is set. 442 */ 443 445 444 DLLEXPORT libtrace_out_t *trace_create_output(const char *uri) { 446 libtrace_out_t *libtrace = 445 libtrace_out_t *libtrace = 447 446 (libtrace_out_t*)malloc(sizeof(libtrace_out_t)); 448 447 449 448 char *scan = 0; 450 449 const char *uridata = 0; … … 457 456 libtrace->format = NULL; 458 457 libtrace->uridata = NULL; 459 458 460 459 /* Parse the URI to determine what capture format we want to write */ 461 460 … … 465 464 return libtrace; 466 465 } 467 466 468 467 /* Attempt to find the format in the list of supported formats */ 469 468 for(tmp=formats_list;tmp;tmp=tmp->next) { … … 534 533 535 534 /* Start an output trace */ 536 DLLEXPORT int trace_start_output(libtrace_out_t *libtrace) 535 DLLEXPORT int trace_start_output(libtrace_out_t *libtrace) 537 536 { 538 537 assert(libtrace); … … 592 591 593 592 /* If we get here, either the native configuration failed or the 594 * format did not support configuration. However, libtrace can 593 * format did not support configuration. However, libtrace can 595 594 * deal with some options itself, so give that a go */ 596 595 switch(option) { … … 600 599 trace_get_err(libtrace); 601 600 } 602 if (*(int*)value<0 601 if (*(int*)value<0 603 602 || *(int*)value>LIBTRACE_PACKET_BUFSIZE) { 604 603 trace_set_err(libtrace,TRACE_ERR_BAD_STATE, … … 622 621 case TRACE_OPTION_META_FREQ: 623 622 if (!trace_is_err(libtrace)) { 624 trace_set_err(libtrace, 623 trace_set_err(libtrace, 625 624 TRACE_ERR_OPTION_UNAVAIL, 626 625 "This format does not support meta-data gathering"); … … 629 628 case TRACE_OPTION_EVENT_REALTIME: 630 629 if (!trace_is_err(libtrace)) { 631 trace_set_err(libtrace, 630 trace_set_err(libtrace, 632 631 TRACE_ERR_OPTION_UNAVAIL, 633 632 "This format does not support realtime events"); … … 637 636 /* Dealt with earlier */ 638 637 return -1; 639 638 640 639 } 641 640 if (!trace_is_err(libtrace)) { … … 671 670 trace_option_output_t option, 672 671 void *value) { 673 672 674 673 /* Unlike the input options, libtrace does not natively support any of 675 674 * the output options - the format module must be able to deal with … … 778 777 * @param libtrace the output trace file to be destroyed 779 778 */ 780 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) 779 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) 781 780 { 782 781 assert(libtrace); … … 792 791 libtrace_packet_t *packet = 793 792 (libtrace_packet_t*)calloc((size_t)1,sizeof(libtrace_packet_t)); 793 794 if (packet == NULL) 795 return NULL; 794 796 795 797 packet->buf_control=TRACE_CTRL_PACKET; … … 821 823 /* Reset the cache - better to recalculate than try to convert 822 824 * the values over to the new packet */ 823 trace_clear_cache(dest); 825 trace_clear_cache(dest); 824 826 /* Ooooh nasty memcpys! This is why we want to avoid copying packets 825 827 * as much as possible */ … … 843 845 free(packet->buffer); 844 846 } 845 packet->buf_control=(buf_control_t)'\0'; 847 packet->buf_control=(buf_control_t)'\0'; 846 848 /* A "bad" value to force an assert 847 849 * if this packet is ever reused … … 894 896 * block until a packet is read (or EOF is reached). 895 897 * 896 * @param libtrace 897 * @param packet 898 * @param libtrace the libtrace opaque pointer 899 * @param packet the packet opaque pointer 898 900 * @returns 0 on EOF, negative value on error 899 901 * … … 908 910 return -1; 909 911 } 910 if (!(packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 912 if (!(packet->buf_control==TRACE_CTRL_PACKET 913 || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 911 914 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid\n"); 912 915 return -1; … … 969 972 * appropriate capture format header for the format type that the packet is 970 973 * being converted to. This also allows for a packet to be converted into 971 * just about capture format that is supported by libtrace, provided the 974 * just about capture format that is supported by libtrace, provided the 972 975 * format header is present in the buffer. 973 976 * 974 977 * This function is primarily used to convert packets received via the RT 975 978 * protocol back into their original capture format. The RT header encapsulates 976 * the original capture format header, so after removing it the packet must 979 * the original capture format header, so after removing it the packet must 977 980 * have it's header and payload pointers updated and the packet format and type 978 981 * changed, amongst other things. 979 982 * 980 * Intended only for internal use at this point - this function is not 983 * Intended only for internal use at this point - this function is not 981 984 * available through the external libtrace API. 982 985 */ … … 986 989 assert(packet); 987 990 assert(trace); 988 991 989 992 /* XXX Proper error handling?? */ 990 993 if (buffer == NULL) … … 995 998 return -1; 996 999 } 997 1000 998 1001 packet->trace = trace; 999 1002 pthread_mutex_lock(&trace->libtrace_lock); 1000 1003 trace->last_packet = packet; 1001 1004 pthread_mutex_unlock(&trace->libtrace_lock); 1002 1003 1005 /* Clear packet cache */ 1004 1006 trace_clear_cache(packet); … … 1008 1010 buffer, rt_type, flags); 1009 1011 } 1010 trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 1012 trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 1011 1013 "This format does not support preparing packets\n"); 1012 1014 return -1; … … 1050 1052 * wire lengths to be the "remaining" value. If the packet has 1051 1053 * been padded to increase the capture length, we don't want 1052 * to allow subsequent protocol decoders to consider the 1054 * to allow subsequent protocol decoders to consider the 1053 1055 * padding as part of the packet. 1054 1056 * … … 1060 1062 * better off returning an incomplete TCP header in that case. 1061 1063 */ 1062 1064 1063 1065 cap_len = trace_get_capture_length(packet); 1064 1066 wire_len = trace_get_wire_length(packet); … … 1069 1071 * massively negative wire lens. We could assert fail here on 1070 1072 * them, but we could at least try the capture length instead. 1071 * 1073 * 1072 1074 * You may still run into problems if you try to write that 1073 1075 * packet, but at least reading should work OK. … … 1085 1087 1086 1088 1087 /* Get a pointer to the first byte of the packet payload 1089 /* Get a pointer to the first byte of the packet payload 1088 1090 * 1089 1091 * DEPRECATED - use trace_get_packet_buffer() instead */ … … 1092 1094 } 1093 1095 1094 /* Get the current time in DAG time format 1095 * @param packet 1096 /* Get the current time in DAG time format 1097 * @param packet a pointer to a libtrace_packet structure 1096 1098 * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds 1097 1099 * past 1970-01-01, the lower 32bits are partial seconds) 1098 */ 1100 */ 1099 1101 DLLEXPORT uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet) { 1100 1102 if (packet->trace->format->get_erf_timestamp) { … … 1122 1124 return (uint64_t)0; 1123 1125 } 1124 1125 1126 } 1126 1127 … … 1131 1132 * @author Daniel Lawson 1132 1133 * @author Perry Lorier 1133 */ 1134 */ 1134 1135 DLLEXPORT struct timeval trace_get_timeval(const libtrace_packet_t *packet) { 1135 1136 struct timeval tv; … … 1143 1144 tv.tv_sec = ts >> 32; 1144 1145 tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32; 1145 1146 1147 1148 1146 if (tv.tv_usec >= 1000000) { 1147 tv.tv_usec -= 1000000; 1148 tv.tv_sec += 1; 1149 } 1149 1150 } else if (packet->trace->format->get_timespec) { 1150 1151 struct timespec ts = packet->trace->format->get_timespec(packet); … … 1175 1176 ts.tv_sec = erfts >> 32; 1176 1177 ts.tv_nsec = ((erfts&0xFFFFFFFF)*1000000000)>>32; 1177 1178 1179 1180 1178 if (ts.tv_nsec >= 1000000000) { 1179 ts.tv_nsec -= 1000000000; 1180 ts.tv_sec += 1; 1181 } 1181 1182 return ts; 1182 1183 } else if (packet->trace->format->get_timeval) { … … 1202 1203 1203 1204 /* Get the current time in floating point seconds 1204 * @param packet 1205 * @param packet a pointer to a libtrace_packet structure 1205 1206 * @returns time that this packet was seen in 64bit floating point seconds 1206 */ 1207 */ 1207 1208 DLLEXPORT double trace_get_seconds(const libtrace_packet_t *packet) { 1208 1209 double seconds = 0.0; … … 1231 1232 } 1232 1233 1233 DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet) 1234 DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet) 1234 1235 { 1235 1236 /* Cache the capture length */ … … 1238 1239 return ~0U; 1239 1240 /* Cast away constness because this is "just" a cache */ 1240 ((libtrace_packet_t*)packet)->capture_length = 1241 ((libtrace_packet_t*)packet)->capture_length = 1241 1242 packet->trace->format->get_capture_length(packet); 1242 1243 } … … 1246 1247 return packet->capture_length; 1247 1248 } 1248 1249 1249 1250 /* Get the size of the packet as it was seen on the wire. 1250 1251 * @param packet a pointer to a libtrace_packet structure … … 1253 1254 * @note Due to the trace being a header capture, or anonymisation this may 1254 1255 * not be the same as the Capture Len. 1255 */ 1256 */ 1256 1257 DLLEXPORT size_t trace_get_wire_length(const libtrace_packet_t *packet){ 1257 1258 1258 1259 if (packet->wire_length == -1) { 1259 if (!packet->trace->format->get_wire_length) 1260 if (!packet->trace->format->get_wire_length) 1260 1261 return ~0U; 1261 ((libtrace_packet_t *)packet)->wire_length = 1262 ((libtrace_packet_t *)packet)->wire_length = 1262 1263 packet->trace->format->get_wire_length(packet); 1263 1264 } … … 1269 1270 1270 1271 /* Get the length of the capture framing headers. 1271 * @param packet 1272 * @param packet the packet opaque pointer 1272 1273 * @returns the size of the packet as it was on the wire. 1273 * @note this length corresponds to the difference between the size of a 1274 * @note this length corresponds to the difference between the size of a 1274 1275 * captured packet in memory, and the captured length of the packet 1275 */ 1276 */ 1276 1277 DLLEXPORT SIMPLE_FUNCTION 1277 1278 size_t trace_get_framing_length(const libtrace_packet_t *packet) { … … 1284 1285 1285 1286 /* Get the type of the link layer 1286 * @param packet 1287 * @param packet a pointer to a libtrace_packet structure 1287 1288 * @returns libtrace_linktype_t 1288 1289 */ … … 1310 1311 * which in turn is stored inside the new packet object... 1311 1312 */ 1312 DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace, 1313 DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace, 1313 1314 libtrace_packet_t *packet) { 1314 1315 libtrace_eventobj_t event = {TRACE_EVENT_IOWAIT,0,0.0,0}; … … 1322 1323 /* Free the last packet */ 1323 1324 trace_fin_packet(packet); 1324 1325 1325 /* Store the trace we are reading from into the packet opaque 1326 1326 * structure */ … … 1329 1329 if (packet->trace->format->trace_event) { 1330 1330 /* Note: incrementing accepted, filtered etc. packet 1331 * counters is handled by the format-specific 1331 * counters is handled by the format-specific 1332 1332 * function so don't increment them here. 1333 1333 */ … … 1356 1356 filter->filter.bf_insns = (struct bpf_insn *) 1357 1357 malloc(sizeof(struct bpf_insn) * bf_len); 1358 1358 1359 1359 memcpy(filter->filter.bf_insns, bf_insns, 1360 1360 bf_len * sizeof(struct bpf_insn)); 1361 1361 1362 1362 filter->filter.bf_len = bf_len; 1363 1363 filter->filterstring = NULL; 1364 1364 filter->jitfilter = NULL; 1365 1365 /* "flag" indicates that the filter member is valid */ 1366 filter->flag = 1; 1367 1366 filter->flag = 1; 1367 1368 1368 return filter; 1369 1369 #endif … … 1395 1395 pcap_freecode(&filter->filter); 1396 1396 #ifdef HAVE_LLVM 1397 if (filter->jitfilter) 1397 if (filter->jitfilter) 1398 1398 destroy_program(filter->jitfilter); 1399 1399 #endif … … 1413 1413 static int trace_bpf_compile(libtrace_filter_t *filter, 1414 1414 const libtrace_packet_t *packet, 1415 void *linkptr, 1415 void *linkptr, 1416 1416 libtrace_linktype_t linktype ) { 1417 1417 #ifdef HAVE_BPF_FILTER … … 1429 1429 return -1; 1430 1430 } 1431 1431 1432 1432 if (filter->filterstring && ! filter->flag) { 1433 1433 pcap_t *pcap = NULL; … … 1454 1454 /* build filter */ 1455 1455 assert(pcap); 1456 if (pcap_compile( pcap, &filter->filter, filter->filterstring, 1456 if (pcap_compile( pcap, &filter->filter, filter->filterstring, 1457 1457 1, 0)) { 1458 1458 trace_set_err(packet->trace,TRACE_ERR_BAD_FILTER, 1459 "Unable to compile the filter \"%s\": %s", 1459 "Unable to compile the filter \"%s\": %s", 1460 1460 filter->filterstring, 1461 1461 pcap_geterr(pcap)); … … 1498 1498 1499 1499 if (linktype == TRACE_TYPE_NONDATA) 1500 return 1; 1500 return 1; 1501 1501 1502 1502 if (libtrace_to_pcap_dlt(linktype)==TRACE_DLT_ERROR) { 1503 1503 1504 1504 /* If we cannot get a suitable DLT for the packet, it may 1505 1505 * be because the packet is encapsulated in a link type that … … 1507 1507 * popping off headers until we either can find a suitable 1508 1508 * link type or we can't do any more sensible decapsulation. */ 1509 1509 1510 1510 /* Copy the packet, as we don't want to trash the one we 1511 1511 * were passed in */ … … 1515 1515 while (libtrace_to_pcap_dlt(linktype) == TRACE_DLT_ERROR) { 1516 1516 if (!demote_packet(packet_copy)) { 1517 trace_set_err(packet->trace, 1517 trace_set_err(packet->trace, 1518 1518 TRACE_ERR_NO_CONVERSION, 1519 1519 "pcap does not support this format"); … … 1527 1527 1528 1528 } 1529 1529 1530 1530 linkptr = trace_get_packet_buffer(packet_copy,NULL,&clen); 1531 1531 if (!linkptr) { … … 1536 1536 } 1537 1537 1538 /* We need to compile the filter now, because before we didn't know 1538 /* We need to compile the filter now, because before we didn't know 1539 1539 * what the link type was 1540 1540 */ … … 1585 1585 * @returns a signed value containing the direction flag, or -1 if this is not supported 1586 1586 */ 1587 DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, 1588 libtrace_direction_t direction) 1587 DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, 1588 libtrace_direction_t direction) 1589 1589 { 1590 1590 assert(packet); … … 1603 1603 * for a special trace. 1604 1604 */ 1605 DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet) 1605 DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet) 1606 1606 { 1607 1607 assert(packet); … … 1618 1618 #define DYNAMIC(x) ((49152 < (x)) && ((x) < 65535)) 1619 1619 #define SERVER(x) ROOT_SERVER(x) || NONROOT_SERVER(x) 1620 #define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) 1620 #define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) 1621 1621 1622 1622 /* Attempt to deduce the 'server' port … … 1626 1626 * @returns a hint as to which port is the server port 1627 1627 */ 1628 DLLEXPORT int8_t trace_get_server_port(UNUSED uint8_t protocol, 1629 uint16_t source, uint16_t dest) 1628 DLLEXPORT int8_t trace_get_server_port(UNUSED uint8_t protocol, 1629 uint16_t source, uint16_t dest) 1630 1630 { 1631 1631 /* … … 1640 1640 * * flip a coin. 1641 1641 */ 1642 1642 1643 1643 /* equal */ 1644 1644 if (source == dest) … … 1686 1686 return USE_SOURCE; 1687 1687 } 1688 1688 1689 1689 /* nonroot client */ 1690 1690 if (NONROOT_CLIENT(source) && NONROOT_CLIENT(dest)) { 1691 if (source < dest) 1691 if (source < dest) 1692 1692 return USE_SOURCE; 1693 1693 return USE_DEST; … … 1709 1709 return USE_SOURCE; 1710 1710 /* 1711 if (SERVER(source) && CLIENT(dest)) 1711 if (SERVER(source) && CLIENT(dest)) 1712 1712 return USE_SOURCE; 1713 1714 if (SERVER(dest) && CLIENT(source)) 1713 1714 if (SERVER(dest) && CLIENT(source)) 1715 1715 return USE_DEST; 1716 if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) 1716 if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) 1717 1717 return USE_SOURCE; 1718 if (ROOT_SERVER(dest) && !ROOT_SERVER(source)) 1718 if (ROOT_SERVER(dest) && !ROOT_SERVER(source)) 1719 1719 return USE_DEST; 1720 1720 */ … … 1722 1722 if (source < dest) { 1723 1723 return USE_SOURCE; 1724 } 1724 } 1725 1725 return USE_DEST; 1726 1726 1727 1727 } 1728 1728 … … 1753 1753 * 1754 1754 * Returns a pointer to the URI data, but updates the format parameter to 1755 * point to a copy of the format component. 1755 * point to a copy of the format component. 1756 1756 */ 1757 1757 1758 1758 DLLEXPORT const char * trace_parse_uri(const char *uri, char **format) { 1759 1759 const char *uridata = 0; 1760 1760 1761 1761 if((uridata = strchr(uri,':')) == NULL) { 1762 1762 /* Badly formed URI - needs a : */ … … 1775 1775 /* Push uridata past the delimiter */ 1776 1776 uridata++; 1777 1777 1778 1778 return uridata; 1779 1779 } 1780 1780 1781 enum base_format_t trace_get_format(libtrace_packet_t *packet) 1781 enum base_format_t trace_get_format(libtrace_packet_t *packet) 1782 1782 { 1783 1783 assert(packet); … … 1785 1785 return packet->trace->format->type; 1786 1786 } 1787 1787 1788 1788 DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace) 1789 1789 { … … 1883 1883 } 1884 1884 if (trace->format->seek_seconds) { 1885 double seconds = 1885 double seconds = 1886 1886 (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX); 1887 1887 return trace->format->seek_seconds(trace,seconds); … … 1907 1907 } 1908 1908 if (trace->format->seek_erf) { 1909 uint64_t timestamp = 1909 uint64_t timestamp = 1910 1910 ((uint64_t)((uint32_t)seconds) << 32) + \ 1911 1911 (uint64_t)(( seconds - (uint32_t)seconds ) * UINT_MAX); … … 1970 1970 1971 1971 1972 /* Creates a libtrace packet from scratch using the contents of the provided 1972 /* Creates a libtrace packet from scratch using the contents of the provided 1973 1973 * buffer as the packet payload. 1974 1974 * 1975 1975 * Unlike trace_prepare_packet(), the buffer should not contain any capture 1976 * format headers; instead this function will add the PCAP header to the 1976 * format headers; instead this function will add the PCAP header to the 1977 1977 * packet record. This also means only PCAP packets can be constructed using 1978 1978 * this function. … … 1996 1996 /* We need a trace to attach the constructed packet to (and it needs 1997 1997 * to be PCAP) */ 1998 if (NULL == deadtrace) 1998 if (NULL == deadtrace) 1999 1999 deadtrace=trace_create_dead("pcapfile"); 2000 2000 … … 2014 2014 2015 2015 /* Now fill in the libtrace packet itself */ 2016 assert(deadtrace); 2016 2017 packet->trace=deadtrace; 2017 2018 size=len+sizeof(hdr); 2019 if (size < LIBTRACE_PACKET_BUFSIZE) 2020 size = LIBTRACE_PACKET_BUFSIZE; 2018 2021 if (packet->buf_control==TRACE_CTRL_PACKET) { 2019 packet->buffer=realloc(packet->buffer,size);2022 packet->buffer = realloc(packet->buffer, size); 2020 2023 } 2021 2024 else { 2022 packet->buffer =malloc(size);2025 packet->buffer = malloc(size); 2023 2026 } 2024 2027 packet->buf_control=TRACE_CTRL_PACKET; 2025 2028 packet->header=packet->buffer; 2026 2029 packet->payload=(void*)((char*)packet->buffer+sizeof(hdr)); 2027 2028 /* Ugh, memcpy - sadly necessary */ 2029 memcpy(packet->header,&hdr,sizeof(hdr)); 2030 memcpy(packet->payload,data,(size_t)len); 2030 2031 /* Ugh, memmove - sadly necessary, also beware that we might be 2032 * moving data around within this packet, so ordering is important. 2033 */ 2034 memmove(packet->payload, data, (size_t)len); 2035 memmove(packet->header, &hdr, sizeof(hdr)); 2031 2036 packet->type=pcap_linktype_to_rt(libtrace_to_pcap_linktype(linktype)); 2032 2037 … … 2298 2303 2299 2304 /* Now, verify that the format has at least the minimum functionality. 2300 * 2305 * 2301 2306 * This #if can be changed to a 1 to output warnings about inconsistent 2302 2307 * functions being provided by format modules. This generally is very 2303 2308 * noisy, as almost all modules don't implement one or more functions 2304 * for various reasons. This is very useful when checking a new 2309 * for various reasons. This is very useful when checking a new 2305 2310 * format module is sane. 2306 */ 2311 */ 2307 2312 #if 0 2308 2313 if (f->init_input) { … … 2318 2323 REQUIRE(get_framing_length); 2319 2324 REQUIRE(trace_event); 2320 if (!f->get_erf_timestamp 2325 if (!f->get_erf_timestamp 2321 2326 && !f->get_seconds 2322 2327 && !f->get_timeval) {
Note: See TracChangeset
for help on using the changeset viewer.