From: Remi Gacogne Date: Tue, 4 Feb 2025 15:46:39 +0000 (+0100) Subject: dnsdist: Make hard-coded values configurable in xdp.py X-Git-Tag: dnsdist-2.0.0-alpha1~124^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=030cb125e3dfaedd1277ff913b6d825232071693;p=thirdparty%2Fpdns.git dnsdist: Make hard-coded values configurable in xdp.py - Maximum size of eBPF maps - Number of network queues in XSK mode --- diff --git a/contrib/xdp-filter.ebpf.src b/contrib/xdp-filter.ebpf.src index ec0d07145d..f25ba2c08e 100644 --- a/contrib/xdp-filter.ebpf.src +++ b/contrib/xdp-filter.ebpf.src @@ -2,9 +2,17 @@ #define DISABLE_LOGGING 1 -BPF_TABLE_PINNED("hash", uint32_t, struct map_value, v4filter, 1024, "/sys/fs/bpf/dnsdist/addr-v4"); -BPF_TABLE_PINNED("hash", struct in6_addr, struct map_value, v6filter, 1024, "/sys/fs/bpf/dnsdist/addr-v6"); -BPF_TABLE_PINNED("hash", struct dns_qname, struct map_value, qnamefilter, 1024, "/sys/fs/bpf/dnsdist/qnames"); +#if !defined(DDIST_MAPS_SIZE) +#define DDIST_MAPS_SIZE 1024 +#endif /* DDIST_MAPS_SIZE */ + +#if !defined(DDIST_MAX_NUMBER_OF_QUEUES) +#define DDIST_MAX_NUMBER_OF_QUEUES 64 +#endif /* DDIST_MAX_NUMBER_OF_QUEUES */ + +BPF_TABLE_PINNED("hash", uint32_t, struct map_value, v4filter, DDIST_MAPS_SIZE, "/sys/fs/bpf/dnsdist/addr-v4"); +BPF_TABLE_PINNED("hash", struct in6_addr, struct map_value, v6filter, DDIST_MAPS_SIZE, "/sys/fs/bpf/dnsdist/addr-v6"); +BPF_TABLE_PINNED("hash", struct dns_qname, struct map_value, qnamefilter, DDIST_MAPS_SIZE, "/sys/fs/bpf/dnsdist/qnames"); #ifndef DISABLE_LOGGING BPF_TABLE_PINNED("prog", int, int, progsarray, 2, "/sys/fs/bpf/dnsdist/progs"); #endif /* DISABLE_LOGGING */ @@ -18,8 +26,8 @@ BPF_TABLE_PINNED("prog", int, int, progsarray, 2, "/sys/fs/bpf/dnsdist/progs"); BPF_F_TABLE(_table_type ":" _pinned, _key_type, _leaf_type, _name, _max_entries, _flags) #endif -BPF_TABLE_PINNED7("lpm_trie", struct CIDR4, struct map_value, cidr4filter, 1024, "/sys/fs/bpf/dnsdist/cidr4", BPF_F_NO_PREALLOC); -BPF_TABLE_PINNED7("lpm_trie", struct CIDR6, struct map_value, cidr6filter, 1024, "/sys/fs/bpf/dnsdist/cidr6", BPF_F_NO_PREALLOC); +BPF_TABLE_PINNED7("lpm_trie", struct CIDR4, struct map_value, cidr4filter, DDIST_MAPS_SIZE, "/sys/fs/bpf/dnsdist/cidr4", BPF_F_NO_PREALLOC); +BPF_TABLE_PINNED7("lpm_trie", struct CIDR6, struct map_value, cidr6filter, DDIST_MAPS_SIZE, "/sys/fs/bpf/dnsdist/cidr6", BPF_F_NO_PREALLOC); #ifdef UseXsk #define BPF_XSKMAP_PIN(_name, _max_entries, _pinned) \ @@ -34,9 +42,9 @@ BPF_TABLE_PINNED7("lpm_trie", struct CIDR6, struct map_value, cidr6filter, 1024, }; \ __attribute__((section("maps/xskmap:" _pinned))) struct _name##_table_t _name = {.max_entries = (_max_entries)} -BPF_XSKMAP_PIN(xsk_map, 16, "/sys/fs/bpf/dnsdist/xskmap"); -BPF_TABLE_PINNED("hash", struct IPv4AndPort, bool, xskDestinationsV4, 1024, "/sys/fs/bpf/dnsdist/xsk-destinations-v4"); -BPF_TABLE_PINNED("hash", struct IPv6AndPort, bool, xskDestinationsV6, 1024, "/sys/fs/bpf/dnsdist/xsk-destinations-v6"); +BPF_XSKMAP_PIN(xsk_map, DDIST_MAX_NUMBER_OF_QUEUES, "/sys/fs/bpf/dnsdist/xskmap"); +BPF_TABLE_PINNED("hash", struct IPv4AndPort, bool, xskDestinationsV4, DDIST_MAPS_SIZE, "/sys/fs/bpf/dnsdist/xsk-destinations-v4"); +BPF_TABLE_PINNED("hash", struct IPv6AndPort, bool, xskDestinationsV6, DDIST_MAPS_SIZE, "/sys/fs/bpf/dnsdist/xsk-destinations-v6"); #endif /* UseXsk */ #define COMPARE_PORT(x, p) ((x) == bpf_htons(p)) diff --git a/contrib/xdp.py b/contrib/xdp.py index 46725e8fd6..9ad0124931 100644 --- a/contrib/xdp.py +++ b/contrib/xdp.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 import argparse import ctypes as ct -import netaddr import socket +import netaddr from bcc import BPF # Constants @@ -26,14 +26,17 @@ blocked_qnames = [("localhost", "A", DROP_ACTION), ("test.com", "*", TC_ACTION)] # Main parser = argparse.ArgumentParser(description='XDP helper for DNSDist') -parser.add_argument('--xsk', action='store_true', help='Enable XSK (AF_XDP) mode', default=False) parser.add_argument('--interface', '-i', type=str, default='eth0', help='The interface on which the filter will be attached') +parser.add_argument('--maps-size', '-m', type=int, default=1024, help='Maximum number of entries in the eBPF maps') +parser.add_argument('--number-of-queues', '-q', type=int, default=64, help='Maximum number of network queues in XSK (AF_XDP) mode') +parser.add_argument('--xsk', action='store_true', help='Enable XSK (AF_XDP) mode', default=False) parameters = parser.parse_args() -cflag = [] +cflag = [f'-DDDIST_MAX_NUMBER_OF_QUEUES={parameters.number_of_queues}', + f'-DDDIST_MAPS_SIZE={parameters.maps_size}'] if parameters.xsk: print(f'Enabling XSK (AF_XDP) on {parameters.interface}..') - cflag.append("-DUseXsk") + cflag.append('-DUseXsk') else: Ports = [53] portsStr = ', '.join(str(port) for port in Ports) @@ -51,6 +54,7 @@ v6filter = xdp.get_table("v6filter") cidr4filter = xdp.get_table("cidr4filter") cidr6filter = xdp.get_table("cidr6filter") qnamefilter = xdp.get_table("qnamefilter") +xskDestinations = None if parameters.xsk: xskDestinations = xdp.get_table("xskDestinationsV4")