selftests/bpf: Implement set_hw_ring_size function to configure interface ring size

Introduce a new function called set_hw_ring_size that allows for the
dynamic configuration of the ring size within the interface.

Signed-off-by: Tushar Vyavahare <tushar.vyavahare@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20240402114529.545475-5-tushar.vyavahare@intel.com
This commit is contained in:
Tushar Vyavahare 2024-04-02 11:45:26 +00:00 committed by Daniel Borkmann
parent 90a695c3d3
commit bee3a7b076
2 changed files with 25 additions and 0 deletions

View File

@ -521,3 +521,27 @@ int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
close(sockfd);
return 0;
}
int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
{
struct ifreq ifr = {0};
int sockfd, err;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
return -errno;
memcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
ring_param->cmd = ETHTOOL_SRINGPARAM;
ifr.ifr_data = (char *)ring_param;
if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) {
err = errno;
close(sockfd);
return -err;
}
close(sockfd);
return 0;
}

View File

@ -65,6 +65,7 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,
char *ping_command(int family);
int get_socket_local_port(int sock_fd);
int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
struct nstoken;
/**