Changeset 1950

Show
Ignore:
Timestamp:
01/14/08 10:09:59 (12 months ago)
Author:
aturner
Message:

link libfragroute to tcprewrite and parse args. refs #42

Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r1946 r1950  
    11# $Id: Makefile.am 1632 2007-02-03 18:46:16Z aturner $ 
    22if COMPILE_FRAGROUTE 
    3     LIBFRAGROUTE = ./fragroute/libfragroute.a 
     3    LIBFRAGROUTE = ./fragroute/libfragroute.a @LDNETLIB@ 
    44    FRAGROUTE_DIR = fragroute 
    55else 
     
    5454        @AUTOGEN@ $(opts_list) tcpreplay_opts.def 
    5555 
    56 tcprewrite_CFLAGS = $(LIBOPTS_CFLAGS) -I.. $(LNAV_CFLAGS) -DTCPREWRITE -DHAVE_CACHEFILE_SUPPORT 
     56tcprewrite_CFLAGS = $(LIBOPTS_CFLAGS) -I.. @LDNETINC@ $(LNAV_CFLAGS) -DTCPREWRITE -DHAVE_CACHEFILE_SUPPORT 
    5757tcprewrite_LDADD = ./tcpedit/libtcpedit.a ./common/libcommon.a \ 
    5858        $(LIBSTRL) @LNETLIB@ @LPCAPLIB@ $(LIBOPTS_LDADD) @DMALLOC_LIB@ \ 
  • trunk/src/tcprewrite.c

    r1944 r1950  
    7878    int optct, rcode; 
    7979    pcap_t *dlt_pcap; 
    80      
     80    char ebuf[FRAGROUTE_ERRBUF_LEN]; 
    8181    tcprewrite_init(); 
    8282 
     
    117117    dbgx(1, "DLT of dlt_pcap is %s", 
    118118        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    } 
    119124 
    120125#ifdef ENABLE_VERBOSE 
     
    187192#endif 
    188193 
     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 
    189213    /* open up the input file */ 
    190214    options.infile = safe_strdup(OPT_ARG(INFILE)); 
     
    203227    const u_char *pktdata = NULL;               /* packet from libpcap */ 
    204228    u_char **packet = NULL;                     /* packet from tcpedit */ 
     229    char *frag = NULL; 
    205230    COUNTER packetnum = 0; 
    206     int rcode; 
     231    int rcode, frag_len; 
    207232 
    208233    pkthdr_ptr = &pkthdr; 
     
    235260            goto WRITE_PACKET; /* still need to write it so cache stays in sync */ 
    236261 
    237         packet = &pktdata; 
     262        packet = (u_char **)&pktdata; 
    238263        if ((rcode = tcpedit_packet(tcpedit, &pkthdr_ptr, packet, cache_result)) == TCPEDIT_ERROR) { 
    239264            return -1; 
     
    246271 
    247272WRITE_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        } 
    250293 
    251294    } /* while() */ 
  • trunk/src/tcprewrite.h

    r1944 r1950  
    4343#endif 
    4444 
     45#ifdef ENABLE_FRAGROUTE 
     46#include "fragroute/fragroute.h" 
     47#endif 
    4548 
    4649/* runtime options */ 
     
    6467    char *tcpdump_args; 
    6568#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 
    6678    tcpedit_t *tcpedit; 
    6779};