Rework stat incrementing in XDP program.
This commit is contained in:
29
src/xdp/utils/stats.c
Normal file
29
src/xdp/utils/stats.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <xdp/utils/stats.h>
|
||||
|
||||
static __always_inline int inc_pkt_stats(stats_t* stats, STATS_TYPE_T type)
|
||||
{
|
||||
if (!stats)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case STATS_TYPE_ALLOWED:
|
||||
stats->allowed++;
|
||||
|
||||
break;
|
||||
|
||||
case STATS_TYPE_PASSED:
|
||||
stats->passed++;
|
||||
|
||||
break;
|
||||
|
||||
case STATS_TYPE_DROPPED:
|
||||
stats->dropped++;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
22
src/xdp/utils/stats.h
Normal file
22
src/xdp/utils/stats.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/all.h>
|
||||
|
||||
#include <linux/bpf.h>
|
||||
|
||||
#include <xdp/xdp_helpers.h>
|
||||
#include <xdp/prog_dispatcher.h>
|
||||
|
||||
enum STATS_TYPE
|
||||
{
|
||||
STATS_TYPE_ALLOWED = 0,
|
||||
STATS_TYPE_PASSED,
|
||||
STATS_TYPE_DROPPED
|
||||
} typedef STATS_TYPE_T;
|
||||
|
||||
static __always_inline int inc_pkt_stats(stats_t* stats, STATS_TYPE_T type);
|
||||
|
||||
// The source file is included directly below instead of compiled and linked as an object because when linking, there is no guarantee the compiler will inline the function (which is crucial for performance).
|
||||
// I'd prefer not to include the function logic inside of the header file.
|
||||
// More Info: https://stackoverflow.com/questions/24289599/always-inline-does-not-work-when-function-is-implemented-in-different-file
|
||||
#include "stats.c"
|
||||
Reference in New Issue
Block a user