Skip to content
Snippets Groups Projects
Commit 0e301fc8 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

stats: add protocol counters for XDP

parent 8cbf116c
No related branches found
No related tags found
No related merge requests found
......@@ -380,6 +380,7 @@ typedef enum {
KNOTD_QUERY_FLAG_LIMIT_ANY = 1 << 2, /*!< Limit ANY QTYPE (respond with TC=1). */
KNOTD_QUERY_FLAG_LIMIT_SIZE = 1 << 3, /*!< Apply UDP size limit. */
KNOTD_QUERY_FLAG_COOKIE = 1 << 4, /*!< Valid DNS Cookie indication. */
KNOTD_QUERY_FLAG_XDP = 1 << 5, /*!< Processing over XDP indication. */
} knotd_query_flag_t;
/*! Query processing data context parameters. */
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2020 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
......@@ -119,17 +119,21 @@ enum {
PROTOCOL_TCP4,
PROTOCOL_UDP6,
PROTOCOL_TCP6,
PROTOCOL_UDP4_XDP,
PROTOCOL_UDP6_XDP,
PROTOCOL__COUNT
};
static char *protocol_to_str(uint32_t idx, uint32_t count)
{
switch (idx) {
case PROTOCOL_UDP4: return strdup("udp4");
case PROTOCOL_TCP4: return strdup("tcp4");
case PROTOCOL_UDP6: return strdup("udp6");
case PROTOCOL_TCP6: return strdup("tcp6");
default: assert(0); return NULL;
case PROTOCOL_UDP4: return strdup("udp4");
case PROTOCOL_TCP4: return strdup("tcp4");
case PROTOCOL_UDP6: return strdup("udp6");
case PROTOCOL_TCP6: return strdup("tcp6");
case PROTOCOL_UDP4_XDP: return strdup("udp4-xdp");
case PROTOCOL_UDP6_XDP: return strdup("udp6-xdp");
default: assert(0); return NULL;
}
}
......@@ -486,18 +490,29 @@ static knotd_state_t update_counters(knotd_state_t state, knot_pkt_t *pkt,
// Count the request protocol.
if (stats->protocol) {
bool xdp = qdata->params->flags & KNOTD_QUERY_FLAG_XDP;
if (qdata->params->remote->ss_family == AF_INET) {
if (qdata->params->flags & KNOTD_QUERY_FLAG_LIMIT_SIZE) {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_UDP4, 1);
if (xdp) {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_UDP4_XDP, 1);
} else {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_UDP4, 1);
}
} else {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_TCP4, 1);
}
} else {
if (qdata->params->flags & KNOTD_QUERY_FLAG_LIMIT_SIZE) {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_UDP6, 1);
if (xdp) {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_UDP6_XDP, 1);
} else {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_UDP6, 1);
}
} else {
knotd_mod_stats_incr(mod, CTR_PROTOCOL,
PROTOCOL_TCP6, 1);
......
......@@ -74,6 +74,8 @@ If enabled, all incoming requests are counted by the network protocol:
* tcp4 - TCP over IPv4
* udp6 - UDP over IPv6
* tcp6 - TCP over IPv6
* udp4-xdp - UDP over IPv4 through XDP
* udp6-xdp - UDP over IPv6 through XDP
*Default:* on
......
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2020 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
......@@ -62,14 +62,15 @@ static bool udp_state_active(int state)
}
static void udp_handle(udp_context_t *udp, int fd, struct sockaddr_storage *ss,
struct iovec *rx, struct iovec *tx)
struct iovec *rx, struct iovec *tx, bool use_xdp)
{
/* Create query processing parameter. */
knotd_qdata_params_t params = {
.remote = ss,
.flags = KNOTD_QUERY_FLAG_NO_AXFR | KNOTD_QUERY_FLAG_NO_IXFR | /* No transfers. */
KNOTD_QUERY_FLAG_LIMIT_SIZE | /* Enforce UDP packet size limit. */
KNOTD_QUERY_FLAG_LIMIT_ANY, /* Limit ANY over UDP (depends on zone as well). */
KNOTD_QUERY_FLAG_LIMIT_ANY | /* Limit ANY over UDP (depends on zone as well). */
(use_xdp ? KNOTD_QUERY_FLAG_XDP : 0), /* Mark XDP processing. */
.socket = fd,
.server = udp->server,
.thread_id = udp->thread_id
......@@ -215,7 +216,7 @@ static int udp_recvfrom_handle(udp_context_t *ctx, void *d, void *unused)
udp_pktinfo_handle(&rq->msg[RX], &rq->msg[TX]);
/* Process received pkt. */
udp_handle(ctx, rq->fd, &rq->addr, &rq->iov[RX], &rq->iov[TX]);
udp_handle(ctx, rq->fd, &rq->addr, &rq->iov[RX], &rq->iov[TX], false);
return KNOT_EOK;
}
......@@ -324,7 +325,7 @@ static int udp_recvmmsg_handle(udp_context_t *ctx, void *d, void *unused)
udp_pktinfo_handle(&rq->msgs[RX][i].msg_hdr, &rq->msgs[TX][i].msg_hdr);
udp_handle(ctx, rq->fd, rq->addrs + i, rx, tx);
udp_handle(ctx, rq->fd, rq->addrs + i, rx, tx, false);
rq->msgs[TX][i].msg_len = tx->iov_len;
rq->msgs[TX][i].msg_hdr.msg_namelen = 0;
if (tx->iov_len > 0) {
......@@ -410,7 +411,7 @@ static int xdp_recvmmsg_handle(udp_context_t *ctx, void *d, void *xdp_sock)
}
udp_handle(ctx, knot_xsk_get_poll_fd(xdp_sock), &rq->msgs_rx[i].ip_from,
&rq->msgs_rx[i].payload, &rq->msgs_tx[i].payload);
&rq->msgs_rx[i].payload, &rq->msgs_tx[i].payload, true);
knot_xsk_free_recvd(xdp_sock, &rq->msgs_rx[i]);
......
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2020 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
......@@ -77,7 +77,7 @@ static int udp_stdin_handle(udp_context_t *ctx, void *d, void *unused)
{
UNUSED(unused);
udp_stdin_t *rq = (udp_stdin_t *)d;
udp_handle(ctx, STDIN_FILENO, &rq->addr, &rq->iov[RX], &rq->iov[TX]);
udp_handle(ctx, STDIN_FILENO, &rq->addr, &rq->iov[RX], &rq->iov[TX], false);
return 0;
}
......
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