include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=libpfring
-PKG_VERSION:=8.4.0
-PKG_RELEASE:=2
+PKG_VERSION:=8.6.1
+PKG_RELEASE:=1
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://codeload.github.com/ntop/PF_RING/tar.gz/$(PKG_VERSION)?
-PKG_HASH:=2756a45ab250da11850160beb62aa879075aedfb49bf8f323b404f02b0c36670
-PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/PF_RING-$(PKG_VERSION)
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_VERSION:=$(PKG_VERSION)
+PKG_SOURCE_URL:=https://github.com/ntop/PF_RING
+PKG_MIRROR_HASH:=2c4623e4a3cd601a94cfdaf748e0cd7aa93e8ec850d3cd4c2ec5d33419e45fbb
PKG_MAINTAINER:=Banglang Huang <banglang.huang@foxmail.com>
--- a/userland/configure
+++ b/userland/configure
-@@ -3868,12 +3868,6 @@ $as_echo "no" >&6; }
+@@ -3873,12 +3873,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. */
-@@ -3886,7 +3880,7 @@ else
+@@ -3891,7 +3885,7 @@ else
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
cat >>confdefs.h <<_ACEOF
-@@ -3900,7 +3894,6 @@ $as_echo "no" >&6; }
+@@ -3905,7 +3899,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;
--- /dev/null
+--- a/kernel/pf_ring.c
++++ b/kernel/pf_ring.c
+@@ -4713,8 +4713,8 @@ void reserve_memory(unsigned long base,
+ {
+ struct page *page, *page_end;
+
+- page_end = virt_to_page(base + mem_len - 1);
+- for(page = virt_to_page(base); page <= page_end; page++)
++ page_end = virt_to_page((void*)base + mem_len - 1);
++ for(page = virt_to_page((void*)base); page <= page_end; page++)
+ SetPageReserved(page);
+ }
+
+@@ -4722,8 +4722,8 @@ void unreserve_memory(unsigned long base
+ {
+ struct page *page, *page_end;
+
+- page_end = virt_to_page(base + mem_len - 1);
+- for(page = virt_to_page(base); page <= page_end; page++)
++ page_end = virt_to_page((void*)base + mem_len - 1);
++ for(page = virt_to_page((void*)base); page <= page_end; page++)
+ ClearPageReserved(page);
+ }
+
--- a/kernel/pf_ring.c
+++ b/kernel/pf_ring.c
-@@ -3902,7 +3902,7 @@ static int hash_pkt_cluster(ring_cluster
+@@ -3903,7 +3903,7 @@ static int hash_pkt_cluster(ring_cluster
break;
}
/* else, fall through, because it's like 2-tuple for non-TCP packets */
-From fae2437c2af80d3ea64f5bc9678a5b697772295b Mon Sep 17 00:00:00 2001
+From 1b7780e9ecb46c6a5bbc8a831778a683f8ae80d8 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Mon, 18 Mar 2024 10:03:43 +0100
Subject: [PATCH] kernel: pf_ring: better define sa_data size
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
- kernel/pf_ring.c | 22 ++++++++++++++++++----
- 1 file changed, 18 insertions(+), 4 deletions(-)
+ kernel/pf_ring.c | 20 ++++++++++++++++----
+ 1 file changed, 16 insertions(+), 4 deletions(-)
--- a/kernel/pf_ring.c
+++ b/kernel/pf_ring.c
-@@ -155,6 +155,18 @@
+@@ -158,6 +158,18 @@
#endif
#endif
/* ************************************************* */
#if(LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
-@@ -1029,7 +1041,7 @@ pf_ring_device *pf_ring_device_name_look
- so the total interface name length is 13 chars (plus \0 trailer).
- The check below is to trap this case.
- */
-- || ((l >= 13) && (strncmp(dev_ptr->device_name, name, 13) == 0)))
-+ || ((l >= RING_SA_DATA_LEN - 1) && (strncmp(dev_ptr->device_name, name, RING_SA_DATA_LEN - 1) == 0)))
+@@ -1032,7 +1044,7 @@ pf_ring_device *pf_ring_device_name_look
+ so the total interface name length is 13 chars (plus \0 trailer).
+ The check below is to trap this case.
+ */
+- || ((l >= 13) && (strncmp(dev_ptr->device_name, name, 13) == 0)))
++ || ((l >= RING_SA_DATA_LEN - 1) && (strncmp(dev_ptr->device_name, name, RING_SA_DATA_LEN - 1) == 0)))
&& device_net_eq(dev_ptr, net))
return dev_ptr;
}
-@@ -5571,15 +5583,15 @@ static int ring_bind(struct socket *sock
- * Check legality
- */
- if (addr_len == sizeof(struct sockaddr)) {
+@@ -5605,15 +5617,15 @@ static int ring_bind(struct socket *sock
+ #ifndef RING_USE_SOCKADDR_LL
+ } else if (addr_len == sizeof(struct sockaddr)) { /* Deprecated */
+
- char name[sizeof(sa->sa_data)+1];
+ char name[RING_SA_DATA_LEN];
--- /dev/null
+From 5557b6ffe8d4eeb93532d043649b40eb10120bf7 Mon Sep 17 00:00:00 2001
+From: Gavin <gavin.bravery@jagsiacs.co.uk>
+Date: Wed, 25 Oct 2023 11:40:50 +0100
+Subject: [PATCH] Update pf_ring.c
+
+Change to remove .sendpage assignment, as that attribute seems to have gone away in 6.5.3 kernel.
+---
+ kernel/pf_ring.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+--- a/kernel/pf_ring.c
++++ b/kernel/pf_ring.c
+@@ -8470,7 +8470,9 @@ static struct proto_ops ring_ops = {
+ .getname = sock_no_getname,
+ .listen = sock_no_listen,
+ .shutdown = sock_no_shutdown,
++ #if(LINUX_VERSION_CODE < KERNEL_VERSION(6,5,3))
+ .sendpage = sock_no_sendpage,
++ #endif
+
+ /* Now the operations that really occur. */
+ .release = ring_release,