Skip to content
Snippets Groups Projects
Commit 3c67592f authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman
Browse files

modules: enable measuring RTT for xdp-tcp

parent 36d5f841
No related branches found
No related tags found
1 merge request!1394xdp-tcp: evolution and bugfixes
/* Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -404,6 +404,7 @@ typedef struct {
unsigned thread_id; /*!< Current thread id. */
void *server; /*!< Server object private item. */
const struct knot_xdp_msg *xdp_msg; /*!< Possible XDP message context. */
const struct knot_tcp_conn *xdp_conn; /*!< Possible XDP TCP connection context. */
} knotd_qdata_params_t;
/*! Query processing data context. */
......@@ -446,6 +447,15 @@ const struct sockaddr_storage *knotd_qdata_local_addr(knotd_qdata_t *qdata,
*/
const struct sockaddr_storage *knotd_qdata_remote_addr(knotd_qdata_t *qdata);
/*!
* Gets the measured TCP round-trip-time.
*
* \param[in] qdata Query data.
*
* \return RTT in microseconds or 0 if error or not available.
*/
uint32_t knotd_qdata_rtt(knotd_qdata_t *qdata);
/*!
* Gets the current zone name.
*
......
/* Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -97,9 +97,7 @@ static knotd_state_t export(knotd_state_t state, knot_pkt_t *pkt,
knot_probe_data_t d;
int ret = knot_probe_data_set(&d, proto, local, remote, qdata->query, reply, rcode);
if (ret == KNOT_EOK) {
if (tcp && qdata->params->xdp_msg == NULL) {
d.tcp_rtt = knot_probe_tcp_rtt(qdata->params->socket);
}
d.tcp_rtt = knotd_qdata_rtt(qdata);
if (qdata->query->opt_rr != NULL) {
d.reply.ede = qdata->rcode_ede;
}
......
/* Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -22,6 +22,7 @@
#include "contrib/sockaddr.h"
#include "libknot/attribute.h"
#include "libknot/probe/data.h"
#include "libknot/xdp.h"
#include "knot/common/log.h"
#include "knot/conf/module.h"
......@@ -661,6 +662,26 @@ const struct sockaddr_storage *knotd_qdata_remote_addr(knotd_qdata_t *qdata)
}
}
_public_
uint32_t knotd_qdata_rtt(knotd_qdata_t *qdata)
{
if (qdata == NULL ||
(qdata->params->flags & KNOTD_QUERY_FLAG_LIMIT_SIZE)) { // not TCP
return 0;
}
if (qdata->params->xdp_msg != NULL) {
#ifdef ENABLE_XDP
return qdata->params->xdp_conn->establish_rtt;
#else
assert(0);
return 0;
#endif
} else {
return knot_probe_tcp_rtt(qdata->params->socket);
}
}
_public_
const knot_dname_t *knotd_qdata_zone_name(knotd_qdata_t *qdata)
{
......
......@@ -201,6 +201,7 @@ static void handle_tcp(xdp_handle_ctx_t *ctx, knot_layer_t *layer,
for (size_t j = 0; j < rl->inbufs_count; j++) {
// Consume the query.
handle_init(params, layer, rl->msg, &rl->inbufs[j]);
params->xdp_conn = rl->conn;
// Process the reply.
knot_pkt_t *ans = knot_pkt_new(ans_buf, sizeof(ans_buf), layer->mm);
......
......@@ -233,7 +233,12 @@ int knot_tcp_recv(knot_tcp_relay_t *relays, knot_xdp_msg_t *msgs, uint32_t count
memcpy(conn->last_eth_loc, msg->eth_to, sizeof(conn->last_eth_loc));
conn->window_size = (uint32_t)msg->win * (1LU << conn->window_scale);
conn->last_active = get_timestamp();
uint32_t now = get_timestamp();
if (conn->establish_rtt == 0 && conn->last_active != 0) {
conn->establish_rtt = now - conn->last_active;
}
conn->last_active = now;
rem_node(tcp_conn_node(conn));
add_tail(tcp_table_timeout(tcp_table), tcp_conn_node(conn));
......@@ -304,6 +309,7 @@ int knot_tcp_recv(knot_tcp_relay_t *relays, knot_xdp_msg_t *msgs, uint32_t count
break;
case XDP_TCP_ESTABLISHING:
conn->state = XDP_TCP_NORMAL;
relay->action = XDP_TCP_ESTABLISH;
break;
case XDP_TCP_CLOSING2:
tcp_table_del(pconn, tcp_table);
......
......@@ -71,6 +71,7 @@ typedef struct knot_tcp_conn {
uint32_t acked;
uint32_t window_size;
uint32_t last_active;
uint32_t establish_rtt;
knot_tcp_state_t state;
struct iovec inbuf;
tcp_outbufs_t outbufs;
......
......@@ -440,6 +440,8 @@ void test_ibufs_size(void)
for (int i = 0; i < CONNS; i++) {
msgs[i].flags = KNOT_XDP_MSG_TCP | KNOT_XDP_MSG_ACK;
}
fix_seqacks(msgs, CONNS);
(void)knot_tcp_recv(rls, msgs, CONNS, test_table, NULL);
is_int(0, test_table->inbufs_total, "inbufs: initial total zero");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment