From e5c11bb20c65c77c05245f5e3e623e4f5b1cc5b3 Mon Sep 17 00:00:00 2001 From: Christian Deacon Date: Sun, 23 Feb 2025 07:15:37 -0500 Subject: [PATCH] Organize codeand potentially increase performance in XDP program. --- src/xdp/prog.c | 2 +- src/xdp/utils/helpers.c | 4 ++-- src/xdp/utils/helpers.h | 2 +- src/xdp/utils/rl.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/xdp/prog.c b/src/xdp/prog.c index 9f63816..4542a82 100644 --- a/src/xdp/prog.c +++ b/src/xdp/prog.c @@ -246,7 +246,7 @@ int xdp_prog_main(struct xdp_md *ctx) UpdateIpStats(&pps, &bps, iph->saddr, src_port, protocol, pkt_len, now); } - for (u8 i = 0; i < MAX_FILTERS; i++) + for (int i = 0; i < MAX_FILTERS; i++) { u32 key = i; diff --git a/src/xdp/utils/helpers.c b/src/xdp/utils/helpers.c index 5d5da17..5b10d10 100644 --- a/src/xdp/utils/helpers.c +++ b/src/xdp/utils/helpers.c @@ -8,8 +8,8 @@ * @param cidr The CIDR range. * * @return 1 on yes, 0 on no. -*/ -static __always_inline u8 IsIpInRange(u32 src_ip, u32 net_ip, u8 cidr) + */ +static __always_inline int IsIpInRange(u32 src_ip, u32 net_ip, u8 cidr) { return !((src_ip ^ net_ip) & htonl(0xFFFFFFFFu << (32 - cidr))); } \ No newline at end of file diff --git a/src/xdp/utils/helpers.h b/src/xdp/utils/helpers.h index 82eaab6..9a457ac 100644 --- a/src/xdp/utils/helpers.h +++ b/src/xdp/utils/helpers.h @@ -28,7 +28,7 @@ #define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) #endif -static __always_inline u8 IsIpInRange(u32 src_ip, u32 net_ip, u8 cidr); +static __always_inline int IsIpInRange(u32 src_ip, u32 net_ip, u8 cidr); // NOTE: We include the C source file below because we can't link object files which includes the function logic into the main XDP program because we need to ensure the function is always inlined for performance which doesn't work with linked objects. // More Info: https://stackoverflow.com/questions/24289599/always-inline-does-not-work-when-function-is-implemented-in-different-file diff --git a/src/xdp/utils/rl.c b/src/xdp/utils/rl.c index 1df4587..fa6d777 100644 --- a/src/xdp/utils/rl.c +++ b/src/xdp/utils/rl.c @@ -12,7 +12,7 @@ * @param now The current time since boot in nanoseconds.alignas * * @return void -*/ + */ static __always_inline void UpdateIpStats(u64 *pps, u64 *bps, u32 ip, u16 port, u8 protocol, u16 pkt_len, u64 now) { #ifdef USE_FLOW_RL @@ -77,7 +77,7 @@ static __always_inline void UpdateIpStats(u64 *pps, u64 *bps, u32 ip, u16 port, * @param now The current time since boot in nanoseconds.alignas * * @return void -*/ + */ static __always_inline void UpdateIp6Stats(u64 *pps, u64 *bps, u128 *ip, u16 port, u8 protocol, u16 pkt_len, u64 now) { #ifdef USE_FLOW_RL