--- a/userland/configure
+++ b/userland/configure
-@@ -3875,12 +3875,6 @@ $as_echo "no" >&6; }
+@@ -3868,12 +3868,6 @@ $as_echo "no" >&6; }
if test "$IS_FREEBSD" != "1" && test "$cross_compiling" != "yes" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if r/w locks are supported" >&5
$as_echo_n "checking if r/w locks are supported... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
-@@ -3893,7 +3887,7 @@ else
+@@ -3886,7 +3880,7 @@ else
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
cat >>confdefs.h <<_ACEOF
-@@ -3907,7 +3901,6 @@ $as_echo "no" >&6; }
+@@ -3900,7 +3894,6 @@ $as_echo "no" >&6; }
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
--- /dev/null
+From 405caa1424358032574230ec5479e64834869298 Mon Sep 17 00:00:00 2001
+From: Alfredo Cardigliano <cardigliano@ntop.org>
+Date: Thu, 13 Apr 2023 13:03:28 +0200
+Subject: [PATCH] Implement probabilistic sampling
+
+---
+ kernel/linux/pf_ring.h | 4 +++-
+ kernel/pf_ring.c | 34 ++++++++++++++++++++++++----------
+ 2 files changed, 27 insertions(+), 11 deletions(-)
+
+--- a/kernel/linux/pf_ring.h
++++ b/kernel/linux/pf_ring.h
+@@ -1310,7 +1310,9 @@ struct pf_ring_socket {
+ u_char *ring_slots; /* Points to ring_memory+sizeof(FlowSlotInfo) */
+
+ /* Packet Sampling */
+- u_int32_t pktToSample, sample_rate;
++ u_int32_t sample_rate;
++ u_int32_t pkts_to_sample;
++ u_int32_t sample_rnd_shift;
+
+ /* Virtual Filtering Device */
+ virtual_filtering_device_element *v_filtering_dev;
+--- a/kernel/pf_ring.c
++++ b/kernel/pf_ring.c
+@@ -3695,6 +3695,26 @@ int bpf_filter_skb(struct sk_buff *skb,
+
+ /* ********************************** */
+
++int sample_packet(struct pf_ring_socket *pfr) {
++ if(pfr->pkts_to_sample <= 1) {
++ u_int32_t rnd = 0;
++
++ get_random_bytes(&rnd, sizeof(u_int32_t));
++ rnd = rnd % pfr->sample_rate;
++
++ pfr->pkts_to_sample = pfr->sample_rate - pfr->sample_rnd_shift + rnd;
++
++ pfr->sample_rnd_shift = rnd;
++
++ return 1; /* Pass packet */
++ } else {
++ pfr->pkts_to_sample--;
++ return 0; /* Discard packet */
++ }
++}
++
++/* ********************************** */
++
+ u_int32_t default_rehash_rss_func(struct sk_buff *skb, struct pfring_pkthdr *hdr)
+ {
+ return hash_pkt_header(hdr, 0);
+@@ -3805,12 +3825,9 @@ static int add_skb_to_ring(struct sk_buf
+ if(pfr->sample_rate > 1) {
+ spin_lock_bh(&pfr->ring_index_lock);
+
+- if(pfr->pktToSample <= 1) {
+- pfr->pktToSample = pfr->sample_rate;
+- } else {
++ if(!sample_packet(pfr)) {
++ /* Discard packet */
+ pfr->slots_info->tot_pkts++;
+- pfr->pktToSample--;
+-
+ spin_unlock_bh(&pfr->ring_index_lock);
+ atomic_dec(&pfr->num_ring_users);
+ return(-1);
+@@ -4161,11 +4178,8 @@ int pf_ring_skb_ring_handler(struct sk_b
+
+ if(pfr->sample_rate > 1) {
+ spin_lock_bh(&pfr->ring_index_lock);
+- if(pfr->pktToSample <= 1) {
+- pfr->pktToSample = pfr->sample_rate;
+- } else {
++ if (!sample_packet(pfr)) {
+ pfr->slots_info->tot_pkts++;
+- pfr->pktToSample--;
+ rc = 0;
+ }
+ spin_unlock_bh(&pfr->ring_index_lock);
+@@ -7957,7 +7971,7 @@ static int ring_getsockopt(struct socket
+ if(copy_to_user(optval, lowest_if_mac, ETH_ALEN))
+ return(-EFAULT);
+ } else {
+- char *dev_addr = pfr->ring_dev->dev->dev_addr;
++ const char *dev_addr = pfr->ring_dev->dev->dev_addr;
+
+ if (dev_addr == NULL) /* e.g. 'any' device */
+ dev_addr = empty_mac;
--- a/kernel/pf_ring.c
+++ b/kernel/pf_ring.c
-@@ -3940,7 +3940,7 @@ static int hash_pkt_cluster(ring_cluster_element *cluster_ptr,
+@@ -3902,7 +3902,7 @@ static int hash_pkt_cluster(ring_cluster
break;
}
/* else, fall through, because it's like 2-tuple for non-TCP packets */
case cluster_per_flow_2_tuple:
case cluster_per_inner_flow_2_tuple:
flags |= mask_2_tuple;
-@@ -5485,8 +5485,7 @@ static int ring_release(struct socket *sock)
- remove_cluster_referee(pfr);
-
- if((pfr->zc_device_entry != NULL)
-- && pfr->zc_device_entry->zc_dev.dev
-- && pfr->zc_device_entry->zc_dev.dev->name) {
-+ && pfr->zc_device_entry->zc_dev.dev) {
- pfring_release_zc_dev(pfr);
- }
-
-@@ -5617,8 +5616,6 @@ static int ring_bind(struct socket *sock, struct sockaddr *sa, int addr_len)
- return(-EINVAL);
- if(sa->sa_family != PF_RING)
- return(-EINVAL);
-- if(sa->sa_data == NULL)
-- return(-EINVAL);
-
- memcpy(name, sa->sa_data, sizeof(sa->sa_data));
-