Skip to content

Commit

Permalink
Fix build on v5.15 (ct_event)
Browse files Browse the repository at this point in the history
    CC [M]  ipt_NETFLOW.o
  ipt_NETFLOW.c: In function ‘netflow_conntrack_event’:
  ipt_NETFLOW.c:4622:31: error: ‘struct nf_ct_event_notifier’ has no member named ‘fcn’
   4622 |                 ret = notifier->fcn(events, item);
	|                               ^~
  ipt_NETFLOW.c: At top level:
  ipt_NETFLOW.c:4687:10: error: ‘struct nf_ct_event_notifier’ has no member named ‘fcn’
   4687 |         .fcn = netflow_conntrack_event
	|          ^~~
  ipt_NETFLOW.c:4687:16: error: initialization of ‘int (*)(unsigned int,  const struct nf_ct_event *)’ from incompatible pointer type ‘int (*)(const unsigned int,  struct nf_ct_event *)’ [-Werror=incompatible-pointer-types]
   4687 |         .fcn = netflow_conntrack_event
	|                ^~~~~~~~~~~~~~~~~~~~~~~
  ipt_NETFLOW.c:4687:16: note: (near initialization for ‘ctnl_notifier.ct_event’)
  ipt_NETFLOW.c: In function ‘unset_notifier_cb’:
  ipt_NETFLOW.c:5455:25: error: too many arguments to function ‘nf_conntrack_unregister_notifier’
   5455 |                         nf_conntrack_unregister_notifier(NET_ARG &ctnl_notifier);
	|                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from ./include/net/netfilter/nf_conntrack_core.h:18,
		   from ipt_NETFLOW.c:68:
  ./include/net/netfilter/nf_conntrack_ecache.h:88:6: note: declared here
     88 | void nf_conntrack_unregister_notifier(struct net *net);
	|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: https://github.com/rcmcronny
Fixes: #186
aabc committed Nov 25, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 60581e2 commit 6a55739
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions compat.h
Original file line number Diff line number Diff line change
@@ -781,4 +781,8 @@ struct module *find_module(const char *name)
# endif
#endif

#ifndef HAVE_NF_CT_EVENT_NOTIFIER_CT_EVENT
# define ct_event fcn
#endif

#endif /* COMPAT_NETFLOW_H */
16 changes: 16 additions & 0 deletions gen_compat_def
Original file line number Diff line number Diff line change
@@ -90,6 +90,20 @@ kbuild_test_struct() {
EOF
}

# Test that struct have member
kbuild_test_member() {
echo -n "Test member $* " >&2
structname=${1%.*}
member=${1#*.}
def=${1^^}
def=${def//./_}
kbuild_test_compile $def "struct $1" ${2-} <<-EOF
#include <linux/module.h>
${2:+#include <$2>}
MODULE_LICENSE("GPL");
typeof(((struct $structname*)0)->$member) test;
EOF
}
echo "// Autogenerated for $KDIR"
echo

@@ -110,6 +124,8 @@ kbuild_test_symbol put_unaligned_be24 asm/unaligned.h
# totalram_pages changed from atomic to inline function.
kbuild_test_symbol totalram_pages linux/mm.h
kbuild_test_ref totalram_pages linux/mm.h
# b86c0e6429da ("netfilter: ecache: prepare for event notifier merge")
kbuild_test_member nf_ct_event_notifier.ct_event net/netfilter/nf_conntrack_ecache.h

echo "// End of compat_def.h"

16 changes: 11 additions & 5 deletions ipt_NETFLOW.c
Original file line number Diff line number Diff line change
@@ -4597,7 +4597,7 @@ static void rate_timer_calc(
#ifdef CONFIG_NF_NAT_NEEDED
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
static struct nf_ct_event_notifier *saved_event_cb __read_mostly = NULL;
static int netflow_conntrack_event(const unsigned int events, struct nf_ct_event *item)
static int netflow_conntrack_event(const unsigned int events, const struct nf_ct_event *item)
#else
static int netflow_conntrack_event(struct notifier_block *this, unsigned long events, void *ptr)
#endif
@@ -4619,7 +4619,7 @@ static int netflow_conntrack_event(struct notifier_block *this, unsigned long ev
/* Call netlink first. */
notifier = rcu_dereference(saved_event_cb);
if (likely(notifier))
ret = notifier->fcn(events, item);
ret = notifier->ct_event(events, item);
#endif
if (unlikely(!natevents))
return ret;
@@ -4684,7 +4684,7 @@ static struct notifier_block ctnl_notifier = {
};
#else
static struct nf_ct_event_notifier ctnl_notifier = {
.fcn = netflow_conntrack_event
.ct_event = netflow_conntrack_event
};
#endif /* since 2.6.31 */
#endif /* CONFIG_NF_NAT_NEEDED */
@@ -5451,9 +5451,15 @@ static void unset_notifier_cb(NET_STRUCT)

notifier = rcu_dereference(nf_conntrack_event_cb);
if (notifier == &ctnl_notifier) {
if (saved_event_cb == NULL)
if (saved_event_cb == NULL) {
#ifdef HAVE_NF_CT_EVENT_NOTIFIER_CT_EVENT
/* b86c0e6429da ("netfilter: ecache: prepare for event
* notifier merge") */
nf_conntrack_unregister_notifier(net);
#else
nf_conntrack_unregister_notifier(NET_ARG &ctnl_notifier);
else
#endif
} else
rcu_assign_pointer(nf_conntrack_event_cb, saved_event_cb);
} else
printk(KERN_ERR "ipt_NETFLOW: natevents already disabled.\n");

1 comment on commit 6a55739

@DocMAX
Copy link

@DocMAX DocMAX commented on 6a55739 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is problematic! Please have a look!

Error: unexpected error from compiler
make -s -B -C /mnt/zeus/hdd/sources/openwrt/sources/snapshot/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/linux-mvebu_cortexa9/linux-5.15.86 M=/mnt/zeus/hdd/sources/openwrt/sources/snapshot/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/linux-mvebu_cs
/mnt/zeus/hdd/sources/openwrt/sources/snapshot/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/linux-mvebu_cortexa9/ipt-netflow-40fefb2/cc-test-build/test.c:4:41: error: invalid use of undefined type 'struct nf_ct_event_notifier'
    4 | typeof(((struct nf_ct_event_notifier*)0)->ct_event) test;
      |                                         ^~
make[5]: *** [scripts/Makefile.build:289: /mnt/zeus/hdd/sources/openwrt/sources/snapshot/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/linux-mvebu_cortexa9/ipt-netflow-40fefb2/cc-test-build/test.o] Error 1
make[4]: *** [Makefile:1903: /mnt/zeus/hdd/sources/openwrt/sources/snapshot/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/linux-mvebu_cortexa9/ipt-netflow-40fefb2/cc-test-build] Error 2

Please sign in to comment.