diff --git a/README.md b/README.md index fc25c173e..18b7d0c48 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Tcpreplay ========= [![Build Status](https://travis-ci.org/appneta/tcpreplay.svg?branch=master)](https://travis-ci.org/appneta/tcpreplay) [![Coverity Scan Build Status](https://scan.coverity.com/projects/12017/badge.svg)](https://scan.coverity.com/projects/12017) -[![Code Climate](https://codeclimate.com/github/appneta/tcpreplay.png)](https://codeclimate.com/github/appneta/tcpreplay) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0e49d208c69e440182ba21109ecaf31d)](https://www.codacy.com/app/fklassen/tcpreplay?utm_source=github.com&utm_medium=referral&utm_content=appneta/tcpreplay&utm_campaign=badger) [![Website](https://img.shields.io/website-up-down-green-red/http/shields.io.svg)](http://tcpreplay.appneta.com) diff --git a/autogen.sh b/autogen.sh index c69d116c1..214724208 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,4 +1,9 @@ #!/bin/sh + +set -e + +cd $(dirname $0) + rm -f config/config.guess config/config.sub config/ltmain.sh 2>/dev/null rm -f aclocal.m4 2>/dev/null aclocal -I libopts/m4/ diff --git a/configure.ac b/configure.ac index 43e65392b..42ac87d44 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ dnl $Id$ AC_PREREQ([2.69]) dnl Set version info here! -AC_INIT([tcpreplay],[4.3.0-beta1], +AC_INIT([tcpreplay],[4.3.0-beta2], [https://github.com/appneta/tcpreplay/issues], [tcpreplay], [http://tcpreplay.sourceforge.net/]) @@ -544,6 +544,7 @@ AC_ARG_ENABLE(dynamic-link, AC_MSG_ERROR([Cannot specify both --enable-dynamic-link and --enable-static-link]) fi ]) + if test $static_link = yes; then AC_DEFINE([ENABLE_STATIC_LINK], [1], [Use static libraries ( .a or .A.tbd )]) else @@ -587,10 +588,11 @@ AC_ARG_ENABLE([tuntap], linux*) AC_CHECK_HEADER([linux/if_tun.h], [have_tuntap=yes]) ;; - freebsd*) + *) AC_CHECK_HEADER([net/if_tun.h], [have_tuntap=yes]) ;; esac]) + if test $have_tuntap = yes ; then AC_DEFINE([HAVE_TUNTAP], [1], [Do we have TUNTAP device support?]) @@ -1760,38 +1762,71 @@ AC_ARG_WITH(testnic, nic2=$withval AC_MSG_RESULT([Using --with-testnic=$withval])], [ +case $host in + *-*-linux*) + nic1=eth0 + nic2=eth0 + ;; + + *-*-solaris*) + nic1=hme0 + nic2=hme0 + ;; + + *-*-sunos*) + nic1=hme0 + nic2=hme0 + ;; + + *-apple-darwin*) + nic1=en0 + nic2=en0 + ;; + + *-*-openbsd*) + nic1=xl0 + nic2=xl0 + ;; + + *-*-freebsd*) + nic1=em0 + nic2=em0 + ;; + + *-*-cygwin) + nic1=%0 + nic2=%0 + ;; + + *) + AC_MSG_RESULT([$host is unknown! Using first non-loopback interface]) + nic1=%0 + nic2=%0 + ;; +esac]) dnl There's a bug in OS X which causes pcap_findalldevs() to make the wifi NIC to disassociate dnl so under OSX we disable the interface list feature disable_pcap_findalldevs=no - osx_frameworks=no dnl these need to be dynamic based on OS case $host in *-*-linux*) - nic1=eth0 - nic2=eth0 AC_DEFINE([HAVE_LINUX], [1], [Building Linux]) AC_MSG_RESULT(Linux) ;; *-*-solaris*) - nic1=hme0 - nic2=hme0 AC_DEFINE([HAVE_SOLARIS], [1], [Building Solaris]) AC_MSG_RESULT(Solaris) ;; *-*-sunos*) - nic1=hme0 - nic2=hme0 AC_DEFINE([HAVE_SUNOS], [1], [Building SunOS]) AC_MSG_RESULT(SunOS) ;; *-apple-darwin*) - nic1=en0 - nic2=en0 if test x$libpcap_version_096 = xno ; then disable_pcap_findalldevs=yes fi @@ -1801,33 +1836,24 @@ case $host in ;; *-*-openbsd*) - nic1=xl0 - nic2=xl0 AC_DEFINE([HAVE_OPENBSD], [1], [Building Open BSD]) AC_MSG_RESULT(OpenBSD) ;; *-*-freebsd*) - nic1=em0 - nic2=em0 AC_DEFINE([HAVE_FREEBSD], [1], [Building Free BSD]) AC_MSG_RESULT(FreeBSD) ;; *-*-cygwin) AC_MSG_RESULT(Win32/Cygwin) - nic1=%0 - nic2=%0 AC_DEFINE([HAVE_CYGWIN], [1], [Building Cygwin]) ;; *) - AC_MSG_RESULT([$host is unknown! Using first non-loopback interface]) - nic1=%0 - nic2=%0 + AC_MSG_RESULT([$host is unknown!]) ;; -esac]) - +esac AM_CONDITIONAL([ENABLE_OSX_FRAMEWORKS], test "$osx_frameworks" = "yes") AC_ARG_WITH(testnic2, diff --git a/docs/CHANGELOG b/docs/CHANGELOG index d9dc5a927..23b08c78a 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -1,3 +1,17 @@ +10/18/2018 Version 4.3.0 beta2 + - fix issues identifed by Codacy (#493) + - CVE-2018-18408 use-after-free in post_args (#489) + - CVE-2018-18407 heap-buffer-overflow csum_replace4 (#488) + - CVE-2018-17974 heap-buffer-overflow dlt_en10mb_encode (#486) + - CVE-2018-17580 heap-buffer-overflow fast_edit_packet (#485) + - CVE-2018-17582 heap-buffer-overflow in get_next_packet (#484) + - Out-of-tree build (#482) + - Fails to open tap0 on Zephyr (#411) + - CVE-2018-13112 heap-buffer-overflow in get_l2len (#477 dup #408) + - Respect 2nd packet timing (#418) + - manpage typos (#413) + - Fix replay when using --with-testnic (#178) + 01/18/2018 Version 4.3.0 beta1 - Travis CI build fails due to new build images (#432) - Unable to build with libpcap 1.8.1 (#430) @@ -51,7 +65,7 @@ - Packet destortion --fuzz-seed option by Gabriel Ganne (#302) - Add --unique-ip-loops option to modify IPs every few loops (#296) - Netmap startup delay increase (#290) - - tcpcapinfo buffer overflow vulnerablily (#278) + - CVE-2017-6429 tcpcapinfo buffer overflow vulnerablily (#278) - Update git-clone instructions by Kyle McDonald (#277) - Allow fractions for --pps option (#270) - Print per-loop stats with --stats=0 (#269) diff --git a/docs/CREDIT b/docs/CREDIT index aad4e7906..7af65345f 100644 --- a/docs/CREDIT +++ b/docs/CREDIT @@ -58,7 +58,7 @@ Bojan Smojver Stas Grabois - For his efforts to add IPv6 support to tcpprep and the tcpedit engine - For adding IPv6 support to fragroute - + Fred Klassen - AppNeta - New maintainer of Tcpreplay - Added netmap support for wire-rate performance on commodity hardware @@ -78,3 +78,4 @@ Pedro Arthur Duarte [aka JEdi] Gabriel Ganne - Data fuzz rewrite feature + - Out-of-tree build diff --git a/src/Makefile.am b/src/Makefile.am index 48a58d821..ef08a02fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,25 +27,25 @@ autoopts: tcpreplay_opts.c tcprewrite_opts.c tcpbridge_opts.c tcpliveplay_opts.c opts_list=-L tcpedit tcpprep.1: tcpprep_opts.def - @AUTOGEN@ -T agman-cmd.tpl $(opts_list) tcpprep_opts.def + @AUTOGEN@ -T agman-cmd.tpl $(opts_list) $< tcprewrite.1: tcprewrite_opts.def tcpedit/tcpedit_opts.def - @AUTOGEN@ -T agman-cmd.tpl $(opts_list) tcprewrite_opts.def + @AUTOGEN@ -T agman-cmd.tpl $(opts_list) $< tcpreplay-edit.1: tcpreplay_opts.def - @AUTOGEN@ -T agman-cmd.tpl $(opts_list) -DTCPREPLAY_EDIT -DTCPREPLAY_EDIT_MAN tcpreplay_opts.def + @AUTOGEN@ -T agman-cmd.tpl $(opts_list) -DTCPREPLAY_EDIT -DTCPREPLAY_EDIT_MAN $< tcpreplay.1: tcpreplay_opts.def - @AUTOGEN@ -T agman-cmd.tpl $(opts_list) tcpreplay_opts.def + @AUTOGEN@ -T agman-cmd.tpl $(opts_list) $< tcpbridge.1: tcpbridge_opts.def - @AUTOGEN@ -T agman-cmd.tpl $(opts_list) tcpbridge_opts.def + @AUTOGEN@ -T agman-cmd.tpl $(opts_list) $< tcpliveplay.1: tcpliveplay_opts.def - @AUTOGEN@ -T agman-cmd.tpl $(opts_list) tcpliveplay_opts.def + @AUTOGEN@ -T agman-cmd.tpl $(opts_list) $< tcpcapinfo.1: tcpcapinfo_opts.def - @AUTOGEN@ -T agman-cmd.tpl $(opts_list) tcpcapinfo_opts.def + @AUTOGEN@ -T agman-cmd.tpl $(opts_list) $< man_MANS = tcpreplay.1 tcpprep.1 tcprewrite.1 tcpreplay-edit.1 tcpcapinfo.1 EXTRA_DIST = tcpreplay.1 tcpprep.1 tcprewrite.1 tcpbridge.1 tcpreplay-edit.1 \ @@ -62,7 +62,7 @@ bin_PROGRAMS += tcpliveplay man_MANS += tcpliveplay.1 endif -tcpreplay_edit_CFLAGS = $(LIBOPTS_CFLAGS) -I.. -Itcpedit $(LNAV_CFLAGS) @LDNETINC@ -DTCPREPLAY -DTCPREPLAY_EDIT -DHAVE_CACHEFILE_SUPPORT +tcpreplay_edit_CFLAGS = $(LIBOPTS_CFLAGS) -I$(srcdir)/.. -I$(srcdir)/tcpedit $(LNAV_CFLAGS) @LDNETINC@ -DTCPREPLAY -DTCPREPLAY_EDIT -DHAVE_CACHEFILE_SUPPORT tcpreplay_edit_LDADD = ./tcpedit/libtcpedit.a ./common/libcommon.a $(LIBSTRL) @LPCAPLIB@ @LDNETLIB@ $(LIBOPTS_LDADD) tcpreplay_edit_SOURCES = tcpreplay_edit_opts.c send_packets.c signal_handler.c tcpreplay.c tcpreplay_api.c replay.c tcpreplay_edit_OBJECTS: tcpreplay_opts.h @@ -70,9 +70,9 @@ tcpreplay_edit_opts.h: tcpreplay_edit_opts.c BUILT_SOURCES += tcpreplay_edit_opts.h tcpreplay_edit_opts.c: tcpreplay_opts.def - @AUTOGEN@ $(opts_list) @NETMAPFLAGS@ -DTCPREPLAY_EDIT -b tcpreplay_edit_opts tcpreplay_opts.def + @AUTOGEN@ $(opts_list) @NETMAPFLAGS@ -DTCPREPLAY_EDIT -b tcpreplay_edit_opts $< -tcpreplay_CFLAGS = $(LIBOPTS_CFLAGS) -I.. $(LNAV_CFLAGS) @LDNETINC@ -DTCPREPLAY +tcpreplay_CFLAGS = $(LIBOPTS_CFLAGS) -I$(srcdir)/.. $(LNAV_CFLAGS) @LDNETINC@ -DTCPREPLAY tcpreplay_SOURCES = tcpreplay_opts.c send_packets.c signal_handler.c tcpreplay.c tcpreplay_api.c replay.c tcpreplay_LDADD = ./common/libcommon.a $(LIBSTRL) @LPCAPLIB@ @LDNETLIB@ $(LIBOPTS_LDADD) tcpreplay_OBJECTS: tcpreplay_opts.h @@ -80,14 +80,14 @@ tcpreplay_opts.h: tcpreplay_opts.c BUILT_SOURCES += tcpreplay_opts.h tcpreplay_opts.c: tcpreplay_opts.def - @AUTOGEN@ $(opts_list) @NETMAPFLAGS@ tcpreplay_opts.def + @AUTOGEN@ $(opts_list) @NETMAPFLAGS@ $< if ENABLE_OSX_FRAMEWORKS tcpreplay_LDFLAGS = -framework CoreServices -framework Carbon tcpreplay_edit_LDFLAGS = -framework CoreServices -framework Carbon endif -tcpliveplay_CFLAGS = $(LIBOPTS_CFLAGS) -I.. $(LNAV_CFLAGS) -DTCPREPLAY -DTCPLIVEPLAY +tcpliveplay_CFLAGS = $(LIBOPTS_CFLAGS) -I$(srcdir)/.. $(LNAV_CFLAGS) -DTCPREPLAY -DTCPLIVEPLAY tcpliveplay_SOURCES = tcpliveplay_opts.c tcpliveplay.c tcpliveplay_LDADD = ./common/libcommon.a $(LIBSTRL) @LPCAPLIB@ @LDNETLIB@ $(LIBOPTS_LDADD) tcpliveplay_OBJECTS: tcpliveplay_opts.h @@ -95,10 +95,10 @@ tcpliveplay_opts.h: tcpliveplay_opts.c BUILT_SOURCES += tcpliveplay_opts.h tcpliveplay_opts.c: tcpliveplay_opts.def - @AUTOGEN@ $(opts_list) tcpliveplay_opts.def + @AUTOGEN@ $(opts_list) $< -tcprewrite_CFLAGS = $(LIBOPTS_CFLAGS) -I.. -Itcpedit @LDNETINC@ $(LNAV_CFLAGS) -DTCPREWRITE -DHAVE_CACHEFILE_SUPPORT +tcprewrite_CFLAGS = $(LIBOPTS_CFLAGS) -I$(srcdir)/.. -I$(srcdir)/tcpedit @LDNETINC@ $(LNAV_CFLAGS) -DTCPREWRITE -DHAVE_CACHEFILE_SUPPORT tcprewrite_LDADD = ./tcpedit/libtcpedit.a ./common/libcommon.a \ $(LIBSTRL) @LPCAPLIB@ $(LIBOPTS_LDADD) @DMALLOC_LIB@ \ $(LIBFRAGROUTE) @@ -108,9 +108,9 @@ tcprewrite_opts.h: tcprewrite_opts.c BUILT_SOURCES += tcprewrite_opts.h tcprewrite_opts.c: tcprewrite_opts.def tcpedit/tcpedit_opts.def - @AUTOGEN@ $(opts_list) tcprewrite_opts.def + @AUTOGEN@ $(opts_list) $< -tcpcapinfo_CFLAGS = $(LIBOPTS_CFLAGS) -I.. $(LNAV_CFLAGS) @LDNETINC@ -DTCPCAPINFO +tcpcapinfo_CFLAGS = $(LIBOPTS_CFLAGS) -I$(srcdir)/.. $(LNAV_CFLAGS) @LDNETINC@ -DTCPCAPINFO tcpcapinfo_LDADD = ./common/libcommon.a \ $(LIBSTRL) @LPCAPLIB@ $(LIBOPTS_LDADD) @DMALLOC_LIB@ tcpcapinfo_SOURCES = tcpcapinfo_opts.c tcpcapinfo.c @@ -119,9 +119,9 @@ tcpcapinfo_opts.h: tcpcapinfo_opts.c BUILT_SOURCES += tcpcapinfo_opts.h tcpcapinfo_opts.c: tcpcapinfo_opts.def - @AUTOGEN@ $(opts_list) tcpcapinfo_opts.def + @AUTOGEN@ $(opts_list) $< -tcpprep_CFLAGS = $(LIBOPTS_CFLAGS) -I.. $(LNAV_CFLAGS) @LDNETINC@ -DTCPPREP +tcpprep_CFLAGS = $(LIBOPTS_CFLAGS) -I$(srcdir)/.. $(LNAV_CFLAGS) @LDNETINC@ -DTCPPREP tcpprep_LDADD = ./common/libcommon.a \ $(LIBSTRL) @LPCAPLIB@ $(LIBOPTS_LDADD) @DMALLOC_LIB@ tcpprep_SOURCES = tcpprep_opts.c tcpprep.c tree.c tcpprep_api.c @@ -130,9 +130,9 @@ tcpprep_opts.h: tcpprep_opts.c BUILT_SOURCES += tcpprep_opts.h tcpprep_opts.c: tcpprep_opts.def - @AUTOGEN@ tcpprep_opts.def + @AUTOGEN@ $< -tcpbridge_CFLAGS = $(LIBOPTS_CFLAGS) -I.. -Itcpedit $(LNAV_CFLAGS) @LDNETINC@ -DTCPBRIDGE +tcpbridge_CFLAGS = $(LIBOPTS_CFLAGS) -I$(srcdir)/.. -I$(srcdir)/tcpedit $(LNAV_CFLAGS) @LDNETINC@ -DTCPBRIDGE tcpbridge_LDADD = ./tcpedit/libtcpedit.a ./common/libcommon.a \ $(LIBSTRL) @LPCAPLIB@ @LDNETLIB@ $(LIBOPTS_LDADD) @DMALLOC_LIB@ if ENABLE_OSX_FRAMEWORKS @@ -144,7 +144,7 @@ tcpbridge_opts.h: tcpbridge_opts.c BUILT_SOURCES += tcpbridge_opts.h tcpbridge_opts.c: tcpbridge_opts.def tcpedit/tcpedit_opts.def - @AUTOGEN@ $(opts_list) tcpbridge_opts.def + @AUTOGEN@ $(opts_list) $< noinst_HEADERS = tcpreplay.h tcpprep.h bridge.h defines.h tree.h tcpliveplay.h \ send_packets.h signal_handler.h common.h tcpreplay_opts.h tcpliveplay_opts.h \ diff --git a/src/bridge.c b/src/bridge.c index d84f81672..5fa4f9d7e 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -339,7 +339,8 @@ live_callback(struct live_data_t *livedata, struct pcap_pkthdr *pkthdr, /* look for include or exclude CIDR match */ if (livedata->options->xX.cidr != NULL) { - if (!process_xX_by_cidr_ipv4(livedata->options->xX.mode, livedata->options->xX.cidr, ip_hdr)) { + if (!ip_hdr || + !process_xX_by_cidr_ipv4(livedata->options->xX.mode, livedata->options->xX.cidr, ip_hdr)) { dbg(2, "Skipping IPv4 packet due to CIDR match"); return (1); } diff --git a/src/common/Makefile.am b/src/common/Makefile.am index f2a2961a5..a964938d8 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -25,7 +25,7 @@ if COMPILE_NETMAP libcommon_a_SOURCES += netmap.c endif -AM_CFLAGS = -I.. -I../.. $(LNAV_CFLAGS) @LDNETINC@ +AM_CFLAGS = -I$(srcdir)/.. -I$(srcdir)/../.. $(LNAV_CFLAGS) @LDNETINC@ if ! SYSTEM_STRLCPY libcommon_a_LIBADD = ../../lib/libstrl.a diff --git a/src/common/cidr.c b/src/common/cidr.c index 223d569df..54a15d17b 100644 --- a/src/common/cidr.c +++ b/src/common/cidr.c @@ -241,7 +241,7 @@ cidr2cidr(char *cidr) if (octets[count] > 255) goto error; - snprintf(tempoctet, sizeof(octets[count]), "%d", octets[count]); + snprintf(tempoctet, sizeof(octets[count]), "%u", octets[count]); strcat(networkip, tempoctet); /* we don't want a '.' at the end of the last octet */ if (count < 3) diff --git a/src/common/flows.c b/src/common/flows.c index e1960e420..b52ac5295 100644 --- a/src/common/flows.c +++ b/src/common/flows.c @@ -158,7 +158,6 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr * const u_char *pktdata, const int datalink, const int expiry) { uint16_t ether_type = 0; - vlan_hdr_t *vlan_hdr; ipv4_hdr_t *ip_hdr = NULL; ipv6_hdr_t *ip6_hdr = NULL; tcp_hdr_t *tcp_hdr; @@ -231,10 +230,11 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr * if ((pktdata[3] & 0x80) == 0x80) { l2_len = ntohs(*((uint16_t*)&pktdata[4])); l2_len += 6; - } else + } else { l2_len = 4; /* no header extensions */ + } - /* fall through */ + /* no break */ case DLT_EN10MB: /* set l2_len if we did not fell through */ if (l2_len == 0) @@ -246,7 +246,7 @@ flow_entry_type_t flow_decode(flow_hash_table_t *fht, const struct pcap_pkthdr * ether_type = ntohs(((eth_hdr_t*)(pktdata + l2_len))->ether_type); while (ether_type == ETHERTYPE_VLAN) { - vlan_hdr = (vlan_hdr_t *)(pktdata + l2_len); + vlan_hdr_t *vlan_hdr = (vlan_hdr_t *)(pktdata + l2_len); entry.vlan = vlan_hdr->vlan_priority_c_vid & htons(0xfff); ether_type = ntohs(vlan_hdr->vlan_len); l2_len += 4; diff --git a/src/common/get.c b/src/common/get.c index fc24197c3..060020a22 100644 --- a/src/common/get.c +++ b/src/common/get.c @@ -111,7 +111,7 @@ get_l2protocol(const u_char *pktdata, const int datalen, const int datalink) } else { eth_hdr_offset = 4; /* no header extensions */ } - /* fall through */ + /* no break */ case DLT_EN10MB: if (datalen >= (int)(sizeof(eth_hdr_t) + eth_hdr_offset)) { eth_hdr = (eth_hdr_t *)(pktdata + eth_hdr_offset); diff --git a/src/common/get.h b/src/common/get.h index 6cfab2b37..c2f3461f5 100644 --- a/src/common/get.h +++ b/src/common/get.h @@ -33,7 +33,7 @@ u_int16_t get_l2protocol(const u_char *pktdata, const int datalen, const int dat void *get_layer4_v4(const ipv4_hdr_t *ip_hdr, const int len); void *get_layer4_v6(const ipv6_hdr_t *ip_hdr, const int len); -u_int8_t get_ipv6_l4proto(const ipv6_hdr_t *ip6_hdr, const int len); +u_int8_t get_ipv6_l4proto(const ipv6_hdr_t *ip6_hdr, int len); void *get_ipv6_next(struct tcpr_ipv6_ext_hdr_base *exthdr, const int len); const u_char *get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff); diff --git a/src/common/interface.c b/src/common/interface.c index 18ae521ce..1c88ee0a4 100644 --- a/src/common/interface.c +++ b/src/common/interface.c @@ -84,8 +84,8 @@ get_interface_list(void) int fd = -1; nmreq_t nmr; #endif -#if defined HAVE_LIBPCAP_NETMAP || defined HAVE_NETMAP - u_int32_t netmap_version = -1; +#ifdef HAVE_NETMAP + u_int32_t netmap_version; #endif #ifndef HAVE_WIN32 @@ -135,8 +135,6 @@ get_interface_list(void) strncpy(nmr.nr_name, pcap_if_ptr->name, sizeof(nmr.nr_name)); nmr.nr_version = netmap_version; if (ioctl(fd, NIOCGINFO, &nmr) == 0) { - int x; - #endif /* HAVE_NETMAP */ #if defined HAVE_LIBPCAP_NETMAP || defined HAVE_NETMAP list_ptr->next = (interface_list_t *)safe_malloc(sizeof(interface_list_t)); @@ -150,8 +148,11 @@ get_interface_list(void) snprintf(list_ptr->name, sizeof(list_ptr->name), "netmap:%s", pcap_if_ptr->name); sprintf(list_ptr->alias, "%%%d", i++); list_ptr->flags = pcap_if_ptr->flags; - +#endif /* HAVE_LIBPCAP_NETMAP || HAVE_NETMAP */ +#ifdef HAVE_NETMAP if (netmap_version >= 10) { + int x; + list_ptr->next = (interface_list_t *)safe_malloc(sizeof(interface_list_t)); list_ptr = list_ptr->next; snprintf(list_ptr->name, sizeof(list_ptr->name), "netmap:%s!", pcap_if_ptr->name); @@ -169,10 +170,6 @@ get_interface_list(void) snprintf(list_ptr->name, sizeof(list_ptr->name), "netmap:%s^", pcap_if_ptr->name); sprintf(list_ptr->alias, "%%%d", i++); list_ptr->flags = pcap_if_ptr->flags; - } -#endif /* HAVE_LIBPCAP_NETMAP || HAVE_NETMAP */ -#ifdef HAVE_NETMAP - if (netmap_version >= 10) { for (x = 0; x < nmr.nr_rx_rings; ++x) { list_ptr->next = (interface_list_t *)safe_malloc(sizeof(interface_list_t)); list_ptr = list_ptr->next; diff --git a/src/common/list.c b/src/common/list.c index e61d1b093..467c7027b 100644 --- a/src/common/list.c +++ b/src/common/list.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* * Copyright (c) 2001-2010 Aaron Turner * Copyright (c) 2013-2018 Fred Klassen - AppNeta @@ -62,7 +60,6 @@ parse_list(tcpr_list_t ** listdata, char *ourstr) char *first, *second; int rcode; regex_t preg; - char ebuf[EBUF_SIZE]; char regex[] = "^[0-9]+(-[0-9]+)?$"; char *token = NULL; u_int i; @@ -70,6 +67,7 @@ parse_list(tcpr_list_t ** listdata, char *ourstr) /* compile the regex first */ if ((rcode = regcomp(&preg, regex, REG_EXTENDED | REG_NOSUB)) != 0) { + char ebuf[EBUF_SIZE]; regerror(rcode, &preg, ebuf, sizeof(ebuf)); errx(-1, "Unable to compile regex (%s): %s", regex, ebuf); } diff --git a/src/common/sendpacket.c b/src/common/sendpacket.c index 5713197c6..5e341dc67 100644 --- a/src/common/sendpacket.c +++ b/src/common/sendpacket.c @@ -486,7 +486,6 @@ sendpacket_open(const char *device, char *errbuf, tcpr_dir_t direction, errx(-1, "\"%s\" is a block device and is not a valid Tcpreplay device", device); break; - break; case S_IFDIR: errx(-1, "\"%s\" is a directory and is not a valid Tcpreplay device", device); diff --git a/src/common/services.c b/src/common/services.c index b35b0166d..fe2aed098 100644 --- a/src/common/services.c +++ b/src/common/services.c @@ -71,11 +71,6 @@ parse_services(const char *file, tcpr_services_t *services) /* look for format of 1234/tcp */ if ((regexec(&preg, service_line, nmatch, pmatch, 0)) == 0) { /* matches */ uint16_t portc; - - if (nmatch < 2) { - err(-1, "WTF? I matched the line, but I don't know where!"); - } - /* strip out the port & proto from the line */ strncpy(port, &service_line[pmatch[1].rm_so], (pmatch[1].rm_eo - pmatch[1].rm_so)); strncpy(proto, &service_line[pmatch[2].rm_so], (pmatch[2].rm_eo - pmatch[2].rm_so)); diff --git a/src/common/utils.c b/src/common/utils.c index d7eccbe36..4e56891f6 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -48,7 +48,8 @@ _our_safe_malloc(size_t len, const char *funcname, const int line, const char *f u_char *ptr; if ((ptr = malloc(len)) == NULL) { - fprintf(stderr, "ERROR in %s:%s() line %d: Unable to malloc() %zu bytes", file, funcname, line, len); + fprintf(stderr, "ERROR in %s:%s() line %d: Unable to malloc() %zu bytes/n", + file, funcname, line, len); exit(-1); } @@ -119,6 +120,57 @@ _our_safe_free(void *ptr, const char *funcname, const int line, const char *file ptr = NULL; } +/** + * get next packet in pcap file + */ +u_char *_our_safe_pcap_next(pcap_t *pcap, struct pcap_pkthdr *pkthdr, + const char *funcname, const int line, const char *file) +{ + u_char *pktdata = (u_char *)pcap_next(pcap, pkthdr); + + if (pktdata) { + if (pkthdr->len > MAXPACKET) { + fprintf(stderr, "safe_pcap_next ERROR: Invalid packet length in %s:%s() line %d: %u is greater than maximum %u\n", + file, funcname, line, pkthdr->len, MAXPACKET); + exit(-1); + } + + if (pkthdr->len < pkthdr->caplen) { + fprintf(stderr, "safe_pcap_next ERROR: Invalid packet length in %s:%s() line %d: packet length %u is less than capture length %u\n", + file, funcname, line, pkthdr->len, pkthdr->caplen); + exit(-1); + } + } + + return pktdata; +} + +/** + * get next packet in pcap file (extended) + */ +int _our_safe_pcap_next_ex(pcap_t *pcap, struct pcap_pkthdr **pkthdr, + const u_char **pktdata, const char *funcname, + const int line, const char *file) +{ + int res = pcap_next_ex(pcap, pkthdr, pktdata); + + if (*pktdata && *pkthdr) { + if ((*pkthdr)->len > MAXPACKET) { + fprintf(stderr, "safe_pcap_next_ex ERROR: Invalid packet length in %s:%s() line %d: %u is greater than maximum %u\n", + file, funcname, line, (*pkthdr)->len, MAXPACKET); + exit(-1); + } + + if ((*pkthdr)->len < (*pkthdr)->caplen) { + fprintf(stderr, "safe_pcap_next_ex ERROR: Invalid packet length in %s:%s() line %d: packet length %u is less than capture length %u\n", + file, funcname, line, (*pkthdr)->len, (*pkthdr)->caplen); + exit(-1); + } + } + + return res; +} + /** * Print various packet statistics */ diff --git a/src/common/utils.h b/src/common/utils.h index db066c34b..98c317508 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -63,6 +63,15 @@ char *_our_safe_strdup(const char *str, const char *, const int, const char *); #define safe_free(x) _our_safe_free(x, __FUNCTION__, __LINE__, __FILE__) void _our_safe_free(void *ptr, const char *, const int, const char *); +#define safe_pcap_next(x, y) _our_safe_pcap_next(x, y, __FUNCTION__, __LINE__, __FILE__) +u_char *_our_safe_pcap_next(pcap_t *pcap, struct pcap_pkthdr *pkthdr, + const char *funcname, const int line, const char *file); + +#define safe_pcap_next_ex(x, y, z) _our_safe_pcap_next_ex(x, y, z, __FUNCTION__, __LINE__, __FILE__) +int _our_safe_pcap_next_ex(pcap_t *pcap, struct pcap_pkthdr **pkthdr, + const u_char **pktdata, const char *funcname, + const int line, const char *file); + #define MAX_ARGS 128 #ifndef HAVE_INET_ATON diff --git a/src/config.h.in b/src/config.h.in index a8450898d..d5277e415 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -594,8 +594,7 @@ slash. */ #undef LSTAT_FOLLOWS_SLASHED_SYMLINK -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ +/* Define to the sub-directory where libtool stores uninstalled libraries. */ #undef LT_OBJDIR /* Define to 1 if `major', `minor', and `makedev' are declared in . diff --git a/src/fragroute/Makefile.am b/src/fragroute/Makefile.am index 3ff630f14..e9d664177 100644 --- a/src/fragroute/Makefile.am +++ b/src/fragroute/Makefile.am @@ -7,7 +7,7 @@ libfragroute_a_SOURCES = fragroute.c bget.c mod.c pkt.c argv.c \ iputil.c mod_ip6_opt.c mod_ip6_qos.c -libfragroute_a_CFLAGS = -I.. -I../.. @LDNETINC@ +libfragroute_a_CFLAGS = -I$(srcdir)/.. -I$(srcdir)/../.. @LDNETINC@ # libfragroute_a_LIBS = @LDNETLIB@ diff --git a/src/fragroute/bget.c b/src/fragroute/bget.c index f2190f275..a03037975 100644 --- a/src/fragroute/bget.c +++ b/src/fragroute/bget.c @@ -811,11 +811,11 @@ void brel(buf) { struct bfhead *b, *bn; + assert(buf != NULL); b = BFH(((char *) buf) - sizeof(struct bhead)); #ifdef BufStats numrel++; /* Increment number of brel() calls */ #endif - assert(buf != NULL); #ifdef BECtl if (b->bh.bsize == 0) { /* Directly-acquired buffer? */ diff --git a/src/fragroute/fragroute.c b/src/fragroute/fragroute.c index 336fd64ee..1481742ff 100644 --- a/src/fragroute/fragroute.c +++ b/src/fragroute/fragroute.c @@ -42,7 +42,6 @@ fragroute_close(fragroute_t *ctx) assert(ctx); free(ctx->pktq); free(ctx); - ctx = NULL; pkt_close(); } diff --git a/src/fragroute/mod_ip6_opt.c b/src/fragroute/mod_ip6_opt.c index 7efbbcb9d..46b5b6c44 100644 --- a/src/fragroute/mod_ip6_opt.c +++ b/src/fragroute/mod_ip6_opt.c @@ -56,7 +56,6 @@ void * ip6_opt_open(int argc, char *argv[]) { struct ip6_opt_data *opt; - int i, j; if (argc < 4) return (NULL); @@ -65,8 +64,9 @@ ip6_opt_open(int argc, char *argv[]) return (NULL); if (strcasecmp(argv[1], "route") == 0) { - opt->type = OPT6_TYPE_ROUTE; + int i, j; + opt->type = OPT6_TYPE_ROUTE; if ((opt->u.route.segments = atoi(argv[2])) < 1 || opt->u.route.segments > MAX_ADDRS) { warnx(" must be >= 1"); diff --git a/src/fragroute/mod_ip6_qos.c b/src/fragroute/mod_ip6_qos.c index f2439b4e6..e3ffcc2e3 100644 --- a/src/fragroute/mod_ip6_qos.c +++ b/src/fragroute/mod_ip6_qos.c @@ -41,11 +41,11 @@ ip6_qos_open(int argc, char *argv[]) if ((data = calloc(1, sizeof(*data))) == NULL) return (NULL); - if (sscanf(argv[1], "%x", &data->ip6_tc) != 1 || + if (sscanf(argv[1], "%x", (unsigned int*)&data->ip6_tc) != 1 || data->ip6_tc < 0 || data->ip6_tc > 255) return (ip6_qos_close(data)); - if (sscanf(argv[2], "%x", &data->ip6_fl) != 1 || + if (sscanf(argv[2], "%x", (unsigned int*)&data->ip6_fl) != 1 || data->ip6_fl < 0 || data->ip6_fl > 0x100000) return (ip6_qos_close(data)); diff --git a/src/send_packets.c b/src/send_packets.c index 7570d6e02..78e954bc2 100644 --- a/src/send_packets.c +++ b/src/send_packets.c @@ -495,7 +495,16 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) bool preload = options->file_cache[idx].cached; bool top_speed = (options->speed.mode == speed_topspeed || (options->speed.mode == speed_mbpsrate && options->speed.speed == 0)); - bool now_is_now; + bool now_is_now = false; + + if (!timerisset(&ctx->stats.start_time)) { + gettimeofday(&ctx->stats.start_time, NULL); + if (ctx->options->stats >= 0) { + char buf[64]; + if (format_date_time(&ctx->stats.start_time, buf, sizeof(buf)) > 0) + printf("Test start: %s ...\n", buf); + } + } ctx->skip_packets = 0; start_us = TIMEVAL_TO_MICROSEC(&ctx->stats.start_time); @@ -512,12 +521,8 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) prev_packet = NULL; } - if (!top_speed) { + if (!top_speed) gettimeofday(&now, NULL); - now_is_now = true; - } else { - now_is_now = false; - } /* MAIN LOOP * Keep sending while we have packets or until @@ -557,12 +562,6 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) pktlen = options->use_pkthdr_len ? (COUNTER)pkthdr_ptr->len : (COUNTER)pkthdr_ptr->caplen; #endif - /* do we need to print the packet via tcpdump? */ -#ifdef ENABLE_VERBOSE - if (options->verbose) - tcpdump_print(options->tcpdump, &pkthdr, pktdata); -#endif - if (ctx->options->unique_ip && ctx->unique_iteration && ctx->unique_iteration > ctx->last_unique_iteration) { /* edit packet to ensure every pass has unique IP addresses */ @@ -578,7 +577,8 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) if (ctx->first_time) { /* get time and timestamp of the first packet */ gettimeofday(&now, NULL); - memcpy(&first_pkt_ts, &pkthdr.ts, sizeof(struct timeval)); + now_is_now = true; + memcpy(&first_pkt_ts, &pkthdr.ts, sizeof(first_pkt_ts)); } /* @@ -630,8 +630,13 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) tcpr_sleep(ctx, sp, &ctx->nap, &now, options->accurate); } - dbgx(2, "Sending packet #" COUNTER_SPEC, packetnum); +#ifdef ENABLE_VERBOSE + /* do we need to print the packet via tcpdump? */ + if (options->verbose) + tcpdump_print(options->tcpdump, &pkthdr, pktdata); +#endif + dbgx(2, "Sending packet #" COUNTER_SPEC, packetnum); /* write packet out on network */ if (sendpacket(sp, pktdata, pktlen, &pkthdr) < (int)pktlen) warnx("Unable to send packet: %s", sendpacket_geterr(sp)); @@ -666,13 +671,13 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) } #if defined HAVE_NETMAP - if (sp->first_packet) { + if (sp->first_packet || timesisset(&ctx->nap)) { wake_send_queues(sp, options); sp->first_packet = false; } #endif /* stop sending based on the duration limit... */ - if ((end_us > 0 && (COUNTER)TIMEVAL_TO_MICROSEC(&now) > end_us) || + if ((end_us > 0 && TIMEVAL_TO_MICROSEC(&now) > end_us) || /* ... or stop sending based on the limit -L? */ (limit_send > 0 && ctx->stats.pkts_sent >= limit_send)) { ctx->abort = true; @@ -728,7 +733,16 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t * COUNTER skip_length = 0; bool top_speed = (options->speed.mode == speed_topspeed || (options->speed.mode == speed_mbpsrate && options->speed.speed == 0)); - bool now_is_now; + bool now_is_now = false; + + if (!timerisset(&ctx->stats.start_time)) { + gettimeofday(&ctx->stats.start_time, NULL); + if (ctx->options->stats >= 0) { + char buf[64]; + if (format_date_time(&ctx->stats.start_time, buf, sizeof(buf)) > 0) + printf("Test start: %s ...\n", buf); + } + } ctx->skip_packets = 0; start_us = TIMEVAL_TO_MICROSEC(&ctx->stats.start_time); @@ -751,12 +765,8 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t * pktdata1 = get_next_packet(ctx, pcap1, &pkthdr1, cache_file_idx1, prev_packet1); pktdata2 = get_next_packet(ctx, pcap2, &pkthdr2, cache_file_idx2, prev_packet2); - if (!top_speed) { + if (!top_speed) gettimeofday(&now, NULL); - now_is_now = true; - } else { - now_is_now = false; - } /* MAIN LOOP * Keep sending while we have packets or until @@ -823,12 +833,6 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t * pktlen = options->use_pkthdr_len ? (COUNTER)pkthdr_ptr->len : (COUNTER)pkthdr_ptr->caplen; #endif - /* do we need to print the packet via tcpdump? */ -#ifdef ENABLE_VERBOSE - if (options->verbose) - tcpdump_print(options->tcpdump, pkthdr_ptr, pktdata); -#endif - if (ctx->options->unique_ip && ctx->unique_iteration && ctx->unique_iteration > ctx->last_unique_iteration) { /* edit packet to ensure every pass is unique */ @@ -843,7 +847,8 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t * if (ctx->first_time) { /* get time and timestamp of the first packet */ gettimeofday(&now, NULL); - memcpy(&first_pkt_ts, &pkthdr_ptr->ts, sizeof(struct timeval)); + now_is_now = true; + memcpy(&first_pkt_ts, &pkthdr_ptr->ts, sizeof(first_pkt_ts)); } /* @@ -895,8 +900,13 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t * tcpr_sleep(ctx, sp, &ctx->nap, &now, options->accurate); } - dbgx(2, "Sending packet #" COUNTER_SPEC, packetnum); +#ifdef ENABLE_VERBOSE + /* do we need to print the packet via tcpdump? */ + if (options->verbose) + tcpdump_print(options->tcpdump, pkthdr_ptr, pktdata); +#endif + dbgx(2, "Sending packet #" COUNTER_SPEC, packetnum); /* write packet out on network */ if (sendpacket(sp, pktdata, pktlen, pkthdr_ptr) < (int)pktlen) warnx("Unable to send packet: %s", sendpacket_geterr(sp)); @@ -927,7 +937,7 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t * } #if defined HAVE_NETMAP - if (sp->first_packet) { + if (sp->first_packet || timesisset(&ctx->nap)) { wake_send_queues(sp, options); sp->first_packet = false; } @@ -941,7 +951,7 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t * } /* stop sending based on the duration limit... */ - if ((end_us > 0 && (COUNTER)TIMEVAL_TO_MICROSEC(&now) > end_us) || + if ((end_us > 0 && TIMEVAL_TO_MICROSEC(&now) > end_us) || /* ... or stop sending based on the limit -L? */ (limit_send > 0 && ctx->stats.pkts_sent >= limit_send)) { ctx->abort = true; @@ -1021,7 +1031,7 @@ get_next_packet(tcpreplay_t *ctx, pcap_t *pcap, struct pcap_pkthdr *pkthdr, int /* * We should read the pcap file, and cache the results */ - pktdata = (u_char *)pcap_next(pcap, pkthdr); + pktdata = safe_pcap_next(pcap, pkthdr); if (pktdata != NULL) { if (*prev_packet == NULL) { /* @@ -1051,7 +1061,7 @@ get_next_packet(tcpreplay_t *ctx, pcap_t *pcap, struct pcap_pkthdr *pkthdr, int /* * Read pcap file as normal */ - pktdata = (u_char *)pcap_next(pcap, pkthdr); + pktdata = safe_pcap_next(pcap, pkthdr); } /* this get's casted to a const on the way out */ @@ -1133,9 +1143,9 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta, case speed_multiplier: /* * Replay packets a factor of the time they were originally sent. + * Make sure the packet is not late. */ - if (timerisset(last_delta)) { - /* make sure the packet is not late */ + { COUNTER delta_us, delta_pkt_time; now_us = TIMSTAMP_TO_MICROSEC(sent_timestamp); delta_pkt_time = TIMEVAL_TO_MICROSEC(pkt_time_delta); @@ -1143,25 +1153,14 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta, if (timercmp(pkt_time_delta, last_delta, >) && (delta_pkt_time > delta_us)) { /* pkt_time_delta has increased, so handle normally */ timersub(pkt_time_delta, last_delta, &nap_for); - dbgx(3, "original packet delta pkt_time: " TIMEVAL_FORMAT, - nap_for.tv_sec, nap_for.tv_usec); - TIMEVAL_TO_TIMESPEC(&nap_for, &ctx->nap); - dbgx(3, "original packet delta time: " TIMESPEC_FORMAT, - ctx->nap.tv_sec, ctx->nap.tv_nsec); + dbgx(3, "original packet delta time: " TIMESPEC_FORMAT, ctx->nap.tv_sec, ctx->nap.tv_nsec); timesdiv_float(&ctx->nap, options->speed.multiplier); - dbgx(3, "original packet delta/div: " TIMESPEC_FORMAT, - ctx->nap.tv_sec, ctx->nap.tv_nsec); + dbgx(3, "original packet delta/div: " TIMESPEC_FORMAT, ctx->nap.tv_sec, ctx->nap.tv_nsec); } else { /* Don't sleep if this packet is late or in the past */ update_time = false; } - - update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len, - now_us, delta_us, delta_pkt_time); - } else { - /* Don't sleep if this is our first packet */ - update_time = false; } break; @@ -1191,9 +1190,7 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta, tx_us = now_us - *start_us; *skip_length = ((tx_us - next_tx_us) * bps) / 8000000; } - - update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len, - now_us, tx_us, next_tx_us); + update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len, now_us, tx_us, next_tx_us); } dbgx(3, "packet size=" COUNTER_SPEC "\t\tnap=" TIMESPEC_FORMAT, len, @@ -1220,8 +1217,7 @@ static bool calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time_delta, else ctx->skip_packets = options->speed.pps_multi; - update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len, - now_us, tx_us, next_tx_us); + update_current_timestamp_trace_entry(ctx->stats.bytes_sent + (COUNTER)len, now_us, tx_us, next_tx_us); } dbgx(3, "packet count=" COUNTER_SPEC "\t\tnap=" TIMESPEC_FORMAT, ctx->stats.pkts_sent, diff --git a/src/tcpbridge.c b/src/tcpbridge.c index 41ada589e..16baa5c1d 100644 --- a/src/tcpbridge.c +++ b/src/tcpbridge.c @@ -215,8 +215,9 @@ post_args(_U_ int argc, _U_ char *argv[]) warnx("Unable to get MAC address: %s", sendpacket_geterr(sp)); err(-1, "Please consult the man page for using the -M option."); } - sendpacket_close(sp); + memcpy(options.intf1_mac, eth_buff, ETHER_ADDR_LEN); + sendpacket_close(sp); } if (memcmp(options.intf2_mac, "\00\00\00\00\00\00", ETHER_ADDR_LEN) == 0) { @@ -227,8 +228,9 @@ post_args(_U_ int argc, _U_ char *argv[]) warnx("Unable to get MAC address: %s", sendpacket_geterr(sp)); err(-1, "Please consult the man page for using the -M option."); } - sendpacket_close(sp); + memcpy(options.intf2_mac, eth_buff, ETHER_ADDR_LEN); + sendpacket_close(sp); } /* diff --git a/src/tcpbridge_opts.def b/src/tcpbridge_opts.def index 93a1a8c6c..30240e73c 100644 --- a/src/tcpbridge_opts.def +++ b/src/tcpbridge_opts.def @@ -4,9 +4,9 @@ * Copyright (c) 2001-2010 Aaron Turner * Copyright (c) 2013-2018 Fred Klassen - AppNeta * - * The Tcpreplay Suite of tools is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * The Tcpreplay Suite of tools is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the * License, or with the authors permission any later version. * * The Tcpreplay Suite is distributed in the hope that it will be useful, @@ -25,7 +25,7 @@ autogen definitions options; copyright = { date = "2000-2018"; owner = "Aaron Turner and Fred Klassen"; - eaddr = "tcpreplay-users@lists.sourceforge.net"; + eaddr = "tcpreplay-users@lists.sourceforge.net"; type = gpl; author = <<- EOText Copyright 2013-2018 Fred Klassen - AppNeta @@ -66,7 +66,7 @@ include = "#include \"defines.h\"\n" homerc = "$$/"; explain = <<- EOExplain -tcpbridge is a tool for selectively briding network traffic across two interfaces +tcpbridge is a tool for selectively bridging network traffic across two interfaces and optionally modifying the packets in between EOExplain; @@ -98,12 +98,12 @@ tcpbridge can only send packets as fast as your computer's interface, processor and system bus will allow. Connecting both interfaces to the same subnet may create a broadcast storm and -take down the network. Improper use of the packet editing functions may have +take down the network. Improper use of the packet editing functions may have other undefined and possible negative consequences. Some operating systems by default do not allow for forging source MAC addresses. Please consult your operating system's documentation and the -tcpreplay FAQ if you experiance this issue. +tcpreplay FAQ if you experience this issue. EOMan; /* @@ -121,7 +121,7 @@ flag = { arg-default = 0; descrip = "Enable debugging output"; doc = <<- EOText -If configured with --enable-debug, then you can specify a verbosity +If configured with --enable-debug, then you can specify a verbosity level for debugging output. Higher numbers increase verbosity. EOText; }; @@ -156,8 +156,8 @@ flag = { max = 1; descrip = "Send and receive in only one direction"; doc = <<- EOText -Normally, tcpbridge will send and receive traffic in both directions -(bi-directionally). However, if you choose this option, traffic will +Normally, tcpbridge will send and receive traffic in both directions +(bi-directionally). However, if you choose this option, traffic will be sent uni-directionally. EOText; }; @@ -257,7 +257,7 @@ corresponds to the packet number in the capture file. @example --include=P:1-5,9,15,72- @end example -would send packets 1 thru 5, the 9th and 15th packet, and packets 72 until the +would send packets 1 through 5, the 9th and 15th packet, and packets 72 until the end of the file @item F:'' - BPF filter. See the @file{tcpdump(8)} man page for syntax. @@ -304,7 +304,7 @@ corresponds to the packet number in the capture file. @example --exclude=P:1-5,9,15,72- @end example -would drop packets 1 thru 5, the 9th and 15th packet, and packets 72 until the +would drop packets 1 through 5, the 9th and 15th packet, and packets 72 until the end of the file @end table EOText; diff --git a/src/tcpedit/Makefile.am b/src/tcpedit/Makefile.am index cfcd2653d..15e9a767e 100644 --- a/src/tcpedit/Makefile.am +++ b/src/tcpedit/Makefile.am @@ -12,17 +12,17 @@ libtcpedit_a_SOURCES = tcpedit.c parse_args.c edit_packet.c \ manpages: tcpedit.1 tcpedit.1: tcpedit_stub.def - @AUTOGEN@ -T agman1.tpl --base-name tcpedit tcpedit_stub.def + @AUTOGEN@ -T agman1.tpl --base-name tcpedit $< tcpedit.c: tcpedit_stub.h # Get AutoOpts search path #opts_list=`find plugins -type d -not -regex ".*\.svn.*" -not -regex ".*\.deps.*" -exec echo -n "-L {} " \;` -tcpedit_stub.h: tcpedit_opts.def tcpedit_stub.def $(srcdir)/plugins/dlt_stub.def - @AUTOGEN@ $(opts_list) tcpedit_stub.def +tcpedit_stub.h: tcpedit_stub.def tcpedit_opts.def plugins/dlt_stub.def + @AUTOGEN@ $(opts_list) $< -AM_CFLAGS = -I.. -I../common -I../.. @LDNETINC@ $(LIBOPTS_CFLAGS) $(LNAV_CFLAGS) +AM_CFLAGS = -I$(srcdir). -I$(srcdir)/.. -I$(srcdir)/../common -I$(srcdir)/../.. @LDNETINC@ $(LIBOPTS_CFLAGS) $(LNAV_CFLAGS) noinst_HEADERS = tcpedit.h edit_packet.h portmap.h \ tcpedit_stub.h parse_args.h dlt.h checksum.h \ @@ -36,5 +36,5 @@ MAINTAINERCLEANFILES = Makefile.in tcpedit_stub.h tcpedit.1 EXTRA_DIST = tcpedit_stub.def tcpedit_opts.def -include $(srcdir)/plugins/Makefile.am +include plugins/Makefile.am diff --git a/src/tcpedit/edit_packet.c b/src/tcpedit/edit_packet.c index 19f41a4f1..3dcf2a3fd 100644 --- a/src/tcpedit/edit_packet.c +++ b/src/tcpedit/edit_packet.c @@ -152,13 +152,13 @@ fix_ipv6_checksums(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, ipv6_hdr_t *i void fix_ipv4_length(struct pcap_pkthdr *pkthdr, ipv4_hdr_t *ip_hdr) { if (!ip_hdr->ip_len) - ip_hdr->ip_len = pkthdr->len; + ip_hdr->ip_len = htons((uint16_t)pkthdr->len); } void fix_ipv6_length(struct pcap_pkthdr *pkthdr, ipv6_hdr_t *ip6_hdr) { if (!ip6_hdr->ip_len) - ip6_hdr->ip_len = pkthdr->len; + ip6_hdr->ip_len = htons((uint16_t)pkthdr->len); } static void ipv4_l34_csum_replace(uint8_t *data, uint8_t protocol, @@ -232,18 +232,37 @@ static void ipv6_l34_csum_replace(uint8_t *data, uint8_t protocol, } -static void ipv4_addr_csum_replace(ipv4_hdr_t *ip_hdr, uint32_t old_ip, uint32_t new_ip) +static void ipv4_addr_csum_replace(ipv4_hdr_t *ip_hdr, uint32_t old_ip, + uint32_t new_ip, int len) { - uint8_t *l4 = NULL, protocol; + uint8_t *l4, protocol; + assert(ip_hdr); + if (len < sizeof(*ip_hdr)) + return; + ipv4_l34_csum_replace((uint8_t*)ip_hdr, IPPROTO_IP, old_ip, new_ip); - protocol = ip_hdr->ip_p; - if (protocol == IPPROTO_TCP || protocol == IPPROTO_UDP) - l4 = get_layer4_v4(ip_hdr, 65536); + protocol = ip_hdr->ip_p; + switch (protocol) { + case IPPROTO_UDP: + l4 = get_layer4_v4(ip_hdr, len); + len -= ip_hdr->ip_hl << 2; + len -= TCPR_UDP_H; + break; + + case IPPROTO_TCP: + l4 = get_layer4_v4(ip_hdr, len); + len -= ip_hdr->ip_hl << 2; + len -= TCPR_TCP_H; + break; - if (!l4) + default: + l4 = NULL; + } + + if (!l4 || len < 0) return; /* if this is a fragment, don't attempt to checksum the Layer4 header */ @@ -252,17 +271,34 @@ static void ipv4_addr_csum_replace(ipv4_hdr_t *ip_hdr, uint32_t old_ip, uint32_t } static void ipv6_addr_csum_replace(ipv6_hdr_t *ip6_hdr, - struct tcpr_in6_addr *old_ip, struct tcpr_in6_addr *new_ip) + struct tcpr_in6_addr *old_ip, struct tcpr_in6_addr *new_ip, int len) { - uint8_t *l4 = NULL, protocol; + uint8_t *l4, protocol; + assert(ip6_hdr); - protocol = get_ipv6_l4proto(ip6_hdr, 65536); - if (protocol == IPPROTO_TCP || protocol == IPPROTO_UDP || - protocol == IPPROTO_ICMP || protocol == IPPROTO_ICMP6) - l4 = get_layer4_v6(ip6_hdr, 65536); + if (len < sizeof(*ip6_hdr)) + return; - if (!l4) + protocol = get_ipv6_l4proto(ip6_hdr, len); + switch (protocol) { + case IPPROTO_UDP: + l4 = get_layer4_v6(ip6_hdr, len); + len -= sizeof(*ip6_hdr); + len -= TCPR_UDP_H; + break; + + case IPPROTO_TCP: + l4 = get_layer4_v6(ip6_hdr, len); + len -= sizeof(*ip6_hdr); + len -= TCPR_TCP_H; + break; + + default: + l4 = NULL; + } + + if (!l4 || len < 0) return; ipv6_l34_csum_replace(l4, protocol, (uint32_t*)old_ip, (uint32_t*)new_ip); @@ -317,7 +353,7 @@ randomize_ipv6_addr(tcpedit_t *tcpedit, struct tcpr_in6_addr *addr) */ int randomize_ipv4(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, - u_char *pktdata, ipv4_hdr_t *ip_hdr) + u_char *pktdata, ipv4_hdr_t *ip_hdr, int len) { #ifdef DEBUG char srcip[16], dstip[16]; @@ -340,14 +376,14 @@ randomize_ipv4(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, || !tcpedit->skip_broadcast) { uint32_t old_ip = ip_hdr->ip_dst.s_addr; ip_hdr->ip_dst.s_addr = randomize_ipv4_addr(tcpedit, ip_hdr->ip_dst.s_addr); - ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_dst.s_addr); + ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_dst.s_addr, len); } if ((tcpedit->skip_broadcast && is_unicast_ipv4(tcpedit, (u_int32_t)ip_hdr->ip_src.s_addr)) || !tcpedit->skip_broadcast) { uint32_t old_ip = ip_hdr->ip_src.s_addr; ip_hdr->ip_src.s_addr = randomize_ipv4_addr(tcpedit, ip_hdr->ip_src.s_addr); - ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_src.s_addr); + ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_src.s_addr, len); } #ifdef DEBUG @@ -362,7 +398,7 @@ randomize_ipv4(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, int randomize_ipv6(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, - u_char *pktdata, ipv6_hdr_t *ip6_hdr) + u_char *pktdata, ipv6_hdr_t *ip6_hdr, int len) { #ifdef DEBUG char srcip[INET6_ADDRSTRLEN], dstip[INET6_ADDRSTRLEN]; @@ -386,7 +422,7 @@ randomize_ipv6(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, struct tcpr_in6_addr old_ip6; memcpy(&old_ip6, &ip6_hdr->ip_dst, sizeof(old_ip6)); randomize_ipv6_addr(tcpedit, &ip6_hdr->ip_dst); - ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_dst); + ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_dst, len); } if ((tcpedit->skip_broadcast && !is_multicast_ipv6(tcpedit, &ip6_hdr->ip_src)) @@ -394,7 +430,7 @@ randomize_ipv6(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, struct tcpr_in6_addr old_ip6; memcpy(&old_ip6, &ip6_hdr->ip_src, sizeof(old_ip6)); randomize_ipv6_addr(tcpedit, &ip6_hdr->ip_src); - ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_src); + ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_src, len); } #ifdef DEBUG @@ -522,10 +558,9 @@ extract_data(tcpedit_t *tcpedit, const u_char *pktdata, int caplen, char *l7data[]) { int datalen = 0; /* amount of data beyond ip header */ - ipv4_hdr_t *ip_hdr = NULL; - tcp_hdr_t *tcp_hdr = NULL; + ipv4_hdr_t *ip_hdr; u_char ipbuff[MAXPACKET]; - u_char *dataptr = NULL; + u_char *dataptr; int ip_len; assert(tcpedit); @@ -557,7 +592,7 @@ extract_data(tcpedit_t *tcpedit, const u_char *pktdata, int caplen, /* TCP ? */ if (ip_hdr->ip_p == IPPROTO_TCP) { - tcp_hdr = (tcp_hdr_t *) get_layer4_v4(ip_hdr, datalen); + tcp_hdr_t *tcp_hdr = (tcp_hdr_t *) get_layer4_v4(ip_hdr, datalen); datalen -= tcp_hdr->th_off << 2; if (datalen <= 0) goto nodata; @@ -760,7 +795,8 @@ remap_ipv6(tcpedit_t *tcpedit, tcpr_cidr_t *cidr, struct tcpr_in6_addr *addr) * return 0 if no change, 1 or 2 if changed */ int -rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction) +rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction, + int len) { tcpr_cidrmap_t *cidrmap1 = NULL, *cidrmap2 = NULL; int didsrc = 0, diddst = 0, loop = 1; @@ -775,7 +811,7 @@ rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction) if (ip_in_cidr(ipmap->from, ip_hdr->ip_src.s_addr)) { uint32_t old_ip = ip_hdr->ip_src.s_addr; ip_hdr->ip_src.s_addr = remap_ipv4(tcpedit, ipmap->to, ip_hdr->ip_src.s_addr); - ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_src.s_addr); + ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_src.s_addr, len); dbgx(2, "Remapped src addr to: %s", get_addr2name4(ip_hdr->ip_src.s_addr, RESOLVE)); break; } @@ -787,7 +823,7 @@ rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction) if (ip_in_cidr(ipmap->from, ip_hdr->ip_dst.s_addr)) { uint32_t old_ip = ip_hdr->ip_dst.s_addr; ip_hdr->ip_dst.s_addr = remap_ipv4(tcpedit, ipmap->to, ip_hdr->ip_dst.s_addr); - ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_dst.s_addr); + ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_dst.s_addr, len); dbgx(2, "Remapped dst addr to: %s", get_addr2name4(ip_hdr->ip_dst.s_addr, RESOLVE)); break; } @@ -813,14 +849,14 @@ rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction) if ((! diddst) && ip_in_cidr(cidrmap2->from, ip_hdr->ip_dst.s_addr)) { uint32_t old_ip = ip_hdr->ip_dst.s_addr; ip_hdr->ip_dst.s_addr = remap_ipv4(tcpedit, cidrmap2->to, ip_hdr->ip_dst.s_addr); - ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_dst.s_addr); + ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_dst.s_addr, len); dbgx(2, "Remapped dst addr to: %s", get_addr2name4(ip_hdr->ip_dst.s_addr, RESOLVE)); diddst = 1; } if ((! didsrc) && ip_in_cidr(cidrmap1->from, ip_hdr->ip_src.s_addr)) { uint32_t old_ip = ip_hdr->ip_src.s_addr; ip_hdr->ip_src.s_addr = remap_ipv4(tcpedit, cidrmap1->to, ip_hdr->ip_src.s_addr); - ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_src.s_addr); + ipv4_addr_csum_replace(ip_hdr, old_ip, ip_hdr->ip_src.s_addr, len); dbgx(2, "Remapped src addr to: %s", get_addr2name4(ip_hdr->ip_src.s_addr, RESOLVE)); didsrc = 1; } @@ -855,7 +891,8 @@ rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction) } int -rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip6_hdr, tcpr_dir_t direction) +rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip6_hdr, tcpr_dir_t direction, + int len) { tcpr_cidrmap_t *cidrmap1 = NULL, *cidrmap2 = NULL; int didsrc = 0, diddst = 0, loop = 1; @@ -871,7 +908,7 @@ rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip6_hdr, tcpr_dir_t direction) struct tcpr_in6_addr old_ip6; memcpy(&old_ip6, &ip6_hdr->ip_src, sizeof(old_ip6)); remap_ipv6(tcpedit, ipmap->to, &ip6_hdr->ip_src); - ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_src); + ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_src, len); dbgx(2, "Remapped src addr to: %s", get_addr2name6(&ip6_hdr->ip_src, RESOLVE)); break; } @@ -884,7 +921,7 @@ rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip6_hdr, tcpr_dir_t direction) struct tcpr_in6_addr old_ip6; memcpy(&old_ip6, &ip6_hdr->ip_dst, sizeof(old_ip6)); remap_ipv6(tcpedit, ipmap->to, &ip6_hdr->ip_dst); - ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_dst); + ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_dst, len); dbgx(2, "Remapped dst addr to: %s", get_addr2name6(&ip6_hdr->ip_dst, RESOLVE)); break; } @@ -911,7 +948,7 @@ rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip6_hdr, tcpr_dir_t direction) struct tcpr_in6_addr old_ip6; memcpy(&old_ip6, &ip6_hdr->ip_dst, sizeof(old_ip6)); remap_ipv6(tcpedit, cidrmap2->to, &ip6_hdr->ip_dst); - ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_dst); + ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_dst, len); dbgx(2, "Remapped dst addr to: %s", get_addr2name6(&ip6_hdr->ip_dst, RESOLVE)); diddst = 1; } @@ -919,7 +956,7 @@ rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip6_hdr, tcpr_dir_t direction) struct tcpr_in6_addr old_ip6; memcpy(&old_ip6, &ip6_hdr->ip_src, sizeof(old_ip6)); remap_ipv6(tcpedit, cidrmap1->to, &ip6_hdr->ip_src); - ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_src); + ipv6_addr_csum_replace(ip6_hdr, &old_ip6, &ip6_hdr->ip_src, len); dbgx(2, "Remapped src addr to: %s", get_addr2name6(&ip6_hdr->ip_src, RESOLVE)); didsrc = 1; } @@ -964,7 +1001,6 @@ randomize_iparp(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, arp_hdr_t *arp_hdr = NULL; int l2len = 0; uint32_t *ip; - u_char *add_hdr; #ifdef FORCE_ALIGN uint32_t iptemp; #endif @@ -984,8 +1020,8 @@ randomize_iparp(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, (ntohs(arp_hdr->ar_op) == ARPOP_REPLY))) { /* jump to the addresses */ - add_hdr = (u_char *)arp_hdr; - add_hdr += sizeof(arp_hdr_t) + arp_hdr->ar_hln; + u_char *add_hdr = ((u_char *)arp_hdr) + sizeof(arp_hdr_t) + + arp_hdr->ar_hln; #ifdef FORCE_ALIGN /* copy IP to a temporary buffer for processing */ memcpy(&iptemp, add_hdr, sizeof(uint32_t)); diff --git a/src/tcpedit/edit_packet.h b/src/tcpedit/edit_packet.h index 3d086685a..c65ef6d4d 100644 --- a/src/tcpedit/edit_packet.h +++ b/src/tcpedit/edit_packet.h @@ -28,10 +28,10 @@ int untrunc_packet(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, u_char **pktdata, ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr); int randomize_ipv4(tcpedit_t *tcpedit, struct pcap_pkthdr *pktdhr, - u_char *pktdata, ipv4_hdr_t *ip_hdr); + u_char *pktdata, ipv4_hdr_t *ip_hdr, int len); int randomize_ipv6(tcpedit_t *tcpedit, struct pcap_pkthdr *pktdhr, - u_char *pktdata, ipv6_hdr_t *ip_hdr); + u_char *pktdata, ipv6_hdr_t *ip_hdr, int len); int randomize_iparp(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, u_char *pktdata, int datalink); @@ -49,9 +49,11 @@ void fix_ipv6_length(struct pcap_pkthdr *pkthdr, ipv6_hdr_t *ip6_hdr); int extract_data(tcpedit_t *tcpedit, const u_char *pktdata, int caplen, char *l7data[]); -int rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction); +int rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction, + int len); -int rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip_hdr, tcpr_dir_t direction); +int rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip_hdr, tcpr_dir_t direction, + int len); int rewrite_iparp(tcpedit_t *tcpedit, arp_hdr_t *arp_hdr, int direction); diff --git a/src/tcpedit/fuzzing.c b/src/tcpedit/fuzzing.c index 382a56fde..edae84c30 100644 --- a/src/tcpedit/fuzzing.c +++ b/src/tcpedit/fuzzing.c @@ -106,7 +106,7 @@ fuzzing(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, plugin = tcpedit->dlt_ctx->encoder; l2len = plugin->plugin_l2len(ctx, packet, caplen); l2proto = ntohs(ctx->proto); - if (caplen < l2len) + if (l2len == -1 || caplen < l2len) goto done; /* @@ -124,7 +124,7 @@ fuzzing(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, switch (l2proto) { case (ETHERTYPE_IP): { - l4data = get_layer4_v4((ipv4_hdr_t*)l3data, caplen); + l4data = get_layer4_v4((ipv4_hdr_t*)l3data, caplen - l2len); if (!l4data) goto done; @@ -132,7 +132,7 @@ fuzzing(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, break; } case (ETHERTYPE_IP6): { - l4data = get_layer4_v6((ipv6_hdr_t*)l3data, caplen); + l4data = get_layer4_v6((ipv6_hdr_t*)l3data, caplen - l2len); if (!l4data) goto done; diff --git a/src/tcpedit/plugins/Makefile.am b/src/tcpedit/plugins/Makefile.am index 9ff8cc619..c99e27413 100644 --- a/src/tcpedit/plugins/Makefile.am +++ b/src/tcpedit/plugins/Makefile.am @@ -1,36 +1,49 @@ # $Id: $ -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_plugins.c \ - $(srcdir)/plugins/ethernet.c $(srcdir)/plugins/dlt_utils.c +libtcpedit_a_SOURCES += \ + %reldir%/dlt_plugins.c \ + %reldir%/ethernet.c \ + %reldir%/ethernet.h \ + %reldir%/dlt_utils.c \ + %reldir%/dlt_utils.h -noinst_HEADERS += $(srcdir)/plugins/ethernet.h \ - $(srcdir)/plugins/dlt_utils.h $(srcdir)/plugins/ethernet.h +noinst_HEADERS += \ + %reldir%/ethernet.h \ + %reldir%/dlt_utils.h -AM_CFLAGS += -I. -I$(srcdir)/plugins -I$(srcdir)/../common $(LIBOPTS_CFLAGS) +AM_CFLAGS += -I$(srcdir)/%reldir% $(LIBOPTS_CFLAGS) -EXTRA_DIST += $(srcdir)/plugins/dlt_opts.def $(srcdir)/plugins/dlt_stub.def +EXTRA_DIST += %reldir%/dlt_opts.def %reldir%/dlt_stub.def -MOSTLYCLEANFILES += $(srcdir)/plugins/*~ +MOSTLYCLEANFILES += *~ -MAINTAINERCLEANFILES += Makefile.in +MAINTAINERCLEANFILES += %reldir%/Makefile.in -DLT_STUB_DEPS = $(srcdir)/plugins/dlt_opts.def +DLT_STUB_DEPS = %reldir%/dlt_opts.def -$(srcdir)/plugins/dlt_stub.def: $(DLT_STUB_DEPS) +dlt_stub.def: $(DLT_STUB_DEPS) + +TCPEDIT_PLUGINS_DEPS =\ + %reldir%/dlt_utils.h \ + %reldir%/../tcpedit_stub.h \ + %reldir%/../plugins.h \ + %reldir%/../plugins_api.h \ + %reldir%/../plugins_types.h \ + %reldir%/../tcpedit_api.h ######################################################## # Add your plugin Makefile.am's below this line ######################################################## -include $(srcdir)/plugins/dlt_en10mb/Makefile.am -include $(srcdir)/plugins/dlt_hdlc/Makefile.am -include $(srcdir)/plugins/dlt_user/Makefile.am -include $(srcdir)/plugins/dlt_raw/Makefile.am -include $(srcdir)/plugins/dlt_null/Makefile.am -include $(srcdir)/plugins/dlt_loop/Makefile.am -include $(srcdir)/plugins/dlt_linuxsll/Makefile.am -include $(srcdir)/plugins/dlt_ieee80211/Makefile.am -include $(srcdir)/plugins/dlt_radiotap/Makefile.am -include $(srcdir)/plugins/dlt_jnpr_ether/Makefile.am -include $(srcdir)/plugins/dlt_pppserial/Makefile.am +include %reldir%/dlt_en10mb/Makefile.am +include %reldir%/dlt_hdlc/Makefile.am +include %reldir%/dlt_user/Makefile.am +include %reldir%/dlt_raw/Makefile.am +include %reldir%/dlt_null/Makefile.am +include %reldir%/dlt_loop/Makefile.am +include %reldir%/dlt_linuxsll/Makefile.am +include %reldir%/dlt_ieee80211/Makefile.am +include %reldir%/dlt_radiotap/Makefile.am +include %reldir%/dlt_jnpr_ether/Makefile.am +include %reldir%/dlt_pppserial/Makefile.am diff --git a/src/tcpedit/plugins/dlt_en10mb/Makefile.am b/src/tcpedit/plugins/dlt_en10mb/Makefile.am index a5ed66393..07db265e8 100644 --- a/src/tcpedit/plugins/dlt_en10mb/Makefile.am +++ b/src/tcpedit/plugins/dlt_en10mb/Makefile.am @@ -6,25 +6,28 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_en10mb/en10mb.c \ - $(srcdir)/plugins/dlt_en10mb/en10mb_api.c +libtcpedit_a_SOURCES += \ + %reldir%/en10mb.c \ + %reldir%/en10mb_api.c -noinst_HEADERS += $(srcdir)/plugins/dlt_en10mb/en10mb.h \ - $(srcdir)/plugins/dlt_en10mb/en10mb_api.h \ - $(srcdir)/plugins/dlt_en10mb/en10mb_types.h \ - $(srcdir)/tcpedit_types.h +noinst_HEADERS += \ + %reldir%/en10mb.h \ + %reldir%/en10mb_api.h \ + %reldir%/en10mb_types.h \ + %reldir%/../../tcpedit_types.h -EXTRA_DIST += $(srcdir)/plugins/dlt_en10mb/en10mb_opts.def +EXTRA_DIST += %reldir%/en10mb_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_en10mb/en10mb.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h $(srcdir)/plugins/dlt_en10mb/en10mb.h $(srcdir)/plugins/dlt_en10mb/en10mb_api.h \ - $(srcdir)/plugins/dlt_en10mb/en10mb_types.h +en10mb.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/en10mb.h \ + %reldir%/en10mb_api.h \ + %reldir%/en10mb_types.h # Note: # You probably don't want to touch anything below this line until the end of the plugin -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_en10mb/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_en10mb diff --git a/src/tcpedit/plugins/dlt_en10mb/en10mb.c b/src/tcpedit/plugins/dlt_en10mb/en10mb.c index 8e08c9464..8e18c15b8 100644 --- a/src/tcpedit/plugins/dlt_en10mb/en10mb.c +++ b/src/tcpedit/plugins/dlt_en10mb/en10mb.c @@ -483,9 +483,21 @@ dlt_en10mb_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, tcpr_dir_t dir) return TCPEDIT_ERROR; } + if (pktlen < ctx->l2len) { + tcpedit_seterr(ctx->tcpedit, + "Unable to process packet #" COUNTER_SPEC " since its new length less then %d L2 bytes.", + ctx->tcpedit->runtime.packetnum, ctx->l2len); + return TCPEDIT_ERROR; + } + /* Make space for our new L2 header */ - if (newl2len != ctx->l2len) + if (newl2len != ctx->l2len) { + if (pktlen + (newl2len - ctx->l2len) > MAXPACKET) + errx(-1, "New frame too big, new length %d exceeds %d", + pktlen + (newl2len - ctx->l2len), MAXPACKET); + memmove(packet + newl2len, packet + ctx->l2len, pktlen - ctx->l2len); + } /* update the total packet length */ pktlen += newl2len - ctx->l2len; @@ -686,8 +698,7 @@ dlt_en10mb_get_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen) assert(packet); l2len = dlt_en10mb_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_copy(ctx, packet, pktlen, l2len); @@ -708,8 +719,7 @@ dlt_en10mb_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, u_c assert(l3data); l2len = dlt_en10mb_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, l3data, l2len); @@ -752,26 +762,26 @@ int dlt_en10mb_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) { int l2len; - struct tcpr_ethernet_hdr *eth = NULL; + uint16_t ether_type; assert(ctx); assert(packet); - eth = (struct tcpr_ethernet_hdr *)packet; - switch (ntohs(eth->ether_type)) { - case ETHERTYPE_VLAN: - l2len = 18; - break; - - default: - l2len = 14; - break; + l2len = sizeof(eth_hdr_t); + if (pktlen < l2len) + return -1; + + ether_type = ntohs(((eth_hdr_t*)(packet + l2len))->ether_type); + while (ether_type == ETHERTYPE_VLAN) { + vlan_hdr_t *vlan_hdr = (vlan_hdr_t *)(packet + l2len); + ether_type = ntohs(vlan_hdr->vlan_len); + l2len += 4; } if (l2len > 0) { if (pktlen < l2len) { /* can happen if fuzzing is enabled */ - return 0; + return -1; } return l2len; diff --git a/src/tcpedit/plugins/dlt_hdlc/Makefile.am b/src/tcpedit/plugins/dlt_hdlc/Makefile.am index acfd54f23..bff76c52c 100644 --- a/src/tcpedit/plugins/dlt_hdlc/Makefile.am +++ b/src/tcpedit/plugins/dlt_hdlc/Makefile.am @@ -6,24 +6,27 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_hdlc/hdlc.c \ - $(srcdir)/plugins/dlt_hdlc/hdlc_api.c +libtcpedit_a_SOURCES += \ + %reldir%/hdlc.c \ + %reldir%/hdlc_api.c -noinst_HEADERS += $(srcdir)/plugins/dlt_hdlc/hdlc.h \ - $(srcdir)/plugins/dlt_hdlc/hdlc_api.h \ - $(srcdir)/plugins/dlt_hdlc/hdlc_types.h +noinst_HEADERS += \ + %reldir%/hdlc.h \ + %reldir%/hdlc_api.h \ + %reldir%/hdlc_types.h -EXTRA_DIST += $(srcdir)/plugins/dlt_hdlc/hdlc_opts.def +EXTRA_DIST += %reldir%/hdlc_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_hdlc/hdlc.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h $(srcdir)/plugins/dlt_hdlc/hdlc.h $(srcdir)/plugins/dlt_hdlc/hdlc_api.h \ - $(srcdir)/plugins/dlt_hdlc/hdlc_types.h +hdlc.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/hdlc.h \ + %reldir%/hdlc_api.h \ + %reldir%/hdlc_types.h # Note: # You probably don't want to touch anything below this line until the end of the plugin -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_hdlc/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_hdlc diff --git a/src/tcpedit/plugins/dlt_hdlc/hdlc.c b/src/tcpedit/plugins/dlt_hdlc/hdlc.c index bf4331575..4b9707bf5 100644 --- a/src/tcpedit/plugins/dlt_hdlc/hdlc.c +++ b/src/tcpedit/plugins/dlt_hdlc/hdlc.c @@ -322,10 +322,8 @@ dlt_hdlc_get_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen) assert(ctx); assert(packet); - /* FIXME: Is there anything else we need to do?? */ l2len = dlt_hdlc_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_copy(ctx, packet, pktlen, l2len); @@ -345,10 +343,8 @@ dlt_hdlc_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, u_cha assert(packet); assert(l3data); - /* FIXME: Is there anything else we need to do?? */ l2len = dlt_hdlc_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, l3data, l2len); @@ -364,7 +360,7 @@ dlt_hdlc_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) assert(packet); if (pktlen < 4) - return 0; + return -1; /* HDLC is a static 4 bytes */ return 4; diff --git a/src/tcpedit/plugins/dlt_ieee80211/Makefile.am b/src/tcpedit/plugins/dlt_ieee80211/Makefile.am index 96e377491..16567242f 100644 --- a/src/tcpedit/plugins/dlt_ieee80211/Makefile.am +++ b/src/tcpedit/plugins/dlt_ieee80211/Makefile.am @@ -6,24 +6,29 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_ieee80211/ieee80211.c $(srcdir)/plugins/dlt_ieee80211/ieee80211_hdr.c +libtcpedit_a_SOURCES += \ + %reldir%/ieee80211.c \ + %reldir%/ieee80211_hdr.c -noinst_HEADERS += $(srcdir)/plugins/dlt_ieee80211/ieee80211.h $(srcdir)/plugins/dlt_ieee80211/ieee80211_hdr.h \ - $(srcdir)/plugins/dlt_ieee80211/ieee80211_types.h +noinst_HEADERS += \ + %reldir%/ieee80211.h \ + %reldir%/ieee80211_hdr.h \ + %reldir%/ieee80211_types.h -EXTRA_DIST += $(srcdir)/plugins/dlt_ieee80211/ieee80211_opts.def +EXTRA_DIST += %reldir%/ieee80211_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_ieee80211/ieee80211.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h $(srcdir)/plugins/dlt_ieee80211/ieee80211_hdr.c \ - $(srcdir)/plugins/dlt_ieee80211/ieee80211_hdr.h $(srcdir)/plugins/dlt_ieee80211/ieee80211_types.h \ - $(srcdir)/plugins/dlt_ieee80211/ieee80211.h +ieee80211.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/ieee80211_hdr.c \ + %reldir%/ieee80211_hdr.h \ + %reldir%/ieee80211_types.h \ + %reldir%/ieee80211.h # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_ieee80211/ieee80211_opts.def +DLT_STUB_DEPS += %reldir%/ieee80211_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_ieee80211/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_ieee80211 diff --git a/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c b/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c index 31560e17b..fb9075bdc 100644 --- a/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c +++ b/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c @@ -187,8 +187,7 @@ dlt_ieee80211_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) assert(packet); l2len = dlt_ieee80211_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return TCPEDIT_ERROR; dbgx(3, "Decoding 802.11 packet " COUNTER_SPEC, ctx->tcpedit->runtime.packetnum); @@ -240,7 +239,7 @@ dlt_ieee80211_proto(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) assert(packet); l2len = dlt_ieee80211_l2len(ctx, packet, pktlen); - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return TCPEDIT_ERROR; /* check 802.11 frame control field */ @@ -287,8 +286,7 @@ dlt_ieee80211_get_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen) assert(packet); l2len = dlt_ieee80211_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; dbgx(1, "Getting data for packet " COUNTER_SPEC " from offset: %d", ctx->tcpedit->runtime.packetnum, l2len); @@ -311,8 +309,7 @@ dlt_ieee80211_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, assert(l3data); l2len = dlt_ieee80211_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, l3data, l2len); diff --git a/src/tcpedit/plugins/dlt_ieee80211/ieee80211_hdr.c b/src/tcpedit/plugins/dlt_ieee80211/ieee80211_hdr.c index 8a42ec1a5..090e0ae1b 100644 --- a/src/tcpedit/plugins/dlt_ieee80211/ieee80211_hdr.c +++ b/src/tcpedit/plugins/dlt_ieee80211/ieee80211_hdr.c @@ -143,8 +143,6 @@ ieee80211_is_encrypted(tcpeditdlt_t *ctx, const void *packet, const int pktlen) u_char * ieee80211_get_src(const void *header) { - ieee80211_hdr_t *addr3; - ieee80211_addr4_hdr_t *addr4; uint16_t *frame_control, fc; assert(header); @@ -152,10 +150,10 @@ ieee80211_get_src(const void *header) fc = ntohs(*frame_control); if (ieee80211_USE_4(fc)) { - addr4 = (ieee80211_addr4_hdr_t *)header; + ieee80211_addr4_hdr_t *addr4 = (ieee80211_addr4_hdr_t *)header; return addr4->addr4; } else { - addr3 = (ieee80211_hdr_t *)header; + ieee80211_hdr_t *addr3 = (ieee80211_hdr_t *)header; switch (fc & (ieee80211_FC_TO_DS_MASK + ieee80211_FC_FROM_DS_MASK)) { case ieee80211_FC_TO_DS_MASK: return addr3->addr2; diff --git a/src/tcpedit/plugins/dlt_jnpr_ether/Makefile.am b/src/tcpedit/plugins/dlt_jnpr_ether/Makefile.am index e2fb5f2bd..b1b5a49be 100644 --- a/src/tcpedit/plugins/dlt_jnpr_ether/Makefile.am +++ b/src/tcpedit/plugins/dlt_jnpr_ether/Makefile.am @@ -6,26 +6,29 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether.c \ - $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether.c +libtcpedit_a_SOURCES += \ + %reldir%/jnpr_ether.c \ + %reldir%/jnpr_ether.c -noinst_HEADERS += $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether.h \ - $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether_api.h \ - $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether_types.h +noinst_HEADERS += \ + %reldir%/jnpr_ether.h \ + %reldir%/jnpr_ether_api.h \ + %reldir%/jnpr_ether_types.h -EXTRA_DIST += $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether_opts.def +EXTRA_DIST += %reldir%/jnpr_ether_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether.h $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether_api.h \ - $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether_types.h - +jnpr_ether.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/jnpr_ether.h \ + %reldir%/jnpr_ether_api.h \ + %reldir%/jnpr_ether_types.h + # Note: # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_jnpr_ether/jnpr_ether_opts.def +DLT_STUB_DEPS += %reldir%/jnpr_ether_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_jnpr_ether/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_jnpr_ether diff --git a/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c b/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c index ff1708051..392576965 100644 --- a/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c +++ b/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c @@ -341,8 +341,7 @@ dlt_jnpr_ether_get_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen) } l2len = dlt_jnpr_ether_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_copy(ctx, packet, pktlen, l2len); @@ -363,8 +362,7 @@ dlt_jnpr_ether_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, assert(l3data); l2len = dlt_jnpr_ether_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, l3data, l2len); @@ -405,14 +403,14 @@ dlt_jnpr_ether_get_mac(tcpeditdlt_t *ctx, tcpeditdlt_mac_type_t mac, const u_cha int dlt_jnpr_ether_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) { - uint16_t len; + uint16_t len, res; jnpr_ether_config_t *config; assert(ctx); assert(packet); if (pktlen < JUNIPER_ETHER_EXTLEN_OFFSET + 2) - return 0; + return -1; config = (jnpr_ether_config_t *)ctx->encoder->config; @@ -423,7 +421,11 @@ dlt_jnpr_ether_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) dbgx(3, "juniper header len: %u", len); /* add the 802.3 length */ - len += tcpedit_dlt_l2len(config->subctx, DLT_EN10MB, (packet + len), (pktlen - len)); + res = tcpedit_dlt_l2len(config->subctx, DLT_EN10MB, (packet + len), (pktlen - len)); + if (res == -1) + return TCPEDIT_ERROR; + + len += res; dbgx(3, "total l2len: %u", len); /* and return that */ diff --git a/src/tcpedit/plugins/dlt_linuxsll/Makefile.am b/src/tcpedit/plugins/dlt_linuxsll/Makefile.am index 79b1eb007..4ebf886a9 100644 --- a/src/tcpedit/plugins/dlt_linuxsll/Makefile.am +++ b/src/tcpedit/plugins/dlt_linuxsll/Makefile.am @@ -6,24 +6,25 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_linuxsll/linuxsll.c +libtcpedit_a_SOURCES += %reldir%/linuxsll.c -noinst_HEADERS += $(srcdir)/plugins/dlt_linuxsll/linuxsll.h \ - $(srcdir)/plugins/dlt_linuxsll/linuxsll_types.h +noinst_HEADERS += \ + %reldir%/linuxsll.h \ + %reldir%/linuxsll_types.h -EXTRA_DIST += $(srcdir)/plugins/dlt_linuxsll/linuxsll_opts.def +EXTRA_DIST += %reldir%/linuxsll_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_linuxsll/linuxsll.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins/dlt_linuxsll/linuxsll.h $(srcdir)/plugins/dlt_linuxsll/linuxsll_types.h \ - $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h +linuxsll.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/../../tcpedit_api.h \ + %reldir%/linuxsll.h \ + %reldir%/linuxsll_types.h # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_linuxsll/linuxsll_opts.def +DLT_STUB_DEPS += %reldir%/linuxsll_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_linuxsll/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_linuxsll diff --git a/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c b/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c index aaf58d78e..e84075d98 100644 --- a/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c +++ b/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c @@ -240,8 +240,7 @@ dlt_linuxsll_get_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen) assert(packet); l2len = dlt_linuxsll_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_copy(ctx, packet, pktlen, l2len); @@ -262,8 +261,7 @@ dlt_linuxsll_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, u assert(l3data); l2len = dlt_linuxsll_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, l3data, l2len); @@ -279,7 +277,7 @@ dlt_linuxsll_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) assert(packet); if (pktlen < (int)sizeof(linux_sll_header_t)) - return 0; + return -1; return sizeof(linux_sll_header_t); } diff --git a/src/tcpedit/plugins/dlt_loop/Makefile.am b/src/tcpedit/plugins/dlt_loop/Makefile.am index ef4bdee2d..2d46eb348 100644 --- a/src/tcpedit/plugins/dlt_loop/Makefile.am +++ b/src/tcpedit/plugins/dlt_loop/Makefile.am @@ -6,22 +6,21 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_loop/loop.c +libtcpedit_a_SOURCES += %reldir%/loop.c -noinst_HEADERS += $(srcdir)/plugins/dlt_loop/loop.h +noinst_HEADERS += %reldir%/loop.h -EXTRA_DIST += $(srcdir)/plugins/dlt_loop/loop_opts.def +EXTRA_DIST += %reldir%/loop_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_loop/loop.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins/dlt_loop/loop.h $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h +loop.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/loop.h # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_loop/loop_opts.def +DLT_STUB_DEPS += %reldir%/loop_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_loop/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_loop diff --git a/src/tcpedit/plugins/dlt_null/Makefile.am b/src/tcpedit/plugins/dlt_null/Makefile.am index fbc901343..f8fd5c5ef 100644 --- a/src/tcpedit/plugins/dlt_null/Makefile.am +++ b/src/tcpedit/plugins/dlt_null/Makefile.am @@ -6,23 +6,22 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_null/null.c +libtcpedit_a_SOURCES += %reldir%/null.c -noinst_HEADERS += $(srcdir)/plugins/dlt_null/null.h +noinst_HEADERS += %reldir%/null.h -EXTRA_DIST += $(srcdir)/plugins/dlt_null/null_opts.def +EXTRA_DIST += %reldir%/null_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_null/null.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins/dlt_null/null.h $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h +null.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/null.h # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_null/null_opts.def +DLT_STUB_DEPS += %reldir%/null_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_null/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_null diff --git a/src/tcpedit/plugins/dlt_plugins.c b/src/tcpedit/plugins/dlt_plugins.c index 1b1f78b23..018f5152e 100644 --- a/src/tcpedit/plugins/dlt_plugins.c +++ b/src/tcpedit/plugins/dlt_plugins.c @@ -304,6 +304,8 @@ int tcpedit_dlt_l2len(tcpeditdlt_t *ctx, int dlt, const u_char *packet, const int pktlen) { tcpeditdlt_plugin_t *plugin; + int res; + assert(ctx); assert(dlt >= 0); assert(packet); @@ -312,7 +314,15 @@ tcpedit_dlt_l2len(tcpeditdlt_t *ctx, int dlt, const u_char *packet, const int pk tcpedit_seterr(ctx->tcpedit, "Unable to find plugin for DLT 0x%04x", dlt); return -1; } - return plugin->plugin_l2len(ctx, packet, pktlen); + + res = plugin->plugin_l2len(ctx, packet, pktlen); + if (res == -1) { + tcpedit_seterr(ctx->tcpedit, "Packet length %d is to short to contain a layer 2 header for DLT 0x%04x", + pktlen, dlt); + return -1; + } + + return res; } /** @@ -342,6 +352,7 @@ u_char * tcpedit_dlt_l3data(tcpeditdlt_t *ctx, int dlt, u_char *packet, const int pktlen) { tcpeditdlt_plugin_t *plugin; + u_char *res; assert(ctx); assert(dlt >= 0); @@ -352,7 +363,12 @@ tcpedit_dlt_l3data(tcpeditdlt_t *ctx, int dlt, u_char *packet, const int pktlen) return NULL; } - return plugin->plugin_get_layer3(ctx, packet, pktlen); + res = plugin->plugin_get_layer3(ctx, packet, pktlen); + if (res == NULL) + tcpedit_seterr(ctx->tcpedit, "Packet length %d is to short to contain a layer 3 header for DLT 0x%04x", + pktlen, dlt); + + return res; } /** @@ -367,6 +383,8 @@ u_char * tcpedit_dlt_merge_l3data(tcpeditdlt_t *ctx, int dlt, u_char *packet, const int pktlen, u_char *l3data) { tcpeditdlt_plugin_t *plugin; + u_char *res; + assert(ctx); assert(dlt >= 0); assert(packet); @@ -379,7 +397,12 @@ tcpedit_dlt_merge_l3data(tcpeditdlt_t *ctx, int dlt, u_char *packet, const int p return NULL; } - return plugin->plugin_merge_layer3(ctx, packet, pktlen, l3data); + res = plugin->plugin_merge_layer3(ctx, packet, pktlen, l3data); + if (res == NULL) + tcpedit_seterr(ctx->tcpedit, "Packet length %d is to short for layer 3 merge for DLT 0x%04x", + pktlen, dlt); + + return res; } diff --git a/src/tcpedit/plugins/dlt_pppserial/Makefile.am b/src/tcpedit/plugins/dlt_pppserial/Makefile.am index 76cead3e2..d0498a0c7 100644 --- a/src/tcpedit/plugins/dlt_pppserial/Makefile.am +++ b/src/tcpedit/plugins/dlt_pppserial/Makefile.am @@ -6,26 +6,29 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_pppserial/pppserial.c \ - $(srcdir)/plugins/dlt_pppserial/pppserial.c +libtcpedit_a_SOURCES += \ + %reldir%/pppserial.c \ + %reldir%/pppserial.c -noinst_HEADERS += $(srcdir)/plugins/dlt_pppserial/pppserial.h \ - $(srcdir)/plugins/dlt_pppserial/pppserial_api.h \ - $(srcdir)/plugins/dlt_pppserial/pppserial_types.h +noinst_HEADERS += \ + %reldir%/pppserial.h \ + %reldir%/pppserial_api.h \ + %reldir%/pppserial_types.h -EXTRA_DIST += $(srcdir)/plugins/dlt_pppserial/pppserial_opts.def +EXTRA_DIST += %reldir%/pppserial_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_pppserial/pppserial.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h $(srcdir)/plugins/dlt_pppserial/pppserial.h $(srcdir)/plugins/dlt_pppserial/pppserial_api.h \ - $(srcdir)/plugins/dlt_pppserial/pppserial_types.h +pppserial.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/pppserial.h \ + %reldir%/pppserial_api.h \ + %reldir%/pppserial_types.h # Note: # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_pppserial/pppserial_opts.def +DLT_STUB_DEPS += %reldir%/pppserial_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_pppserial/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_pppserial diff --git a/src/tcpedit/plugins/dlt_pppserial/pppserial.c b/src/tcpedit/plugins/dlt_pppserial/pppserial.c index addc060fb..dafb47db2 100644 --- a/src/tcpedit/plugins/dlt_pppserial/pppserial.c +++ b/src/tcpedit/plugins/dlt_pppserial/pppserial.c @@ -301,8 +301,7 @@ dlt_pppserial_get_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen) /* FIXME: Is there anything else we need to do?? */ l2len = dlt_pppserial_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_copy(ctx, packet, pktlen, l2len); @@ -324,8 +323,7 @@ dlt_pppserial_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, /* FIXME: Is there anything else we need to do?? */ l2len = dlt_pppserial_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, l3data, l2len); @@ -353,7 +351,7 @@ dlt_pppserial_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) assert(packet); if (pktlen < 4) - return 0; + return -1; return 4; } diff --git a/src/tcpedit/plugins/dlt_radiotap/Makefile.am b/src/tcpedit/plugins/dlt_radiotap/Makefile.am index 90a98d8a8..d2f949af9 100644 --- a/src/tcpedit/plugins/dlt_radiotap/Makefile.am +++ b/src/tcpedit/plugins/dlt_radiotap/Makefile.am @@ -6,23 +6,22 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_radiotap/radiotap.c +libtcpedit_a_SOURCES += %reldir%/radiotap.c -noinst_HEADERS += $(srcdir)/plugins/dlt_radiotap/radiotap.h +noinst_HEADERS += %reldir%/radiotap.h -EXTRA_DIST += $(srcdir)/plugins/dlt_radiotap/radiotap_opts.def +EXTRA_DIST += %reldir%/radiotap_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_radiotap/radiotap.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins/dlt_radiotap/radiotap.h $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h +radiotap.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/radiotap.h # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_radiotap/radiotap_opts.def +DLT_STUB_DEPS += %reldir%/radiotap_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_radiotap/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_radiotap diff --git a/src/tcpedit/plugins/dlt_radiotap/radiotap.c b/src/tcpedit/plugins/dlt_radiotap/radiotap.c index 58faf0619..fe9d93eda 100644 --- a/src/tcpedit/plugins/dlt_radiotap/radiotap.c +++ b/src/tcpedit/plugins/dlt_radiotap/radiotap.c @@ -313,7 +313,7 @@ dlt_radiotap_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) assert(packet); if (pktlen < 4) - return 0; + return -1; memcpy(&radiolen, &packet[2], 2); /* little endian to host */ @@ -327,12 +327,19 @@ dlt_radiotap_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) int dlt_radiotap_80211_l2len(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) { - int radiolen; + int radiolen, res; u_char *data; radiolen = dlt_radiotap_l2len(ctx, packet, pktlen); + if (radiolen == -1) + return TCPEDIT_ERROR; + data = dlt_radiotap_get_80211(ctx, packet, pktlen, radiolen); - radiolen += dlt_ieee80211_l2len(ctx, data, pktlen - radiolen); + res = dlt_ieee80211_l2len(ctx, data, pktlen - radiolen); + if (res == -1) + return TCPEDIT_ERROR; + + radiolen += res; return radiolen; } diff --git a/src/tcpedit/plugins/dlt_raw/Makefile.am b/src/tcpedit/plugins/dlt_raw/Makefile.am index aa6bcc3f7..f8e95de27 100644 --- a/src/tcpedit/plugins/dlt_raw/Makefile.am +++ b/src/tcpedit/plugins/dlt_raw/Makefile.am @@ -6,22 +6,21 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_raw/raw.c +libtcpedit_a_SOURCES += %reldir%/raw.c -noinst_HEADERS += $(srcdir)/plugins/dlt_raw/raw.h +noinst_HEADERS += %reldir%/raw.h -EXTRA_DIST += $(srcdir)/plugins/dlt_raw/raw_opts.def +EXTRA_DIST += %reldir%/raw_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_raw/raw.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins/dlt_raw/raw.h $ $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h +raw.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/raw.h # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_raw/raw_opts.def +DLT_STUB_DEPS += %reldir%/raw_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_raw/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_raw diff --git a/src/tcpedit/plugins/dlt_template/Makefile.am b/src/tcpedit/plugins/dlt_template/Makefile.am index b926f68aa..55ab82a4b 100644 --- a/src/tcpedit/plugins/dlt_template/Makefile.am +++ b/src/tcpedit/plugins/dlt_template/Makefile.am @@ -6,26 +6,36 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_%{plugin}/%{plugin}.c \ - $(srcdir)/plugins/dlt_%{plugin}/%{plugin}.c +eol = -noinst_HEADERS += $(srcdir)/plugins/dlt_%{plugin}/%{plugin}.h \ - $(srcdir)/plugins/dlt_%{plugin}/%{plugin}_api.h \ - $(srcdir)/plugins/dlt_%{plugin}/%{plugin}_types.h +libtcpedit_a_SOURCES += \ + %reldir%/%{plugin}.c \ + %reldir%/%{plugin}.h \ + %reldir%/%{plugin}_api.h \ + %reldir%/%{plugin}_types.h \ + $(eol) -EXTRA_DIST += $(srcdir)/plugins/dlt_%{plugin}/%{plugin}_opts.def +noinst_HEADERS += \ + %reldir%/%{plugin}.h \ + %reldir%/%{plugin}_api.h \ + %reldir%/%{plugin}_types.h \ + $(eol) + +EXTRA_DIST += %reldir%/%{plugin}_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_%{plugin}/%{plugin}.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h $(srcdir)/plugins/dlt_%{plugin}/%{plugin}.h $(srcdir)/plugins/dlt_%{plugin}/%{plugin}_api.h \ - $(srcdir)/plugins/dlt_%{plugin}/%{plugin}_types.h +%{plugin}.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/%{plugin}.h \ + %reldir%/%{plugin}_api.h \ + %reldir%/%{plugin}_types.h \ + $(eol) # Note: # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_%{plugin}/%{plugin}_opts.def +DLT_STUB_DEPS += %reldir%/%{plugin}_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_%{plugin}/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_%{plugin} diff --git a/src/tcpedit/plugins/dlt_user/Makefile.am b/src/tcpedit/plugins/dlt_user/Makefile.am index 8d879301a..9abe4fab6 100644 --- a/src/tcpedit/plugins/dlt_user/Makefile.am +++ b/src/tcpedit/plugins/dlt_user/Makefile.am @@ -6,25 +6,27 @@ # add any other files (like documentation, notes, etc) to EXTRA_DIST # add your dependancy information (see comment below) -libtcpedit_a_SOURCES += $(srcdir)/plugins/dlt_user/user.c \ - $(srcdir)/plugins/dlt_user/user_api.c +libtcpedit_a_SOURCES += \ + %reldir%/user.c \ + %reldir%/user_api.c -noinst_HEADERS += $(srcdir)/plugins/dlt_user/user.h \ - $(srcdir)/plugins/dlt_user/user_api.h \ - $(srcdir)/plugins/dlt_user/user_types.h +noinst_HEADERS += \ + %reldir%/user.h \ + %reldir%/user_api.h \ + %reldir%/user_types.h -EXTRA_DIST += $(srcdir)/plugins/dlt_user/user_opts.def +EXTRA_DIST += %reldir%/user_opts.def # dependancies for your plugin source code. Edit as necessary -$(srcdir)/plugins/dlt_user/user.c: $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins/dlt_user/user.h $(srcdir)/tcpedit_stub.h $(srcdir)/plugins/dlt_utils.h \ - $(srcdir)/plugins.h $(srcdir)/plugins_api.h $(srcdir)/plugins_types.h \ - $(srcdir)/tcpedit_api.h $(srcdir)/plugins/dlt_user/user_api.h +user.c: \ + $(TCPEDIT_PLUGINS_DEPS) \ + %reldir%/user.h \ + %reldir%/user_api.h # You probably don't want to touch anything below this line until the end of the plugin -DLT_STUB_DEPS += $(srcdir)/plugins/dlt_user/user_opts.def +DLT_STUB_DEPS += %reldir%/user_opts.def -MOSTLYCLEANFILES += $(srcdir)/plugins/dlt_user/*~ +MOSTLYCLEANFILES += *~ # END OF: dlt_user diff --git a/src/tcpedit/plugins/dlt_user/user.c b/src/tcpedit/plugins/dlt_user/user.c index 4f7ded4b0..dc9631c20 100644 --- a/src/tcpedit/plugins/dlt_user/user.c +++ b/src/tcpedit/plugins/dlt_user/user.c @@ -294,7 +294,7 @@ dlt_user_get_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen) /* FIXME: Is there anything else we need to do?? */ l2len = dlt_user_l2len(ctx, packet, pktlen); - if (l2len < 0 || pktlen < l2len) + if (l2len == -1 || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_copy(ctx, packet, pktlen, l2len); @@ -316,8 +316,7 @@ dlt_user_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, const int pktlen, u_cha /* FIXME: Is there anything else we need to do?? */ l2len = dlt_user_l2len(ctx, packet, pktlen); - - if (pktlen < l2len) + if (l2len == TCPEDIT_ERROR || pktlen < l2len) return NULL; return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, l3data, l2len); diff --git a/src/tcpedit/portmap.c b/src/tcpedit/portmap.c index 1138e3e81..284573d30 100644 --- a/src/tcpedit/portmap.c +++ b/src/tcpedit/portmap.c @@ -63,7 +63,7 @@ ports2PORT(char *ports) { tcpedit_portmap_t *portmap = NULL, *portmap_head = NULL, *portmap_last = NULL; char *from_s, *to_s, *from_begin, *from_end, *badchar; - long from_l, to_l, from_b, from_e, i; + long from_l, to_l; char *token = NULL, *token2 = NULL; assert(ports); @@ -105,15 +105,17 @@ ports2PORT(char *ports) /* process a range, setting from_begin & from_end */ if (strchr(from_s, '-')) { + long i; + from_begin = strtok_r(from_s, "-", &token2); from_end = strtok_r(NULL, "-", &token2); - from_b = strtol(from_begin, &badchar, 10); + long from_b = strtol(from_begin, &badchar, 10); if (strlen(badchar) != 0) { free(portmap); return NULL; } - from_e = strtol(from_end, &badchar, 10); + long from_e = strtol(from_end, &badchar, 10); if (from_b > 65535 || from_b < 0 || from_e > 65535 || from_e < 0) { free(portmap); return NULL; @@ -184,7 +186,7 @@ int parse_portmap(tcpedit_portmap_t ** portmap, const char *ourstr) { tcpedit_portmap_t *portmap_ptr; - char *substr = NULL, *ourstrcpy = NULL, *token = NULL; + char *substr, *ourstrcpy, *token = NULL; assert(ourstr); ourstrcpy = safe_strdup(ourstr); diff --git a/src/tcpedit/tcpedit.c b/src/tcpedit/tcpedit.c index b23fadbe1..1b6ec403e 100644 --- a/src/tcpedit/tcpedit.c +++ b/src/tcpedit/tcpedit.c @@ -87,7 +87,8 @@ tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr, ipv4_hdr_t *ip_hdr = NULL; ipv6_hdr_t *ip6_hdr = NULL; arp_hdr_t *arp_hdr = NULL; - int l2len = 0, l2proto, retval = 0, dst_dlt, src_dlt, pktlen, lendiff; + int l2len, l2proto, retval = 0; + int dst_dlt, src_dlt, pktlen, lendiff; int ipflags = 0, tclass = 0; int needtorecalc = 0; /* did the packet change? if so, checksum */ u_char *packet; @@ -146,22 +147,54 @@ tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr, dst_dlt = tcpedit_dlt_dst(tcpedit->dlt_ctx); l2len = tcpedit_dlt_l2len(tcpedit->dlt_ctx, dst_dlt, packet, (*pkthdr)->caplen); + if (l2len == -1) + return TCPEDIT_ERROR; dbgx(2, "dst_dlt = %04x\tsrc_dlt = %04x\tproto = %04x\tl2len = %d", dst_dlt, src_dlt, ntohs(l2proto), l2len); /* does packet have an IP header? if so set our pointer to it */ if (l2proto == htons(ETHERTYPE_IP)) { + u_char *p; + + if ((*pkthdr)->caplen < l2len + sizeof(*ip_hdr)) { + tcpedit_seterr(tcpedit, "Packet length %d is to short to contain a layer IP header for DLT 0x%04x", + pktlen, dst_dlt); + return TCPEDIT_ERROR; + } + ip_hdr = (ipv4_hdr_t *)tcpedit_dlt_l3data(tcpedit->dlt_ctx, dst_dlt, packet, (*pkthdr)->caplen); - if (ip_hdr == NULL) { + if (ip_hdr == NULL) return TCPEDIT_ERROR; - } - dbgx(3, "Packet has an IPv4 header: %p...", ip_hdr); + + p = get_layer4_v4(ip_hdr, (*pkthdr)->caplen - l2len); + if (!p) { + tcpedit_seterr(tcpedit, "Packet length %d is to short to contain a layer %d byte IP header for DLT 0x%04x", + pktlen, ip_hdr->ip_hl << 2, dst_dlt); + return TCPEDIT_ERROR; + } + + dbgx(3, "Packet has an IPv4 header: 0x%p...", ip_hdr); } else if (l2proto == htons(ETHERTYPE_IP6)) { + u_char *p; + + if ((*pkthdr)->caplen < l2len + sizeof(*ip6_hdr)) { + tcpedit_seterr(tcpedit, "Packet length %d is to short to contain a layer IPv6 header for DLT 0x%04x", + pktlen, dst_dlt); + return TCPEDIT_ERROR; + } + ip6_hdr = (ipv6_hdr_t *)tcpedit_dlt_l3data(tcpedit->dlt_ctx, dst_dlt, packet, (*pkthdr)->caplen); - if (ip6_hdr == NULL) { + if (ip6_hdr == NULL) + return TCPEDIT_ERROR; + + p = get_layer4_v6(ip6_hdr, (*pkthdr)->caplen - l2len); + if (!p) { + tcpedit_seterr(tcpedit, "Packet length %d is to short to contain a layer %d byte IPv6 header for DLT 0x%04x", + pktlen, ip_hdr->ip_hl << 2, dst_dlt); return TCPEDIT_ERROR; } - dbgx(3, "Packet has an IPv6 header: %p...", ip6_hdr); + + dbgx(3, "Packet has an IPv6 header: 0x%p...", ip6_hdr); } else { dbgx(3, "Packet isn't IPv4 or IPv6: 0x%04x", l2proto); /* non-IP packets have a NULL ip_hdr struct */ @@ -245,10 +278,12 @@ tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr, if (tcpedit->rewrite_ip) { /* IP packets */ if (ip_hdr != NULL) { - if ((retval = rewrite_ipv4l3(tcpedit, ip_hdr, direction)) < 0) + if ((retval = rewrite_ipv4l3(tcpedit, ip_hdr, direction, + (*pkthdr)->caplen - l2len)) < 0) return TCPEDIT_ERROR; } else if (ip6_hdr != NULL) { - if ((retval = rewrite_ipv6l3(tcpedit, ip6_hdr, direction)) < 0) + if ((retval = rewrite_ipv6l3(tcpedit, ip6_hdr, direction, + (*pkthdr)->caplen - l2len)) < 0) return TCPEDIT_ERROR; } @@ -270,12 +305,12 @@ tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr, /* IPv4 Packets */ if (ip_hdr != NULL) { if ((retval = randomize_ipv4(tcpedit, *pkthdr, packet, - ip_hdr)) < 0) + ip_hdr, (*pkthdr)->caplen - l2len)) < 0) return TCPEDIT_ERROR; } else if (ip6_hdr != NULL) { if ((retval = randomize_ipv6(tcpedit, *pkthdr, packet, - ip6_hdr)) < 0) + ip6_hdr, (*pkthdr)->caplen - l2len)) < 0) return TCPEDIT_ERROR; /* ARP packets */ @@ -546,21 +581,6 @@ tcpedit_l3data(tcpedit_t *tcpedit, tcpedit_coder code, u_char *packet, const int return result; } -/** - * return the length of the layer 2 header. Returns TCPEDIT_ERROR on error - */ -int -tcpedit_l2len(tcpedit_t *tcpedit, tcpedit_coder code, u_char *packet, const int pktlen) -{ - int result = 0; - if (code == BEFORE_PROCESS) { - result = tcpedit_dlt_l2len(tcpedit->dlt_ctx, tcpedit->dlt_ctx->decoder->dlt, packet, pktlen); - } else { - result = tcpedit_dlt_l2len(tcpedit->dlt_ctx, tcpedit->dlt_ctx->encoder->dlt, packet, pktlen); - } - return result; -} - /** * Returns the layer 3 type, often encoded as the layer2.proto field */ @@ -575,24 +595,3 @@ tcpedit_l3proto(tcpedit_t *tcpedit, tcpedit_coder code, const u_char *packet, co } return ntohs(result); } - -/* -u_char * -tcpedit_srcmac(tcpedit_t *tcpedit, tcpedit_coder code, u_char *packet, const int pktlen) -{ - -} - -u_char * -tcpedit_dstmac(tcpedit_t *tcpedit, tcpedit_coder code, u_char *packet, const int pktlen) -{ - -} - -int -tcpedit_maclen(tcpedit_t *tcpedit, tcpedit_coder code) -{ - -} - -*/ diff --git a/src/tcpedit/tcpedit.h b/src/tcpedit/tcpedit.h index 58f7dd115..7030833f3 100644 --- a/src/tcpedit/tcpedit.h +++ b/src/tcpedit/tcpedit.h @@ -51,7 +51,6 @@ int tcpedit_packet(tcpedit_t *tcpedit, struct pcap_pkthdr **pkthdr, int tcpedit_close(tcpedit_t *tcpedit); int tcpedit_get_output_dlt(tcpedit_t *tcpedit); -int tcpedit_l2len(tcpedit_t *tcpedit, tcpedit_coder code, u_char *packet, const int pktlen); const u_char *tcpedit_l3data(tcpedit_t *tcpedit, tcpedit_coder code, u_char *packet, const int pktlen); int tcpedit_l3proto(tcpedit_t *tcpedit, tcpedit_coder code, const u_char *packet, const int pktlen); diff --git a/src/tcpedit/tcpedit_opts.def b/src/tcpedit/tcpedit_opts.def index 5cb19f69b..a01347c5e 100644 --- a/src/tcpedit/tcpedit_opts.def +++ b/src/tcpedit/tcpedit_opts.def @@ -2,9 +2,9 @@ * Copyright (c) 2001-2010 Aaron Turner * Copyright (c) 2013-2018 Fred Klassen - AppNeta * - * The Tcpreplay Suite of tools is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * The Tcpreplay Suite of tools is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the * License, or with the authors permission any later version. * * The Tcpreplay Suite is distributed in the hope that it will be useful, @@ -30,7 +30,7 @@ flag = { stack-arg; descrip = "Rewrite TCP/UDP ports"; doc = <<- EOText -Specify a list of comma delimited port mappingings consisting of +Specify a list of comma delimited port mappings consisting of colon delimited port number pairs. Each colon delimited port pair consists of the port to match followed by the port number to rewrite. @@ -51,11 +51,11 @@ flag = { descrip = "Randomize src/dst IPv4/v6 addresses w/ given seed"; max = 1; doc = <<- EOText -Causes the source and destination IPv4/v6 addresses to be pseudo +Causes the source and destination IPv4/v6 addresses to be pseudo randomized but still maintain client/server relationships. -Since the randomization is deterministic based on the seed, +Since the randomization is deterministic based on the seed, you can reuse the same seed value to recreate the traffic. -EOText; +EOText; }; flag = { @@ -82,7 +82,7 @@ IPv6 Example: @example --pnat=[2001:db8::/32]:[dead::/16],[2001:db8::/32]:[::ffff:0:0/96] @end example -EOText; +EOText; }; flag = { @@ -141,7 +141,7 @@ flag = { value = b; descrip = "Skip rewriting broadcast/multicast IPv4/v6 addresses"; doc = <<- EOText -By default --seed, --pnat and --endpoints will rewrite +By default --seed, --pnat and --endpoints will rewrite broadcast and multicast IPv4/v6 and MAC addresses. Setting this flag will keep broadcast/multicast IPv4/v6 and MAC addresses from being rewritten. EOText; @@ -153,7 +153,7 @@ flag = { descrip = "Force recalculation of IPv4/TCP/UDP header checksums"; doc = <<- EOText Causes each IPv4/v6 packet to have their checksums recalculated and -fixed. Automatically enabled for packets modified with @samp{--seed}, +fixed. Automatically enabled for packets modified with @samp{--seed}, @samp{--pnat}, @samp{--endpoints} or @samp{--fixlen}. EOText; }; @@ -167,7 +167,7 @@ flag = { default = DEFAULT_MTU; descrip = "Override default MTU length (1500 bytes)"; doc = <<- EOText -Override the default 1500 byte MTU size for determining the maximum padding length +Override the default 1500 byte MTU size for determining the maximum padding length (--fixlen=pad) or when truncating (--mtu-trunc). EOText; }; @@ -177,7 +177,7 @@ flag = { max = 1; descrip = "Truncate packets larger then specified MTU"; doc = <<- EOText -Similar to --fixlen, this option will truncate data in packets from Layer 3 and above to be +Similar to --fixlen, this option will truncate data in packets from Layer 3 and above to be no larger then the MTU. EOText; }; @@ -189,7 +189,7 @@ flag = { doc = <<- EOText Note, this option is pretty dangerous! We do not actually check to see if a FCS actually exists in the frame, we just blindly delete the last 4 bytes. Hence, -you should only use this if you know know that your OS provides the FCS when +you should only use this if you know know that your OS provides the FCS when reading raw packets. EOText; }; @@ -240,7 +240,7 @@ flag = { arg-range = "0->1048575"; max = 1; doc = <<- EOText -Allows you to override the 20bit IPv6 Flow Label field. Has no effect on IPv4 +Allows you to override the 20bit IPv6 Flow Label field. Has no effect on IPv4 packets. EOText; }; @@ -259,7 +259,7 @@ to reflect the stored packet length. @table @bullet @item @var{pad} -Truncated packets will be padded out so that the packet length matches the +Truncated packets will be padded out so that the packet length matches the IPv4 total length @item @var{trunc} @@ -279,9 +279,9 @@ flag = { descrip = "Fuzz 1 in X packets. Edit bytes, length, or emulate packet drop"; doc = <<- EOText This fuzzing was designed as to test layer 7 protocols such as voip protocols. -It modifies randomly 1 out of X packets (where X = @var{--fuzz-factor}) in order -for stateful protocols to cover more of their code. The random fuzzing actions -focus on data start and end because it often is the part of the data application +It modifies randomly 1 out of X packets (where X = @var{--fuzz-factor}) in order +for stateful protocols to cover more of their code. The random fuzzing actions +focus on data start and end because it often is the part of the data application protocols base their decisions on. Possible fuzzing actions list: @@ -289,7 +289,7 @@ Possible fuzzing actions list: * reduce packet size * edit packet Bytes: * Not all Bytes have the same probability of appearance in real life. - Replace with 0x00, 0xFF, or a random byte with equal likelyhook + Replace with 0x00, 0xFF, or a random byte with equal likelihood. * Not all Bytes have the same significance in a packet. Replace the start, the end, or the middle of the packet with equal likelihood. * do nothing (7 out of 8 packets) @@ -307,8 +307,8 @@ flag = { doc = <<- EOText Sets the ratio of for @var{--fuzz-seed} option. By default this value is 8, which means 1 in 8 packets are modified by fuzzing. Note that this ratio is -based on the random number genereated by the supplied fuzz seed. Therefore by -default you cannot expect that exactly every eighth packet will be modified. +based on the random number generated by the supplied fuzz seed. Therefore by +default you cannot expect that exactly every eighth packet will be modified. EOText; }; diff --git a/src/tcpliveplay.c b/src/tcpliveplay.c index 271374154..8ab60ecc2 100644 --- a/src/tcpliveplay.c +++ b/src/tcpliveplay.c @@ -259,7 +259,7 @@ main(int argc, char **argv) /* Start replay by sending the first packet, the SYN, from the schedule */ else if(sched[0].local){ /* Send first packet*/ sendpacket(sp, sched[sched_index].packet_ptr, sched[sched_index].pkthdr.len, &sched[sched_index].pkthdr); - printf("Sending Local Packet............... [%d]\n",sched_index+1); + printf("Sending Local Packet............... [%u]\n",sched_index+1); sched_index++; /* Proceed in the schedule */ } @@ -296,8 +296,8 @@ main(int argc, char **argv) } */ /* Do the following if we receive a packet that ACKs for the same ACKing of next packet */ else if((tcphdr_rprev->th_seq==htonl(sched[sched_index].exp_rseq)) && (tcphdr_rprev->th_ack==htonl(sched[sched_index].exp_rack)) && (size_payload_prev>0)){ - printf("Received Remote Packet............... [%d]\n",sched_index+1); - printf("Skipping Packet...................... [%d] to Packet [%d]\n",sched_index+1, sched_index+2); + printf("Received Remote Packet............... [%u]\n",sched_index+1); + printf("Skipping Packet...................... [%u] to Packet [%u]\n",sched_index+1, sched_index+2); printf("Next Remote Packet Expectation met.\nProceeding in replay...\n"); sched_index++; } @@ -505,7 +505,7 @@ setup_sched(struct tcp_sched* sched){ } /*Before sending any packet, setup the schedule with the proper parameters*/ - while((packet = pcap_next(local_handle,&header))) { + while((packet = safe_pcap_next(local_handle,&header))) { pkt_counter++; /*increment number of packets seen*/ memcpy(&sched[i].pkthdr, &header, sizeof(struct pcap_pkthdr)); @@ -714,17 +714,16 @@ set_offline_filter(char* file) void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet){ - ether_hdr *etherhdr = NULL; - tcp_hdr *tcphdr = NULL; - ipv4_hdr *iphdr = NULL; + ether_hdr *etherhdr; + tcp_hdr *tcphdr; + ipv4_hdr *iphdr; unsigned int size_ip, size_tcp, size_payload; unsigned int flags = 0; /* This is to get rid of the warning */ args = NULL; - if(args == NULL) header = NULL; - if(header == NULL) args = NULL; + header = NULL; /* Extract and examine recieved packet headers */ etherhdr = (ether_hdr*)(packet); @@ -957,7 +956,6 @@ rewrite(input_addr* new_remoteip, struct mac_addr* new_remotemac, input_addr* my struct pcap_pkthdr *header; pcap_dumper_t *dumpfile; input_addr sip; /* Source IP */ - unsigned int flags; int local_packets = 0; bool initstep1 = false; /* keep track of successful handshake step */ bool warned = false; @@ -986,7 +984,8 @@ rewrite(input_addr* new_remoteip, struct mac_addr* new_remotemac, input_addr* my } /*Modify each packet's IP & MAC based on the passed args then do a checksum of each packet*/ - for (pkt_counter = 0; pcap_next_ex(pcap, &header, &packet) > 0; pkt_counter++){ + for (pkt_counter = 0; safe_pcap_next_ex(pcap, &header, &packet) > 0; pkt_counter++){ + unsigned int flags; if (!warned && header->len > header->caplen) { fprintf(stderr, "warning: packet capture truncated to %d byte packets\n", diff --git a/src/tcpliveplay_opts.def b/src/tcpliveplay_opts.def index 8a20f9243..ccce4eefe 100644 --- a/src/tcpliveplay_opts.def +++ b/src/tcpliveplay_opts.def @@ -38,7 +38,7 @@ include = "#include \"defines.h\"\n" "#include \n" "#include \n" "#include \n"; - + homerc = "$$/"; @@ -48,21 +48,21 @@ homerc = "$$/"; #endif explain = <<- EOExplain -This program, 'tcpliveplay' replays a captured set of packets using new TCP -connections with the captured TCP payloads against a remote host in order to -do comprehensive vulnerability testings. +This program, 'tcpliveplay' replays a captured set of packets using new TCP +connections with the captured TCP payloads against a remote host in order to +do comprehensive vulnerability testing. EOExplain; detail = <<- EODetail -The basic operation of tcpliveplay is it rewrites the given pcap file -in a scheduled event format and responds with the apporiate packet if +The basic operation of tcpliveplay is it rewrites the given pcap file +in a scheduled event format and responds with the appropriate packet if the remote host meets tcp protocal's SEQ/ACK expectation. Once expectations -are met, then the local packets are sent with the same payload except with -new tcp SEQ & ACK numbers meeting the response from the remote hose. +are met, then the local packets are sent with the same payload except with +new tcp SEQ & ACK numbers meeting the response from the remote hose. -The inputted pcap file are rewritten to start at the first encounter of the -SYN packet for correct operation making this packet be the first action in -the event schedule of local host doing the replay. +The input pcap file are rewritten to start at the first encounter of the +SYN packet for correct operation making this packet be the first action in +the event schedule of local host doing the replay. For more details, please see the Tcpreplay Manual at: http://tcpreplay.appneta.com @@ -85,15 +85,15 @@ tcpdump(1), tcpprep(1), tcprewrite(1), tcpreplay(1) tcpliveplay can only send packets as fast as your computer's interface, processor and system bus will allow. -If the remote host responds differently than expected (meaning differently -than remote captured data) due to network changes then the replay abort +If the remote host responds differently than expected (meaning differently +than remote captured data) due to network changes then the replay abort and ask you to try again. -The replay only modifies layer 2 and 3 of each packet during the replay. -The payload is replayed exactly the same as the original capture. +The replay only modifies layer 2 and 3 of each packet during the replay. +The payload is replayed exactly the same as the original capture. Timing may be an issue because the tcpliveplay sends the appropriate packet -once the remote host's packet meets the correct expectation. +once the remote host's packet meets the correct expectation. EOMan; /* @@ -111,7 +111,7 @@ flag = { arg-default = 0; descrip = "Enable debugging output"; doc = <<- EOText -If configured with --enable-debug, then you can specify a verbosity +If configured with --enable-debug, then you can specify a verbosity level for debugging output. Higher numbers increase verbosity. EOText; }; diff --git a/src/tcpprep.c b/src/tcpprep.c index 7e763375c..a072cddff 100644 --- a/src/tcpprep.c +++ b/src/tcpprep.c @@ -331,7 +331,7 @@ process_raw_packets(pcap_t * pcap) assert(pcap); - while ((pktdata = pcap_next(pcap, &pkthdr)) != NULL) { + while ((pktdata = safe_pcap_next(pcap, &pkthdr)) != NULL) { packetnum++; dbgx(1, "Packet " COUNTER_SPEC, packetnum); diff --git a/src/tcpprep_api.c b/src/tcpprep_api.c index 39e3f99ef..0a7d9716e 100644 --- a/src/tcpprep_api.c +++ b/src/tcpprep_api.c @@ -221,12 +221,12 @@ int tcpprep_set_regex(tcpprep_t *ctx, char *value) { int regex_error; - char ebuf[EBUF_SIZE]; assert(ctx); if ((regex_error = regcomp(&ctx->options->preg, value, REG_EXTENDED|REG_NOSUB))) { + char ebuf[EBUF_SIZE]; regerror(regex_error, &ctx->options->preg, ebuf, EBUF_SIZE); tcpprep_seterr(ctx, "Unable to compile regex (%s): %s", value, regex_error); return -1; diff --git a/src/tcpprep_opts.def b/src/tcpprep_opts.def index 715777955..552dff5d6 100644 --- a/src/tcpprep_opts.def +++ b/src/tcpprep_opts.def @@ -4,9 +4,9 @@ * Copyright (c) 2001-2010 Aaron Turner * Copyright (c) 2013-2018 Fred Klassen - AppNeta * - * The Tcpreplay Suite of tools is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * The Tcpreplay Suite of tools is free software: you can redistribute it + * and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the * License, or with the authors permission any later version. * * The Tcpreplay Suite is distributed in the hope that it will be useful, @@ -23,7 +23,7 @@ autogen definitions options; copyright = { date = "2000-2018"; owner = "Aaron Turner and Fred Klassen"; - eaddr = "tcpreplay-users@lists.sourceforge.net"; + eaddr = "tcpreplay-users@lists.sourceforge.net"; type = gpl; author = <<- EOText Copyright 2013-2018 Fred Klassen - AppNeta @@ -66,8 +66,8 @@ EOExplain; detail = <<- EODetail The basic operation of tcpreplay is to resend all packets from the -input file(s) out a single file. Tcpprep processes a pcap file and -applies a set of user-specified rules to create a cache file which +input file(s) out a single file. Tcpprep processes a pcap file and +applies a set of user-specified rules to create a cache file which tells tcpreplay whether or not to send each packet and which interface the packet should be sent out of. @@ -92,7 +92,7 @@ flag = { arg-default = 0; descrip = "Enable debugging output"; doc = <<- EOText -If configured with --enable-debug, then you can specify a verbosity +If configured with --enable-debug, then you can specify a verbosity level for debugging output. Higher numbers increase verbosity. EOText; }; @@ -140,15 +140,15 @@ for clients and servers. Valid hints are: @table @bullet @item @var{bridge} -Bridge mode processes each packet to try to determine if the sender is a +Bridge mode processes each packet to try to determine if the sender is a client or server. Once all the packets are processed, the results are weighed according to the server/client ratio (@samp{--ratio}) and systems are assigned an interface. If tcpprep is unable to determine what role a system plays, tcpprep will abort. @item @var{router} -Router mode works just like bridge mode, except that after weighing is done, -systems which are undetermined are considered a server if they fall inside a +Router mode works just like bridge mode, except that after weighing is done, +systems which are undetermined are considered a server if they fall inside a network known to contain other servers. Router has a greater chance of successfully splitting clients and servers but is not 100% foolproof. @item @@ -162,8 +162,8 @@ treated as servers. Server mode should always complete successfully. @item @var{first} First mode works by looking at the first time each IP is seen in the SRC and DST -fields in the IP header. If the host is first seen in the SRC field, it is a -client and if it's first seen in the DST field, it is marked as a server. This +fields in the IP header. If the host is first seen in the SRC field, it is a +client and if it's first seen in the DST field, it is marked as a server. This effectively replicates the processing of the tomahawk test tool. First mode should always complete successfully. @end table @@ -222,7 +222,7 @@ flag = { char ebuf[EBUF_SIZE]; tcpprep->options->mode = REGEX_MODE; - if ((regex_error = regcomp(&tcpprep->options->preg, OPT_ARG(REGEX), + if ((regex_error = regcomp(&tcpprep->options->preg, OPT_ARG(REGEX), REG_EXTENDED|REG_NOSUB))) { regerror(regex_error, &tcpprep->options->preg, ebuf, EBUF_SIZE); errx(-1, "Unable to compile regex: %s", ebuf); @@ -250,7 +250,7 @@ flag = { EOPort; doc = <<- EOText -Specifies that TCP and UDP traffic over IPv4 and IPv6 should be classified +Specifies that TCP and UDP traffic over IPv4 and IPv6 should be classified as client or server based upon the destination port of the header. EOText; }; @@ -284,7 +284,7 @@ flag = { descrip = "Matches to be client instead of server"; doc = <<- EOText Normally the @samp{--mac}, @samp{--regex} and @samp{--cidr} flags specify are used to specify -the servers and non-IP packets are classified as clients. By using @samp{--reverse}, these +the servers and non-IP packets are classified as clients. By using @samp{--reverse}, these features are reversed so that the flags specify clients and non-IP packets are classified as servers. EOText; @@ -300,7 +300,7 @@ flag = { /* our comment_len is only 16bit - myargs[] */ if (strlen(OPT_ARG(COMMENT)) > ((1 << 16) - 1 - MYARGS_LEN)) - errx(-1, "Comment length %zu is longer then max allowed (%d)", + errx(-1, "Comment length %zu is longer then max allowed (%d)", strlen(OPT_ARG(COMMENT)), (1 << 16) - 1 - MYARGS_LEN); /* save the comment */ @@ -417,7 +417,7 @@ corresponds to the packet number in the capture file. @example -x P:1-5,9,15,72- @end example -would skip packets 1 thru 5, the 9th and 15th packet, and packets 72 until the +would skip packets 1 through 5, the 9th and 15th packet, and packets 72 until the end of the file @end table EOText; diff --git a/src/tcpreplay.c b/src/tcpreplay.c index 012fe06cc..86aeb6eb6 100644 --- a/src/tcpreplay.c +++ b/src/tcpreplay.c @@ -61,7 +61,6 @@ main(int argc, char *argv[]) { int i, optct = 0; int rcode; - char buf[1024]; fflush(NULL); @@ -147,6 +146,8 @@ main(int argc, char *argv[]) } if (ctx->stats.bytes_sent > 0) { + char buf[1024]; + packet_stats(&ctx->stats); if (ctx->options->flow_stats) flow_stats(ctx); diff --git a/src/tcpreplay_api.c b/src/tcpreplay_api.c index 1adfe74c5..811004feb 100644 --- a/src/tcpreplay_api.c +++ b/src/tcpreplay_api.c @@ -1103,20 +1103,11 @@ tcpreplay_replay(tcpreplay_t *ctx) return -1; } + init_timestamp(&ctx->stats.start_time); init_timestamp(&ctx->stats.last_time); init_timestamp(&ctx->stats.last_print); init_timestamp(&ctx->stats.end_time); - if (gettimeofday(&ctx->stats.start_time, NULL) < 0) { - tcpreplay_seterr(ctx, "gettimeofday() failed: %s", strerror(errno)); - return -1; - } - - if (ctx->options->stats >= 0) { - if (format_date_time(&ctx->stats.start_time, buf, sizeof(buf)) > 0) - printf("Test start: %s ...\n", buf); - } - ctx->running = true; total_loops = ctx->options->loop; loop = 0; diff --git a/src/tcpreplay_opts.def b/src/tcpreplay_opts.def index 68f4f3b29..099b58460 100644 --- a/src/tcpreplay_opts.def +++ b/src/tcpreplay_opts.def @@ -359,6 +359,7 @@ EOText; flag = { name = duration; arg-type = number; + flags-must = loop; max = 1; arg-default = -1; arg-range = "1->"; diff --git a/src/tcprewrite.c b/src/tcprewrite.c index 1494d6522..2adfcc456 100644 --- a/src/tcprewrite.c +++ b/src/tcprewrite.c @@ -258,7 +258,7 @@ rewrite_packets(tcpedit_t *tcpedit, pcap_t *pin, pcap_dumper_t *pout) * Keep sending while we have packets or until * we've sent enough packets */ - while ((pktconst = pcap_next(pin, pkthdr_ptr)) != NULL) { + while ((pktconst = safe_pcap_next(pin, pkthdr_ptr)) != NULL) { packetnum++; dbgx(2, "packet " COUNTER_SPEC " caplen %d", packetnum, pkthdr.caplen); diff --git a/src/tree.c b/src/tree.c index bad5bead2..9b51afe5f 100644 --- a/src/tree.c +++ b/src/tree.c @@ -232,7 +232,7 @@ tcpr_tree_to_cidr(const int masklen, const int type) tcpr_dir_t check_ip_tree(const int mode, const unsigned long ip) { - tcpr_tree_t *node = NULL, *finder = NULL; + tcpr_tree_t *node, *finder; finder = new_tree(); finder->family = AF_INET; @@ -629,7 +629,6 @@ ipv6_cmp(const struct tcpr_in6_addr *a, const struct tcpr_in6_addr *b) int tree_comp(tcpr_tree_t *t1, tcpr_tree_t *t2) { - int ret; if (t1->family > t2->family) { dbgx(2, "family %d > %d", t1->family, t2->family); return 1; @@ -660,7 +659,7 @@ tree_comp(tcpr_tree_t *t1, tcpr_tree_t *t2) } if (t1->family == AF_INET6) { - ret = ipv6_cmp(&t1->u.ip6, &t1->u.ip6); + int ret = ipv6_cmp(&t1->u.ip6, &t1->u.ip6); dbgx(2, "cmp(%s, %s) = %d", get_addr2name6(&t1->u.ip6, RESOLVE), get_addr2name6(&t2->u.ip6, RESOLVE), ret); return ret; diff --git a/test/Makefile.am b/test/Makefile.am index 00d2c890d..7f8a3f62e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -13,6 +13,8 @@ TCPREPLAY=../src/tcpreplay TCPREWRITE=../src/tcprewrite TCPBRIDGE=../src/tcpbridge +TEST_PCAP=$(srcdir)/test.pcap + EXTRA_DIST = test.pcap test.auto_bridge test.auto_client test.auto_router \ test.auto_server test.auto_first test.cidr test.comment test.port test.mac \ test.cidr_reverse test.mac_reverse test.regex_reverse \ @@ -60,105 +62,105 @@ standard: standard_prep $(STANDARD_REWRITE) $(PRINTF) "Warning: only creating %s endian standard test files\n" $(REWRITE_WARN) standard_prep: - $(TCPPREP) -i test.pcap -o test.auto_router -a router - $(TCPPREP) -i test.pcap -o test.auto_bridge -a bridge - $(TCPPREP) -i test.pcap -o test.auto_client -a client - $(TCPPREP) -i test.pcap -o test.auto_server -a server + $(TCPPREP) -i $(TEST_PCAP) -o test.auto_router -a router + $(TCPPREP) -i $(TEST_PCAP) -o test.auto_bridge -a bridge + $(TCPPREP) -i $(TEST_PCAP) -o test.auto_client -a client + $(TCPPREP) -i $(TEST_PCAP) -o test.auto_server -a server $(TCPPREP) -i test.pcap -o test.auto_first -a first $(TCPPREP) --load-opts config -o test.prep_config - $(TCPPREP) -i test.pcap -o test.port -p - $(TCPPREP) -i test.pcap -o test.mac -e 00:1f:f3:3c:e1:13 - $(TCPPREP) -i test.pcap -o test.cidr -c '96.17.211.0/24' - $(TCPPREP) -i test.pcap -o test.regex -r '96.17.211.*' - $(TCPPREP) -i test.pcap -o test.comment -C "This is a comment" -p - $(TCPPREP) -i test.pcap -o test.mac_reverse -e 00:1f:f3:3c:e1:13 --reverse - $(TCPPREP) -i test.pcap -o test.cidr_reverse -c '96.17.211.0/24' --reverse - $(TCPPREP) -i test.pcap -o test.regex_reverse -r '96.17.211.*' --reverse - $(TCPPREP) -i test.pcap -o test.exclude_packets -c '96.17.211.0/24' --exclude 'P:61-65,88-91' - $(TCPPREP) -i test.pcap -o test.include_packets -c '96.17.211.0/24' --include 'P:61-65,88-91' - $(TCPPREP) -i test.pcap -o test.include_source -c '96.17.211.0/24' --include 'S:96.0.0.0/8' - $(TCPPREP) -i test.pcap -o test.include_dest -c '96.17.211.0/24' --include 'D:96.0.0.0/8' + $(TCPPREP) -i $(TEST_PCAP) -o test.port -p + $(TCPPREP) -i $(TEST_PCAP) -o test.mac -e 00:1f:f3:3c:e1:13 + $(TCPPREP) -i $(TEST_PCAP) -o test.cidr -c '96.17.211.0/24' + $(TCPPREP) -i $(TEST_PCAP) -o test.regex -r '96.17.211.*' + $(TCPPREP) -i $(TEST_PCAP) -o test.comment -C "This is a comment" -p + $(TCPPREP) -i $(TEST_PCAP) -o test.mac_reverse -e 00:1f:f3:3c:e1:13 --reverse + $(TCPPREP) -i $(TEST_PCAP) -o test.cidr_reverse -c '96.17.211.0/24' --reverse + $(TCPPREP) -i $(TEST_PCAP) -o test.regex_reverse -r '96.17.211.*' --reverse + $(TCPPREP) -i $(TEST_PCAP) -o test.exclude_packets -c '96.17.211.0/24' --exclude 'P:61-65,88-91' + $(TCPPREP) -i $(TEST_PCAP) -o test.include_packets -c '96.17.211.0/24' --include 'P:61-65,88-91' + $(TCPPREP) -i $(TEST_PCAP) -o test.include_source -c '96.17.211.0/24' --include 'S:96.0.0.0/8' + $(TCPPREP) -i $(TEST_PCAP) -o test.include_dest -c '96.17.211.0/24' --include 'D:96.0.0.0/8' standard_bigendian: - $(TCPREWRITE) -i test.pcap -o test.rewrite_seed -s 55 - $(TCPREWRITE) -i test.pcap -o test.rewrite_tos --tos=50 - $(TCPREWRITE) -i test.pcap -o test.rewrite_portmap -r 80:8080 - $(TCPREWRITE) -i test.pcap -o test.rewrite_range_portmap -r 1-100:49148 - $(TCPREWRITE) -i test.pcap -o test.rewrite_endpoint \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_seed -s 55 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_tos --tos=50 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_portmap -r 80:8080 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_range_portmap -r 1-100:49148 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_endpoint \ -e 10.10.0.1:10.10.0.2 -c test.auto_router - $(TCPREWRITE) -i test.pcap -o test.rewrite_pnat \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_pnat \ -N 96.17.211.0/24:172.16.0.0/24 - $(TCPREWRITE) -i test.pcap -o test.rewrite_pad -F pad - $(TCPREWRITE) -i test.pcap -o test.rewrite_trunc -F trunc - $(TCPREWRITE) -i test.pcap -o test.rewrite_mac \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_pad -F pad + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_trunc -F trunc + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_mac \ --enet-dmac=00:12:13:14:15:16,00:22:33:44:55:66 \ - --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c test.auto_router - $(TCPREWRITE) -i test.pcap -o test.rewrite_enet_subsmac \ + --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c $(srcdir)/test.auto_router + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_enet_subsmac \ --enet-subsmac=00:1f:f3:3c:e1:13,00:22:33:44:55:66 \ --enet-subsmac=f8:1e:df:e5:84:3a,00:66:55:44:33:22 - $(TCPREWRITE) -i test.pcap -o test.rewrite_mac_seed --enet-mac-seed=42 - $(TCPREWRITE) -i test.pcap -o test.rewrite_mac_seed_keep --enet-mac-seed=42 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_mac_seed --enet-mac-seed=42 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_mac_seed_keep --enet-mac-seed=42 \ --enet-mac-seed-keep-bytes=3 - $(TCPREWRITE) -i test.pcap -o test.rewrite_layer2 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_layer2 \ --dlt=user --user-dlink=00,50,da,5d,46,55,0,7,eb,30,a4,c3,08,0 - $(TCPREWRITE) -i test.pcap -o test.rewrite_config --enet-vlan=add --enet-vlan-tag=45 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_config --enet-vlan=add --enet-vlan-tag=45 \ --enet-vlan-cfi=1 --enet-vlan-pri=5 - $(TCPREWRITE) -i test.pcap -o test.rewrite_skip -b -s 55 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_skip -b -s 55 \ --enet-dmac=00:12:13:14:15:16,00:22:33:44:55:66 \ - --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c test.auto_router - $(TCPREWRITE) -i test.pcap -o test.rewrite_dltuser --dlt=user \ + --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c $(srcdir)/test.auto_router + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_dltuser --dlt=user \ --user-dlink=0x0f,0x00,0x08,0x00 --user-dlt=104 - $(TCPREWRITE) -i test.pcap -o test.rewrite_dlthdlc --dlt=hdlc \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_dlthdlc --dlt=hdlc \ --hdlc-control=0 --hdlc-address=0x0F - $(TCPREWRITE) -i test.rewrite_config -o test.rewrite_vlandel \ + $(TCPREWRITE) -i $(srcdir)/test.rewrite_config -o test.rewrite_vlandel \ --enet-vlan=del - $(TCPREWRITE) -i test.pcap -o test.rewrite_efcs --efcs - $(TCPREWRITE) -i test.pcap -o test.rewrite_1ttl --ttl=58 - $(TCPREWRITE) -i test.pcap -o test.rewrite_2ttl --ttl=+58 - $(TCPREWRITE) -i test.pcap -o test.rewrite_3ttl --ttl=-58 - $(TCPREWRITE) -i test.pcap -o test.rewrite_mtutrunc --mtu-trunc --mtu=300 - $(TCPREWRITE) -i test.pcap -o test.rewrite_l7fuzzing \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_efcs --efcs + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_1ttl --ttl=58 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_2ttl --ttl=+58 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_3ttl --ttl=-58 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_mtutrunc --mtu-trunc --mtu=300 + $(TCPREWRITE) -i $(TEST_PCAP) -o test.rewrite_l7fuzzing \ --fuzz-seed=42 --fuzz-factor=2 standard_littleendian: - $(TCPREWRITE) -i test.pcap -o test2.rewrite_seed -s 55 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_tos --tos=50 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_portmap -r 80:8080 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_range_portmap -r 1-100:49148 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_endpoint \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_seed -s 55 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_tos --tos=50 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_portmap -r 80:8080 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_range_portmap -r 1-100:49148 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_endpoint \ -e 10.10.0.1:10.10.0.2 -c test.auto_router - $(TCPREWRITE) -i test.pcap -o test2.rewrite_pnat \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_pnat \ -N 96.17.211.0/24:172.16.0.0/24 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_pad -F pad - $(TCPREWRITE) -i test.pcap -o test2.rewrite_trunc -F trunc - $(TCPREWRITE) -i test.pcap -o test2.rewrite_mac \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_pad -F pad + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_trunc -F trunc + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_mac \ --enet-dmac=00:12:13:14:15:16,00:22:33:44:55:66 \ - --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c test.auto_router - $(TCPREWRITE) -i test.pcap -o test2.rewrite_enet_subsmac \ + --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c $(srcdir)/test.auto_router + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_enet_subsmac \ --enet-subsmac=00:1f:f3:3c:e1:13,00:22:33:44:55:66 \ --enet-subsmac=f8:1e:df:e5:84:3a,00:66:55:44:33:22 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_mac_seed --enet-mac-seed=42 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_mac_seed_keep --enet-mac-seed=42 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_mac_seed --enet-mac-seed=42 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_mac_seed_keep --enet-mac-seed=42 \ --enet-mac-seed-keep-bytes=3 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_layer2 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_layer2 \ --dlt=user --user-dlink=00,50,da,5d,46,55,0,7,eb,30,a4,c3,08,0 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_config --enet-vlan=add --enet-vlan-tag=45 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_config --enet-vlan=add --enet-vlan-tag=45 \ --enet-vlan-cfi=1 --enet-vlan-pri=5 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_skip -b -s 55 \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_skip -b -s 55 \ --enet-dmac=00:12:13:14:15:16,00:22:33:44:55:66 \ - --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c test.auto_router - $(TCPREWRITE) -i test.pcap -o test2.rewrite_dltuser --dlt=user \ + --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c $(srcdir)/test.auto_router + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_dltuser --dlt=user \ --user-dlink=0x0f,0x00,0x08,0x00 --user-dlt=104 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_dlthdlc --dlt=hdlc \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_dlthdlc --dlt=hdlc \ --hdlc-control=0 --hdlc-address=0x0F - $(TCPREWRITE) -i test.rewrite_config -o test2.rewrite_vlandel \ + $(TCPREWRITE) -i $(srcdir)/test.rewrite_config -o test2.rewrite_vlandel \ --enet-vlan=del - $(TCPREWRITE) -i test.pcap -o test2.rewrite_efcs --efcs - $(TCPREWRITE) -i test.pcap -o test2.rewrite_1ttl --ttl=58 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_2ttl --ttl=+58 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_3ttl --ttl=-58 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_mtutrunc --mtu-trunc --mtu=300 - $(TCPREWRITE) -i test.pcap -o test2.rewrite_l7fuzzing \ + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_efcs --efcs + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_1ttl --ttl=58 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_2ttl --ttl=+58 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_3ttl --ttl=-58 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_mtutrunc --mtu-trunc --mtu=300 + $(TCPREWRITE) -i $(TEST_PCAP) -o test2.rewrite_l7fuzzing \ --fuzz-seed=42 --fuzz-factor=2 tcpprep: auto_router auto_bridge auto_client auto_server auto_first cidr regex \ @@ -179,502 +181,502 @@ tcpreplay: replay_basic replay_cache replay_pps replay_rate replay_top \ prep_config: $(PRINTF) "%s" "[tcpprep] Config mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Config mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) --load-opts=config -o test.$@1 >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Config mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) --load-opts=config -o test.$@1 >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi auto_router: $(PRINTF) "%s" "[tcpprep] Auto/Router mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Auto/Router mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -a router >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Auto/Router mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -a router >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi auto_bridge: $(PRINTF) "%s" "[tcpprep] Auto/Bridge mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Auto/Bridge mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -a bridge >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Auto/Bridge mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -a bridge >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi auto_client: $(PRINTF) "%s" "[tcpprep] Auto/Client mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Auto/Client mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -a client >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Auto/Client mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -a client >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi auto_server: $(PRINTF) "%s" "[tcpprep] Auto/Server mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Auto/Server mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -a server >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Auto/Server mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -a server >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi auto_first: $(PRINTF) "%s" "[tcpprep] Auto/First mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Auto/First mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -a first >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Auto/First mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -a first >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi regex: $(PRINTF) "%s" "[tcpprep] Regex mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Regex mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -r '96.17.211.*' >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Regex mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -r '96.17.211.*' >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi cidr: $(PRINTF) "%s" "[tcpprep] CIDR mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] CIDR mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] CIDR mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -c '96.17.211.0/24' >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi port: $(PRINTF) "%s" "[tcpprep] Port mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Port mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -p >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Port mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -p >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi mac: $(PRINTF) "%s" "[tcpprep] MAC mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] MAC mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -e 00:1f:f3:3c:e1:13 >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] MAC mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -e 00:1f:f3:3c:e1:13 >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi comment: $(PRINTF) "%s" "[tcpprep] Comment mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Comment mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -C "This is a comment" -p >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Comment mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -C "This is a comment" -p >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi print_comment: $(PRINTF) "%s" "[tcpprep] Print comment mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Print comment mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -P test.comment >test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Print comment mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -P $(srcdir)/test.comment >$(srcdir)/test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi print_info: $(PRINTF) "%s" "[tcpprep] Print info mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Print info mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -I test.comment >test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Print info mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -I $(srcdir)/test.comment >$(srcdir)/test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi regex_reverse: $(PRINTF) "%s" "[tcpprep] Regex reverse mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] Regex reverse mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -r '96.17.211.*' --reverse >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] Regex reverse mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -r '96.17.211.*' --reverse >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi cidr_reverse: $(PRINTF) "%s" "[tcpprep] CIDR reverse mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] CIDR reverse mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --reverse >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] CIDR reverse mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -c '96.17.211.0/24' --reverse >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi mac_reverse: $(PRINTF) "%s" "[tcpprep] MAC reverse mode test: " - $(PRINTF) "%s\n" "*** [tcpprep] MAC reverse mode test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -e 00:1f:f3:3c:e1:13 --reverse >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] MAC reverse mode test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -e 00:1f:f3:3c:e1:13 --reverse >> test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi exclude_packets: $(PRINTF) "%s" "[tcpprep] exclude packets test: " - $(PRINTF) "%s\n" "*** [tcpprep] exclude packets test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --exclude 'P:61-65,88-91' >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] exclude packets test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --exclude 'P:61-65,88-91' >> test.log 2>&1 + diff test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi include_packets: $(PRINTF) "%s" "[tcpprep] include packets test: " - $(PRINTF) "%s\n" "*** [tcpprep] include packets test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --include 'P:61-65,88-91' >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] include packets test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --include 'P:61-65,88-91' >> test.log 2>&1 + diff test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi include_source: $(PRINTF) "%s" "[tcpprep] include source test: " - $(PRINTF) "%s\n" "*** [tcpprep] include source test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --include 'S:96.0.0.0/8' >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] include source test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --include 'S:96.0.0.0/8' >> test.log 2>&1 + diff test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi include_dest: $(PRINTF) "%s" "[tcpprep] include destination test: " - $(PRINTF) "%s\n" "*** [tcpprep] include destination test: " >>test.log - $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --include 'D:96.0.0.0/8' >>test.log 2>&1 - diff test.$@ test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpprep] include destination test: " >> test.log + $(TCPPREP) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -c '96.17.211.0/24' --include 'D:96.0.0.0/8' >> test.log 2>&1 + diff test.$@ test.$@1 >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi replay_basic: $(PRINTF) "%s" "[tcpreplay] Basic test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Basic test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -t test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Basic test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -t $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_cache: $(PRINTF) "%s" "[tcpreplay] Cache test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Cache test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -c test.cidr -i $(nic1) -I $(nic2) -t test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Cache test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -c $(srcdir)/test.cidr -i $(nic1) -I $(nic2) -t $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_accurate: $(PRINTF) "%s" "[tcpreplay] Accurate test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Accurate test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -a -i $(nic1) test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Accurate test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -a -i $(nic1) $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_stats: $(PRINTF) "%s" "[tcpreplay] Statistics test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Statistics test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) --stats=1 -i $(nic1) test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Statistics test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) --stats=1 -i $(nic1) $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_portmap: $(PRINTF) "%s" "[tcprewrite] Portmap test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Portmap test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -r 80:8080 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Portmap test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -r 80:8080 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_range_portmap: $(PRINTF) "%s" "[tcprewrite] Portmap range test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Portmap range test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -r 1-100:49148 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Portmap range test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -r 1-100:49148 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi rewrite_endpoint: $(PRINTF) "%s" "[tcprewrite] Endpoint test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Endpoint test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -e 10.10.0.1:10.10.0.2 \ - -c test.auto_router >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Endpoint test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -e 10.10.0.1:10.10.0.2 \ + -c $(srcdir)/test.auto_router >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_pnat: $(PRINTF) "%s" "[tcprewrite] Pseudo NAT test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Pseudo NAT test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 \ - -N 96.17.211.0/24:172.16.0.0/24 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Pseudo NAT test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 \ + -N 96.17.211.0/24:172.16.0.0/24 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_mac: $(PRINTF) "%s" "[tcprewrite] Src/Dst MAC test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Src/Dst MAC test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 \ + $(PRINTF) "%s\n" "*** [tcprewrite] Src/Dst MAC test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 \ --enet-dmac=00:12:13:14:15:16,00:22:33:44:55:66 \ - --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c test.auto_router >>test.log 2>&1 + --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c $(srcdir)/test.auto_router >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_enet_subsmac: $(PRINTF) "%s" "[tcprewrite] Substitute Src/Dst MAC test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Substitute Src/Dst MAC test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 \ + $(PRINTF) "%s\n" "*** [tcprewrite] Substitute Src/Dst MAC test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 \ --enet-subsmac=00:1f:f3:3c:e1:13,00:22:33:44:55:66 \ - --enet-subsmac=f8:1e:df:e5:84:3a,00:66:55:44:33:22 >>test.log 2>&1 + --enet-subsmac=f8:1e:df:e5:84:3a,00:66:55:44:33:22 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t%s\n" "FAILED"; else $(PRINTF) "\t%s\n" "OK"; fi rewrite_mac_seed: $(PRINTF) "%s" "[tcprewrite] Seeded MAC test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Seeded MAC test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 \ - --enet-mac-seed=42 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Seeded MAC test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 \ + --enet-mac-seed=42 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_mac_seed_keep: $(PRINTF) "%s" "[tcprewrite] Seeded Keep MAC test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Seeded Keep MAC test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 \ - --enet-mac-seed=42 --enet-mac-seed-keep-bytes=3 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Seeded Keep MAC test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 \ + --enet-mac-seed=42 --enet-mac-seed-keep-bytes=3 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi rewrite_trunc: $(PRINTF) "%s" "[tcprewrite] Truncate test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Truncate test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -F trunc -i test.pcap -o test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Truncate test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -F trunc -i $(TEST_PCAP) -o test.$@1 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_pad: $(PRINTF) "%s" "[tcprewrite] Pad test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Pad test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -F pad -i test.pcap -o test.$@1 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Pad test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -F pad -i $(TEST_PCAP) -o test.$@1 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t\t%s\n" "OK"; fi rewrite_seed: $(PRINTF) "%s" "[tcprewrite] Seed IP test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Seed IP test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -s 55 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Seed IP test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -s 55 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_layer2: $(PRINTF) "%s" "[tcprewrite] Layer2 test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Layer2 test: " >>test.log + $(PRINTF) "%s\n" "*** [tcprewrite] Layer2 test: " >> test.log $(TCPREWRITE) $(ENABLE_DEBUG) --dlt=user --user-dlink=00,50,da,5d,46,55,0,7,eb,30,a4,c3,08,0 \ - -i test.pcap -o test.$@1 >>test.log 2>&1 + -i $(TEST_PCAP) -o test.$@1 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_config: $(PRINTF) "%s" "[tcprewrite] Config/VLAN Add test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Config/VLAN Add test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) --load-opts config >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Config/VLAN Add test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) --load-opts config >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi rewrite_skip: $(PRINTF) "%s" "[tcprewrite] Skip bcast test: " - $(PRINTF) "%s\n" "*** [tcprewrite] Skip bcast test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 -b -s 55 \ + $(PRINTF) "%s\n" "*** [tcprewrite] Skip bcast test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 -b -s 55 \ --enet-dmac=00:12:13:14:15:16,00:22:33:44:55:66 \ - --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c test.auto_router >>test.log 2>&1 + --enet-smac=00:22:33:44:55:66,00:12:13:14:15:16 -c $(srcdir)/test.auto_router >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_dltuser: $(PRINTF) "%s" "[tcprewrite] DLT User test: " - $(PRINTF) "%s\n" "*** [tcprewrite] DLT User test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --dlt=user \ - --user-dlink=0x0f,0x00,0x08,0x00 --user-dlt=104 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] DLT User test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --dlt=user \ + --user-dlink=0x0f,0x00,0x08,0x00 --user-dlt=104 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_dlthdlc: $(PRINTF) "%s" "[tcprewrite] DLT Cisco HDLC test: " - $(PRINTF) "%s\n" "*** [tcprewrite] DLT Cisco HDLC test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --dlt=hdlc \ - --hdlc-control=0 --hdlc-address=0x0F >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] DLT Cisco HDLC test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --dlt=hdlc \ + --hdlc-control=0 --hdlc-address=0x0F >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi rewrite_vlandel: $(PRINTF) "%s" "[tcprewrite] VLAN Delete test: " - $(PRINTF) "%s\n" "*** [tcprewrite] VLAN Delete test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.rewrite_config -o test.$@1 \ - --enet-vlan=del >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] VLAN Delete test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(srcdir)/test.rewrite_config -o test.$@1 \ + --enet-vlan=del >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_efcs: $(PRINTF) "%s" "[tcprewrite] Remove EFCS: " - $(PRINTF) "%s\n" "*** [tcprewrite] Remove EFCS: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --efcs >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Remove EFCS: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --efcs >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_1ttl: $(PRINTF) "%s" "[tcprewrite] Force TTL: " - $(PRINTF) "%s\n" "*** [tcprewrite] Force TTL: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --ttl=58 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Force TTL: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --ttl=58 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_2ttl: $(PRINTF) "%s" "[tcprewrite] Increase TTL: " - $(PRINTF) "%s\n" "*** [tcprewrite] Increase TTL: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --ttl=+58 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Increase TTL: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --ttl=+58 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_3ttl: $(PRINTF) "%s" "[tcprewrite] Reduce TTL: " - $(PRINTF) "%s\n" "*** [tcprewrite] Reduce TTL: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --ttl=-58 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] Reduce TTL: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --ttl=-58 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi rewrite_tos: $(PRINTF) "%s" "[tcprewrite] TOS test: " - $(PRINTF) "%s\n" "*** [tcprewrite] TOS test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --tos=50 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] TOS test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --tos=50 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t\t%s\n" "OK"; fi rewrite_mtutrunc: $(PRINTF) "%s" "[tcprewrite] MTU Truncate test: " - $(PRINTF) "%s\n" "*** [tcprewrite] MTU Truncate test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --mtu-trunc --mtu=300 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] MTU Truncate test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --mtu-trunc --mtu=300 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi rewrite_l7fuzzing: $(PRINTF) "%s" "[tcprewrite] L7 fuzzing test: " - $(PRINTF) "%s\n" "*** [tcprewrite] L7 fuzzing test: " >>test.log - $(TCPREWRITE) $(ENABLE_DEBUG) -i test.pcap -o test.$@1 --fuzz-seed=42 --fuzz-factor=2 >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcprewrite] L7 fuzzing test: " >> test.log + $(TCPREWRITE) $(ENABLE_DEBUG) -i $(TEST_PCAP) -o test.$@1 --fuzz-seed=42 --fuzz-factor=2 >> test.log 2>&1 if WORDS_BIGENDIAN - diff test.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test.$@ test.$@1 >> test.log 2>&1 else - diff test2.$@ test.$@1 >>test.log 2>&1 + diff $(srcdir)/test2.$@ test.$@1 >> test.log 2>&1 endif if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_pps: $(PRINTF) "%s" "[tcpreplay] Packets/sec test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Packets/sec test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -p 25 test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Packets/sec test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -p 25 $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_rate: $(PRINTF) "%s" "[tcpreplay] Mbps test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Mbps test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -M 25.0 test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Mbps test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -M 25.0 $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t\t%s\n" "OK"; fi replay_multi: $(PRINTF) "%s" "[tcpreplay] Multiplier test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Multiplier test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -x 25.0 test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Multiplier test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -x 25.0 $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_pps_multi: $(PRINTF) "%s" "[tcpreplay] Packets/sec Multiplier test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Packets/sec Multiplier test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -p 100 --pps-multi=5 test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Packets/sec Multiplier test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -p 100 --pps-multi=5 $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t%s\n" "FAILED"; else $(PRINTF) "\t%s\n" "OK"; fi replay_top: $(PRINTF) "%s" "[tcpreplay] Topspeed test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Topspeed test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -t test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Topspeed test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -t $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_precache: $(PRINTF) "%s" "[tcpreplay] Precache test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Precache test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) --preload-pcap test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Precache test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) --preload-pcap $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi datadump_mode: $(PRINTF) "%s" "[tcpreplay] Data dump test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Data dump mode test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -D -i $(nic1) -I $(nic2) -w primary.data -W secondary.data -c test.cidr -R test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Data dump mode test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -D -i $(nic1) -I $(nic2) -w primary.data -W secondary.data -c $(srcdir)/test.cidr -R $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_config: $(PRINTF) "%s" "[tcpreplay] Config file/VLAN add test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Config file/VLAN add test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) --load-opts=config test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Config file/VLAN add test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) --load-opts=config $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi replay_dualfile: $(PRINTF) "%s" "[tcpreplay] Dual file test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Dual file test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -I $(nic2) --dualfile test.pcap test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Dual file test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) -I $(nic2) --dualfile $(TEST_PCAP) $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t\t%s\n" "OK"; fi replay_maxsleep: $(PRINTF) "%s" "[tcpreplay] Maximum sleep test: " - $(PRINTF) "%s\n" "*** [tcpreplay] Maximum sleep test: " >>test.log - $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) --maxsleep=20 test.pcap test.pcap >>test.log 2>&1 + $(PRINTF) "%s\n" "*** [tcpreplay] Maximum sleep test: " >> test.log + $(TCPREPLAY) $(ENABLE_DEBUG) -i $(nic1) --maxsleep=20 $(TEST_PCAP) $(TEST_PCAP) >> test.log 2>&1 if [ $? ] ; then $(PRINTF) "\t\t%s\n" "FAILED"; else $(PRINTF) "\t\t%s\n" "OK"; fi clean: