Changeset 1344aa8
- Timestamp:
- 07/03/07 13:34:06 (14 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:
- 721c0e4
- Parents:
- e1fdc05
- Location:
- lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/daglegacy.h
re1fdc05 r1344aa8 22 22 uint32_t ts_sec; 23 23 } PACKED atmhdr_t; 24 25 typedef struct legacy_nzix { 26 uint32_t ts; 27 uint32_t crc; 28 uint32_t len; 29 /* The padding has actually been placed in the middle of the IP 30 * header - when we read in the packet, we will move various bits 31 * of the packet around until the padding ends up here and the 32 * IP header is undivided */ 33 uint8_t pad[2]; 34 } PACKED legacy_nzix_t; 24 35 #endif -
lib/format_legacy.c
re1fdc05 r1344aa8 43 43 #include <string.h> 44 44 #include <stdlib.h> 45 #include <regex.h> 45 46 46 47 #ifdef WIN32 … … 56 57 57 58 #define DATA(x) ((struct legacy_format_data_t *)x->format_data) 58 59 59 #define INPUT DATA(libtrace)->input 60 60 … … 64 64 libtrace_io_t *file; 65 65 } input; 66 time_t starttime; /* Used for legacy_nzix */ 67 uint64_t ts_high; /* Used for legacy_nzix */ 68 uint32_t ts_old; /* Used for legacy_nzix */ 66 69 }; 67 70 … … 81 84 } 82 85 86 static int legacynzix_get_framing_length(const libtrace_packet_t *packet UNUSED) 87 { 88 return sizeof(legacy_nzix_t); 89 } 90 83 91 static int erf_init_input(libtrace_t *libtrace) 84 92 { … … 87 95 DATA(libtrace)->input.file = NULL; 88 96 97 return 0; 98 } 99 100 static time_t trtime(char *s) { 101 /* XXX: this function may not be particularly portable to 102 * other platforms, e.g. *BSDs, Windows */ 103 struct tm tm; 104 char *tz; 105 time_t ret; 106 static char envbuf[256]; 107 108 if(sscanf(s, "%4u%2u%2u-%2u%2u%2u", &tm.tm_year, &tm.tm_mon, 109 &tm.tm_mday, &tm.tm_hour, &tm.tm_min, 110 &tm.tm_sec) != 6) { 111 return (time_t)0; 112 } 113 tm.tm_year = tm.tm_year - 1900; 114 tm.tm_mon --; 115 tm.tm_wday = 0; /* ignored */ 116 tm.tm_yday = 0; /* ignored */ 117 tm.tm_isdst = -1; /* forces check for summer time */ 118 119 tz = getenv("TZ"); 120 if (putenv("TZ=Pacific/Auckland")) { 121 perror("putenv"); 122 return (time_t)0; 123 } 124 tzset(); 125 ret = mktime(&tm); 126 127 return ret; 128 } 129 130 131 static int legacynzix_init_input(libtrace_t *libtrace) { 132 133 int retval; 134 char *filename = libtrace->uridata; 135 regex_t reg; 136 regmatch_t match; 137 138 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 139 140 DATA(libtrace)->input.file = NULL; 141 142 if((retval = regcomp(®, "[0-9]{8}-[0-9]{6}", REG_EXTENDED)) != 0) { 143 trace_set_err(libtrace, errno, "Failed to compile regex"); 144 return -1; 145 } 146 if ((retval = regexec(®, filename, 1, &match, 0)) !=0) { 147 trace_set_err(libtrace, errno, "Failed to exec regex"); 148 return -1; 149 } 150 DATA(libtrace)->starttime = trtime(&filename[match.rm_so]); 151 DATA(libtrace)->ts_high = 0; 152 DATA(libtrace)->ts_old = 0; 89 153 return 0; 90 154 } … … 159 223 } 160 224 225 static int legacynzix_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 226 /* Firstly, I apologize for all the constants being thrown around in 227 * this function, but it does befit the hackish origins of the 228 * NZIX format that I use them. Anyone who wants to clean them up is 229 * welcome to do so */ 230 int numbytes; 231 void *buffer; 232 char *data_ptr; 233 234 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 235 packet->buf_control = TRACE_CTRL_PACKET; 236 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 237 } 238 buffer = packet->buffer; 239 240 packet->type = TRACE_RT_DATA_LEGACY_NZIX; 241 242 while (1) { 243 if ((numbytes = libtrace_io_read(INPUT.file, buffer, 244 (size_t)68)) != 68) { 245 if (numbytes < 0) { 246 trace_set_err(libtrace,errno,"read(%s)",libtrace->uridata); 247 } else if (numbytes > 0) 248 continue; 249 return numbytes; 250 } 251 /* Packets with a zero length are GPS timestamp packets 252 * but they aren't inserted at the right time to be 253 * useful - instead we'll ignore them unless we can think 254 * of a compelling reason to do otherwise */ 255 if (((legacy_nzix_t *)buffer)->len == 0) 256 continue; 257 258 break; 259 } 260 261 /* lets move the padding so that it's in the framing header */ 262 data_ptr = ((char *)buffer) + 12; 263 memmove(data_ptr + 2, data_ptr, 26); 264 265 packet->header = packet->buffer; 266 packet->payload = (void*)((char*)packet->buffer + 267 libtrace->format->get_framing_length(packet)); 268 return 68; 269 } 270 271 161 272 static libtrace_linktype_t legacypos_get_link_type(const libtrace_packet_t *packet UNUSED) { 162 273 return TRACE_TYPE_PPP; … … 171 282 } 172 283 284 static libtrace_linktype_t legacynzix_get_link_type(const libtrace_packet_t *packet UNUSED) { 285 return TRACE_TYPE_ETH; 286 } 287 173 288 static int legacy_get_capture_length(const libtrace_packet_t *packet UNUSED) { 174 289 return 64; 290 } 291 292 static int legacynzix_get_capture_length(const libtrace_packet_t *packet UNUSED) 293 { 294 return 54; 175 295 } 176 296 … … 190 310 } 191 311 312 static int legacynzix_get_wire_length(const libtrace_packet_t *packet) { 313 legacy_nzix_t *lnzix = (legacy_nzix_t *)packet->header; 314 return lnzix->len; 315 } 316 192 317 static uint64_t legacy_get_erf_timestamp(const libtrace_packet_t *packet) 193 318 { … … 195 320 return legacy->ts; 196 321 } 322 323 static uint32_t ts_cmp(uint32_t ts_a, uint32_t ts_b) { 324 325 /* each ts is actually a 30 bit value */ 326 ts_a <<= 2; 327 ts_b <<= 2; 328 329 330 if (ts_a > ts_b) 331 return (ts_a - ts_b); 332 else 333 return (ts_b - ts_a); 334 335 } 336 337 static struct timeval legacynzix_get_timeval(const libtrace_packet_t *packet) { 338 uint64_t new_ts = DATA(packet->trace)->ts_high; 339 uint32_t old_ts = DATA(packet->trace)->ts_old; 340 struct timeval tv; 341 uint32_t hdr_ts; 342 343 double dts; 344 345 legacy_nzix_t *legacy = (legacy_nzix_t *)packet->header; 346 347 hdr_ts = legacy->ts; 348 349 /* seems we only need 30 bits to represent our timestamp */ 350 hdr_ts >>=2; 351 /* try a sequence number wrap-around comparison */ 352 if (ts_cmp(hdr_ts, old_ts) > (UINT32_MAX / 2) ) 353 new_ts += (1LL << 30); /* wraparound */ 354 new_ts &= ~((1LL << 30) -1); /* mask lower 30 bits */ 355 new_ts += hdr_ts; /* packet ts is the new 30 bits */ 356 DATA(packet->trace)->ts_old = hdr_ts; 357 358 tv.tv_sec = DATA(packet->trace)->starttime + (new_ts / (1000 * 1000)); 359 tv.tv_usec = new_ts % (1000 * 1000); 360 DATA(packet->trace)->ts_high = new_ts; 361 362 363 dts = tv.tv_sec + (double)tv.tv_usec / 1000 / 1000; 364 return tv; 365 366 } 197 367 198 368 static void legacypos_help(void) { … … 226 396 printf("\n"); 227 397 printf("\te.g.: legacyeth:/tmp/trace.gz\n"); 398 printf("\n"); 399 } 400 401 static void legacynzix_help(void) { 402 printf("legacynzix format module: $Revision$\n"); 403 printf("Supported input URIs:\n"); 404 printf("\tlegacynzix:/path/to/file\t(uncompressed)\n"); 405 printf("\tlegacynzix:/path/to/file.gz\t(gzip-compressed)\n"); 406 printf("\tlegacynzix:-\t(stdin, either compressed or not)\n"); 407 printf("\n"); 408 printf("\te.g.: legacynzix:/tmp/trace.gz\n"); 228 409 printf("\n"); 229 410 } … … 334 515 }; 335 516 517 static struct libtrace_format_t legacynzix = { 518 "legacynzix", 519 "$Id$", 520 TRACE_FORMAT_LEGACY_NZIX, 521 legacynzix_init_input, /* init_input */ 522 NULL, /* config_input */ 523 erf_start_input, /* start_input */ 524 NULL, /* pause_input */ 525 NULL, /* init_output */ 526 NULL, /* config_output */ 527 NULL, /* start_output */ 528 erf_fin_input, /* fin_input */ 529 NULL, /* fin_output */ 530 legacynzix_read_packet, /* read_packet */ 531 NULL, /* fin_packet */ 532 NULL, /* write_packet */ 533 legacynzix_get_link_type, /* get_link_type */ 534 NULL, /* get_direction */ 535 NULL, /* set_direction */ 536 NULL, /* get_erf_timestamp */ 537 legacynzix_get_timeval, /* get_timeval */ 538 NULL, /* get_seconds */ 539 NULL, /* seek_erf */ 540 NULL, /* seek_timeval */ 541 NULL, /* seek_seconds */ 542 legacynzix_get_capture_length, /* get_capture_length */ 543 legacynzix_get_wire_length, /* get_wire_length */ 544 legacynzix_get_framing_length, /* get_framing_length */ 545 NULL, /* set_capture_length */ 546 NULL, /* get_fd */ 547 trace_event_trace, /* trace_event */ 548 legacynzix_help, /* help */ 549 NULL, /* next pointer */ 550 }; 336 551 337 552 void legacy_constructor(void) { … … 339 554 register_format(&legacyeth); 340 555 register_format(&legacyatm); 341 } 556 register_format(&legacynzix); 557 } -
lib/libtrace.h.in
re1fdc05 r1344aa8 263 263 TRACE_FORMAT_BPF =11, 264 264 TRACE_FORMAT_TSH =12, 265 TRACE_FORMAT_ATMHDR =13 265 TRACE_FORMAT_ATMHDR =13, 266 TRACE_FORMAT_LEGACY_NZIX =14 266 267 }; 267 268 … … 301 302 302 303 TRACE_RT_DATA_ATMHDR = TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_ATMHDR, 304 TRACE_RT_DATA_LEGACY_NZIX=TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_LEGACY_NZIX, 303 305 TRACE_RT_DATA_DLT = 2000, /**< Pcap doesn't store the 304 306 * linktype per packet, and -
lib/protocols.c
r7c72e4d r1344aa8 336 336 break; 337 337 } 338 fprintf(stderr, "Don't understand link layer type %i in trace_get_payload_from_link()\n",338 fprintf(stderr, "Don't understand link layer type %i in trace_get_payload_from_link()\n", 339 339 linktype); 340 340 return NULL;
Note: See TracChangeset
for help on using the changeset viewer.