Fix issues with IP range drop map.

This commit is contained in:
Christian Deacon
2025-03-13 08:08:22 -04:00
parent 5a6fff2ba6
commit e9e9027fe7
6 changed files with 15 additions and 16 deletions

View File

@@ -10,13 +10,13 @@
#include <common/all.h>
#include <xdp/utils/maps.h>
#include <xdp/utils/rl.h>
#include <xdp/utils/logging.h>
#include <xdp/utils/stats.h>
#include <xdp/utils/helpers.h>
#include <xdp/utils/maps.h>
struct
{
__uint(priority, 10);

View File

@@ -1,7 +1,5 @@
#include <xdp/utils/helpers.h>
#include <xdp/utils/maps.h>
/**
* Checks if an IP is within a specific CIDR range.
*
@@ -26,11 +24,9 @@ static __always_inline int is_ip_in_range(u32 src_ip, u32 net_ip, u8 cidr)
*/
static __always_inline int check_ip_range_drop(u32 ip)
{
LpmTrieKey key =
{
.prefix_len = 32,
.data = ip
};
lpm_trie_key_t key = {0};
key.prefix_len = 32;
key.data = ip;
u64 *lookup = bpf_map_lookup_elem(&map_range_drop, &key);

View File

@@ -13,6 +13,8 @@
#include <bpf/bpf_helpers.h>
#endif
#include <xdp/utils/maps.h>
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

View File

@@ -30,11 +30,12 @@ struct
} map_block6 SEC(".maps");
#ifdef ENABLE_IP_RANGE_DROP
struct {
struct
{
__uint(type, BPF_MAP_TYPE_LPM_TRIE);
__uint(max_entries, MAX_IP_RANGES);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, LpmTrieKey);
__type(key, lpm_trie_key_t);
__type(value, u64);
} map_range_drop SEC(".maps");
#endif