Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ union nf_inet_addr {
# define BEFORE2632(x,y)
# endif

# if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
# define ctl_table struct ctl_table
# if LINUX_VERSION_CODE >= KERNEL_VERSION(6,11,0)
# define s_ctl_table const struct ctl_table
# elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
# define s_ctl_table struct ctl_table
# else
# define s_ctl_table ctl_table
# endif

# ifndef HAVE_GRSECURITY_H
# define ctl_table_no_const ctl_table
# if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
# define ctl_table_no_const struct ctl_table
# else
# define ctl_table_no_const ctl_table
# endif
# endif
#endif

Expand Down Expand Up @@ -120,6 +128,10 @@ static inline u32 prandom_u32_max(u32 ep_ro)
return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0)
#define prandom_u32 get_random_u32
#define prandom_u32_max get_random_u32_below
#endif

#ifndef min_not_zero
# define min_not_zero(x, y) ({ \
Expand Down Expand Up @@ -799,4 +811,14 @@ static inline bool netif_is_bridge_port(const struct net_device *dev)
}
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,3,0)
#define strscpy strlcpy
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,15,0)
#define compat_del_timer_sync timer_delete_sync
#else
#define compat_del_timer_sync del_timer_sync
#endif

#endif /* COMPAT_NETFLOW_H */
9 changes: 7 additions & 2 deletions gen_compat_def
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ kbuild_test_symbol() {
echo -n "Test function $* " >&2
kbuild_test_compile ${1^^} $1 ${2-} <<-EOF
#include <linux/module.h>
${2:+#include <$2>}
${3:-${2:+#include <$2>}}
MODULE_LICENSE("GPL");
void *test = $1;
EOF
Expand Down Expand Up @@ -121,7 +121,12 @@ kbuild_test_symbol nf_bridge_info_get linux/netfilter_bridge.h
# Stumbled on 5.9
kbuild_test_struct vlan_dev_priv linux/if_vlan.h
# Kernel version check broken by centos8
kbuild_test_symbol put_unaligned_be24 asm/unaligned.h
kbuild_test_symbol put_unaligned_be24 '???/unaligned.h' '#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,12,0)
#include <linux/unaligned.h>
#else
#include <asm/unaligned.h>
#endif'
# totalram_pages changed from atomic to inline function.
kbuild_test_symbol totalram_pages linux/mm.h
kbuild_test_ref totalram_pages linux/mm.h
Expand Down
42 changes: 24 additions & 18 deletions ipt_NETFLOW.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
# include <net/netfilter/nf_conntrack_core.h>
#endif
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,12,0)
#include <linux/unaligned.h>
#else
#include <asm/unaligned.h>
#endif
#ifdef HAVE_LLIST
/* llist.h is officially defined since linux 3.1,
* but centos6 have it backported on its 2.6.32.el6 */
Expand Down Expand Up @@ -1519,7 +1523,7 @@ static int switch_promisc(int newpromisc)

#ifdef CONFIG_SYSCTL
/* sysctl /proc/sys/net/netflow */
static int hsize_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int hsize_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret, hsize;
Expand All @@ -1536,7 +1540,7 @@ static int hsize_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp
return ret;
}

static int sndbuf_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int sndbuf_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand Down Expand Up @@ -1571,7 +1575,7 @@ static int sndbuf_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *fil
}

static void free_templates(void);
static int destination_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int destination_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand All @@ -1588,7 +1592,7 @@ static int destination_procctl(ctl_table *ctl, int write, BEFORE2632(struct file
}

#ifdef ENABLE_AGGR
static int aggregation_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int aggregation_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand All @@ -1603,7 +1607,7 @@ static int aggregation_procctl(ctl_table *ctl, int write, BEFORE2632(struct file
#endif

#ifdef ENABLE_PROMISC
static int promisc_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int promisc_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int newpromisc = promisc;
Expand All @@ -1620,7 +1624,7 @@ static int promisc_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *fi

#ifdef ENABLE_SAMPLER
static int parse_sampler(char *ptr);
static int sampler_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int sampler_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand Down Expand Up @@ -1653,7 +1657,7 @@ static int sampler_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *fi

#ifdef SNMP_RULES
static int add_snmp_rules(char *ptr);
static int snmp_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int snmp_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand All @@ -1678,7 +1682,7 @@ static void clear_ipt_netflow_stat(void)
}
}

static int flush_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int flush_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand Down Expand Up @@ -1707,7 +1711,7 @@ static int flush_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp
return ret;
}

static int protocol_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int protocol_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand Down Expand Up @@ -1740,7 +1744,7 @@ static int protocol_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *f
#ifdef CONFIG_NF_NAT_NEEDED
static void register_ct_events(void);
static void unregister_ct_events(void);
static int natevents_procctl(ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
static int natevents_procctl(s_ctl_table *ctl, int write, BEFORE2632(struct file *filp,)
void __user *buffer, size_t *lenp, loff_t *fpos)
{
int ret;
Expand Down Expand Up @@ -1777,7 +1781,7 @@ static void ctl_table_renumber(ctl_table *table)
#define _CTL_NAME(x)
#define ctl_table_renumber(x)
#endif
static ctl_table netflow_sysctl_table[] = {
static ctl_table_no_const netflow_sysctl_table[] = {
{
.procname = "active_timeout",
.mode = 0644,
Expand Down Expand Up @@ -1905,7 +1909,9 @@ static ctl_table netflow_sysctl_table[] = {
.proc_handler = &natevents_procctl,
},
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,11,0)
{ }
#endif
};

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
Expand Down Expand Up @@ -4087,7 +4093,7 @@ static int ethtool_drvinfo(unsigned char *ptr, size_t size, struct net_device *d
ops->get_drvinfo(dev, &info);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
else if (dev->dev.parent && dev->dev.parent->driver) {
strlcpy(info.driver, dev->dev.parent->driver->name, sizeof(info.driver));
strscpy(info.driver, dev->dev.parent->driver->name, sizeof(info.driver));
}
#endif
n = scnprintf(ptr, len, "%s", info.driver);
Expand Down Expand Up @@ -5688,7 +5694,7 @@ static int __init ipt_netflow_init(void)
if (!destination)
destination = destination_buf;
if (destination != destination_buf) {
strlcpy(destination_buf, destination, sizeof(destination_buf));
strscpy(destination_buf, destination, sizeof(destination_buf));
destination = destination_buf;
}
if (add_destinations(destination) < 0)
Expand All @@ -5698,7 +5704,7 @@ static int __init ipt_netflow_init(void)
if (!aggregation)
aggregation = aggregation_buf;
if (aggregation != aggregation_buf) {
strlcpy(aggregation_buf, aggregation, sizeof(aggregation_buf));
strscpy(aggregation_buf, aggregation, sizeof(aggregation_buf));
aggregation = aggregation_buf;
}
add_aggregation(aggregation);
Expand All @@ -5708,7 +5714,7 @@ static int __init ipt_netflow_init(void)
if (!sampler)
sampler = sampler_buf;
if (sampler != sampler_buf) {
strlcpy(sampler_buf, sampler, sizeof(sampler_buf));
strscpy(sampler_buf, sampler, sizeof(sampler_buf));
sampler = sampler_buf;
}
parse_sampler(sampler);
Expand All @@ -5725,7 +5731,7 @@ static int __init ipt_netflow_init(void)
if (!snmp_rules)
snmp_rules = snmp_rules_buf;
if (snmp_rules != snmp_rules_buf) {
strlcpy(snmp_rules_buf, snmp_rules, sizeof(snmp_rules_buf));
strscpy(snmp_rules_buf, snmp_rules, sizeof(snmp_rules_buf));
snmp_rules = snmp_rules_buf;
}
add_snmp_rules(snmp_rules);
Expand Down Expand Up @@ -5760,7 +5766,7 @@ static int __init ipt_netflow_init(void)
err_stop_timer:
_unschedule_scan_worker();
netflow_scan_and_export(AND_FLUSH);
del_timer_sync(&rate_timer);
compat_del_timer_sync(&rate_timer);
free_templates();
destination_removeall();
#ifdef ENABLE_AGGR
Expand Down Expand Up @@ -5810,7 +5816,7 @@ static void __exit ipt_netflow_fini(void)
#endif
_unschedule_scan_worker();
netflow_scan_and_export(AND_FLUSH);
del_timer_sync(&rate_timer);
compat_del_timer_sync(&rate_timer);

#ifdef HAVE_SYNCHRONIZE_SCHED
synchronize_sched();
Expand Down