Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ AC_SUBST(extra_debug_flag)
dnl Enable timestamp_trace in code/compiler options
timestamp_trace=no
AC_ARG_ENABLE(timestamp-trace,
AS_HELP_STRING([--timestamp-trace],[Enable dumping of trace timestamps at the end of a test]),
AS_HELP_STRING([--enable-timestamp-trace],[Enable dumping of trace timestamps at the end of a test]),
[ if test x$enableval = xyes; then
timestamp_trace=yes
CFLAGS="${CFLAGS} -DTIMESTAMP_TRACE"
Expand Down
21 changes: 8 additions & 13 deletions src/common/err.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,53 +67,48 @@ extern int debug;
* notice() - Informational only via stderr, format string, one or more variables
*/

/* gcc accepts __FUNCTION__, but C99 says use __func__. Necessary for SunPro compiler */
#if !defined(__GNUC__) && !defined(__FUNCTION__)
# define __FUNCTION__ __func__
#endif

void notice(const char *fmt, ...);

#ifdef DEBUG /* then err, errx, warn, warnx print file, func, line */

#define dbg(x, y) do { \
if (debug >= x) \
fprintf(stderr, "DEBUG%d in %s:%s() line %d: %s\n", x, __FILE__, __FUNCTION__, __LINE__, y); \
fprintf(stderr, "DEBUG%d in %s:%s() line %d: %s\n", x, __FILE__, __func__, __LINE__, y); \
} while(0)

#define dbgx(x, y, ...) do { \
if (debug >= x) { \
fprintf(stderr, "DEBUG%d in %s:%s() line %d: " y "\n", x, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); \
fprintf(stderr, "DEBUG%d in %s:%s() line %d: " y "\n", x, __FILE__, __func__, __LINE__, __VA_ARGS__); \
} \
} while(0)

#define warn(x) \
if (print_warnings) \
fprintf(stderr, "Warning in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, x)
fprintf(stderr, "Warning in %s:%s() line %d:\n%s\n", __FILE__, __func__, __LINE__, x)

#define warnx(x, ...) \
if (print_warnings) \
fprintf(stderr, "Warning in %s:%s() line %d:\n" x "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
fprintf(stderr, "Warning in %s:%s() line %d:\n" x "\n", __FILE__, __func__, __LINE__, __VA_ARGS__)

#define err(x, y) do { \
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, y); \
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n%s\n", __FILE__, __func__, __LINE__, y); \
fflush(NULL); \
exit(x); \
} while (0)

#define errx(x, y, ...) do {\
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n " y "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); \
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n " y "\n", __FILE__, __func__, __LINE__, __VA_ARGS__); \
fflush(NULL); \
exit(x); \
} while (0)

#define err_no_exit(y) do { \
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n%s\n", __FILE__, __FUNCTION__, __LINE__, y); \
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n%s\n", __FILE__, __func__, __LINE__, y); \
fflush(NULL); \
} while (0)

#define err_no_exitx(y, ...) do {\
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n " y "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); \
fprintf(stderr, "\nFatal Error in %s:%s() line %d:\n " y "\n", __FILE__, __func__, __LINE__, __VA_ARGS__); \
fflush(NULL); \
} while (0)

Expand Down
1 change: 1 addition & 0 deletions src/common/get.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#pragma once
#include <stdbool.h>

#include "config.h"
#include "defines.h"
Expand Down
8 changes: 5 additions & 3 deletions src/common/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ sendpacket_open(const char *device,
sp = sendpacket_open_tuntap(device, errbuf);
#endif
} else {
#ifdef HAVE_LIBXDP
#if defined HAVE_LIBXDP && \
(defined HAVE_PF_PACKET || defined HAVE_LIBURING || defined HAVE_BPF \
|| defined HAVE_LIBDNET || defined HAVE_PCAP_INJECT || defined HAVE_PCAP_SENDPACKET)
/*
* AF_XDP is tried ahead of the chain below rather than inside it,
* because it is the one method that may legitimately fail and hand
Expand Down Expand Up @@ -831,6 +833,8 @@ sendpacket_open(const char *device,
sp = sendpacket_open_libdnet(device, errbuf);
#elif (defined HAVE_PCAP_INJECT || defined HAVE_PCAP_SENDPACKET)
sp = sendpacket_open_pcap(device, errbuf);
#elif defined HAVE_LIBXDP
sp = sendpacket_open_xsk(device, errbuf, arg);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an AF_XDP-only build (HAVE_LIBXDP defined, none of HAVE_PF_PACKET/HAVE_LIBURING/HAVE_BPF/HAVE_LIBDNET/HAVE_PCAP_INJECT/HAVE_PCAP_SENDPACKET), this new #elif defined HAVE_LIBXDP fallback calls sendpacket_open_xsk(device, errbuf, arg) again with identical arguments right after the first attempt already failed and reset sendpacket_type to fall through to a "default injector".

On such a build, opening a device whose AF_XDP socket setup fails logs "Falling back to the default injection method", but the only default compiled in is the same xsk open — it deterministically fails again with the same errbuf. Wasted duplicate socket setup and a misleading log message promising a fallback that doesn't exist for this build configuration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, and I believe I fixed this. The end result is a combination of ifdefs that I believe is inherent to the way the function is structured, but I do not want to refactor the function as part of this PR which I intend to be "small and safe" (or as much as possible anyway).

Please let me know what you think, I'm willing to spend some time and see what I can do to improve this.

#else
#error "No defined packet injection method for sendpacket_open()"
#endif
Expand Down Expand Up @@ -932,9 +936,7 @@ sendpacket_close(sendpacket_t *sp)
assert(sp);
switch (sp->handle_type) {
case SP_TYPE_KHIAL:
#ifdef HAVE_SOCK_RAW
case SP_TYPE_SOCK_RAW:
#endif
close(sp->handle.fd);
break;

Expand Down
2 changes: 2 additions & 0 deletions src/common/sendpacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#pragma once

#include <stdbool.h>

#include "defines.h"
#include "config.h"
#include <sys/socket.h>
Expand Down
12 changes: 6 additions & 6 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ pcap_t* tcpr_pcap_open(const char *path, char *ebuf);
int tcpr_pcap_file_precision(const char *path);

/* our "safe" implimentations of functions which allocate memory */
#define safe_malloc(x) our_safe_malloc(x, __FUNCTION__, __LINE__, __FILE__)
#define safe_malloc(x) our_safe_malloc(x, __func__, __LINE__, __FILE__)
void *our_safe_malloc(size_t len, const char *, int, const char *);

#define safe_realloc(x, y) our_safe_realloc(x, y, __FUNCTION__, __LINE__, __FILE__)
#define safe_realloc(x, y) our_safe_realloc(x, y, __func__, __LINE__, __FILE__)
void *our_safe_realloc(void *ptr, size_t len, const char *, int, const char *);

#define safe_strdup(x) our_safe_strdup(x, __FUNCTION__, __LINE__, __FILE__)
#define safe_strdup(x) our_safe_strdup(x, __func__, __LINE__, __FILE__)
char *our_safe_strdup(const char *str, const char *, int, const char *);

#define safe_free(x) our_safe_free(x, __FUNCTION__, __LINE__, __FILE__)
#define safe_free(x) our_safe_free(x, __func__, __LINE__, __FILE__)
void our_safe_free(void *ptr, const char *, int, const char *);

#define safe_pcap_next(x, y) our_safe_pcap_next(x, y, __FUNCTION__, __LINE__, __FILE__)
#define safe_pcap_next(x, y) our_safe_pcap_next(x, y, __func__, __LINE__, __FILE__)
u_char *
our_safe_pcap_next(pcap_t *pcap, struct pcap_pkthdr *pkthdr, const char *funcname, int line, const char *file);

#define safe_pcap_next_ex(x, y, z) our_safe_pcap_next_ex(x, y, z, __FUNCTION__, __LINE__, __FILE__)
#define safe_pcap_next_ex(x, y, z) our_safe_pcap_next_ex(x, y, z, __func__, __LINE__, __FILE__)
int our_safe_pcap_next_ex(pcap_t *pcap,
struct pcap_pkthdr **pkthdr,
const u_char **pktdata,
Expand Down
4 changes: 2 additions & 2 deletions src/fragroute/iputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ssize_t
inet_add_option(uint16_t eth_type, void *buf, size_t len, int proto, const void *optbuf, size_t optlen)
{
if (eth_type == ETH_TYPE_IP) {

Check failure on line 19 in src/fragroute/iputil.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/fragroute/iputil.c:19:21 [clang-diagnostic-error]

use of undeclared identifier 'ETH_TYPE_IP'
return ip_add_option(buf, len, proto, optbuf, optlen);
} else if (eth_type == ETH_TYPE_IPV6) {
return inet_add_option_6(buf, len, proto, optbuf, optlen);
Expand Down Expand Up @@ -85,9 +85,9 @@
inet_checksum(uint16_t eth_type, void *buf, size_t len)
{
if (eth_type == ETH_TYPE_IP) {
return ip_checksum(buf, len);
ip_checksum(buf, len);
} else if (eth_type == ETH_TYPE_IPV6) {
return ip6_checksum(buf, len);
ip6_checksum(buf, len);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "common.h"
#include "tcpreplay_api.h"
#include "timestamp_trace.h"
#ifdef TIMESTAMP_TRACE
uint32_t trace_num;
timestamp_trace_entry_t timestamp_trace_entry_array[TRACE_MAX_ENTRIES];
#endif
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_hdlc/hdlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ dlt_hdlc_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char *ipv
if (l2len == -1 || pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_ieee80211/ieee80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ dlt_ieee80211_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char
if (l2len == -1 || pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ dlt_jnpr_ether_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_cha
if (l2len == -1 || pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
3 changes: 3 additions & 0 deletions src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@
#include "jnpr_ether_types.h"

*/

/* ISO C forbids an empty translation unit */
typedef int jnpr_ether_api_unused_t;
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_linuxsll/linuxsll.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ dlt_linuxsll_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char
if (l2len == -1 || pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_linuxsll2/linuxsll2.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ dlt_linuxsll2_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char
if (l2len == -1 || pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_null/null.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ dlt_null_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char *ipv
if (pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_pppserial/pppserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ dlt_pppserial_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char
if (l2len == -1 || pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
3 changes: 3 additions & 0 deletions src/tcpedit/plugins/dlt_pppserial/pppserial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@
#include "tcpr.h"

*/

/* ISO C forbids an empty translation unit */
typedef int pppserial_api_unused_t;
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_radiotap/radiotap.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ dlt_radiotap_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char
radiolen = dlt_radiotap_l2len(ctx, packet, pktlen);
data = dlt_radiotap_get_80211(ctx, packet, pktlen, radiolen);
l2len = dlt_ieee80211_l2len(ctx, data, pktlen);
return tcpedit_dlt_l3data_merge(ctx, data, pktlen - radiolen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, data, pktlen - radiolen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/plugins/dlt_user/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ dlt_user_merge_layer3(tcpeditdlt_t *ctx, u_char *packet, int pktlen, u_char *ipv
if (l2len == TCPEDIT_ERROR || pktlen < l2len)
return NULL;

return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ?: ipv6_data, l2len);
return tcpedit_dlt_l3data_merge(ctx, packet, pktlen, ipv4_data ? ipv4_data : ipv6_data, l2len);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/tcpedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ COUNTER tcpedit_get_pkts_edited(tcpedit_t *tcpedit);
* outside of internal tcpedit functions
*/

#define tcpedit_seterr(x, y, ...) __tcpedit_seterr(x, __FUNCTION__, __LINE__, __FILE__, y, __VA_ARGS__)
#define tcpedit_seterr(x, y, ...) __tcpedit_seterr(x, __func__, __LINE__, __FILE__, y, __VA_ARGS__)
void __tcpedit_seterr(tcpedit_t *tcpedit, const char *func, int line, const char *file, const char *fmt, ...);
void tcpedit_setwarn(tcpedit_t *tcpedit, const char *fmt, ...);

Expand Down
5 changes: 4 additions & 1 deletion src/tcpreplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ tcpedit_t *tcpedit;

#include "send_packets.h"
#include "signal_handler.h"
#include "timestamp_trace.h"

#ifdef DEBUG
int debug = 0;
Expand Down Expand Up @@ -249,7 +250,9 @@ static void flow_stats(const tcpreplay_t *tcpr_ctx)
flow_non_flow_packets *= tcpr_ctx->last_unique_iteration;
} else {
/* adjust for --unique-ip-loops */
flow_packets = (flow_packets * (tcpr_ctx->last_unique_iteration ?: tcpr_ctx->iteration)) / tcpr_ctx->iteration;
flow_packets = (flow_packets *
(tcpr_ctx->last_unique_iteration ? tcpr_ctx->last_unique_iteration : tcpr_ctx->iteration)) /
tcpr_ctx->iteration;
}

#ifdef TCPREPLAY_EDIT
Expand Down
2 changes: 1 addition & 1 deletion src/tcpreplay_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ int tcpreplay_set_tcpdump(tcpreplay_t *, tcpdump_t *);
* outside of internal tcpreplay API functions
*/

#define tcpreplay_seterr(x, y, ...) __tcpreplay_seterr(x, __FUNCTION__, __LINE__, __FILE__, y, __VA_ARGS__)
#define tcpreplay_seterr(x, y, ...) __tcpreplay_seterr(x, __func__, __LINE__, __FILE__, y, __VA_ARGS__)
void __tcpreplay_seterr(tcpreplay_t *ctx, const char *func, const int line, const char *file, const char *fmt, ...);
void tcpreplay_setwarn(tcpreplay_t *ctx, const char *fmt, ...);

Expand Down
Loading
Loading