Changeset 1950
- Timestamp:
- 01/14/08 10:09:59 (12 months ago)
- Location:
- trunk/src
- Files:
-
- 3 modified
-
Makefile.am (modified) (2 diffs)
-
tcprewrite.c (modified) (6 diffs)
-
tcprewrite.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r1946 r1950 1 1 # $Id: Makefile.am 1632 2007-02-03 18:46:16Z aturner $ 2 2 if COMPILE_FRAGROUTE 3 LIBFRAGROUTE = ./fragroute/libfragroute.a 3 LIBFRAGROUTE = ./fragroute/libfragroute.a @LDNETLIB@ 4 4 FRAGROUTE_DIR = fragroute 5 5 else … … 54 54 @AUTOGEN@ $(opts_list) tcpreplay_opts.def 55 55 56 tcprewrite_CFLAGS = $(LIBOPTS_CFLAGS) -I.. $(LNAV_CFLAGS) -DTCPREWRITE -DHAVE_CACHEFILE_SUPPORT56 tcprewrite_CFLAGS = $(LIBOPTS_CFLAGS) -I.. @LDNETINC@ $(LNAV_CFLAGS) -DTCPREWRITE -DHAVE_CACHEFILE_SUPPORT 57 57 tcprewrite_LDADD = ./tcpedit/libtcpedit.a ./common/libcommon.a \ 58 58 $(LIBSTRL) @LNETLIB@ @LPCAPLIB@ $(LIBOPTS_LDADD) @DMALLOC_LIB@ \ -
trunk/src/tcprewrite.c
r1944 r1950 78 78 int optct, rcode; 79 79 pcap_t *dlt_pcap; 80 80 char ebuf[FRAGROUTE_ERRBUF_LEN]; 81 81 tcprewrite_init(); 82 82 … … 117 117 dbgx(1, "DLT of dlt_pcap is %s", 118 118 pcap_datalink_val_to_name(pcap_datalink(dlt_pcap))); 119 120 if (options.fragroute_args) { 121 if ((options.frag_ctx = fragroute_init(65535, options.fragroute_args, ebuf)) == NULL) 122 errx(1, "%s", ebuf); 123 } 119 124 120 125 #ifdef ENABLE_VERBOSE … … 187 192 #endif 188 193 194 195 #ifdef ENABLE_FRAGROUTE 196 if (HAVE_OPT(FRAGROUTE)) 197 options.fragroute_args = safe_strdup(OPT_ARG(FRAGROUTE)); 198 199 options.fragroute_dir = FRAGROUTE_DIR_BOTH; 200 if (HAVE_OPT(FRAGDIR)) { 201 if (strcmp(OPT_ARG(FRAGDIR), "c2s") == 0) { 202 options.fragroute_dir = FRAGROUTE_DIR_C2S; 203 } else if (strcmp(OPT_ARG(FRAGDIR), "s2c") == 0) { 204 options.fragroute_dir = FRAGROUTE_DIR_S2C; 205 } else if (strcmp(OPT_ARG(FRAGDIR), "both") == 0) { 206 options.fragroute_dir = FRAGROUTE_DIR_BOTH; 207 } else { 208 errx(1, "Unknown --fragdir value: %s", OPT_ARG(FRAGDIR)); 209 } 210 } 211 #endif 212 189 213 /* open up the input file */ 190 214 options.infile = safe_strdup(OPT_ARG(INFILE)); … … 203 227 const u_char *pktdata = NULL; /* packet from libpcap */ 204 228 u_char **packet = NULL; /* packet from tcpedit */ 229 char *frag = NULL; 205 230 COUNTER packetnum = 0; 206 int rcode ;231 int rcode, frag_len; 207 232 208 233 pkthdr_ptr = &pkthdr; … … 235 260 goto WRITE_PACKET; /* still need to write it so cache stays in sync */ 236 261 237 packet = &pktdata;262 packet = (u_char **)&pktdata; 238 263 if ((rcode = tcpedit_packet(tcpedit, &pkthdr_ptr, packet, cache_result)) == TCPEDIT_ERROR) { 239 264 return -1; … … 246 271 247 272 WRITE_PACKET: 248 /* write the packet */ 249 pcap_dump((u_char *)pout, pkthdr_ptr, *packet); 273 if (options.frag_ctx == NULL) { 274 /* write the packet when there's no fragrouting to be done */ 275 pcap_dump((u_char *)pout, pkthdr_ptr, *packet); 276 } else { 277 /* packet needs to be fragmented */ 278 if ((options.fragroute_dir == FRAGROUTE_DIR_BOTH) || 279 (cache_result == TCPR_DIR_C2S && options.fragroute_dir == FRAGROUTE_DIR_C2S) || 280 (cache_result == TCPR_DIR_S2C && options.fragroute_dir == FRAGROUTE_DIR_S2C)) { 281 fragroute_process(options.frag_ctx, *packet, pkthdr_ptr->caplen); 282 while ((frag_len = fragroute_getfragment(options.frag_ctx, &frag)) > 0) { 283 /* frags get the same timestamp as the original packet */ 284 pkthdr_ptr->caplen = frag_len; 285 pkthdr_ptr->len = frag_len; 286 pcap_dump((u_char *)pout, pkthdr_ptr, (u_char *)frag); 287 } 288 } else { 289 /* write the packet without fragroute */ 290 pcap_dump((u_char *)pout, pkthdr_ptr, *packet); 291 } 292 } 250 293 251 294 } /* while() */ -
trunk/src/tcprewrite.h
r1944 r1950 43 43 #endif 44 44 45 #ifdef ENABLE_FRAGROUTE 46 #include "fragroute/fragroute.h" 47 #endif 45 48 46 49 /* runtime options */ … … 64 67 char *tcpdump_args; 65 68 #endif 69 70 #ifdef ENABLE_FRAGROUTE 71 char *fragroute_args; 72 fragroute_t *frag_ctx; 73 #define FRAGROUTE_DIR_C2S 1 74 #define FRAGROUTE_DIR_S2C 2 75 #define FRAGROUTE_DIR_BOTH 4 76 int fragroute_dir; 77 #endif 66 78 tcpedit_t *tcpedit; 67 79 };
