tcpreplay_api.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2018 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  5. *
  6. * The Tcpreplay Suite of tools is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or with the authors permission any later version.
  10. *
  11. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "config.h"
  20. #include "defines.h"
  21. #include "common.h"
  22. #include <ctype.h>
  23. #include <fcntl.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <sys/types.h>
  28. #include <unistd.h>
  29. #include <errno.h>
  30. #include <stdarg.h>
  31. #include "tcpreplay_api.h"
  32. #include "send_packets.h"
  33. #include "replay.h"
  34. #ifdef TCPREPLAY_EDIT
  35. #include "tcpreplay_edit_opts.h"
  36. #else
  37. #include "tcpreplay_opts.h"
  38. #endif
  39. /**
  40. * \brief Returns a string describing the last error.
  41. *
  42. * Value when the last call does not result in an error is undefined
  43. * (may be NULL, may be garbage)
  44. */
  45. char *
  46. tcpreplay_geterr(tcpreplay_t *ctx)
  47. {
  48. assert(ctx);
  49. return(ctx->errstr);
  50. }
  51. /**
  52. * \brief Returns a string describing the last warning.
  53. *
  54. * Value when the last call does not result in an warning is undefined
  55. * (may be NULL, may be garbage)
  56. */
  57. char *
  58. tcpreplay_getwarn(tcpreplay_t *ctx)
  59. {
  60. assert(ctx);
  61. return(ctx->warnstr);
  62. }
  63. /**
  64. * \brief Initialize a new tcpreplay context
  65. *
  66. * Allocates memory and stuff like that. Always returns a buffer or completely
  67. * fails by calling exit() on malloc failure.
  68. */
  69. tcpreplay_t *
  70. tcpreplay_init()
  71. {
  72. tcpreplay_t *ctx;
  73. /* allocations will reset everything to zeros */
  74. ctx = safe_malloc(sizeof(tcpreplay_t));
  75. ctx->options = safe_malloc(sizeof(tcpreplay_opt_t));
  76. /* replay packets only once */
  77. ctx->options->loop = 1;
  78. /* Default mode is to replay pcap once in real-time */
  79. ctx->options->speed.mode = speed_multiplier;
  80. ctx->options->speed.multiplier = 1.0;
  81. /* Set the default timing method */
  82. ctx->options->accurate = accurate_gtod;
  83. /* set the default MTU size */
  84. ctx->options->mtu = DEFAULT_MTU;
  85. /* disable periodic statistics */
  86. ctx->options->stats = -1;
  87. /* disable limit send */
  88. ctx->options->limit_send = -1;
  89. /* default unique-loops */
  90. ctx->options->unique_loops = 1.0;
  91. #ifdef ENABLE_VERBOSE
  92. /* clear out tcpdump struct */
  93. ctx->options->tcpdump = (tcpdump_t *)safe_malloc(sizeof(tcpdump_t));
  94. #endif
  95. if (fcntl(STDERR_FILENO, F_SETFL, O_NONBLOCK) < 0)
  96. tcpreplay_setwarn(ctx, "Unable to set STDERR to non-blocking: %s", strerror(errno));
  97. #ifdef ENABLE_PCAP_FINDALLDEVS
  98. ctx->intlist = get_interface_list();
  99. #else
  100. ctx->intlist = NULL;
  101. #endif
  102. /* set up flows - on by default*/
  103. ctx->options->flow_stats = 1;
  104. ctx->flow_hash_table = flow_hash_table_init(DEFAULT_FLOW_HASH_BUCKET_SIZE);
  105. ctx->sp_type = SP_TYPE_NONE;
  106. ctx->intf1dlt = -1;
  107. ctx->intf2dlt = -1;
  108. ctx->abort = false;
  109. ctx->first_time = true;
  110. return ctx;
  111. }
  112. /**
  113. * \brief Parses the GNU AutoOpts options for tcpreplay
  114. *
  115. * If you're using AutoOpts with tcpreplay_api, then just call this after
  116. * optionProcess() and it will parse all the options for you. As always,
  117. * returns 0 on success, and -1 on error & -2 on warning.
  118. */
  119. int
  120. tcpreplay_post_args(tcpreplay_t *ctx, int argc)
  121. {
  122. char *temp, *intname;
  123. char *ebuf;
  124. tcpreplay_opt_t *options;
  125. int warn = 0;
  126. float n;
  127. int ret = 0;
  128. options = ctx->options;
  129. dbg(2, "tcpreplay_post_args: parsing command arguments");
  130. ebuf = safe_malloc(SENDPACKET_ERRBUF_SIZE);
  131. #ifdef DEBUG
  132. if (HAVE_OPT(DBUG))
  133. debug = OPT_VALUE_DBUG;
  134. #else
  135. if (HAVE_OPT(DBUG)) {
  136. warn ++;
  137. tcpreplay_setwarn(ctx, "%s", "not configured with --enable-debug. Debugging disabled.");
  138. }
  139. #endif
  140. options->loop = OPT_VALUE_LOOP;
  141. options->loopdelay_ms = OPT_VALUE_LOOPDELAY_MS;
  142. if (HAVE_OPT(LIMIT))
  143. options->limit_send = OPT_VALUE_LIMIT;
  144. if (HAVE_OPT(DURATION))
  145. options->limit_time = OPT_VALUE_DURATION;
  146. if (HAVE_OPT(TOPSPEED)) {
  147. options->speed.mode = speed_topspeed;
  148. options->speed.speed = 0;
  149. } else if (HAVE_OPT(PPS)) {
  150. n = atof(OPT_ARG(PPS));
  151. options->speed.speed = (COUNTER)(n * 60.0 * 60.0); /* convert to packets per hour */
  152. options->speed.mode = speed_packetrate;
  153. options->speed.pps_multi = OPT_VALUE_PPS_MULTI;
  154. } else if (HAVE_OPT(ONEATATIME)) {
  155. options->speed.mode = speed_oneatatime;
  156. options->speed.speed = 0;
  157. } else if (HAVE_OPT(MBPS)) {
  158. n = atof(OPT_ARG(MBPS));
  159. if (n) {
  160. options->speed.mode = speed_mbpsrate;
  161. options->speed.speed = (COUNTER)(n * 1000000.0); /* convert to bps */
  162. } else {
  163. options->speed.mode = speed_topspeed;
  164. options->speed.speed = 0;
  165. }
  166. } else if (HAVE_OPT(MULTIPLIER)) {
  167. options->speed.mode = speed_multiplier;
  168. options->speed.multiplier = atof(OPT_ARG(MULTIPLIER));
  169. }
  170. if (HAVE_OPT(MAXSLEEP)) {
  171. options->maxsleep.tv_sec = OPT_VALUE_MAXSLEEP / 1000;
  172. options->maxsleep.tv_nsec = (OPT_VALUE_MAXSLEEP % 1000) * 1000 * 1000;
  173. }
  174. #ifdef ENABLE_VERBOSE
  175. if (HAVE_OPT(VERBOSE))
  176. options->verbose = 1;
  177. if (HAVE_OPT(DECODE))
  178. options->tcpdump->args = safe_strdup(OPT_ARG(DECODE));
  179. #endif
  180. if (HAVE_OPT(STATS))
  181. options->stats = OPT_VALUE_STATS;
  182. /*
  183. * preloading the pcap before the first run
  184. */
  185. if (HAVE_OPT(PRELOAD_PCAP)) {
  186. options->preload_pcap = true;
  187. }
  188. /* Dual file mode */
  189. if (HAVE_OPT(DUALFILE)) {
  190. options->dualfile = true;
  191. if (argc < 2) {
  192. tcpreplay_seterr(ctx, "%s", "--dualfile mode requires at least two pcap files");
  193. ret = -1;
  194. goto out;
  195. }
  196. if (argc % 2 != 0) {
  197. tcpreplay_seterr(ctx, "%s", "--dualfile mode requires an even number of pcap files");
  198. ret = -1;
  199. goto out;
  200. }
  201. }
  202. #ifdef HAVE_NETMAP
  203. options->netmap_delay = OPT_VALUE_NM_DELAY;
  204. #endif
  205. if (HAVE_OPT(NETMAP)) {
  206. #ifdef HAVE_NETMAP
  207. options->netmap = 1;
  208. ctx->sp_type = SP_TYPE_NETMAP;
  209. #else
  210. err(-1, "--netmap feature was not compiled in. See INSTALL.");
  211. #endif
  212. }
  213. if (HAVE_OPT(UNIQUE_IP))
  214. options->unique_ip = 1;
  215. if (HAVE_OPT(UNIQUE_IP_LOOPS)) {
  216. options->unique_loops = atof(OPT_ARG(UNIQUE_IP_LOOPS));
  217. if (options->unique_loops < 1.0) {
  218. tcpreplay_seterr(ctx, "%s", "--unique-ip-loops requires loop count >= 1.0");
  219. ret = -1;
  220. goto out;
  221. }
  222. }
  223. /* flow statistics */
  224. if (HAVE_OPT(NO_FLOW_STATS))
  225. options->flow_stats = 0;
  226. if (HAVE_OPT(FLOW_EXPIRY)) {
  227. options->flow_expiry = OPT_VALUE_FLOW_EXPIRY;
  228. }
  229. if (HAVE_OPT(TIMER)) {
  230. if (strcmp(OPT_ARG(TIMER), "select") == 0) {
  231. #ifdef HAVE_SELECT
  232. options->accurate = accurate_select;
  233. #else
  234. tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with select support");
  235. ret = -1;
  236. goto out;
  237. #endif
  238. } else if (strcmp(OPT_ARG(TIMER), "ioport") == 0) {
  239. #if defined HAVE_IOPORT_SLEEP__
  240. options.accurate = ACCURATE_IOPORT;
  241. ioport_sleep_init();
  242. #else
  243. err(-1, "tcpreplay not compiled with IO Port 0x80 support");
  244. #endif
  245. } else if (strcmp(OPT_ARG(TIMER), "gtod") == 0) {
  246. options->accurate = accurate_gtod;
  247. } else if (strcmp(OPT_ARG(TIMER), "nano") == 0) {
  248. options->accurate = accurate_nanosleep;
  249. } else if (strcmp(OPT_ARG(TIMER), "abstime") == 0) {
  250. tcpreplay_seterr(ctx, "%s", "abstime is deprecated");
  251. ret = -1;
  252. goto out;
  253. } else {
  254. tcpreplay_seterr(ctx, "Unsupported timer mode: %s", OPT_ARG(TIMER));
  255. ret = -1;
  256. goto out;
  257. }
  258. }
  259. #ifdef HAVE_RDTSC
  260. if (HAVE_OPT(RDTSC_CLICKS)) {
  261. rdtsc_calibrate(OPT_VALUE_RDTSC_CLICKS);
  262. }
  263. #endif
  264. if (HAVE_OPT(PKTLEN)) {
  265. options->use_pkthdr_len = true;
  266. warn ++;
  267. tcpreplay_setwarn(ctx, "%s", "--pktlen may cause problems. Use with caution.");
  268. }
  269. if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF1))) == NULL) {
  270. if (!strncmp(OPT_ARG(INTF1), "netmap:", 7) || !strncmp(OPT_ARG(INTF1), "vale", 4))
  271. tcpreplay_seterr(ctx, "Unable to connect to netmap interface %s. Ensure netmap module is installed (see INSTALL).",
  272. OPT_ARG(INTF1));
  273. else
  274. tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF1));
  275. ret = -1;
  276. goto out;
  277. }
  278. if (!strncmp(intname, "netmap:", 7) || !strncmp(intname, "vale:", 5)) {
  279. #ifdef HAVE_NETMAP
  280. options->netmap = 1;
  281. ctx->sp_type = SP_TYPE_NETMAP;
  282. #else
  283. tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with netmap support");
  284. ret = -1;
  285. goto out;
  286. #endif
  287. }
  288. options->intf1_name = safe_strdup(intname);
  289. /* open interfaces for writing */
  290. if ((ctx->intf1 = sendpacket_open(options->intf1_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
  291. tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf1_name, ebuf);
  292. ret = -1;
  293. goto out;
  294. }
  295. #if defined HAVE_NETMAP
  296. ctx->intf1->netmap_delay = ctx->options->netmap_delay;
  297. #endif
  298. ctx->intf1dlt = sendpacket_get_dlt(ctx->intf1);
  299. if (HAVE_OPT(INTF2)) {
  300. if (!HAVE_OPT(CACHEFILE) && !HAVE_OPT(DUALFILE)) {
  301. tcpreplay_seterr(ctx, "--intf2=%s requires either --cachefile or --dualfile", OPT_ARG(INTF2));
  302. ret = -1;
  303. goto out;
  304. }
  305. if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF2))) == NULL) {
  306. tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF2));
  307. ret = -1;
  308. goto out;
  309. }
  310. options->intf2_name = safe_strdup(intname);
  311. /* open interface for writing */
  312. if ((ctx->intf2 = sendpacket_open(options->intf2_name, ebuf, TCPR_DIR_S2C, ctx->sp_type, ctx)) == NULL) {
  313. tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf2_name, ebuf);
  314. }
  315. #if defined HAVE_NETMAP
  316. ctx->intf2->netmap_delay = ctx->options->netmap_delay;
  317. #endif
  318. ctx->intf2dlt = sendpacket_get_dlt(ctx->intf2);
  319. if (ctx->intf2dlt != ctx->intf1dlt) {
  320. tcpreplay_seterr(ctx, "DLT type mismatch for %s (%s) and %s (%s)",
  321. options->intf1_name, pcap_datalink_val_to_name(ctx->intf1dlt),
  322. options->intf2_name, pcap_datalink_val_to_name(ctx->intf2dlt));
  323. ret = -1;
  324. goto out;
  325. }
  326. }
  327. if (HAVE_OPT(CACHEFILE)) {
  328. temp = safe_strdup(OPT_ARG(CACHEFILE));
  329. options->cache_packets = read_cache(&options->cachedata, temp,
  330. &options->comment);
  331. safe_free(temp);
  332. }
  333. /* return -2 on warnings */
  334. if (warn > 0)
  335. ret = -2;
  336. out:
  337. safe_free(ebuf);
  338. return ret;
  339. }
  340. /**
  341. * Closes & free's all memory related to a tcpreplay context
  342. */
  343. void
  344. tcpreplay_close(tcpreplay_t *ctx)
  345. {
  346. tcpreplay_opt_t *options;
  347. interface_list_t *intlist, *intlistnext;
  348. packet_cache_t *packet_cache, *next;
  349. assert(ctx);
  350. assert(ctx->options);
  351. options = ctx->options;
  352. safe_free(options->intf1_name);
  353. safe_free(options->intf2_name);
  354. sendpacket_close(ctx->intf1);
  355. if (ctx->intf2 != NULL)
  356. sendpacket_close(ctx->intf2);
  357. safe_free(options->cachedata);
  358. safe_free(options->comment);
  359. #ifdef ENABLE_VERBOSE
  360. safe_free(options->tcpdump_args);
  361. tcpdump_close(options->tcpdump);
  362. #endif
  363. /* free the flow hash table */
  364. flow_hash_table_release(ctx->flow_hash_table);
  365. /* free the file cache */
  366. packet_cache = options->file_cache->packet_cache;
  367. while (packet_cache != NULL) {
  368. next = packet_cache->next;
  369. safe_free(packet_cache->pktdata);
  370. safe_free(packet_cache);
  371. packet_cache = next;
  372. }
  373. /* free our interface list */
  374. if (ctx->intlist != NULL) {
  375. intlist = ctx->intlist;
  376. while (intlist != NULL) {
  377. intlistnext = intlist->next;
  378. safe_free(intlist);
  379. intlist = intlistnext;
  380. }
  381. }
  382. }
  383. /**
  384. * \brief Specifies an interface to use for sending.
  385. *
  386. * You may call this up to two (2) times with different interfaces
  387. * when using a tcpprep cache file or dualfile mode. Note, both interfaces
  388. * must use the same DLT type
  389. */
  390. int
  391. tcpreplay_set_interface(tcpreplay_t *ctx, tcpreplay_intf intf, char *value)
  392. {
  393. static int int1dlt = -1, int2dlt = -1;
  394. char *intname;
  395. char *ebuf;
  396. int ret = 0;
  397. assert(ctx);
  398. assert(value);
  399. ebuf = safe_malloc(SENDPACKET_ERRBUF_SIZE);
  400. if (intf == intf1) {
  401. if ((intname = get_interface(ctx->intlist, value)) == NULL) {
  402. if (!strncmp(OPT_ARG(INTF1), "netmap:", 7) || !strncmp(OPT_ARG(INTF1), "vale", 4))
  403. tcpreplay_seterr(ctx, "Unable to connect to netmap interface %s. Ensure netmap module is installed (see INSTALL).",
  404. value);
  405. else
  406. tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", value);
  407. ret = -1;
  408. goto out;
  409. }
  410. ctx->options->intf1_name = safe_strdup(intname);
  411. /* open interfaces for writing */
  412. if ((ctx->intf1 = sendpacket_open(ctx->options->intf1_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
  413. tcpreplay_seterr(ctx, "Can't open %s: %s", ctx->options->intf1_name, ebuf);
  414. ret = -1;
  415. goto out;
  416. }
  417. int1dlt = sendpacket_get_dlt(ctx->intf1);
  418. } else if (intf == intf2) {
  419. if ((intname = get_interface(ctx->intlist, value)) == NULL) {
  420. tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", ctx->options->intf2_name);
  421. ret = -1;
  422. goto out;
  423. }
  424. ctx->options->intf2_name = safe_strdup(intname);
  425. /* open interface for writing */
  426. if ((ctx->intf2 = sendpacket_open(ctx->options->intf2_name, ebuf, TCPR_DIR_S2C, ctx->sp_type, ctx)) == NULL) {
  427. tcpreplay_seterr(ctx, "Can't open %s: %s", ctx->options->intf2_name, ebuf);
  428. ret = -1;
  429. goto out;
  430. }
  431. int2dlt = sendpacket_get_dlt(ctx->intf2);
  432. }
  433. /*
  434. * If both interfaces are selected, then make sure both interfaces use
  435. * the same DLT type
  436. */
  437. if (int1dlt != -1 && int2dlt != -1) {
  438. if (int1dlt != int2dlt) {
  439. tcpreplay_seterr(ctx, "DLT type mismatch for %s (%s) and %s (%s)",
  440. ctx->options->intf1_name, pcap_datalink_val_to_name(int1dlt),
  441. ctx->options->intf2_name, pcap_datalink_val_to_name(int2dlt));
  442. ret = -1;
  443. goto out;
  444. }
  445. }
  446. out:
  447. safe_free(ebuf);
  448. return ret;
  449. }
  450. /**
  451. * Set the replay speed mode.
  452. */
  453. int
  454. tcpreplay_set_speed_mode(tcpreplay_t *ctx, tcpreplay_speed_mode value)
  455. {
  456. assert(ctx);
  457. ctx->options->speed.mode = value;
  458. return 0;
  459. }
  460. /**
  461. * Set the approprate speed value. Value is interpreted based on
  462. * how tcpreplay_set_speed_mode() value
  463. */
  464. int
  465. tcpreplay_set_speed_speed(tcpreplay_t *ctx, COUNTER value)
  466. {
  467. assert(ctx);
  468. ctx->options->speed.speed = value;
  469. return 0;
  470. }
  471. /**
  472. * Sending under packets/sec requires an integer value, not float.
  473. * you must first call tcpreplay_set_speed_mode(ctx, speed_packetrate)
  474. */
  475. int
  476. tcpreplay_set_speed_pps_multi(tcpreplay_t *ctx, int value)
  477. {
  478. assert(ctx);
  479. ctx->options->speed.pps_multi = value;
  480. return 0;
  481. }
  482. /**
  483. * How many times should we loop through all the pcap files?
  484. */
  485. int
  486. tcpreplay_set_loop(tcpreplay_t *ctx, u_int32_t value)
  487. {
  488. assert(ctx);
  489. ctx->options->loop = value;
  490. return 0;
  491. }
  492. /**
  493. * Set the unique IP address flag
  494. */
  495. int
  496. tcpreplay_set_unique_ip(tcpreplay_t *ctx, bool value)
  497. {
  498. assert(ctx);
  499. ctx->options->unique_ip = value;
  500. return 0;
  501. }
  502. int
  503. tcpreplay_set_unique_ip_loops(tcpreplay_t *ctx, int value)
  504. {
  505. assert(ctx);
  506. ctx->options->unique_loops = value;
  507. return 0;
  508. }
  509. /**
  510. * Set netmap mode
  511. */
  512. int
  513. tcpreplay_set_netmap(_U_ tcpreplay_t *ctx, _U_ bool value)
  514. {
  515. assert(ctx);
  516. #ifdef HAVE_NETMAP
  517. ctx->options->netmap = value;
  518. return 0;
  519. #else
  520. warn("netmap not compiled in");
  521. return -1;
  522. #endif
  523. }
  524. /**
  525. * Tell tcpreplay to ignore the snaplen (default) and use the "actual"
  526. * packet len instead
  527. */
  528. int
  529. tcpreplay_set_use_pkthdr_len(tcpreplay_t *ctx, bool value)
  530. {
  531. assert(ctx);
  532. ctx->options->use_pkthdr_len = value;
  533. return 0;
  534. }
  535. /**
  536. * Override the outbound MTU
  537. */
  538. int
  539. tcpreplay_set_mtu(tcpreplay_t *ctx, int value)
  540. {
  541. assert(ctx);
  542. ctx->options->mtu = value;
  543. return 0;
  544. }
  545. /**
  546. * Sets the accurate timing mode
  547. */
  548. int
  549. tcpreplay_set_accurate(tcpreplay_t *ctx, tcpreplay_accurate value)
  550. {
  551. assert(ctx);
  552. ctx->options->accurate = value;
  553. return 0;
  554. }
  555. /**
  556. * Sets the number of seconds between printing stats
  557. */
  558. int
  559. tcpreplay_set_stats(tcpreplay_t *ctx, int value)
  560. {
  561. assert(ctx);
  562. ctx->options->stats = value;
  563. return 0;
  564. }
  565. /**
  566. * \brief Enable or disable dual file mode
  567. *
  568. * In dual file mode, we read two files at the same time and use
  569. * one file for each interface.
  570. */
  571. int
  572. tcpreplay_set_dualfile(tcpreplay_t *ctx, bool value)
  573. {
  574. assert(ctx);
  575. ctx->options->dualfile = value;
  576. return 0;
  577. }
  578. /**
  579. * \brief Enable or disable preloading the file cache
  580. *
  581. * Note: This is a global option and forces all pcaps
  582. * to be preloaded for this context. If you turn this
  583. * on, then it forces set_file_cache(true)
  584. */
  585. int
  586. tcpreplay_set_preload_pcap(tcpreplay_t *ctx, bool value)
  587. {
  588. assert(ctx);
  589. ctx->options->preload_pcap = value;
  590. return 0;
  591. }
  592. /**
  593. * \brief Add a pcap file to be sent via tcpreplay
  594. *
  595. * One or more pcap files can be added. Each file will be replayed
  596. * in order
  597. */
  598. int
  599. tcpreplay_add_pcapfile(tcpreplay_t *ctx, char *pcap_file)
  600. {
  601. assert(ctx);
  602. assert(pcap_file);
  603. if (ctx->options->source_cnt < MAX_FILES) {
  604. ctx->options->sources[ctx->options->source_cnt].filename = safe_strdup(pcap_file);
  605. ctx->options->sources[ctx->options->source_cnt].type = source_filename;
  606. /*
  607. * prepare the cache info data struct. This doesn't actually enable
  608. * file caching for this pcap (that is controlled globally via
  609. * tcpreplay_set_file_cache())
  610. */
  611. ctx->options->file_cache[ctx->options->source_cnt].index = ctx->options->source_cnt;
  612. ctx->options->file_cache[ctx->options->source_cnt].cached = false;
  613. ctx->options->file_cache[ctx->options->source_cnt].packet_cache = NULL;
  614. ctx->options->source_cnt += 1;
  615. } else {
  616. tcpreplay_seterr(ctx, "Unable to add more then %u files", MAX_FILES);
  617. return -1;
  618. }
  619. return 0;
  620. }
  621. /**
  622. * Limit the total number of packets to send
  623. */
  624. int
  625. tcpreplay_set_limit_send(tcpreplay_t *ctx, COUNTER value)
  626. {
  627. assert(ctx);
  628. ctx->options->limit_send = value;
  629. return 0;
  630. }
  631. /**
  632. * \brief Specify the tcpprep cache file to use for replaying with two NICs
  633. *
  634. * Note: this only works if you have a single pcap file
  635. * returns -1 on error
  636. */
  637. int
  638. tcpreplay_set_tcpprep_cache(tcpreplay_t *ctx, char *file)
  639. {
  640. assert(ctx);
  641. char *tcpprep_file;
  642. if (ctx->options->source_cnt > 1) {
  643. tcpreplay_seterr(ctx, "%s", "Unable to use tcpprep cache file with a single pcap file");
  644. return -1;
  645. }
  646. tcpprep_file = safe_strdup(file);
  647. ctx->options->cache_packets = read_cache(&ctx->options->cachedata,
  648. tcpprep_file, &ctx->options->comment);
  649. free(tcpprep_file);
  650. return 0;
  651. }
  652. /*
  653. * Verbose mode requires fork() and tcpdump binary, hence won't work
  654. * under Win32 without Cygwin
  655. */
  656. /**
  657. * Enable verbose mode
  658. */
  659. int
  660. tcpreplay_set_verbose(tcpreplay_t *ctx, bool value)
  661. {
  662. assert(ctx);
  663. #ifdef ENABLE_VERBOSE
  664. ctx->options->verbose = value;
  665. return 0;
  666. #else
  667. tcpreplay_seterr(ctx, "%s", "verbose mode not supported");
  668. return -1;
  669. #endif
  670. }
  671. /**
  672. * \brief Set the arguments to be passed to tcpdump
  673. *
  674. * Specify the additional argument to be passed to tcpdump when enabling
  675. * verbose mode. See TCPDUMP_ARGS in tcpdump.h for the default options
  676. */
  677. int
  678. tcpreplay_set_tcpdump_args(tcpreplay_t *ctx, char *value)
  679. {
  680. assert(ctx);
  681. #ifdef ENABLE_VERBOSE
  682. assert(value);
  683. ctx->options->tcpdump_args = safe_strdup(value);
  684. return 0;
  685. #else
  686. tcpreplay_seterr(ctx, "%s", "verbose mode not supported");
  687. return -1;
  688. #endif
  689. }
  690. /**
  691. * \brief Set the path to the tcpdump binary
  692. *
  693. * In order to support the verbose feature, tcpreplay needs to know where
  694. * tcpdump lives
  695. */
  696. int
  697. tcpreplay_set_tcpdump(tcpreplay_t *ctx, tcpdump_t *value)
  698. {
  699. assert(ctx);
  700. #ifdef ENABLE_VERBOSE
  701. assert(value);
  702. ctx->options->verbose = true;
  703. ctx->options->tcpdump = value;
  704. return 0;
  705. #else
  706. tcpreplay_seterr(ctx, "%s", "verbose mode not supported");
  707. return -1;
  708. #endif
  709. }
  710. /**
  711. * \brief Set the callback function for handing manual iteration
  712. *
  713. * Obviously for this to work, you need to first set speed_mode = speed_oneatatime
  714. * returns 0 on success, < 0 on error
  715. */
  716. int
  717. tcpreplay_set_manual_callback(tcpreplay_t *ctx, tcpreplay_manual_callback callback)
  718. {
  719. assert(ctx);
  720. assert(callback);
  721. if (ctx->options->speed.mode != speed_oneatatime) {
  722. tcpreplay_seterr(ctx, "%s",
  723. "Unable to set manual callback because speed mode is not 'speed_oneatatime'");
  724. return -1;
  725. }
  726. ctx->options->speed.manual_callback = callback;
  727. return 0;
  728. }
  729. /**
  730. * \brief return the number of packets sent so far
  731. */
  732. COUNTER
  733. tcpreplay_get_pkts_sent(tcpreplay_t *ctx)
  734. {
  735. assert(ctx);
  736. ctx->static_stats.pkts_sent = ctx->stats.pkts_sent;
  737. return ctx->static_stats.pkts_sent;
  738. }
  739. /**
  740. * \brief return the number of bytes sent so far
  741. */
  742. COUNTER
  743. tcpreplay_get_bytes_sent(tcpreplay_t *ctx)
  744. {
  745. assert(ctx);
  746. ctx->static_stats.bytes_sent = ctx->stats.bytes_sent;
  747. return ctx->static_stats.bytes_sent;
  748. }
  749. /**
  750. * \brief return the number of failed attempts to send a packet
  751. */
  752. COUNTER
  753. tcpreplay_get_failed(tcpreplay_t *ctx)
  754. {
  755. assert(ctx);
  756. ctx->static_stats.failed = ctx->stats.failed;
  757. return ctx->static_stats.failed;
  758. }
  759. /**
  760. * \brief returns a pointer to the timeval structure of when replay first started
  761. */
  762. const struct timeval *
  763. tcpreplay_get_start_time(tcpreplay_t *ctx)
  764. {
  765. assert(ctx);
  766. TIMEVAL_SET(&ctx->static_stats.start_time, &ctx->stats.start_time);
  767. return &ctx->static_stats.start_time;
  768. }
  769. /**
  770. * \brief returns a pointer to the timeval structure of when replay finished
  771. */
  772. const struct timeval *
  773. tcpreplay_get_end_time(tcpreplay_t *ctx)
  774. {
  775. assert(ctx);
  776. TIMEVAL_SET(&ctx->static_stats.end_time, &ctx->stats.end_time);
  777. return &ctx->static_stats.end_time;
  778. }
  779. /**
  780. * \brief Internal function to set the tcpreplay error string
  781. *
  782. * Used to set the error string when there is an error, result is retrieved
  783. * using tcpedit_geterr(). You shouldn't ever actually call this, but use
  784. * tcpreplay_seterr() which is a macro wrapping this instead.
  785. */
  786. void
  787. __tcpreplay_seterr(tcpreplay_t *ctx, const char *func,
  788. const int line, const char *file, const char *fmt, ...)
  789. {
  790. va_list ap;
  791. char errormsg[TCPREPLAY_ERRSTR_LEN];
  792. assert(ctx);
  793. assert(file);
  794. assert(func);
  795. assert(line);
  796. va_start(ap, fmt);
  797. if (fmt != NULL) {
  798. (void)vsnprintf(errormsg,
  799. (TCPREPLAY_ERRSTR_LEN - 1), fmt, ap);
  800. }
  801. va_end(ap);
  802. #ifdef DEBUG
  803. snprintf(ctx->errstr, (TCPREPLAY_ERRSTR_LEN -1), "From %s:%s() line %d:\n%s",
  804. file, func, line, errormsg);
  805. #else
  806. snprintf(ctx->errstr, (TCPREPLAY_ERRSTR_LEN -1), "%s", errormsg);
  807. #endif
  808. }
  809. /**
  810. * \brief Internal function to set the tcpedit warning string
  811. *
  812. * Used to set the warning string when there is an non-fatal issue, result is retrieved
  813. * using tcpedit_getwarn().
  814. */
  815. void
  816. tcpreplay_setwarn(tcpreplay_t *ctx, const char *fmt, ...)
  817. {
  818. va_list ap;
  819. assert(ctx);
  820. va_start(ap, fmt);
  821. if (fmt != NULL)
  822. (void)vsnprintf(ctx->warnstr, (TCPREPLAY_ERRSTR_LEN - 1), fmt, ap);
  823. va_end(ap);
  824. }
  825. /**
  826. * \brief Does all the prep work before calling tcpreplay_replay()
  827. *
  828. * Technically this validates our config options, preloads the tcpprep
  829. * cache file, loads the packet cache and anything else which might
  830. * cause a delay for starting to send packets with tcpreplay_replay()
  831. */
  832. int
  833. tcpreplay_prepare(tcpreplay_t *ctx)
  834. {
  835. char *intname, *ebuf;
  836. int int1dlt, int2dlt, i;
  837. int ret = 0;
  838. assert(ctx);
  839. ebuf = safe_malloc(SENDPACKET_ERRBUF_SIZE);
  840. /*
  841. * First, process the validations, basically the same we do in
  842. * tcpreplay_post_args() and AutoOpts
  843. */
  844. if (ctx->options->intf1_name == NULL) {
  845. tcpreplay_seterr(ctx, "%s", "You must specify at least one network interface");
  846. ret = -1;
  847. goto out;
  848. }
  849. if (ctx->options->source_cnt == 0) {
  850. tcpreplay_seterr(ctx, "%s", "You must specify at least one source pcap");
  851. ret = -1;
  852. goto out;
  853. }
  854. if (ctx->options->dualfile) {
  855. if (!(ctx->options->source_cnt >= 2)) {
  856. tcpreplay_seterr(ctx, "%s", "Dual file mode requires 2 or more pcap files");
  857. ret = -1;
  858. goto out;
  859. }
  860. if (ctx->options->source_cnt % 2 != 0) {
  861. tcpreplay_seterr(ctx, "%s", "Dual file mode requires an even number of pcap files");
  862. ret = -1;
  863. goto out;
  864. }
  865. }
  866. if (ctx->options->dualfile && ctx->options->cachedata != NULL) {
  867. tcpreplay_seterr(ctx, "%s", "Can't use dual file mode and tcpprep cache file together");
  868. ret = -1;
  869. goto out;
  870. }
  871. if ((ctx->options->dualfile || ctx->options->cachedata != NULL) &&
  872. ctx->options->intf2_name == NULL) {
  873. tcpreplay_seterr(ctx, "%s", "dual file mode and tcpprep cache files require two interfaces");
  874. }
  875. #ifndef HAVE_SELECT
  876. if (ctx->options->accurate == accurate_select) {
  877. tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with select support");
  878. ret = -1;
  879. goto out;
  880. }
  881. #endif
  882. if ((intname = get_interface(ctx->intlist, ctx->options->intf1_name)) == NULL) {
  883. if (!strncmp(OPT_ARG(INTF1), "netmap:", 7) || !strncmp(OPT_ARG(INTF1), "vale", 4))
  884. tcpreplay_seterr(ctx, "Unable to connect to netmap interface %s. Ensure netmap module is installed (see INSTALL).",
  885. OPT_ARG(INTF1));
  886. else
  887. tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF1));
  888. ret = -1;
  889. goto out;
  890. }
  891. /* open interfaces for writing */
  892. if ((ctx->intf1 = sendpacket_open(ctx->options->intf1_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
  893. tcpreplay_seterr(ctx, "Can't open %s: %s", ctx->options->intf1_name, ebuf);
  894. ret = -1;
  895. goto out;
  896. }
  897. int1dlt = sendpacket_get_dlt(ctx->intf1);
  898. if (ctx->options->intf2_name != NULL) {
  899. if ((intname = get_interface(ctx->intlist, ctx->options->intf2_name)) == NULL) {
  900. tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF2));
  901. ret = -1;
  902. goto out;
  903. }
  904. /* open interfaces for writing */
  905. if ((ctx->intf2 = sendpacket_open(ctx->options->intf2_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
  906. tcpreplay_seterr(ctx, "Can't open %s: %s", ctx->options->intf2_name, ebuf);
  907. ret = -1;
  908. goto out;
  909. }
  910. int2dlt = sendpacket_get_dlt(ctx->intf2);
  911. if (int2dlt != int1dlt) {
  912. tcpreplay_seterr(ctx, "DLT type mismatch for %s (%s) and %s (%s)",
  913. ctx->options->intf1_name, pcap_datalink_val_to_name(int1dlt),
  914. ctx->options->intf2_name, pcap_datalink_val_to_name(int2dlt));
  915. ret = -1;
  916. goto out;
  917. }
  918. }
  919. /*
  920. * Setup up the file cache, if required
  921. */
  922. if (ctx->options->preload_pcap) {
  923. /* Initialise each of the file cache structures */
  924. for (i = 0; i < ctx->options->source_cnt; i++) {
  925. ctx->options->file_cache[i].index = i;
  926. ctx->options->file_cache[i].cached = FALSE;
  927. ctx->options->file_cache[i].packet_cache = NULL;
  928. }
  929. }
  930. out:
  931. safe_free(ebuf);
  932. return ret;
  933. }
  934. /**
  935. * \brief sends the traffic out the interfaces
  936. *
  937. * Designed to be called in a separate thread if you need to. Blocks until
  938. * the replay is complete or you call tcpreplay_abort() in another thread.
  939. */
  940. int
  941. tcpreplay_replay(tcpreplay_t *ctx)
  942. {
  943. int rcode;
  944. COUNTER loop, total_loops;
  945. assert(ctx);
  946. if (!ctx->options->source_cnt) {
  947. tcpreplay_seterr(ctx, "invalid source count: %d", ctx->options->source_cnt);
  948. return -1;
  949. }
  950. if (ctx->options->dualfile && ctx->options->source_cnt < 2) {
  951. tcpreplay_seterr(ctx, "invalid dualfile source count: %d", ctx->options->source_cnt);
  952. return -1;
  953. }
  954. init_timestamp(&ctx->stats.start_time);
  955. init_timestamp(&ctx->stats.time_delta);
  956. init_timestamp(&ctx->stats.end_time);
  957. init_timestamp(&ctx->stats.pkt_ts_delta);
  958. init_timestamp(&ctx->stats.last_print);
  959. ctx->running = true;
  960. total_loops = ctx->options->loop;
  961. loop = 0;
  962. /* main loop, when not looping forever (or until abort) */
  963. if (ctx->options->loop > 0) {
  964. while (ctx->options->loop-- && !ctx->abort) { /* limited loop */
  965. ++loop;
  966. if (ctx->options->stats == 0) {
  967. if (!ctx->unique_iteration || loop == ctx->unique_iteration)
  968. printf("Loop " COUNTER_SPEC " of " COUNTER_SPEC "...\n",
  969. loop, total_loops);
  970. else
  971. printf("Loop " COUNTER_SPEC " of " COUNTER_SPEC " (" COUNTER_SPEC " unique)...\n",
  972. loop, total_loops,
  973. ctx->unique_iteration);
  974. }
  975. if ((rcode = tcpr_replay_index(ctx)) < 0)
  976. return rcode;
  977. if (ctx->options->loop > 0) {
  978. if (!ctx->abort && ctx->options->loopdelay_ms > 0) {
  979. usleep(ctx->options->loopdelay_ms * 1000);
  980. gettimeofday(&ctx->stats.end_time, NULL);
  981. }
  982. if (ctx->options->stats == 0)
  983. packet_stats(&ctx->stats);
  984. }
  985. }
  986. } else {
  987. while (!ctx->abort) { /* loop forever unless user aborts */
  988. ++loop;
  989. if (ctx->options->stats == 0) {
  990. if (!ctx->unique_iteration || loop == ctx->unique_iteration)
  991. printf("Loop " COUNTER_SPEC "...\n", loop);
  992. else
  993. printf("Loop " COUNTER_SPEC " (" COUNTER_SPEC " unique)...\n", loop,
  994. ctx->unique_iteration);
  995. }
  996. if ((rcode = tcpr_replay_index(ctx)) < 0)
  997. return rcode;
  998. if (ctx->options->stats == 0 && !ctx->abort)
  999. packet_stats(&ctx->stats);
  1000. }
  1001. }
  1002. ctx->running = false;
  1003. if (ctx->options->stats >= 0) {
  1004. char buf[64];
  1005. if (format_date_time(&ctx->stats.end_time, buf, sizeof(buf)) > 0)
  1006. printf("Test complete: %s\n", buf);
  1007. }
  1008. return 0;
  1009. }
  1010. /**
  1011. * \brief Abort the tcpreplay_replay execution.
  1012. *
  1013. * This might take a little while since tcpreplay_replay() only checks this
  1014. * once per packet (sleeping between packets can cause delays), however,
  1015. * this function returns once the signal has been sent and does not block
  1016. */
  1017. int
  1018. tcpreplay_abort(tcpreplay_t *ctx)
  1019. {
  1020. assert(ctx);
  1021. ctx->abort = true;
  1022. printf("sendpacket_abort\n");
  1023. if (ctx->intf1 != NULL)
  1024. sendpacket_abort(ctx->intf1);
  1025. if (ctx->intf2 != NULL)
  1026. sendpacket_abort(ctx->intf2);
  1027. return 0;
  1028. }
  1029. /**
  1030. * \brief Temporarily suspend tcpreplay_replay()
  1031. *
  1032. * This might take a little while since tcpreplay_replay() only checks this
  1033. * once per packet (sleeping between packets can cause delays), however,
  1034. * this function returns once the signal has been sent and does not block
  1035. *
  1036. * Note that suspending a running context can create odd timing
  1037. */
  1038. int
  1039. tcpreplay_suspend(tcpreplay_t *ctx)
  1040. {
  1041. assert(ctx);
  1042. ctx->suspend = true;
  1043. return 0;
  1044. }
  1045. /**
  1046. * \brief Restart tcpreplay_replay() after suspend
  1047. *
  1048. * Causes the worker thread to restart sending packets
  1049. */
  1050. int
  1051. tcpreplay_restart(tcpreplay_t *ctx)
  1052. {
  1053. assert(ctx);
  1054. ctx->suspend = false;
  1055. return 0;
  1056. }
  1057. /**
  1058. * \brief Tells you if the given tcpreplay context is currently suspended
  1059. *
  1060. * Suspended == running, but not sending packets
  1061. */
  1062. bool
  1063. tcpreplay_is_suspended(tcpreplay_t *ctx)
  1064. {
  1065. assert(ctx);
  1066. return ctx->suspend;
  1067. }
  1068. /**
  1069. * \brief Tells you if the tcpreplay context is running (not yet finished)
  1070. *
  1071. * Returns true even if it is suspended
  1072. */
  1073. bool
  1074. tcpreplay_is_running(tcpreplay_t *ctx)
  1075. {
  1076. assert(ctx);
  1077. return ctx->running;
  1078. }
  1079. /**
  1080. * \brief returns the current statistics during or after a replay
  1081. *
  1082. * For performance reasons, I don't bother to put a mutex around this and you
  1083. * don't need to either. Just realize that your values may be off by one until
  1084. * tcreplay_replay() returns.
  1085. */
  1086. const tcpreplay_stats_t *
  1087. tcpreplay_get_stats(tcpreplay_t *ctx)
  1088. {
  1089. const tcpreplay_stats_t *ptr;
  1090. assert(ctx);
  1091. /* copy stats over so they don't change while caller is using the buffer */
  1092. memcpy(&ctx->static_stats, &ctx->stats, sizeof(tcpreplay_stats_t));
  1093. ptr = &ctx->static_stats;
  1094. return ptr;
  1095. }
  1096. /**
  1097. * \brief returns the current number of sources/files to be sent
  1098. */
  1099. int
  1100. tcpreplay_get_source_count(tcpreplay_t *ctx)
  1101. {
  1102. assert(ctx);
  1103. return ctx->options->source_cnt;
  1104. }
  1105. /**
  1106. * \brief Returns the current source id being replayed
  1107. */
  1108. int
  1109. tcpreplay_get_current_source(tcpreplay_t *ctx)
  1110. {
  1111. assert(ctx);
  1112. return ctx->current_source;
  1113. }
  1114. /* vim: set tabstop=8 expandtab shiftwidth=4 softtabstop=4: */
  1115. /**
  1116. * \brief Sets printing of flow statistics
  1117. */
  1118. int tcpreplay_set_flow_stats(tcpreplay_t *ctx, bool value)
  1119. {
  1120. assert(ctx);
  1121. ctx->options->flow_stats = value;
  1122. return 0;
  1123. }
  1124. /**
  1125. * \brief Sets the flow expiry in seconds
  1126. */
  1127. int tcpreplay_set_flow_expiry(tcpreplay_t *ctx, int value)
  1128. {
  1129. assert(ctx);
  1130. ctx->options->flow_expiry = value;
  1131. return 0;
  1132. }
  1133. /**
  1134. * \brief Get whether to printof flow statistics
  1135. */
  1136. bool tcpreplay_get_flow_stats(tcpreplay_t *ctx)
  1137. {
  1138. assert(ctx);
  1139. return ctx->options->flow_stats;
  1140. }
  1141. /**
  1142. * \brief Gets the flow expiry in seconds
  1143. */
  1144. int tcpreplay_get_flow_expiry(tcpreplay_t *ctx)
  1145. {
  1146. assert(ctx);
  1147. return ctx->options->flow_expiry;
  1148. }