Skip to content
Snippets Groups Projects
Unverified Commit 2e30e79a authored by Joel Takvorian's avatar Joel Takvorian Committed by GitHub
Browse files

NETOBSERV-2186: set sampling field even without filters for consistency (#691)

* NETOBSERV-2186: set sampling field even without filters for consistency

* Simplify sampling logic

* reformat

* regen .o
parent 5a3a4f8d
No related branches found
No related tags found
No related merge requests found
...@@ -125,6 +125,7 @@ static inline void update_dns(additional_metrics *extra_metrics, pkt_info *pkt, ...@@ -125,6 +125,7 @@ static inline void update_dns(additional_metrics *extra_metrics, pkt_info *pkt,
} }
static inline int flow_monitor(struct __sk_buff *skb, u8 direction) { static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
u32 flow_sampling = 0;
if (!has_filter_sampling) { if (!has_filter_sampling) {
// When no filter sampling is defined, run the sampling check at the earliest for better performances // When no filter sampling is defined, run the sampling check at the earliest for better performances
// If sampling is defined, will only parse 1 out of "sampling" flows // If sampling is defined, will only parse 1 out of "sampling" flows
...@@ -132,6 +133,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) { ...@@ -132,6 +133,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
do_sampling = 0; do_sampling = 0;
return TC_ACT_OK; return TC_ACT_OK;
} }
flow_sampling = sampling;
do_sampling = 1; do_sampling = 1;
} }
...@@ -155,15 +157,14 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) { ...@@ -155,15 +157,14 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
} }
// check if this packet need to be filtered if filtering feature is enabled // check if this packet need to be filtered if filtering feature is enabled
u32 filter_sampling = 0;
bool skip = bool skip =
check_and_do_flow_filtering(&id, pkt.flags, 0, eth_protocol, &filter_sampling, direction); check_and_do_flow_filtering(&id, pkt.flags, 0, eth_protocol, &flow_sampling, direction);
if (has_filter_sampling) { if (has_filter_sampling) {
if (filter_sampling == 0) { if (flow_sampling == 0) {
filter_sampling = sampling; flow_sampling = sampling;
} }
// If sampling is defined, will only parse 1 out of "sampling" flows // If sampling is defined, will only parse 1 out of "sampling" flows
if (filter_sampling > 1 && (bpf_get_prandom_u32() % filter_sampling) != 0) { if (flow_sampling > 1 && (bpf_get_prandom_u32() % flow_sampling) != 0) {
do_sampling = 0; do_sampling = 0;
return TC_ACT_OK; return TC_ACT_OK;
} }
...@@ -179,7 +180,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) { ...@@ -179,7 +180,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
} }
flow_metrics *aggregate_flow = (flow_metrics *)bpf_map_lookup_elem(&aggregated_flows, &id); flow_metrics *aggregate_flow = (flow_metrics *)bpf_map_lookup_elem(&aggregated_flows, &id);
if (aggregate_flow != NULL) { if (aggregate_flow != NULL) {
update_existing_flow(aggregate_flow, &pkt, len, filter_sampling, skb->ifindex, direction); update_existing_flow(aggregate_flow, &pkt, len, flow_sampling, skb->ifindex, direction);
} else { } else {
// Key does not exist in the map, and will need to create a new entry. // Key does not exist in the map, and will need to create a new entry.
flow_metrics new_flow; flow_metrics new_flow;
...@@ -193,7 +194,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) { ...@@ -193,7 +194,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
new_flow.end_mono_time_ts = pkt.current_ts; new_flow.end_mono_time_ts = pkt.current_ts;
new_flow.flags = pkt.flags; new_flow.flags = pkt.flags;
new_flow.dscp = pkt.dscp; new_flow.dscp = pkt.dscp;
new_flow.sampling = filter_sampling; new_flow.sampling = flow_sampling;
__builtin_memcpy(new_flow.dst_mac, eth->h_dest, ETH_ALEN); __builtin_memcpy(new_flow.dst_mac, eth->h_dest, ETH_ALEN);
__builtin_memcpy(new_flow.src_mac, eth->h_source, ETH_ALEN); __builtin_memcpy(new_flow.src_mac, eth->h_source, ETH_ALEN);
...@@ -206,7 +207,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) { ...@@ -206,7 +207,7 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
flow_metrics *aggregate_flow = flow_metrics *aggregate_flow =
(flow_metrics *)bpf_map_lookup_elem(&aggregated_flows, &id); (flow_metrics *)bpf_map_lookup_elem(&aggregated_flows, &id);
if (aggregate_flow != NULL) { if (aggregate_flow != NULL) {
update_existing_flow(aggregate_flow, &pkt, len, filter_sampling, skb->ifindex, update_existing_flow(aggregate_flow, &pkt, len, flow_sampling, skb->ifindex,
direction); direction);
} else { } else {
if (trace_messages) { if (trace_messages) {
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment