tcpprep.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2017 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. /*
  20. * Purpose:
  21. * 1) Remove the performance bottleneck in tcpreplay for choosing an NIC
  22. * 2) Seperate code to make it more manageable
  23. * 3) Add addtional features which require multiple passes of a pcap
  24. *
  25. * Support:
  26. * Right now we support matching source IP based upon on of the following:
  27. * - Regular expression
  28. * - IP address is contained in one of a list of CIDR blocks
  29. * - Auto learning of CIDR block for servers (clients all other)
  30. */
  31. #include "config.h"
  32. #include "defines.h"
  33. #include "common.h"
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <regex.h>
  38. #include <string.h>
  39. #include <unistd.h>
  40. #include <errno.h>
  41. #include "tcpprep.h"
  42. #include "tcpprep_api.h"
  43. #include "tcpprep_opts.h"
  44. #include "lib/tree.h"
  45. #include "tree.h"
  46. #include "lib/sll.h"
  47. #ifndef HAVE_STRLCPY
  48. #include "lib/strlcpy.h"
  49. #endif
  50. /*
  51. * global variables
  52. */
  53. #ifdef DEBUG
  54. int debug = 0;
  55. #endif
  56. tcpprep_t *tcpprep;
  57. int info = 0;
  58. char *ourregex = NULL;
  59. char *cidr = NULL;
  60. tcpr_data_tree_t treeroot;
  61. void print_comment(const char *);
  62. void print_info(const char *);
  63. void print_stats(const char *);
  64. static int check_ipv4_regex(const unsigned long ip);
  65. static int check_ipv6_regex(const struct tcpr_in6_addr *addr);
  66. static COUNTER process_raw_packets(pcap_t * pcap);
  67. static int check_dst_port(ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr, int len);
  68. /*
  69. * main()
  70. */
  71. int
  72. main(int argc, char *argv[])
  73. {
  74. int out_file;
  75. COUNTER totpackets = 0;
  76. char errbuf[PCAP_ERRBUF_SIZE];
  77. int optct = 0;
  78. tcpprep_opt_t *options;
  79. tcpprep = tcpprep_init();
  80. options = tcpprep->options;
  81. optct = optionProcess(&tcpprepOptions, argc, argv);
  82. tcpprep_post_args(tcpprep, argc, argv);
  83. argc -= optct;
  84. argv += optct;
  85. /* open the cache file */
  86. if ((out_file = open(OPT_ARG(CACHEFILE), O_WRONLY | O_CREAT | O_TRUNC,
  87. S_IREAD | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH)) == -1)
  88. errx(-1, "Unable to open cache file %s for writing: %s",
  89. OPT_ARG(CACHEFILE), strerror(errno));
  90. readpcap:
  91. /* open the pcap file */
  92. if ((options->pcap = pcap_open_offline(OPT_ARG(PCAP), errbuf)) == NULL)
  93. errx(-1, "Error opening file: %s", errbuf);
  94. #ifdef HAVE_PCAP_SNAPSHOT
  95. if (pcap_snapshot(options->pcap) < 65535)
  96. warnx("%s was captured using a snaplen of %d bytes. This may mean you have truncated packets.",
  97. OPT_ARG(PCAP), pcap_snapshot(options->pcap));
  98. #endif
  99. /* make sure we support the DLT type */
  100. switch(pcap_datalink(options->pcap)) {
  101. case DLT_EN10MB:
  102. case DLT_LINUX_SLL:
  103. case DLT_RAW:
  104. case DLT_C_HDLC:
  105. case DLT_JUNIPER_ETHER:
  106. case DLT_PPP_SERIAL:
  107. break; /* do nothing because all is good */
  108. default:
  109. errx(-1, "Unsupported pcap DLT type: 0x%x", pcap_datalink(options->pcap));
  110. }
  111. /* Can only split based on MAC address for ethernet */
  112. if ((pcap_datalink(options->pcap) != DLT_EN10MB) &&
  113. (options->mode == MAC_MODE)) {
  114. err(-1, "MAC mode splitting is only supported by DLT_EN10MB packet captures.");
  115. }
  116. #ifdef ENABLE_VERBOSE
  117. if (HAVE_OPT(VERBOSE)) {
  118. tcpdump_open(&tcpprep->tcpdump, options->pcap);
  119. }
  120. #endif
  121. /* do we apply a bpf filter? */
  122. if (options->bpf.filter != NULL) {
  123. if (pcap_compile(options->pcap, &options->bpf.program, options->bpf.filter,
  124. options->bpf.optimize, 0) != 0) {
  125. errx(-1, "Error compiling BPF filter: %s", pcap_geterr(options->pcap));
  126. }
  127. pcap_setfilter(options->pcap, &options->bpf.program);
  128. }
  129. if ((totpackets = process_raw_packets(options->pcap)) == 0) {
  130. pcap_close(options->pcap);
  131. err(-1, "No packets were processed. Filter too limiting?");
  132. }
  133. pcap_close(options->pcap);
  134. #ifdef ENABLE_VERBOSE
  135. tcpdump_close(&tcpprep->tcpdump);
  136. #endif
  137. /* we need to process the pcap file twice in HASH/AUTO mode */
  138. if (options->mode == AUTO_MODE) {
  139. options->mode = options->automode;
  140. if (options->mode == ROUTER_MODE) { /* do we need to convert TREE->CIDR? */
  141. if (info)
  142. notice("Building network list from pre-cache...\n");
  143. if (!process_tree()) {
  144. err(-1, "Error: unable to build a valid list of servers. Aborting.");
  145. }
  146. }
  147. else {
  148. /*
  149. * in bridge mode we need to calculate client/sever
  150. * manually since this is done automatically in
  151. * process_tree()
  152. */
  153. tree_calculate(&treeroot);
  154. }
  155. if (info)
  156. notice("Buliding cache file...\n");
  157. /*
  158. * re-process files, but this time generate
  159. * cache
  160. */
  161. goto readpcap;
  162. }
  163. #ifdef DEBUG
  164. if (debug && (options->cidrdata != NULL))
  165. print_cidr(options->cidrdata);
  166. #endif
  167. /* write cache data */
  168. totpackets = write_cache(options->cachedata, out_file, totpackets,
  169. options->comment);
  170. if (info)
  171. notice("Done.\nCached " COUNTER_SPEC " packets.\n", totpackets);
  172. /* close cache file */
  173. close(out_file);
  174. return 0;
  175. }
  176. /**
  177. * checks the dst port to see if this is destined for a server port.
  178. * returns 1 for true, 0 for false
  179. */
  180. static int
  181. check_dst_port(ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr, int len)
  182. {
  183. tcp_hdr_t *tcp_hdr = NULL;
  184. udp_hdr_t *udp_hdr = NULL;
  185. tcpprep_opt_t *options = tcpprep->options;
  186. uint8_t proto;
  187. u_char *l4;
  188. if (ip_hdr) {
  189. if (len < ((ip_hdr->ip_hl * 4) + 4))
  190. return 0; /* not enough data in the packet to know */
  191. proto = ip_hdr->ip_p;
  192. l4 = get_layer4_v4(ip_hdr, len);
  193. } else if (ip6_hdr) {
  194. if (len < (TCPR_IPV6_H + 4))
  195. return 0; /* not enough data in the packet to know */
  196. proto = get_ipv6_l4proto(ip6_hdr, len);
  197. dbgx(3, "Our layer4 proto is 0x%hhu", proto);
  198. if ((l4 = get_layer4_v6(ip6_hdr, len)) == NULL)
  199. return 0;
  200. dbgx(3, "Found proto %u at offset %p. base %p (%p)", proto, (void *)l4, (void *)ip6_hdr, (void*)(l4 - (u_char *)ip6_hdr));
  201. } else {
  202. assert(0);
  203. }
  204. dbg(3, "Checking the destination port...");
  205. switch(proto) {
  206. case IPPROTO_TCP:
  207. tcp_hdr = (tcp_hdr_t *)l4;
  208. /* is a service? */
  209. if (options->services.tcp[ntohs(tcp_hdr->th_dport)]) {
  210. dbgx(1, "TCP packet is destined for a server port: %d", ntohs(tcp_hdr->th_dport));
  211. return 1;
  212. }
  213. /* nope */
  214. dbgx(1, "TCP packet is NOT destined for a server port: %d", ntohs(tcp_hdr->th_dport));
  215. return 0;
  216. break;
  217. case IPPROTO_UDP:
  218. udp_hdr = (udp_hdr_t *)l4;
  219. /* is a service? */
  220. if (options->services.udp[ntohs(udp_hdr->uh_dport)]) {
  221. dbgx(1, "UDP packet is destined for a server port: %d", ntohs(udp_hdr->uh_dport));
  222. return 1;
  223. }
  224. /* nope */
  225. dbgx(1, "UDP packet is NOT destined for a server port: %d", ntohs(udp_hdr->uh_dport));
  226. return 0;
  227. break;
  228. default:
  229. /* not a TCP or UDP packet... return as non_ip */
  230. dbg(1, "Packet isn't a UDP or TCP packet... no port to process.");
  231. return options->nonip;
  232. }
  233. }
  234. /**
  235. * checks to see if an ip address matches a regex. Returns 1 for true
  236. * 0 for false
  237. */
  238. static int
  239. check_ipv4_regex(const unsigned long ip)
  240. {
  241. int eflags = 0;
  242. u_char src_ip[16];
  243. size_t nmatch = 0;
  244. tcpprep_opt_t *options = tcpprep->options;
  245. memset(src_ip, '\0', sizeof(src_ip));
  246. strlcpy((char *)src_ip, (char *)get_addr2name4(ip, RESOLVE),
  247. sizeof(src_ip));
  248. if (regexec(&options->preg, (char *)src_ip, nmatch, NULL, eflags) == 0) {
  249. return 1;
  250. } else {
  251. return 0;
  252. }
  253. }
  254. static int
  255. check_ipv6_regex(const struct tcpr_in6_addr *addr)
  256. {
  257. int eflags = 0;
  258. u_char src_ip[INET6_ADDRSTRLEN];
  259. size_t nmatch = 0;
  260. tcpprep_opt_t *options = tcpprep->options;
  261. memset(src_ip, '\0', sizeof(src_ip));
  262. strlcpy((char *)src_ip, (char *)get_addr2name6(addr, RESOLVE),
  263. sizeof(src_ip));
  264. if (regexec(&options->preg, (char *)src_ip, nmatch, NULL, eflags) == 0) {
  265. return 1;
  266. } else {
  267. return 0;
  268. }
  269. }
  270. /**
  271. * uses libpcap library to parse the packets and build
  272. * the cache file.
  273. */
  274. static COUNTER
  275. process_raw_packets(pcap_t * pcap)
  276. {
  277. ipv4_hdr_t *ip_hdr = NULL;
  278. ipv6_hdr_t *ip6_hdr = NULL;
  279. eth_hdr_t *eth_hdr = NULL;
  280. struct pcap_pkthdr pkthdr;
  281. const u_char *pktdata = NULL;
  282. COUNTER packetnum = 0;
  283. int l2len;
  284. u_char ipbuff[MAXPACKET], *buffptr;
  285. tcpr_dir_t direction = TCPR_DIR_ERROR;
  286. tcpprep_opt_t *options = tcpprep->options;
  287. assert(pcap);
  288. while ((pktdata = pcap_next(pcap, &pkthdr)) != NULL) {
  289. packetnum++;
  290. dbgx(1, "Packet " COUNTER_SPEC, packetnum);
  291. /* look for include or exclude LIST match */
  292. if (options->xX.list != NULL) {
  293. if (options->xX.mode < xXExclude) {
  294. if (!check_list(options->xX.list, packetnum)) {
  295. add_cache(&(options->cachedata), DONT_SEND, 0);
  296. continue;
  297. }
  298. }
  299. else if (check_list(options->xX.list, packetnum)) {
  300. add_cache(&(options->cachedata), DONT_SEND, 0);
  301. continue;
  302. }
  303. }
  304. /*
  305. * If the packet doesn't include an IPv4 header we should just treat
  306. * it as a non-IP packet, UNLESS we're in MAC mode, in which case
  307. * we should let the MAC matcher below handle it
  308. */
  309. eth_hdr = (eth_hdr_t *)pktdata;
  310. if (options->mode != MAC_MODE) {
  311. dbg(3, "Looking for IPv4/v6 header in non-MAC mode");
  312. /* get the IP header (if any) */
  313. buffptr = ipbuff;
  314. /* first look for IPv4 */
  315. if ((ip_hdr = (ipv4_hdr_t *)get_ipv4(pktdata, pkthdr.caplen,
  316. pcap_datalink(pcap), &buffptr))) {
  317. dbg(2, "Packet is IPv4");
  318. }
  319. /* then look for IPv6 */
  320. else if ((ip6_hdr = (ipv6_hdr_t *)get_ipv6(pktdata, pkthdr.caplen,
  321. pcap_datalink(pcap), &buffptr))) {
  322. dbg(2, "Packet is IPv6");
  323. }
  324. /* we're something else... */
  325. else {
  326. dbg(2, "Packet isn't IPv4/v6");
  327. /* we don't want to cache these packets twice */
  328. if (options->mode != AUTO_MODE) {
  329. dbg(3, "Adding to cache using options for Non-IP packets");
  330. add_cache(&options->cachedata, SEND, options->nonip);
  331. }
  332. /* go to next packet */
  333. continue;
  334. }
  335. l2len = get_l2len(pktdata, pkthdr.caplen, pcap_datalink(pcap));
  336. /* look for include or exclude CIDR match */
  337. if (options->xX.cidr != NULL) {
  338. if (ip_hdr) {
  339. if (!process_xX_by_cidr_ipv4(options->xX.mode, options->xX.cidr, ip_hdr)) {
  340. add_cache(&options->cachedata, DONT_SEND, 0);
  341. continue;
  342. }
  343. } else if (ip6_hdr) {
  344. if (!process_xX_by_cidr_ipv6(options->xX.mode, options->xX.cidr, ip6_hdr)) {
  345. add_cache(&options->cachedata, DONT_SEND, 0);
  346. continue;
  347. }
  348. }
  349. }
  350. }
  351. switch (options->mode) {
  352. case REGEX_MODE:
  353. dbg(2, "processing regex mode...");
  354. if (ip_hdr) {
  355. direction = check_ipv4_regex(ip_hdr->ip_src.s_addr);
  356. } else if (ip6_hdr) {
  357. direction = check_ipv6_regex(&ip6_hdr->ip_src);
  358. }
  359. /* reverse direction? */
  360. if (HAVE_OPT(REVERSE) && (direction == TCPR_DIR_C2S || direction == TCPR_DIR_S2C))
  361. direction = direction == TCPR_DIR_C2S ? TCPR_DIR_S2C : TCPR_DIR_C2S;
  362. add_cache(&options->cachedata, SEND, direction);
  363. break;
  364. case CIDR_MODE:
  365. dbg(2, "processing cidr mode...");
  366. if (ip_hdr) {
  367. direction = check_ip_cidr(options->cidrdata, ip_hdr->ip_src.s_addr) ? TCPR_DIR_C2S : TCPR_DIR_S2C;
  368. } else if (ip6_hdr) {
  369. direction = check_ip6_cidr(options->cidrdata, &ip6_hdr->ip_src) ? TCPR_DIR_C2S : TCPR_DIR_S2C;
  370. }
  371. /* reverse direction? */
  372. if (HAVE_OPT(REVERSE) && (direction == TCPR_DIR_C2S || direction == TCPR_DIR_S2C))
  373. direction = direction == TCPR_DIR_C2S ? TCPR_DIR_S2C : TCPR_DIR_C2S;
  374. add_cache(&options->cachedata, SEND, direction);
  375. break;
  376. case MAC_MODE:
  377. dbg(2, "processing mac mode...");
  378. direction = macinstring(options->maclist, (u_char *)eth_hdr->ether_shost);
  379. /* reverse direction? */
  380. if (HAVE_OPT(REVERSE) && (direction == TCPR_DIR_C2S || direction == TCPR_DIR_S2C))
  381. direction = direction == TCPR_DIR_C2S ? TCPR_DIR_S2C : TCPR_DIR_C2S;
  382. add_cache(&options->cachedata, SEND, direction);
  383. break;
  384. case AUTO_MODE:
  385. dbg(2, "processing first pass of auto mode...");
  386. /* first run through in auto mode: create tree */
  387. if (options->automode != FIRST_MODE) {
  388. if (ip_hdr) {
  389. add_tree_ipv4(ip_hdr->ip_src.s_addr, pktdata);
  390. } else if (ip6_hdr) {
  391. add_tree_ipv6(&ip6_hdr->ip_src, pktdata);
  392. }
  393. } else {
  394. if (ip_hdr) {
  395. add_tree_first_ipv4(pktdata);
  396. } else if (ip6_hdr) {
  397. add_tree_first_ipv6(pktdata);
  398. }
  399. }
  400. break;
  401. case ROUTER_MODE:
  402. /*
  403. * second run through in auto mode: create route
  404. * based cache
  405. */
  406. dbg(2, "processing second pass of auto: router mode...");
  407. if (ip_hdr) {
  408. add_cache(&options->cachedata, SEND,
  409. check_ip_tree(options->nonip, ip_hdr->ip_src.s_addr));
  410. } else {
  411. add_cache(&options->cachedata, SEND,
  412. check_ip6_tree(options->nonip, &ip6_hdr->ip_src));
  413. }
  414. break;
  415. case BRIDGE_MODE:
  416. /*
  417. * second run through in auto mode: create bridge
  418. * based cache
  419. */
  420. dbg(2, "processing second pass of auto: bridge mode...");
  421. if (ip_hdr) {
  422. add_cache(&options->cachedata, SEND,
  423. check_ip_tree(DIR_UNKNOWN, ip_hdr->ip_src.s_addr));
  424. } else {
  425. add_cache(&options->cachedata, SEND,
  426. check_ip6_tree(DIR_UNKNOWN, &ip6_hdr->ip_src));
  427. }
  428. break;
  429. case SERVER_MODE:
  430. /*
  431. * second run through in auto mode: create bridge
  432. * where unknowns are servers
  433. */
  434. dbg(2, "processing second pass of auto: server mode...");
  435. if (ip_hdr) {
  436. add_cache(&options->cachedata, SEND,
  437. check_ip_tree(DIR_SERVER, ip_hdr->ip_src.s_addr));
  438. } else {
  439. add_cache(&options->cachedata, SEND,
  440. check_ip6_tree(DIR_SERVER, &ip6_hdr->ip_src));
  441. }
  442. break;
  443. case CLIENT_MODE:
  444. /*
  445. * second run through in auto mode: create bridge
  446. * where unknowns are clients
  447. */
  448. dbg(2, "processing second pass of auto: client mode...");
  449. if (ip_hdr) {
  450. add_cache(&options->cachedata, SEND,
  451. check_ip_tree(DIR_CLIENT, ip_hdr->ip_src.s_addr));
  452. } else {
  453. add_cache(&options->cachedata, SEND,
  454. check_ip6_tree(DIR_CLIENT, &ip6_hdr->ip_src));
  455. }
  456. break;
  457. case PORT_MODE:
  458. /*
  459. * process ports based on their destination port
  460. */
  461. dbg(2, "processing port mode...");
  462. add_cache(&options->cachedata, SEND,
  463. check_dst_port(ip_hdr, ip6_hdr, (pkthdr.caplen - l2len)));
  464. break;
  465. case FIRST_MODE:
  466. /*
  467. * First packet mode, looks at each host and picks clients
  468. * by the ones which send the first packet in a session
  469. */
  470. dbg(2, "processing second pass of auto: first packet mode...");
  471. if (ip_hdr) {
  472. add_cache(&options->cachedata, SEND,
  473. check_ip_tree(DIR_UNKNOWN, ip_hdr->ip_src.s_addr));
  474. } else {
  475. add_cache(&options->cachedata, SEND,
  476. check_ip6_tree(DIR_UNKNOWN, &ip6_hdr->ip_src));
  477. }
  478. break;
  479. default:
  480. errx(-1, "Whoops! What mode are we in anyways? %d", options->mode);
  481. }
  482. #ifdef ENABLE_VERBOSE
  483. if (options->verbose)
  484. tcpdump_print(&tcpprep->tcpdump, &pkthdr, pktdata);
  485. #endif
  486. }
  487. return packetnum;
  488. }
  489. /**
  490. * print the tcpprep cache file comment
  491. */
  492. void
  493. print_comment(const char *file)
  494. {
  495. char *cachedata = NULL;
  496. char *comment = NULL;
  497. COUNTER count = 0;
  498. count = read_cache(&cachedata, file, &comment);
  499. printf("tcpprep args: %s\n", comment);
  500. printf("Cache contains data for " COUNTER_SPEC " packets\n", count);
  501. exit(0);
  502. }
  503. /**
  504. * prints out the cache file details
  505. */
  506. void
  507. print_info(const char *file)
  508. {
  509. char *cachedata = NULL;
  510. char *comment = NULL;
  511. COUNTER count = 0, i;
  512. count = read_cache(&cachedata, file, &comment);
  513. for (i = 1; i <= count; i ++) {
  514. switch (check_cache(cachedata, i)) {
  515. case TCPR_DIR_C2S:
  516. printf("Packet " COUNTER_SPEC " -> Primary\n", i);
  517. break;
  518. case TCPR_DIR_S2C:
  519. printf("Packet " COUNTER_SPEC " -> Secondary\n", i);
  520. break;
  521. case TCPR_DIR_NOSEND:
  522. printf("Packet " COUNTER_SPEC " -> Don't Send\n", i);
  523. break;
  524. default:
  525. err(-1, "Invalid cachedata value!");
  526. break;
  527. }
  528. }
  529. exit(0);
  530. }
  531. /**
  532. * Print the per-packet statistics
  533. */
  534. void
  535. print_stats(const char *file)
  536. {
  537. char *cachedata = NULL;
  538. char *comment = NULL;
  539. COUNTER count = 0;
  540. COUNTER pri = 0, sec = 0, nosend = 0;
  541. count = read_cache(&cachedata, file, &comment);
  542. for (COUNTER i = 1; i <= count; i ++) {
  543. int cacheval = check_cache(cachedata, i);
  544. switch (cacheval) {
  545. case TCPR_DIR_C2S:
  546. pri ++;
  547. break;
  548. case TCPR_DIR_S2C:
  549. sec ++;
  550. break;
  551. case TCPR_DIR_NOSEND:
  552. nosend ++;
  553. break;
  554. default:
  555. errx(-1, "Unknown cache value: %d", cacheval);
  556. }
  557. }
  558. printf("Primary packets:\t" COUNTER_SPEC "\n", pri);
  559. printf("Secondary packets:\t" COUNTER_SPEC "\n", sec);
  560. printf("Skipped packets:\t" COUNTER_SPEC "\n", nosend);
  561. printf("------------------------------\n");
  562. printf("Total packets:\t\t" COUNTER_SPEC "\n", count);
  563. exit(0);
  564. }