tcpreplay_api.c 35 KB

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