Organize codeand potentially increase performance in XDP program.

This commit is contained in:
Christian Deacon
2025-02-23 07:15:37 -05:00
parent 4e7c563274
commit e5c11bb20c
4 changed files with 6 additions and 6 deletions

View File

@@ -246,7 +246,7 @@ int xdp_prog_main(struct xdp_md *ctx)
UpdateIpStats(&pps, &bps, iph->saddr, src_port, protocol, pkt_len, now); 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; u32 key = i;

View File

@@ -9,7 +9,7 @@
* *
* @return 1 on yes, 0 on no. * @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))); return !((src_ip ^ net_ip) & htonl(0xFFFFFFFFu << (32 - cidr)));
} }

View File

@@ -28,7 +28,7 @@
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) #define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n))
#endif #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. // 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 // More Info: https://stackoverflow.com/questions/24289599/always-inline-does-not-work-when-function-is-implemented-in-different-file