tcprewrite_opts.def 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. autogen definitions options;
  2. copyright = {
  3. date = "2004-2005";
  4. owner = "Aaron Turner";
  5. type = "bsd";
  6. author = <<- EOText
  7. Copyright 2004-2005 Aaron Turner
  8. For support please use the tcpreplay-users@lists.sourceforge.net mailing list.
  9. EOText;
  10. };
  11. package = "tcprewrite";
  12. prog-name = "tcprewrite";
  13. prog-title = "Rewrite the packets in a pcap file.";
  14. long-opts;
  15. gnu-usage;
  16. help-value = "H";
  17. save-opts-value = "";
  18. load-opts-value = "";
  19. detail = <<- EOText
  20. Tcprewrite is a tool to rewrite packets stored in @file{pcap(3)} file format, such
  21. as crated by tools such as @file{tcpdump(1)} and @file{ethereal(1)}. Once a pcap
  22. file has had it's packets rewritten, they can be replayed back out on the network
  23. using @file{tcpreplay(1)}.
  24. tcprewrite currently supports the following DLT types:
  25. * DLT_C_HDLC
  26. * DLT_EN10MB
  27. * DLT_LINUX_SSL
  28. * DLT_RAW
  29. The packet editing features of tcprewrite which distinguish between "client"
  30. and "server" traffic requires a tcpprep(1) cache file.
  31. EOText;
  32. man-doc = <<- EOMan
  33. .SH "SEE ALSO"
  34. tcpdump(1), tcpprep(1), tcpreplay(1)
  35. EOMan;
  36. config-header = "config.h";
  37. include = "#include \"defines.h\"\n"
  38. "#include \"common.h\"\n"
  39. "#include \"tcprewrite.h\"\n"
  40. "#include \"mac.h\"\n"
  41. "extern char pcap_version[];\n"
  42. "extern tcprewrite_opt_t options;\n";
  43. homerc = "$$/";
  44. flag = {
  45. name = dbug;
  46. value = d;
  47. arg-type = number;
  48. descrip = "Enable debugging output";
  49. arg-range = "0->5";
  50. arg-default = 0;
  51. max = 1;
  52. immediate;
  53. doc = <<- EOText
  54. If configured with --enable-debug, then you can specify a verbosity
  55. level for debugging output. Higher numbers increase verbosity.
  56. EOText;
  57. };
  58. flag = {
  59. name = dmac;
  60. value = D;
  61. arg-type = string;
  62. max = 1;
  63. descrip = "Rewrite destination MAC addresses";
  64. flag-code = <<- EODmac
  65. int mask = 0;
  66. mask = dualmac2hex(OPT_ARG(DMAC), options.intf1_dmac, options.intf2_dmac,
  67. strlen(OPT_ARG(DMAC)));
  68. options.mac_mask ^= (mask << 2);
  69. EODmac;
  70. doc = <<- EOText
  71. Takes a pair of comma deliminated ethernet MAC addresses which
  72. will replace the destination MAC address of outbound packets.
  73. The first MAC address will be used for the server traffic
  74. and the optional second MAC address will be used for the client
  75. traffic.
  76. Example:
  77. @example
  78. --dmac 00:12:13:14:15:16,00:22:33:44:55:66
  79. @end example
  80. EOText;
  81. };
  82. flag = {
  83. name = smac;
  84. value = S;
  85. arg-type = string;
  86. max = 1;
  87. descrip = "Rewrite source MAC addresses";
  88. flag-code = <<- EOSmac
  89. int mask = 0;
  90. mask = dualmac2hex(OPT_ARG(SMAC), options.intf1_smac, options.intf2_smac,
  91. strlen(OPT_ARG(SMAC)));
  92. options.mac_mask ^= mask;
  93. EOSmac;
  94. doc = <<- EOText
  95. Takes a pair of comma deliminated ethernet MAC addresses which
  96. will replace the source MAC address of outbound packets.
  97. The first MAC address will be used for the server traffic
  98. and the optional second MAC address will be used for the client traffic.
  99. Example:
  100. @example
  101. --smac 00:12:13:14:15:16,00:22:33:44:55:66
  102. @end example
  103. EOText;
  104. };
  105. flag = {
  106. name = proto;
  107. value = P;
  108. arg-type = number;
  109. max = 1;
  110. descrip = "Override L2 protocol type for DLT_RAW";
  111. arg-range = "0->65535";
  112. doc = <<- EOText
  113. By default, pcap files encapsulated using DLT_RAW will have their protocol
  114. set to ETHERTYPE_IP (0x0800).
  115. EOText;
  116. };
  117. flag = {
  118. name = dlink;
  119. value = l;
  120. arg-type = string;
  121. max = 2;
  122. descrip = "Rewrite Data-Link layer with specified data";
  123. flag-code = <<- EODlink
  124. static int count = 1;
  125. options.l2.enabled = 1;
  126. if (count == 1) {
  127. options.l2.len = read_hexstring(OPT_ARG(DLINK), options.l2.data1, L2DATALEN);
  128. /*
  129. * preemtively copy over our data1[] to data2[] if user doesn't specify
  130. * any data2[] data
  131. */
  132. memcpy(options.l2.data2, options.l2.data1, options.l2.len);
  133. count ++;
  134. } else {
  135. if (options.l2.len != read_hexstring(OPT_ARG(DLINK), options.l2.data2, L2DATALEN))
  136. err(1, "Layer2 data for both interfaces must be the same length");
  137. }
  138. EODlink;
  139. doc = <<- EOText
  140. Provide a series of comma deliminated hex values which will be
  141. used to rewrite or create the Layer 2 header of the packets.
  142. The first instance of this argument will rewrite both server
  143. and client traffic, but if this argument is specified a second
  144. time, it will be used for the client traffic.
  145. Example:
  146. @example
  147. --dlink 01,02,03,04,05,06,00,11,22,33,44,55,66,08,00
  148. @end example
  149. EOText;
  150. };
  151. flag = {
  152. name = portmap;
  153. value = r;
  154. arg-type = string;
  155. max = 1;
  156. descrip = "Rewrite TCP/UDP ports";
  157. flag-code = <<- EOPortmap
  158. EOPortmap;
  159. doc = <<- EOText
  160. Specify a list of comma delimited port mappingings consisting of
  161. colon delimited port number pairs. Each colon delimited port pair
  162. consists of the port to match followed by the port number to rewrite.
  163. Example:
  164. @example
  165. --portmap 80:8000,8080:80
  166. @end example
  167. EOText;
  168. };
  169. flag = {
  170. name = seed;
  171. value = s;
  172. arg-type = number;
  173. descrip = "Randomize src/dst IP addresses w/ given seed";
  174. max = 1;
  175. doc = <<- EOText
  176. Causes the source and destination IP addresses to be pseudo
  177. randomized but still maintain client/server relationships.
  178. Since the randomization is deterministic based on the seed,
  179. you can reuse the same seed value to recreate the traffic.
  180. EOText;
  181. };
  182. flag = {
  183. name = pnat;
  184. value = N;
  185. arg-type = string;
  186. max = 2;
  187. descrip = "Rewrite IP addresses using pseudo-NAT";
  188. flag-code = <<- EOPnat
  189. static int count = 1;
  190. options.rewrite_ip ++;
  191. if (count == 1) {
  192. if (! parse_cidr_map(&options.cidrmap1, OPT_ARG(PNAT)))
  193. errx(1, "Unable to parse primary pseudo-NAT: %s", OPT_ARG(PNAT));
  194. count ++;
  195. } else {
  196. if (! parse_cidr_map(&options.cidrmap2, OPT_ARG(PNAT)))
  197. errx(1, "Unable parse secondary pseudo-NAT: %s", OPT_ARG(PNAT));
  198. }
  199. EOPnat;
  200. doc = <<- EOText
  201. Takes a comma delimited series of colon delimited CIDR
  202. netblock pairs. Each netblock pair is evaluated in order against
  203. the IP addresses. If the IP address in the packet matches the
  204. first netblock, it is rewriten using the second netblock as a
  205. mask against the high order bits.
  206. Example:
  207. @example
  208. --pnat 192.168.0.0/16:10.77.0.0/16,172.16.0.0/12:10.1.0.0/24
  209. @end example
  210. EOText;
  211. };
  212. flag = {
  213. name = endpoints;
  214. value = e;
  215. arg-type = string;
  216. max = 1;
  217. descrip = "Rewrite IP addresses to be between two endpoints";
  218. doc = <<- EOText
  219. Takes a pair of colon delimited IP addresses which will be used to rewrite
  220. all traffic to appear to be between the two IP's.
  221. Example:
  222. @example
  223. --endpoints 172.16.0.1:172.16.0.2
  224. @end example
  225. EOText;
  226. };
  227. flag = {
  228. name = fixcsum;
  229. value = C;
  230. descrip = "Force recalculation of IP/TCP/UDP checksums";
  231. flag-code = <<- EOFixcsum
  232. options.fixcsum = 1;
  233. EOFixcsum;
  234. doc = <<- EOText
  235. Causes each IP packet to have it's checksums recalcualted and
  236. fixed. Automatically enabled for packets modified with @samp{--seed},
  237. @samp{--pnat}, @samp{--endpoints} or @samp{--fixlen}.
  238. EOText;
  239. };
  240. flag = {
  241. name = infile;
  242. value = i;
  243. arg-type = string;
  244. descrip = "Input pcap file to be processed";
  245. max = 1;
  246. immediate;
  247. must-set;
  248. flag-code = <<- EOInfile
  249. char ebuf[PCAP_ERRBUF_SIZE];
  250. options.infile = safe_strdup(OPT_ARG(INFILE));
  251. if ((options.pin = pcap_open_offline(options.infile, ebuf)) == NULL)
  252. errx(1, "Unable to open input pcap file: %s", ebuf);
  253. EOInfile;
  254. doc = "";
  255. };
  256. flag = {
  257. name = outfile;
  258. value = o;
  259. arg-type = string;
  260. descrip = "Output pcap file";
  261. max = 1;
  262. must-set;
  263. doc = "";
  264. };
  265. flag = {
  266. name = cachefile;
  267. value = c;
  268. arg-type = string;
  269. max = 1;
  270. descrip = "Split traffic via tcpprep cache file";
  271. settable;
  272. flag-code = <<- EOCachefile
  273. options.cache_packets =
  274. read_cache(&options.cachedata, OPT_ARG(CACHEFILE), &options.comment);
  275. EOCachefile;
  276. doc = <<- EOText
  277. Use tcpprep cache file to split traffic based upon client/server relationships.
  278. EOText;
  279. };
  280. flag = {
  281. name = mtu;
  282. value = m;
  283. arg-type = number;
  284. max = 1;
  285. arg-range = "1->MAXPACKET";
  286. default = DEFAULT_MTU;
  287. descrip = "Override default MTU length (1500 bytes)";
  288. doc = <<- EOText
  289. Override the default 1500 byte MTU size for determining the maximum padding length.
  290. EOText;
  291. };
  292. flag = {
  293. name = efcs;
  294. value = E;
  295. descrip = "Remove Ethernet checksums (FCS) from end of frames";
  296. flag-code = <<- EOEfcs
  297. options.efcs = 1;
  298. EOEfcs;
  299. doc = <<- EOText
  300. EOText;
  301. };
  302. flag = {
  303. name = fixlen;
  304. value = F;
  305. descrip = "Pad or truncate packet data to match header length";
  306. max = 1;
  307. arg-type = string;
  308. flag-code = <<- EOFixlen
  309. if (strcmp(OPT_ARG(FIXLEN), "pad") == 0) {
  310. options.fixlen = FIXLEN_PAD;
  311. } else if (strcmp(OPT_ARG(FIXLEN), "trunc") == 0) {
  312. options.fixlen = FIXLEN_TRUNC;
  313. } else {
  314. errx(1, "Invalid fixlen argument '%s'. Must be 'trunc' or 'pad'", OPT_ARG(FIXLEN));
  315. }
  316. EOFixlen;
  317. doc = <<- EOText
  318. Packets may be truncated during capture if the snaplen is smaller then the
  319. packet. This option allows you to modify the packet to pad the packet back
  320. out to the size stored in the IPv4 header or rewrite the IP header total length
  321. to reflect the stored packet length.
  322. @table @bullet
  323. @item
  324. @var{pad}
  325. Truncated packets will be padded out so that the packet length matches the
  326. IPv4 total length
  327. @item
  328. @var{trunc}
  329. Truncated packets will have their IPv4 total length field rewritten to match
  330. the actual packet length
  331. EOText;
  332. };
  333. /* rewrite 802.1q vlan tags */
  334. flag = {
  335. name = vlan;
  336. value = T;
  337. max = 1;
  338. descrip = "Specify 802.1q VLAN tag mode";
  339. arg-type = string;
  340. flag-code = <<- EOVlan
  341. if (strcmp(OPT_ARG(VLAN), "add") == 0) {
  342. options.vlan = VLAN_ADD;
  343. } else if (strcmp(OPT_ARG(VLAN), "del") == 0) {
  344. options.vlan = VLAN_DEL;
  345. } else {
  346. errx(1, "Invalid vlan argument '%s'. Must be 'add' or 'del'", OPT_ARG(VLAN));
  347. }
  348. EOVlan;
  349. doc = <<- EOText
  350. Allows you to rewrite ethernet frames to add a 802.1q header to standard 802.3
  351. ethernet headers or remove the 802.1q VLAN tag information.
  352. @table @bullet
  353. @item
  354. @var{add}
  355. Rewrites the existing 802.3 ethernet header as an 802.1q VLAN header
  356. @item
  357. @var{del}
  358. Rewrites the existing 802.1q VLAN header as an 802.3 ethernet header
  359. EOText;
  360. };
  361. flag = {
  362. name = vlan_tag;
  363. value = t;
  364. max = 1;
  365. descrip = "Specify the new 802.1q VLAN tag value";
  366. arg-type = number;
  367. flags-must = vlan;
  368. arg-range = "0->4095"; /* VID's are 12bit unsigned int's */
  369. doc = "";
  370. };
  371. flag = {
  372. name = vlan_cfi;
  373. value = c;
  374. max = 1;
  375. descrip = "Specify the 802.1q VLAN CFI value";
  376. arg-type = number;
  377. flags-must = vlan;
  378. arg-range = "0->1"; /* one bit */
  379. doc = "";
  380. };
  381. flag = {
  382. name = vlan_pri;
  383. value = p;
  384. max = 1;
  385. descrip = "Specify the 802.1q VLAN priority";
  386. flags-must = vlan;
  387. arg-type = number;
  388. arg-range = "0->7"; /* one byte */
  389. doc = "";
  390. };
  391. /* Verbose decoding via tcpdump */
  392. flag = {
  393. ifdef = HAVE_TCPDUMP;
  394. name = verbose;
  395. value = v;
  396. max = 1;
  397. immediate;
  398. descrip = "Print decoded packets via tcpdump to STDOUT";
  399. settable;
  400. doc = "";
  401. };
  402. flag = {
  403. ifdef = HAVE_TCPDUMP;
  404. name = decode;
  405. flags-must = verbose;
  406. value = A;
  407. arg-type = string;
  408. max = 1;
  409. descrip = "Arguments passed to tcpdump decoder";
  410. doc = <<- EOText
  411. When enabling verbose mode (@var{-v}) you may also specify one or
  412. more additional arguments to pass to @code{tcpdump} to modify
  413. the way packets are decoded. By default, -n and -l are used.
  414. Be sure to quote the arguments so that they are not interpreted
  415. by tcprewrite. The following arguments are valid:
  416. [ -aAeNqRStuvxX ]
  417. [ -E spi@ipaddr algo:secret,... ]
  418. [ -s snaplen ]
  419. EOText;
  420. };
  421. flag = {
  422. name = version;
  423. value = V;
  424. descrip = "Print version information";
  425. flag-code = <<- EOVersion
  426. fprintf(stderr, "tcprewrite version: %s (build %s)", VERSION, svn_version());
  427. #ifdef DEBUG
  428. fprintf(stderr, " (debug)");
  429. #endif
  430. fprintf(stderr, "\n");
  431. fprintf(stderr, "Copyright 2001-2005 by Aaron Turner <aturner@pobox.com>\n");
  432. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  433. fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
  434. fprintf(stderr, "Compiled against libpcap: %s\n", pcap_version);
  435. #ifdef ENABLE_64BITS
  436. fprintf(stderr, "64 bit packet counters: enabled\n");
  437. #else
  438. fprintf(stderr, "64 bit packet counters: disabled\n");
  439. #endif
  440. exit(0);
  441. EOVersion;
  442. doc = "";
  443. };
  444. flag = {
  445. name = less-help;
  446. value = h;
  447. immediate;
  448. descrip = "Display less usage information and exit";
  449. flag-code = <<- EOHelp
  450. USAGE(EXIT_FAILURE);
  451. EOHelp;
  452. doc = "";
  453. };