Skip to content
Snippets Groups Projects
Commit 353049c2 authored by Jan Hák's avatar Jan Hák Committed by Daniel Salzman
Browse files

libknot: add MTU getter

parent a87fcc16
No related branches found
No related tags found
1 merge request!1261UDP payload testing
/* Copyright (C) 2020 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2021 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
......@@ -69,6 +69,36 @@ int knot_eth_queues(const char *devname)
return ret;
}
_public_
int knot_eth_mtu(const char *devname)
{
if (devname == NULL) {
return KNOT_EINVAL;
}
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
return knot_map_errno();
}
struct ifreq ifr = { 0 };
strlcpy(ifr.ifr_name, devname, IFNAMSIZ);
int ret = ioctl(fd, SIOCGIFMTU, &ifr);
if (ret != 0) {
if (errno == EOPNOTSUPP) {
ret = KNOT_ENOTSUP;
} else {
ret = knot_map_errno();
}
} else {
ret = ifr.ifr_mtu;
}
close(fd);
return ret;
}
_public_
int knot_eth_name_from_addr(const struct sockaddr_storage *addr, char *out,
size_t out_len)
......
/* Copyright (C) 2020 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2021 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
......@@ -18,6 +18,8 @@
#include <stddef.h>
#define KNOT_XDP_MAX_MTU 1792
/*!
* \brief Get number of combined queues of a network interface.
*
......@@ -29,6 +31,16 @@
*/
int knot_eth_queues(const char *devname);
/*!
* \brief Get value of MTU setup on a network interface.
*
* \param devname Name of the ethdev (e.g. eth1).
*
* \retval < 0 KNOT_E* if error.
* \return >= 0 Interface MTU.
*/
int knot_eth_mtu(const char *devname);
/*!
* \brief Get the corresponding network interface name for the address.
*
......
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