From 95f324d4deec6e27af2194d27e2c5985d55fc6b0 Mon Sep 17 00:00:00 2001 From: yangwei Date: Tue, 3 Sep 2019 17:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EMAX=5FBURST=5FPKTLEN=E5=92=8C?= =?UTF-8?q?MIN=5FBURST=5FPKTLEN=E4=B8=A4=E4=B8=AA=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=8E=A7=E5=88=B6=E6=94=BE=E5=A4=A7=E5=8C=85?= =?UTF-8?q?=E7=9A=84=E9=95=BF=E5=BA=A6=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ clean.sh | 2 +- src/tcpreplay.c | 24 +++++++++++++++++++++--- src/tcpreplay.h | 2 ++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4dcd02b..e111edb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ tcpburst .vscode .DS_Store +GPATH +GRTAGS +GTAGS diff --git a/clean.sh b/clean.sh index ab46084..010f722 100755 --- a/clean.sh +++ b/clean.sh @@ -1,3 +1,3 @@ make clean make distclean -rm tcpburst clean +rm clean diff --git a/src/tcpreplay.c b/src/tcpreplay.c index d457cd1..000e631 100644 --- a/src/tcpreplay.c +++ b/src/tcpreplay.c @@ -1565,7 +1565,7 @@ static const u_char *find_iphdr(const u_char *pkt, size_t pktlen, const u_char * return -1; } - if(pktlen > TCP_BURST_MTU){ + if(pktlen > TCP_BURST_MTU || pktlen > options.max_burst_pkt_len || pktlen < options.min_burst_pkt_len){ //fprintf(stderr, "Tcpburst error! Packet too long:%d, current MTU is:%d\n", pktlen, TCP_BURST_MTU); return -1; } @@ -1960,10 +1960,28 @@ init(void) options.pkt_distance = 0; options.driver_mode = "pcap"; /* default mode is pcap */ options.encap_cfg_file = NULL; + char *env_var = getenv("MAX_BURST_PKTLEN"); + if(env_var != NULL) + { + options.max_burst_pkt_len = atoi(env_var); + } + else + { + options.max_burst_pkt_len = TCP_BURST_MTU; + } + env_var = getenv("MIN_BURST_PKTLEN"); + if(env_var != NULL) + { + options.min_burst_pkt_len = atoi(env_var); + } + else + { + options.min_burst_pkt_len = 0; + } #endif - if (fcntl(STDERR_FILENO, F_SETFL, O_NONBLOCK) < 0) - warnx("Unable to set STDERR to non-blocking: %s", strerror(errno)); + if (fcntl(STDERR_FILENO, F_SETFL, O_NONBLOCK) < 0) + warnx("Unable to set STDERR to non-blocking: %s", strerror(errno)); } /** diff --git a/src/tcpreplay.h b/src/tcpreplay.h index 86a5c53..a2e46d0 100644 --- a/src/tcpreplay.h +++ b/src/tcpreplay.h @@ -120,6 +120,8 @@ struct tcpreplay_opt_s { long cpu_mask; char *encap_cfg_file; /* µ×²ã·âװģʽ */ + int max_burst_pkt_len; + int min_burst_pkt_len; #endif };