tcpreplay_api.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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 _U_)
  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 _U_)
  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 _U_)
  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->abort && ctx->options->loopdelay_ms > 0) {
  999. usleep(ctx->options->loopdelay_ms * 1000);
  1000. gettimeofday(&ctx->stats.end_time, NULL);
  1001. }
  1002. if (ctx->options->stats == 0 && !ctx->abort)
  1003. packet_stats(&ctx->stats);
  1004. }
  1005. }
  1006. ctx->running = false;
  1007. if (ctx->options->stats >= 0) {
  1008. char buf[64];
  1009. if (format_date_time(&ctx->stats.end_time, buf, sizeof(buf)) > 0)
  1010. printf("Test complete: %s\n", buf);
  1011. }
  1012. return 0;
  1013. }
  1014. /**
  1015. * \brief Abort the tcpreplay_replay execution.
  1016. *
  1017. * This might take a little while since tcpreplay_replay() only checks this
  1018. * once per packet (sleeping between packets can cause delays), however,
  1019. * this function returns once the signal has been sent and does not block
  1020. */
  1021. int
  1022. tcpreplay_abort(tcpreplay_t *ctx)
  1023. {
  1024. assert(ctx);
  1025. ctx->abort = true;
  1026. printf("sendpacket_abort\n");
  1027. if (ctx->intf1 != NULL)
  1028. sendpacket_abort(ctx->intf1);
  1029. if (ctx->intf2 != NULL)
  1030. sendpacket_abort(ctx->intf2);
  1031. return 0;
  1032. }
  1033. /**
  1034. * \brief Temporarily suspend tcpreplay_replay()
  1035. *
  1036. * This might take a little while since tcpreplay_replay() only checks this
  1037. * once per packet (sleeping between packets can cause delays), however,
  1038. * this function returns once the signal has been sent and does not block
  1039. *
  1040. * Note that suspending a running context can create odd timing
  1041. */
  1042. int
  1043. tcpreplay_suspend(tcpreplay_t *ctx)
  1044. {
  1045. assert(ctx);
  1046. ctx->suspend = true;
  1047. return 0;
  1048. }
  1049. /**
  1050. * \brief Restart tcpreplay_replay() after suspend
  1051. *
  1052. * Causes the worker thread to restart sending packets
  1053. */
  1054. int
  1055. tcpreplay_restart(tcpreplay_t *ctx)
  1056. {
  1057. assert(ctx);
  1058. ctx->suspend = false;
  1059. return 0;
  1060. }
  1061. /**
  1062. * \brief Tells you if the given tcpreplay context is currently suspended
  1063. *
  1064. * Suspended == running, but not sending packets
  1065. */
  1066. bool
  1067. tcpreplay_is_suspended(tcpreplay_t *ctx)
  1068. {
  1069. assert(ctx);
  1070. return ctx->suspend;
  1071. }
  1072. /**
  1073. * \brief Tells you if the tcpreplay context is running (not yet finished)
  1074. *
  1075. * Returns true even if it is suspended
  1076. */
  1077. bool
  1078. tcpreplay_is_running(tcpreplay_t *ctx)
  1079. {
  1080. assert(ctx);
  1081. return ctx->running;
  1082. }
  1083. /**
  1084. * \brief returns the current statistics during or after a replay
  1085. *
  1086. * For performance reasons, I don't bother to put a mutex around this and you
  1087. * don't need to either. Just realize that your values may be off by one until
  1088. * tcreplay_replay() returns.
  1089. */
  1090. const tcpreplay_stats_t *
  1091. tcpreplay_get_stats(tcpreplay_t *ctx)
  1092. {
  1093. const tcpreplay_stats_t *ptr;
  1094. assert(ctx);
  1095. /* copy stats over so they don't change while caller is using the buffer */
  1096. memcpy(&ctx->static_stats, &ctx->stats, sizeof(tcpreplay_stats_t));
  1097. ptr = &ctx->static_stats;
  1098. return ptr;
  1099. }
  1100. /**
  1101. * \brief returns the current number of sources/files to be sent
  1102. */
  1103. int
  1104. tcpreplay_get_source_count(tcpreplay_t *ctx)
  1105. {
  1106. assert(ctx);
  1107. return ctx->options->source_cnt;
  1108. }
  1109. /**
  1110. * \brief Returns the current source id being replayed
  1111. */
  1112. int
  1113. tcpreplay_get_current_source(tcpreplay_t *ctx)
  1114. {
  1115. assert(ctx);
  1116. return ctx->current_source;
  1117. }
  1118. /* vim: set tabstop=8 expandtab shiftwidth=4 softtabstop=4: */
  1119. /**
  1120. * \brief Sets printing of flow statistics
  1121. */
  1122. int tcpreplay_set_flow_stats(tcpreplay_t *ctx, bool value)
  1123. {
  1124. assert(ctx);
  1125. ctx->options->flow_stats = value;
  1126. return 0;
  1127. }
  1128. /**
  1129. * \brief Sets the flow expiry in seconds
  1130. */
  1131. int tcpreplay_set_flow_expiry(tcpreplay_t *ctx, int value)
  1132. {
  1133. assert(ctx);
  1134. ctx->options->flow_expiry = value;
  1135. return 0;
  1136. }
  1137. /**
  1138. * \brief Get whether to printof flow statistics
  1139. */
  1140. bool tcpreplay_get_flow_stats(tcpreplay_t *ctx)
  1141. {
  1142. assert(ctx);
  1143. return ctx->options->flow_stats;
  1144. }
  1145. /**
  1146. * \brief Gets the flow expiry in seconds
  1147. */
  1148. int tcpreplay_get_flow_expiry(tcpreplay_t *ctx)
  1149. {
  1150. assert(ctx);
  1151. return ctx->options->flow_expiry;
  1152. }