summaryrefslogtreecommitdiffstats
path: root/src/utils/kxdpgun
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/kxdpgun')
-rw-r--r--src/utils/kxdpgun/main.c58
1 files changed, 43 insertions, 15 deletions
diff --git a/src/utils/kxdpgun/main.c b/src/utils/kxdpgun/main.c
index c9db312..8f4d402 100644
--- a/src/utils/kxdpgun/main.c
+++ b/src/utils/kxdpgun/main.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -205,12 +206,12 @@ static void print_stats(kxdpgun_stats_t *st, bool tcp, bool quic, bool recv, uin
{
pthread_mutex_lock(&st->mutex);
-#define ps(counter) ((counter) * 1000 / (st->duration / 1000))
+#define ps(counter) ((typeof(counter))((counter) * 1000 / ((float)st->duration / 1000)))
#define pct(counter) ((counter) * 100.0 / st->qry_sent)
const char *name = tcp ? "SYNs: " : quic ? "initials:" : "queries: ";
- printf("total %s %"PRIu64" (%"PRIu64" pps) (%f%%)\n", name,
- st->qry_sent, ps(st->qry_sent), 100.0 * st->qry_sent / (st->duration / 1000000.0 * qps));
+ printf("total %s %"PRIu64" (%"PRIu64" pps) (%f%%)\n", name, st->qry_sent,
+ ps(st->qry_sent), 100.0 * st->qry_sent / (st->duration / 1000000.0 * qps));
if (st->qry_sent > 0 && recv) {
if (tcp || quic) {
name = tcp ? "established:" : "handshakes: ";
@@ -534,8 +535,8 @@ void *xdp_gun_thread(void *_ctx)
}
if (ctx->thread_id == 0) {
- INFO2("using interface %s, XDP threads %u, %s%s%s, %s mode",
- ctx->dev, ctx->n_threads,
+ INFO2("using interface %s, XDP threads %u, IPv%c/%s%s%s, %s mode",
+ ctx->dev, ctx->n_threads, (ctx->ipv6 ? '6' : '4'),
(ctx->tcp ? "TCP" : ctx->quic ? "QUIC" : "UDP"),
(ctx->sending_mode[0] != '\0' ? " mode " : ""),
(ctx->sending_mode[0] != '\0' ? ctx->sending_mode : ""),
@@ -989,6 +990,41 @@ static int mac_sscan(const char *src, uint8_t *dst)
return KNOT_EOK;
}
+static bool resolve_name(char *target_str, xdp_gun_ctx_t *ctx)
+{
+ struct addrinfo *res = NULL, hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = 0, // any socket type
+ .ai_protocol = 0, // any protocol
+ };
+
+ int err = 0;
+ if ((err = getaddrinfo(target_str, NULL, &hints, &res)) != 0) {
+ ERR2("failed to resolve '%s' (%s)", target_str, gai_strerror(err));
+ goto cleanup;
+ }
+
+ for (struct addrinfo *i = res; i != NULL; i = i->ai_next) {
+ switch (i->ai_family) {
+ case AF_INET:
+ case AF_INET6:
+ ctx->ipv6 = (i->ai_family == AF_INET6);
+ assert(sizeof(ctx->target_ip_ss) >= i->ai_addrlen);
+ memcpy(&ctx->target_ip_ss, i->ai_addr, i->ai_addrlen);
+ goto cleanup;
+ default:
+ break;
+ };
+ }
+ err = 1;
+
+cleanup:
+ if (res != NULL) {
+ freeaddrinfo(res);
+ }
+ return (err == 0);
+}
+
static bool configure_target(char *target_str, char *local_ip, xdp_gun_ctx_t *ctx)
{
int val;
@@ -998,16 +1034,8 @@ static bool configure_target(char *target_str, char *local_ip, xdp_gun_ctx_t *ct
*at = '\0';
}
- ctx->ipv6 = false;
- if (inet_pton(AF_INET, target_str, &ctx->target_ip4.sin_addr) <= 0) {
- ctx->ipv6 = true;
- ctx->target_ip.sin6_family = AF_INET6;
- if (inet_pton(AF_INET6, target_str, &ctx->target_ip.sin6_addr) <= 0) {
- ERR2("invalid target IP");
- return false;
- }
- } else {
- ctx->target_ip.sin6_family = AF_INET;
+ if (!resolve_name(target_str, ctx)) {
+ return false;
}
struct sockaddr_storage via = { 0 };