pping: Inital rate limit implementation

Add a per-flow rate limit, limiting how often new timestamp entries
can be created. As part of this, add per-flow state keeping track
of when last timestamp was created and last seen identifier for each
flow.

Additionally, remove timestamp entry as soon as RTT is
calculated, as last seen identifier is used to find first unique value
instead. Furthermore, remove packet_timestamp struct and only use
__u64 as timestamp, as used memeber is no longer needed.

This initial commit lacks cleanup of flow-state, user-configuration of
rate limit, mechanism to handle bursts etc.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
Simon Sundberg
2021-03-01 18:16:48 +01:00
parent 6e5136092d
commit cecd6b54f2
4 changed files with 102 additions and 31 deletions

View File

@@ -188,7 +188,7 @@ static int clean_map(int map_fd, __u64 max_age)
{
int removed = 0;
struct packet_id key, prev_key = { 0 };
struct packet_timestamp value;
__u64 value;
bool delete_prev = false;
__u64 now_nsec = get_time_ns();
@@ -207,8 +207,8 @@ static int clean_map(int map_fd, __u64 max_age)
}
if (bpf_map_lookup_elem(map_fd, &key, &value) == 0) {
if (now_nsec > value.timestamp &&
now_nsec - value.timestamp > max_age) {
if (now_nsec > value &&
now_nsec - value > max_age) {
delete_prev = true;
}
}