Skip to content

Commit

Permalink
Feature #853 - fix merge conflicts
Browse files Browse the repository at this point in the history
Fix build and run `clang-format`.
  • Loading branch information
fklassen committed Jun 3, 2024
1 parent 457a0f6 commit 5f99ac9
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 101 deletions.
62 changes: 37 additions & 25 deletions src/common/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,13 @@ sendpacket_open(const char *device,

errbuf[0] = '\0';

if (sendpacket_type == SP_TYPE_LIBPCAP_DUMP){
sp =

(device, errbuf);
}else{
#ifdef HAVE_TUNTAP
if (sendpacket_type == SP_TYPE_LIBPCAP_DUMP) {
sp = sendpacket_open_pcap_dump(device, errbuf);

Check warning on line 547 in src/common/sendpacket.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/common/sendpacket.c:547:14 [performance-no-int-to-ptr]

integer to pointer cast pessimizes optimization opportunities
} else {
#ifdef HAVE_TUNTAP
snprintf(sys_dev_dir, sizeof(sys_dev_dir), "/sys/class/net/%s/", device);
device_exists = access(sys_dev_dir, R_OK) == 0;
#endif
#endif

/* khial is universal */
if (stat(device, &sdata) == 0) {
Expand All @@ -574,29 +572,37 @@ sendpacket_open(const char *device,
errx(-1, "\"%s\" is not a valid Tcpreplay device", device);
}
}
#ifdef HAVE_TUNTAP
#ifdef HAVE_TUNTAP
} else if (strncmp(device, "tap", 3) == 0 && !device_exists) {
sp = sendpacket_open_tuntap(device, errbuf);
#endif
#endif
} else {
#ifdef HAVE_NETMAP
if (sendpacket_type == SP_TYPE_NETMAP)
#ifdef HAVE_NETMAP
if (sendpacket_type == SP_TYPE_NETMAP) {
sp = (sendpacket_t *)sendpacket_open_netmap(device, errbuf, arg);
} else
#endif
#ifdef HAVE_LIBXDP \
if (sendpacket_type == SP_TYPE_LIBXDP)
sp = sendpacket_open_xsk(device, errbuf);
else
#endif
#if defined HAVE_PF_PACKET
#endif
#if defined HAVE_PF_PACKET
sp = sendpacket_open_pf(device, errbuf);
#elif defined HAVE_BPF
#elif defined HAVE_BPF
sp = sendpacket_open_bpf(device, errbuf);
#elif defined HAVE_LIBDNET
#elif defined HAVE_LIBDNET
sp = sendpacket_open_libdnet(device, errbuf);
#elif (defined HAVE_PCAP_INJECT || defined HAVE_PCAP_SENDPACKET)
#elif (defined HAVE_PCAP_INJECT || defined HAVE_PCAP_SENDPACKET)
sp = sendpacket_open_pcap(device, errbuf);
#else
#error "No defined packet injection method for sendpacket_open()"
#endif
#elif defined HAVE_LIBXDP
sp = sendpacket_open_xsk(device, errbuf);
#else
#error "No defined packet injection method for sendpacket_open()"
#endif
}
}

if (sp) {
sp->open = 1;
sp->cache_dir = direction;
Expand Down Expand Up @@ -736,7 +742,7 @@ sendpacket_get_hwaddr(sendpacket_t *sp)

if (sp->handle_type == SP_TYPE_KHIAL) {
addr = sendpacket_get_hwaddr_khial(sp);
} else if( sp->handle_type == SP_TYPE_LIBPCAP_DUMP) {
} else if (sp->handle_type == SP_TYPE_LIBPCAP_DUMP) {
sendpacket_seterr(sp, "Error: sendpacket_get_hwaddr() not yet supported for pcap dump");
return NULL;
} else {
Expand Down Expand Up @@ -1304,11 +1310,17 @@ sendpacket_get_dlt(sendpacket_t *sp)
{
int dlt = DLT_EN10MB;

if (sp->handle_type == SP_TYPE_KHIAL || sp->handle_type == SP_TYPE_NETMAP || sp->handle_type == SP_TYPE_TUNTAP || sp->handle_type == SP_TYPE_LIBPCAP_DUMP) {
/* always EN10MB */
} else {
#if defined HAVE_BPF
int rcode;
switch (sp->handle_type) {
case SP_TYPE_KHIAL:
case SP_TYPE_NETMAP:
case SP_TYPE_TUNTAP:
case SP_TYPE_LIBPCAP_DUMP:
case SP_TYPE_LIBXDP:
/* always EN10MB */
return dlt;
default:
;
}

#if defined HAVE_BPF
if ((ioctl(sp->handle.fd, BIOCGDLT, &dlt)) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/sendpacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef enum sendpacket_type_e {
SP_TYPE_KHIAL,
SP_TYPE_NETMAP,
SP_TYPE_TUNTAP,
SP_TYPE_LIBPCAP_DUMP
SP_TYPE_LIBPCAP_DUMP,
SP_TYPE_LIBXDP
} sendpacket_type_t;

Expand Down
155 changes: 80 additions & 75 deletions src/tcpreplay_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,95 +338,100 @@ tcpreplay_post_args(tcpreplay_t *ctx, int argc)
tcpreplay_setwarn(ctx, "%s", "--pktlen may cause problems. Use with caution.");
}

switch (WHICH_IDX_INTF1){
case INDEX_OPT_WRITE:
options->intf1_name = safe_strdup(OPT_ARG(INTF1));
ctx->sp_type = SP_TYPE_LIBPCAP_DUMP;
/* open interfaces for writing */
if ((ctx->intf1 = sendpacket_open(options->intf1_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf1_name, ebuf);
ret = -1;
goto out;
switch (WHICH_IDX_INTF1) {
case INDEX_OPT_WRITE:
options->intf1_name = safe_strdup(OPT_ARG(INTF1));
ctx->sp_type = SP_TYPE_LIBPCAP_DUMP;
/* open interfaces for writing */
if ((ctx->intf1 = sendpacket_open(options->intf1_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf1_name, ebuf);
ret = -1;
goto out;
}
break;

case INDEX_OPT_INTF1:
if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF1))) == NULL) {
if (!strncmp(OPT_ARG(INTF1), "netmap:", 7) || !strncmp(OPT_ARG(INTF1), "vale", 4)) {

Check warning on line 355 in src/tcpreplay_api.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpreplay_api.c:355:13 [bugprone-branch-clone]

if with identical then and else branches
tcpreplay_seterr(
ctx,
"Unable to connect to netmap interface %s. Ensure netmap module is installed (see INSTALL).",
OPT_ARG(INTF1));
} else {
tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF1));
}
break;

case INDEX_OPT_INTF1:
if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF1))) == NULL) {
if (!strncmp(OPT_ARG(INTF1), "netmap:", 7) || !strncmp(OPT_ARG(INTF1), "vale", 4))
tcpreplay_seterr(ctx, "Unable to connect to netmap interface %s. Ensure netmap module is installed (see INSTALL).",
OPT_ARG(INTF1));
else
tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF1));

ret = -1;
goto out;
}

if (!strncmp(intname, "netmap:", 7) || !strncmp(intname, "vale:", 5)) {
#ifdef HAVE_NETMAP
options->netmap = 1;
ctx->sp_type = SP_TYPE_NETMAP;
#else
tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with netmap support");
ret = -1;
goto out;
#endif
}
ret = -1;
goto out;
}

options->intf1_name = safe_strdup(intname);
if (!strncmp(intname, "netmap:", 7) || !strncmp(intname, "vale:", 5)) {
#ifdef HAVE_NETMAP
options->netmap = 1;
ctx->sp_type = SP_TYPE_NETMAP;
#else
tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with netmap support");
ret = -1;
goto out;
#endif
}

/* open interfaces for writing */
if ((ctx->intf1 = sendpacket_open(options->intf1_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf1_name, ebuf);
ret = -1;
goto out;
}
options->intf1_name = safe_strdup(intname);

/* open interfaces for writing */
if ((ctx->intf1 = sendpacket_open(options->intf1_name, ebuf, TCPR_DIR_C2S, ctx->sp_type, ctx)) == NULL) {
tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf1_name, ebuf);
ret = -1;
goto out;
}
#ifdef HAVE_LIBXDP
ctx->intf1->batch_size = OPT_VALUE_XDP_BATCH_SIZE;
ctx->intf1->batch_size = OPT_VALUE_XDP_BATCH_SIZE;
#endif
#if defined HAVE_NETMAP
ctx->intf1->netmap_delay = ctx->options->netmap_delay;
#endif
#if defined HAVE_NETMAP
ctx->intf1->netmap_delay = ctx->options->netmap_delay;
#endif

ctx->intf1dlt = sendpacket_get_dlt(ctx->intf1);
ctx->intf1dlt = sendpacket_get_dlt(ctx->intf1);

if (HAVE_OPT(INTF2)) {
if (!HAVE_OPT(CACHEFILE) && !HAVE_OPT(DUALFILE)) {
tcpreplay_seterr(ctx, "--intf2=%s requires either --cachefile or --dualfile", OPT_ARG(INTF2));
ret = -1;
goto out;
}
if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF2))) == NULL) {
tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF2));
ret = -1;
goto out;
}
if (HAVE_OPT(INTF2)) {
if (!HAVE_OPT(CACHEFILE) && !HAVE_OPT(DUALFILE)) {
tcpreplay_seterr(ctx, "--intf2=%s requires either --cachefile or --dualfile", OPT_ARG(INTF2));
ret = -1;
goto out;
}
if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF2))) == NULL) {
tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF2));
ret = -1;
goto out;
}

options->intf2_name = safe_strdup(intname);
options->intf2_name = safe_strdup(intname);

/* open interface for writing */
if ((ctx->intf2 = sendpacket_open(options->intf2_name, ebuf, TCPR_DIR_S2C, ctx->sp_type, ctx)) == NULL) {
tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf2_name, ebuf);
}
/* open interface for writing */
if ((ctx->intf2 = sendpacket_open(options->intf2_name, ebuf, TCPR_DIR_S2C, ctx->sp_type, ctx)) == NULL) {
tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf2_name, ebuf);
}

#if defined HAVE_NETMAP
ctx->intf2->netmap_delay = ctx->options->netmap_delay;
#endif

ctx->intf2dlt = sendpacket_get_dlt(ctx->intf2);
if (ctx->intf2dlt != ctx->intf1dlt) {
tcpreplay_seterr(ctx, "DLT type mismatch for %s (%s) and %s (%s)",
options->intf1_name, pcap_datalink_val_to_name(ctx->intf1dlt),
options->intf2_name, pcap_datalink_val_to_name(ctx->intf2dlt));
ret = -1;
goto out;
}
#if defined HAVE_NETMAP
ctx->intf2->netmap_delay = ctx->options->netmap_delay;
#endif

ctx->intf2dlt = sendpacket_get_dlt(ctx->intf2);
if (ctx->intf2dlt != ctx->intf1dlt) {
tcpreplay_seterr(ctx,
"DLT type mismatch for %s (%s) and %s (%s)",
options->intf1_name,
pcap_datalink_val_to_name(ctx->intf1dlt),
options->intf2_name,
pcap_datalink_val_to_name(ctx->intf2dlt));
ret = -1;
goto out;
}
break;
}
break;

default:
assert(false); //shouldn't happen!
default:
assert(false); // shouldn't happen!
}

if (HAVE_OPT(CACHEFILE)) {
Expand Down

0 comments on commit 5f99ac9

Please sign in to comment.