The current approach for the compat layer is to include the compat.h file at exactly the right time to provide additional functionality and to live patch the batman-adv sources. This has the problem that the compat.h file becomes harder to read over time. Also live patching and adding of missing functionality partially conflict. This becomes obvious when the include order in some files is different compared to the one the author of an compat.h entry expected.
A different approach is to inject intermediate header files which add additional features. This allows to reduce the size of compat.h and only leaves the live patching part in it. The compat.h can then added automatically to each compile run before anything else is included. compat.h has therefore the control which headers must be included before the live patching of the batman-adv source can begin.
Signed-off-by: Sven Eckelmann sven@narfation.org --- v4: * rebased on top of master with merged patches from https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.html * moved newly added dev_get_iflink to compat-include/linux/netdevice.h v3: no change v2: no change
Makefile | 4 + compat-include/linux/atomic.h | 29 +++ compat-include/linux/bug.h | 38 ++++ compat-include/linux/compiler.h | 40 ++++ compat-include/linux/etherdevice.h | 45 +++++ compat-include/linux/export.h | 29 +++ compat-include/linux/if_ether.h | 33 ++++ compat-include/linux/if_vlan.h | 44 +++++ compat-include/linux/kconfig.h | 42 ++++ compat-include/linux/kernel.h | 44 +++++ compat-include/linux/list.h | 54 ++++++ compat-include/linux/moduleparam.h | 72 +++++++ compat-include/linux/net.h | 39 ++++ compat-include/linux/netdev_features.h | 35 ++++ compat-include/linux/netdevice.h | 120 ++++++++++++ compat-include/linux/percpu.h | 48 +++++ compat-include/linux/printk.h | 39 ++++ compat-include/linux/random.h | 33 ++++ compat-include/linux/rculist.h | 49 +++++ compat-include/linux/rcupdate.h | 39 ++++ compat-include/linux/seq_file.h | 36 ++++ compat-include/linux/skbuff.h | 94 +++++++++ compat-include/linux/slab.h | 33 ++++ compat.h | 342 ++------------------------------- main.h | 2 +- 25 files changed, 1056 insertions(+), 327 deletions(-) create mode 100644 compat-include/linux/atomic.h create mode 100644 compat-include/linux/bug.h create mode 100644 compat-include/linux/compiler.h create mode 100644 compat-include/linux/etherdevice.h create mode 100644 compat-include/linux/export.h create mode 100644 compat-include/linux/if_ether.h create mode 100644 compat-include/linux/if_vlan.h create mode 100644 compat-include/linux/kconfig.h create mode 100644 compat-include/linux/kernel.h create mode 100644 compat-include/linux/list.h create mode 100644 compat-include/linux/moduleparam.h create mode 100644 compat-include/linux/net.h create mode 100644 compat-include/linux/netdev_features.h create mode 100644 compat-include/linux/netdevice.h create mode 100644 compat-include/linux/percpu.h create mode 100644 compat-include/linux/printk.h create mode 100644 compat-include/linux/random.h create mode 100644 compat-include/linux/rculist.h create mode 100644 compat-include/linux/rcupdate.h create mode 100644 compat-include/linux/seq_file.h create mode 100644 compat-include/linux/skbuff.h create mode 100644 compat-include/linux/slab.h
diff --git a/Makefile b/Makefile index 4f6c30a..fd7ae8d 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,10 @@ RM ?= rm -f REVISION= $(shell if [ -d "$(PWD)/.git" ]; then \ echo $$(git --git-dir="$(PWD)/.git" describe --always --dirty --match "v*" |sed 's/^v//' 2> /dev/null || echo "[unknown]"); \ fi) +NOSTDINC_FLAGS := \ + -I$(PWD)/compat-include/ \ + -include $(PWD)/compat.h \ + $(CFLAGS)
CONFIG_BATMAN_ADV=m batman-adv-y += compat.o diff --git a/compat-include/linux/atomic.h b/compat-include/linux/atomic.h new file mode 100644 index 0000000..304af51 --- /dev/null +++ b/compat-include/linux/atomic.h @@ -0,0 +1,29 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_ATOMIC_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_ATOMIC_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37) +#include_next <linux/atomic.h> +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_ATOMIC_H_ */ diff --git a/compat-include/linux/bug.h b/compat-include/linux/bug.h new file mode 100644 index 0000000..66f79f8 --- /dev/null +++ b/compat-include/linux/bug.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_BUG_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_BUG_H_ + +#include <linux/version.h> +#include_next <linux/bug.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) + +#undef BUILD_BUG_ON +#ifdef __CHECKER__ +#define BUILD_BUG_ON(condition) (0) +#else /* __CHECKER__ */ +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) +#endif /* __CHECKER__ */ + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_BUG_H_ */ diff --git a/compat-include/linux/compiler.h b/compat-include/linux/compiler.h new file mode 100644 index 0000000..1717105 --- /dev/null +++ b/compat-include/linux/compiler.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_COMPILER_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_COMPILER_H_ + +#include <linux/version.h> +#include_next <linux/compiler.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define __always_unused __attribute__((unused)) +#define __percpu + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) + +#define __rcu + +#endif /* < KERNEL_VERSION(2, 6, 36) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_COMPILER_H_ */ diff --git a/compat-include/linux/etherdevice.h b/compat-include/linux/etherdevice.h new file mode 100644 index 0000000..c20b43c --- /dev/null +++ b/compat-include/linux/etherdevice.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_ETHERDEVICE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_ETHERDEVICE_H_ + +#include <linux/version.h> +#include_next <linux/etherdevice.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) + +#define eth_hw_addr_random(dev) batadv_eth_hw_addr_random(dev) + +static inline void batadv_eth_hw_addr_random(struct net_device *dev) +{ + random_ether_addr(dev->dev_addr); +} + +#endif /* < KERNEL_VERSION(3, 4, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) + +#define ether_addr_equal_unaligned(_a, _b) (memcmp(_a, _b, ETH_ALEN) == 0) +#define ether_addr_copy(_a, _b) memcpy(_a, _b, ETH_ALEN) + +#endif /* < KERNEL_VERSION(3, 14, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_ETHERDEVICE_H_ */ diff --git a/compat-include/linux/export.h b/compat-include/linux/export.h new file mode 100644 index 0000000..3b31a2d --- /dev/null +++ b/compat-include/linux/export.h @@ -0,0 +1,29 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_EXPORT_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_EXPORT_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0) +#include_next <linux/export.h> +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_EXPORT_H_ */ diff --git a/compat-include/linux/if_ether.h b/compat-include/linux/if_ether.h new file mode 100644 index 0000000..5ea164f --- /dev/null +++ b/compat-include/linux/if_ether.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_IF_ETHER_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_IF_ETHER_H_ + +#include <linux/version.h> +#include_next <linux/if_ether.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) + +#define ETH_P_BATMAN 0x4305 + +#endif /* < KERNEL_VERSION(3, 8, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_IF_ETHER_H_ */ diff --git a/compat-include/linux/if_vlan.h b/compat-include/linux/if_vlan.h new file mode 100644 index 0000000..3b146b4 --- /dev/null +++ b/compat-include/linux/if_vlan.h @@ -0,0 +1,44 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ + +#include <linux/version.h> +#include_next <linux/if_vlan.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ +#define VLAN_PRIO_SHIFT 13 + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) + +#define vlan_insert_tag(skb, proto, vid) __vlan_put_tag(skb, vid) + +#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) + +#define vlan_insert_tag(skb, proto, vid) vlan_insert_tag(skb, vid) + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ */ diff --git a/compat-include/linux/kconfig.h b/compat-include/linux/kconfig.h new file mode 100644 index 0000000..be8aa02 --- /dev/null +++ b/compat-include/linux/kconfig.h @@ -0,0 +1,42 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_KCONFIG_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_KCONFIG_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0) +#include_next <linux/kconfig.h> +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) + +#define __ARG_PLACEHOLDER_1 0, +#define config_enabled(cfg) _config_enabled(cfg) +#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) +#define ___config_enabled(__ignored, val, ...) val + +#define IS_ENABLED(option) \ + (config_enabled(option) || config_enabled(option##_MODULE)) + +#endif /* < KERNEL_VERSION(3, 1, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_KCONFIG_H_ */ diff --git a/compat-include/linux/kernel.h b/compat-include/linux/kernel.h new file mode 100644 index 0000000..81b2862 --- /dev/null +++ b/compat-include/linux/kernel.h @@ -0,0 +1,44 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_KERNEL_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_KERNEL_H_ + +#include <linux/version.h> +#include_next <linux/kernel.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) + +#define kstrtou32(cp, base, v)\ +({\ + unsigned long _v;\ + int _r;\ + _r = strict_strtoul(cp, base, &_v);\ + *(v) = (uint32_t)_v;\ + if ((unsigned long)*(v) != _v)\ + _r = -ERANGE;\ + _r;\ +}) +#define kstrtoul strict_strtoul +#define kstrtol strict_strtol + +#endif /* < KERNEL_VERSION(2, 6, 39) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_KERNEL_H_ */ diff --git a/compat-include/linux/list.h b/compat-include/linux/list.h new file mode 100644 index 0000000..dcd604c --- /dev/null +++ b/compat-include/linux/list.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_LIST_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_LIST_H_ + +#include <linux/version.h> +#include_next <linux/list.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +#undef hlist_for_each_entry +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +#undef hlist_for_each_entry_safe +#define hlist_for_each_entry_safe(pos, n, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ + pos && ({ n = pos->member.next; 1; }); \ + pos = hlist_entry_safe(n, typeof(*pos), member)) + +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) + +#define hlist_add_behind(n, prev) hlist_add_after(prev, n) + +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_LIST_H_ */ diff --git a/compat-include/linux/moduleparam.h b/compat-include/linux/moduleparam.h new file mode 100644 index 0000000..fd8ac41 --- /dev/null +++ b/compat-include/linux/moduleparam.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_MODULEPARAM_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_MODULEPARAM_H_ + +#include <linux/version.h> +#include_next <linux/moduleparam.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) + +#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ + __module_param_call(p1, p2, p3, p4, p5, p7) + +#else + +#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ + __module_param_call(p1, p2, p3, p4, p5, p6, p7) + +#endif /* < KERNEL_VERSION(2, 6, 31) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) + +struct kernel_param_ops { + /* Returns 0, or -errno. arg is in kp->arg. */ + int (*set)(const char *val, const struct kernel_param *kp); + /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ + int (*get)(char *buffer, struct kernel_param *kp); + /* Optional function to free kp->arg when module unloaded. */ + void (*free)(void *arg); +}; + +#define module_param_cb(name, ops, arg, perm) \ + static int __compat_set_param_##name(const char *val, \ + struct kernel_param *kp) \ + { return (ops)->set(val, kp); } \ + static int __compat_get_param_##name(char *buffer, \ + struct kernel_param *kp) \ + { return (ops)->get(buffer, kp); } \ + __compat__module_param_call(MODULE_PARAM_PREFIX, name, \ + __compat_set_param_##name, \ + __compat_get_param_##name, arg, \ + __same_type((arg), bool *), perm) + +static inline int batadv_param_set_copystring(const char *val, + const struct kernel_param *kp) +{ + return param_set_copystring(val, (struct kernel_param *)kp); +} + +#define param_set_copystring batadv_param_set_copystring + +#endif /* < KERNEL_VERSION(2, 6, 36) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_MODULEPARAM_H_ */ diff --git a/compat-include/linux/net.h b/compat-include/linux/net.h new file mode 100644 index 0000000..fcd7873 --- /dev/null +++ b/compat-include/linux/net.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NET_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NET_H_ + +#include <linux/version.h> +#include_next <linux/net.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) + +#ifndef net_ratelimited_function +#define net_ratelimited_function(func, ...) \ + do { \ + if (net_ratelimit()) \ + func(__VA_ARGS__); \ + } while (0) +#endif /* ifndef net_ratelimited_function */ + +#endif /* < KERNEL_VERSION(3, 5, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NET_H_ */ diff --git a/compat-include/linux/netdev_features.h b/compat-include/linux/netdev_features.h new file mode 100644 index 0000000..36c9c2f --- /dev/null +++ b/compat-include/linux/netdev_features.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETDEV_FEATURES_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETDEV_FEATURES_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0) +#include_next <linux/netdev_features.h> +#endif /* >= KERNEL_VERSION(3, 3, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) + +#define NETIF_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_FILTER + +#endif /* < KERNEL_VERSION(3, 10, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETDEV_FEATURES_H_ */ diff --git a/compat-include/linux/netdevice.h b/compat-include/linux/netdevice.h new file mode 100644 index 0000000..8d77bd8 --- /dev/null +++ b/compat-include/linux/netdevice.h @@ -0,0 +1,120 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETDEVICE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETDEVICE_H_ + +#include <linux/version.h> +#include_next <linux/netdevice.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) + +#include <linux/netdev_features.h> + +#endif /* < KERNEL_VERSION(3, 3, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev) + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) + +#include <linux/etherdevice.h> + +#undef netdev_for_each_mc_addr +#define netdev_for_each_mc_addr(mclist, dev) \ + for (mclist = (struct batadv_dev_addr_list *)dev->mc_list; mclist; \ + mclist = (struct batadv_dev_addr_list *)mclist->next) + +/* Note, that this breaks the usage of the normal 'struct netdev_hw_addr' + * for kernels < 2.6.35 in batman-adv! + */ +#define netdev_hw_addr batadv_dev_addr_list +struct batadv_dev_addr_list { + struct dev_addr_list *next; + u8 addr[MAX_ADDR_LEN]; + u8 da_addrlen; + u8 da_synced; + int da_users; + int da_gusers; +}; + +#endif /* < KERNEL_VERSION(2, 6, 35) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) + +#define NET_ADDR_RANDOM 0 + +#endif /* < KERNEL_VERSION(2, 6, 36) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) + +/* On older kernels net_dev->master is reserved for iface bonding. */ +static inline int batadv_netdev_set_master(struct net_device *slave, + struct net_device *master) +{ + return 0; +} + +#define netdev_set_master batadv_netdev_set_master + +#endif /* < KERNEL_VERSION(2, 6, 39) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#define netdev_master_upper_dev_link netdev_set_master +#define netdev_upper_dev_unlink(slave, master) netdev_set_master(slave, NULL) +#define netdev_master_upper_dev_get(dev) \ +({\ + ASSERT_RTNL();\ + dev->master;\ +}) + +#endif /* < KERNEL_VERSION(3, 9, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) + +#define netdev_notifier_info_to_dev(ptr) ptr + +#endif /* < KERNEL_VERSION(3, 11, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) + +/* alloc_netdev() was defined differently before 2.6.38 */ +#undef alloc_netdev +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) +#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ + alloc_netdev_mq(sizeof_priv, name, setup, 1) +#else +#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ + alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1) +#endif /* nested < KERNEL_VERSION(2, 6, 38) */ + +#endif /* < KERNEL_VERSION(3, 17, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0) + +#define dev_get_iflink(_net_dev) ((_net_dev)->iflink) + +#endif /* < KERNEL_VERSION(3, 19, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETDEVICE_H_ */ diff --git a/compat-include/linux/percpu.h b/compat-include/linux/percpu.h new file mode 100644 index 0000000..82355e4 --- /dev/null +++ b/compat-include/linux/percpu.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_PERCPU_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_PERCPU_H_ + +#include <linux/version.h> +#include_next <linux/percpu.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) + +#undef __alloc_percpu +#define __alloc_percpu(size, align) \ + percpu_alloc_mask((size), GFP_KERNEL, cpu_possible_map) + +#endif /* < KERNEL_VERSION(2, 6, 30) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define this_cpu_add(x, c) batadv_this_cpu_add(&(x), c) + +static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count) +{ + int cpu = get_cpu(); + *per_cpu_ptr(count_ptr, cpu) += count; + put_cpu(); +} + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_PERCPU_H_ */ diff --git a/compat-include/linux/printk.h b/compat-include/linux/printk.h new file mode 100644 index 0000000..c69c406 --- /dev/null +++ b/compat-include/linux/printk.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_PRINTK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_PRINTK_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37) +#include_next <linux/printk.h> +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) + +#define pr_warn pr_warning + +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_PRINTK_H_ */ + +#ifndef pr_fmt +#define pr_fmt(fmt) fmt +#endif diff --git a/compat-include/linux/random.h b/compat-include/linux/random.h new file mode 100644 index 0000000..ce12f1a --- /dev/null +++ b/compat-include/linux/random.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_RANDOM_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_RANDOM_H_ + +#include <linux/version.h> +#include_next <linux/random.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#define prandom_u32() random32() + +#endif /* < KERNEL_VERSION(3, 9, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_RANDOM_H_ */ diff --git a/compat-include/linux/rculist.h b/compat-include/linux/rculist.h new file mode 100644 index 0000000..4736db1 --- /dev/null +++ b/compat-include/linux/rculist.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_RCULIST_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_RCULIST_H_ + +#include <linux/version.h> +#include_next <linux/rculist.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) + +#define hlist_first_rcu(head) \ + (*((struct hlist_node __rcu **)(&(head)->first))) + +#define hlist_next_rcu(node) \ + (*((struct hlist_node __rcu **)(&(node)->next))) + +#endif /* < KERNEL_VERSION(2, 6, 37) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#undef hlist_for_each_entry_rcu +#define hlist_for_each_entry_rcu(pos, head, member) \ + for (pos = hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(head)),\ + typeof(*(pos)), member); \ + pos; \ + pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ + &(pos)->member)), typeof(*(pos)), member)) + +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_RCULIST_H_ */ diff --git a/compat-include/linux/rcupdate.h b/compat-include/linux/rcupdate.h new file mode 100644 index 0000000..f3ed948 --- /dev/null +++ b/compat-include/linux/rcupdate.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_RCUPDATE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_RCUPDATE_H_ + +#include <linux/version.h> +#include_next <linux/rcupdate.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) + +#define rcu_dereference_protected(p, c) (p) + +#define rcu_dereference_raw(p) ({ \ + typeof(p) _________p1 = ACCESS_ONCE(p); \ + smp_read_barrier_depends(); \ + (_________p1); \ + }) + +#endif /* < KERNEL_VERSION(2, 6, 34) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_RCUPDATE_H_ */ diff --git a/compat-include/linux/seq_file.h b/compat-include/linux/seq_file.h new file mode 100644 index 0000000..5eaaec8 --- /dev/null +++ b/compat-include/linux/seq_file.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_SEQ_FILE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_SEQ_FILE_H_ + +#include <linux/version.h> +#include_next <linux/seq_file.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) + +static inline bool seq_has_overflowed(struct seq_file *m) +{ + return m->count == m->size; +} + +#endif /* < KERNEL_VERSION(3, 19, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_SEQ_FILE_H_ */ diff --git a/compat-include/linux/skbuff.h b/compat-include/linux/skbuff.h new file mode 100644 index 0000000..ed911ef --- /dev/null +++ b/compat-include/linux/skbuff.h @@ -0,0 +1,94 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_SKBUFF_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_SKBUFF_H_ + +#include <linux/version.h> +#include_next <linux/skbuff.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) + +#define consume_skb(_skb) kfree_skb(_skb) + +#endif /* < KERNEL_VERSION(2, 6, 30) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, + unsigned int length) +{ + struct sk_buff *skb = netdev_alloc_skb(dev, length + NET_IP_ALIGN); + + if (NET_IP_ALIGN && skb) + skb_reserve(skb, NET_IP_ALIGN); + return skb; +} + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) + +static inline void skb_reset_mac_len(struct sk_buff *skb) +{ + skb->mac_len = skb->network_header - skb->mac_header; +} + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) + +/* hack for not correctly set mac_len. This may happen for some special + * configurations like batman-adv on VLANs. + * + * This is pretty dirty, but we only use skb_share_check() in main.c right + * before mac_len is checked, and the recomputation shouldn't hurt too much. + */ +#define skb_share_check(skb, b) \ + ({ \ + struct sk_buff *_t_skb; \ + _t_skb = skb_share_check(skb, b); \ + if (_t_skb) \ + skb_reset_mac_len(_t_skb); \ + _t_skb; \ + }) + +#endif /* < KERNEL_VERSION(3, 8, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) + +/* older kernels still need to call skb_abort_seq_read() */ +#define skb_seq_read(consumed, data, st) \ + ({ \ + int __len = skb_seq_read(consumed, data, st); \ + if (__len == 0) \ + skb_abort_seq_read(st); \ + __len; \ + }) + +#endif /* < KERNEL_VERSION(3, 11, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) + +#define pskb_copy_for_clone pskb_copy + +#endif /* < KERNEL_VERSION(3, 16, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_SKBUFF_H_ */ diff --git a/compat-include/linux/slab.h b/compat-include/linux/slab.h new file mode 100644 index 0000000..569c5aa --- /dev/null +++ b/compat-include/linux/slab.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_ + +#include <linux/version.h> +#include_next <linux/slab.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) + +#define kmalloc_array(n, size, flags) kmalloc(n * size, flags) + +#endif /* < KERNEL_VERSION(3, 4, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_ */ diff --git a/compat.h b/compat.h index df37fdc..35e3dbd 100644 --- a/compat.h +++ b/compat.h @@ -22,30 +22,7 @@ #define _NET_BATMAN_ADV_COMPAT_H_
#include <linux/version.h> /* LINUX_VERSION_CODE */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) - -#define consume_skb(_skb) kfree_skb(_skb) - -#undef __alloc_percpu -#define __alloc_percpu(size, align) \ - percpu_alloc_mask((size), GFP_KERNEL, cpu_possible_map) - -#endif /* < KERNEL_VERSION(2, 6, 30) */ - - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) - -#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ - __module_param_call(p1, p2, p3, p4, p5, p7) - -#else - -#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ - __module_param_call(p1, p2, p3, p4, p5, p6, p7) - -#endif /* < KERNEL_VERSION(2, 6, 31) */ - +#include <linux/kconfig.h>
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) #include <linux/autoconf.h> @@ -56,154 +33,47 @@
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
-#define __always_unused __attribute__((unused)) -#define __percpu - #define skb_iif iif
-#define this_cpu_add(x, c) batadv_this_cpu_add(&(x), c) - -static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count) -{ - int cpu = get_cpu(); - *per_cpu_ptr(count_ptr, cpu) += count; - put_cpu(); -} - #define batadv_softif_destroy_netlink(dev, head) batadv_softif_destroy_netlink(dev) -#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev) - -static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, - unsigned int length) -{ - struct sk_buff *skb = netdev_alloc_skb(dev, length + NET_IP_ALIGN); - - if (NET_IP_ALIGN && skb) - skb_reserve(skb, NET_IP_ALIGN); - return skb; -} - -#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ -#define VLAN_PRIO_SHIFT 13
#endif /* < KERNEL_VERSION(2, 6, 33) */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) - -#define rcu_dereference_protected(p, c) (p) - -#define rcu_dereference_raw(p) ({ \ - typeof(p) _________p1 = ACCESS_ONCE(p); \ - smp_read_barrier_depends(); \ - (_________p1); \ - }) - -#endif /* < KERNEL_VERSION(2, 6, 34) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) +#include <linux/netdevice.h>
-#define pr_warn pr_warning +#define netdev_master_upper_dev_get_rcu(dev) \ + (dev->br_port ? dev : NULL); \ + break;
-#undef netdev_for_each_mc_addr -#define netdev_for_each_mc_addr(mclist, dev) \ - for (mclist = (struct batadv_dev_addr_list *)dev->mc_list; mclist; \ - mclist = (struct batadv_dev_addr_list *)mclist->next) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
-/* Note, that this breaks the usage of the normal 'struct netdev_hw_addr' - * for kernels < 2.6.35 in batman-adv! - */ -#define netdev_hw_addr batadv_dev_addr_list -struct batadv_dev_addr_list { - struct dev_addr_list *next; - u8 addr[MAX_ADDR_LEN]; - u8 da_addrlen; - u8 da_synced; - int da_users; - int da_gusers; -}; +#include <linux/netdevice.h>
-#endif /* < KERNEL_VERSION(2, 6, 35) */ +#define netdev_master_upper_dev_get_rcu(dev) \ + (dev->priv_flags & IFF_BRIDGE_PORT ? dev : NULL); \ + break;
+#endif /* < KERNEL_VERSION(2, 6, 36) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
-#define __rcu #define IFF_BRIDGE_PORT 0 || (hard_iface->net_dev->br_port ? 1 : 0)
-struct kernel_param_ops { - /* Returns 0, or -errno. arg is in kp->arg. */ - int (*set)(const char *val, const struct kernel_param *kp); - /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ - int (*get)(char *buffer, struct kernel_param *kp); - /* Optional function to free kp->arg when module unloaded. */ - void (*free)(void *arg); -}; - -#define module_param_cb(name, ops, arg, perm) \ - static int __compat_set_param_##name(const char *val, \ - struct kernel_param *kp) \ - { return (ops)->set(val, kp); } \ - static int __compat_get_param_##name(char *buffer, \ - struct kernel_param *kp) \ - { return (ops)->get(buffer, kp); } \ - __compat__module_param_call(MODULE_PARAM_PREFIX, name, \ - __compat_set_param_##name, \ - __compat_get_param_##name, arg, \ - __same_type((arg), bool *), perm) - -static inline int batadv_param_set_copystring(const char *val, - const struct kernel_param *kp) -{ - return param_set_copystring(val, (struct kernel_param *)kp); -} -#define param_set_copystring batadv_param_set_copystring - /* hack for dev->addr_assign_type &= ~NET_ADDR_RANDOM; */ #define addr_assign_type ifindex -#define NET_ADDR_RANDOM 0 - -#define netdev_master_upper_dev_get_rcu(dev) \ - (dev->br_port ? dev : NULL); \ - break;
#endif /* < KERNEL_VERSION(2, 6, 36) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) - -#define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first))) -#define hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next))) - -#endif /* < KERNEL_VERSION(2, 6, 37) */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
-#define kstrtou32(cp, base, v)\ -({\ - unsigned long _v;\ - int _r;\ - _r = strict_strtoul(cp, base, &_v);\ - *(v) = (uint32_t)_v;\ - if ((unsigned long)*(v) != _v)\ - _r = -ERANGE;\ - _r;\ -}) -#define kstrtoul strict_strtoul -#define kstrtol strict_strtol - -/* On older kernels net_dev->master is reserved for iface bonding. */ -static inline int batadv_netdev_set_master(struct net_device *slave, - struct net_device *master) -{ - return 0; -} - -#define netdev_set_master batadv_netdev_set_master - /* Hack for removing ndo_add/del_slave at the end of net_device_ops. * This is somewhat ugly because it requires that ndo_validate_addr * is at the end of this struct in soft-interface.c. */ +#include <linux/netdevice.h> + #define ndo_validate_addr \ ndo_validate_addr = eth_validate_addr, \ }; \ @@ -223,7 +93,8 @@ static const struct { \ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0)
#define kfree_rcu(ptr, rcu_head) call_rcu(&ptr->rcu_head, batadv_free_rcu_##ptr) -#define vlan_insert_tag(skb, proto, vid) __vlan_put_tag(skb, vid) + +struct rcu_head;
void batadv_free_rcu_orig_vlan(struct rcu_head *rcu); void batadv_free_rcu_softif_vlan(struct rcu_head *rcu); @@ -236,32 +107,8 @@ void batadv_free_rcu_nc_path(struct rcu_head *rcu); void batadv_free_rcu_tvlv_handler(struct rcu_head *rcu); void batadv_free_rcu_vlan(struct rcu_head *rcu);
-static inline void skb_reset_mac_len(struct sk_buff *skb) -{ - skb->mac_len = skb->network_header - skb->mac_header; -} - -#undef BUILD_BUG_ON -#ifdef __CHECKER__ -#define BUILD_BUG_ON(condition) (0) -#else /* __CHECKER__ */ -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) -#endif /* __CHECKER__ */ - #endif /* < KERNEL_VERSION(3, 0, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) - -#define __ARG_PLACEHOLDER_1 0, -#define config_enabled(cfg) _config_enabled(cfg) -#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) -#define ___config_enabled(__ignored, val, ...) val - -#define IS_ENABLED(option) \ - (config_enabled(option) || config_enabled(option##_MODULE)) - -#endif /* < KERNEL_VERSION(3, 1, 0) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
@@ -288,56 +135,8 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
#endif /* < KERNEL_VERSION(3, 3, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) - -#define eth_hw_addr_random(dev) batadv_eth_hw_addr_random(dev) - -static inline void batadv_eth_hw_addr_random(struct net_device *dev) -{ - random_ether_addr(dev->dev_addr); -} - -#define kmalloc_array(n, size, flags) kmalloc(n * size, flags) - -#endif /* < KERNEL_VERSION(3, 4, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) - -#ifndef net_ratelimited_function -#define net_ratelimited_function(func, ...) \ - do { \ - if (net_ratelimit()) \ - func(__VA_ARGS__); \ - } while (0) -#endif /* ifndef net_ratelimited_function */ - -#endif /* < KERNEL_VERSION(3, 5, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) - -#define ETH_P_BATMAN 0x4305 - -/* hack for not correctly set mac_len. This may happen for some special - * configurations like batman-adv on VLANs. - * - * This is pretty dirty, but we only use skb_share_check() in main.c right - * before mac_len is checked, and the recomputation shouldn't hurt too much. - */ -#define skb_share_check(skb, b) \ - ({ \ - struct sk_buff *_t_skb; \ - _t_skb = skb_share_check(skb, b); \ - if (_t_skb) \ - skb_reset_mac_len(_t_skb); \ - _t_skb; \ - }) - -#endif /* < KERNEL_VERSION(3, 8, 0) */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
-#define prandom_u32() random32() - #define batadv_interface_set_mac_addr(x, y) \ __batadv_interface_set_mac_addr(struct net_device *dev, void *p);\ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p) \ @@ -362,61 +161,10 @@ static int batadv_interface_tx(struct sk_buff *skb, \ static int __batadv_interface_tx(struct sk_buff *skb, \ struct net_device *soft_iface)
-#define netdev_master_upper_dev_link netdev_set_master -#define netdev_upper_dev_unlink(slave, master) netdev_set_master(slave, NULL) -#define netdev_master_upper_dev_get(dev) \ -({\ - ASSERT_RTNL();\ - dev->master;\ -}) -#define hlist_entry_safe(ptr, type, member) \ - ({ typeof(ptr) ____ptr = (ptr); \ - ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ - }) - -#undef hlist_for_each_entry -#define hlist_for_each_entry(pos, head, member) \ - for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ - pos; \ - pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) - -#undef hlist_for_each_entry_rcu -#define hlist_for_each_entry_rcu(pos, head, member) \ - for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ - typeof(*(pos)), member); \ - pos; \ - pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ - &(pos)->member)), typeof(*(pos)), member)) - -#undef hlist_for_each_entry_safe -#define hlist_for_each_entry_safe(pos, n, head, member) \ - for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ - pos && ({ n = pos->member.next; 1; }); \ - pos = hlist_entry_safe(n, typeof(*pos), member)) - -#ifndef netdev_master_upper_dev_get_rcu -#define netdev_master_upper_dev_get_rcu(dev) \ - (dev->priv_flags & IFF_BRIDGE_PORT ? dev : NULL); \ - break; - -#endif /* netdev_master_upper_dev_get_rcu */ - #endif /* < KERNEL_VERSION(3, 9, 0) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
-#ifndef vlan_insert_tag - -/* include this header early to let the following define - * not mess up the original function prototype. - */ -#include <linux/if_vlan.h> -#define vlan_insert_tag(skb, proto, vid) vlan_insert_tag(skb, vid) - -#endif /* vlan_insert_tag */ - -#define NETIF_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_FILTER - #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
#define batadv_interface_add_vid(x, y, z) \ @@ -444,62 +192,4 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
#endif /* < KERNEL_VERSION(3, 10, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) - -#define netdev_notifier_info_to_dev(ptr) ptr - -/* older kernels still need to call skb_abort_seq_read() */ -#define skb_seq_read(consumed, data, st) \ - ({ \ - int __len = skb_seq_read(consumed, data, st); \ - if (__len == 0) \ - skb_abort_seq_read(st); \ - __len; \ - }) -#endif /* < KERNEL_VERSION(3, 11, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) - -#define ether_addr_equal_unaligned(_a, _b) (memcmp(_a, _b, ETH_ALEN) == 0) -#define ether_addr_copy(_a, _b) memcpy(_a, _b, ETH_ALEN) - -#endif /* < KERNEL_VERSION(3, 14, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) - -#define pskb_copy_for_clone pskb_copy - -#endif /* < KERNEL_VERSION(3, 16, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) - -#define hlist_add_behind(n, prev) hlist_add_after(prev, n) - -/* alloc_netdev() was defined differently before 2.6.38 */ -#undef alloc_netdev -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) -#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ - alloc_netdev_mq(sizeof_priv, name, setup, 1) -#else -#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ - alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1) -#endif /* nested < KERNEL_VERSION(2, 6, 38) */ - -#endif /* < KERNEL_VERSION(3, 17, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) - -static inline bool seq_has_overflowed(struct seq_file *m) -{ - return m->count == m->size; -} - -#endif /* < KERNEL_VERSION(3, 19, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0) - -#define dev_get_iflink(_net_dev) ((_net_dev)->iflink) - -#endif /* < KERNEL_VERSION(3, 19, 0) */ - #endif /* _NET_BATMAN_ADV_COMPAT_H_ */ diff --git a/main.h b/main.h index 569846b..1d5340c 100644 --- a/main.h +++ b/main.h @@ -182,7 +182,7 @@ enum batadv_uev_type { #include <linux/jiffies.h> #include <linux/seq_file.h> #include <linux/if_vlan.h> -#include "compat.h" +#include <linux/printk.h>
#include "types.h"
The header files could not be build indepdent from each other. This is happened because headers didn't include the files for things they've used. This was problematic because the success of a build depended on the knowledge about the right order of local includes.
Also source files were not including everything they've used explicitly. Instead they required that transitive includes are always stable. This is problematic because some transitive includes are not obvious, depend on config settings and may not be stable in the future.
The order for include blocks are:
* primary headers (main.h and the *.h file of a *.c file) * global linux headers * required local headers * extra forward declarations for pointers in function/struct declarations
The only exceptions are linux/bitops.h and linux/if_ether.h in packet.h. This header file is shared with userspace applications like batctl and must therefore build together with userspace applications. The header linux/bitops.h is not part of the uapi headers and linux/if_ether.h conflicts with the musl implementation of netinet/if_ether.h. The maintainers rejected the use of __KERNEL__ preprocessor checks and thus these two headers are only in main.h. All files using packet.h first have to include main.h to work correctly.
Reported-by: Markus Pargmann mpa@pengutronix.de Signed-off-by: Sven Eckelmann sven@narfation.org --- v4: * rebased on top of master with merged patches from https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.html * removed newly added batadv_free_rcu_vlan * remove empty compat.c v3: rewritten parts of the description + moved problematic headers out of packet.h v2: rewritten parts of the description
bat_iv_ogm.c | 42 +++++++++++++++++++++++++++++++------ bitarray.c | 4 ++-- bitarray.h | 6 ++++++ bridge_loop_avoidance.c | 38 ++++++++++++++++++++++++++------- bridge_loop_avoidance.h | 10 +++++++++ debugfs.c | 37 +++++++++++++++++++++++++------- debugfs.h | 7 +++++++ distributed-arp-table.c | 28 ++++++++++++++++++++----- distributed-arp-table.h | 13 +++++++++--- fragmentation.c | 22 ++++++++++++++++--- fragmentation.h | 9 ++++++++ gateway_client.c | 34 +++++++++++++++++++++++------- gateway_client.h | 8 +++++++ gateway_common.c | 11 +++++++++- gateway_common.h | 7 +++++++ hard-interface.c | 38 ++++++++++++++++++++++----------- hard-interface.h | 11 ++++++++++ hash.c | 6 +++++- hash.h | 9 ++++++++ icmp_socket.c | 33 +++++++++++++++++++++++++---- icmp_socket.h | 7 +++++++ main.c | 56 ++++++++++++++++++++++++++++++++++--------------- main.h | 30 ++++++++++++-------------- multicast.c | 29 ++++++++++++++++++++++--- multicast.h | 6 ++++++ network-coding.c | 37 ++++++++++++++++++++++++++++---- network-coding.h | 13 ++++++++++++ originator.c | 28 ++++++++++++++++++------- originator.h | 13 ++++++++++++ packet.h | 3 +++ routing.c | 36 ++++++++++++++++++++++--------- routing.h | 10 +++++++++ send.c | 36 +++++++++++++++++++++++-------- send.h | 13 ++++++++++++ soft-interface.c | 54 ++++++++++++++++++++++++++++++++++------------- soft-interface.h | 11 ++++++++++ sysfs.c | 31 +++++++++++++++++++++------ sysfs.h | 10 +++++++++ translation-table.c | 39 +++++++++++++++++++++++++++------- translation-table.h | 9 ++++++++ types.h | 18 ++++++++++++++-- 41 files changed, 703 insertions(+), 159 deletions(-)
diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c index 04bd220..f3214ed 100644 --- a/bat_iv_ogm.c +++ b/bat_iv_ogm.c @@ -15,16 +15,46 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
+#include "bat_algo.h" #include "main.h" -#include "translation-table.h" + +#include <linux/atomic.h> +#include <linux/bitmap.h> +#include <linux/bitops.h> +#include <linux/bug.h> +#include <linux/byteorder/generic.h> +#include <linux/cache.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/init.h> +#include <linux/jiffies.h> +#include <linux/list.h> +#include <linux/netdevice.h> +#include <linux/pkt_sched.h> +#include <linux/printk.h> +#include <linux/random.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/seq_file.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/types.h> +#include <linux/workqueue.h> + +#include "bitarray.h" +#include "hard-interface.h" +#include "hash.h" +#include "network-coding.h" #include "originator.h" +#include "packet.h" #include "routing.h" -#include "gateway_common.h" -#include "gateway_client.h" -#include "hard-interface.h" #include "send.h" -#include "bat_algo.h" -#include "network-coding.h" +#include "translation-table.h"
/** * enum batadv_dup_status - duplicate status diff --git a/bitarray.c b/bitarray.c index e3da07a..ea483f5 100644 --- a/bitarray.c +++ b/bitarray.c @@ -15,10 +15,10 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "bitarray.h" +#include "main.h"
-#include <linux/bitops.h> +#include <linux/bitmap.h>
/* shift the packet array by n places. */ static void batadv_bitmap_shift_left(unsigned long *seq_bits, int32_t n) diff --git a/bitarray.h b/bitarray.h index 2acaafe..0240fc2 100644 --- a/bitarray.h +++ b/bitarray.h @@ -18,6 +18,12 @@ #ifndef _NET_BATMAN_ADV_BITARRAY_H_ #define _NET_BATMAN_ADV_BITARRAY_H_
+#include "main.h" + +#include <linux/bitops.h> +#include <linux/compiler.h> +#include <linux/types.h> + /* Returns 1 if the corresponding bit in the given seq_bits indicates true * and curr_seqno is within range of last_seqno. Otherwise returns 0. */ diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index 6927589..1882b91 100644 --- a/bridge_loop_avoidance.c +++ b/bridge_loop_avoidance.c @@ -15,19 +15,41 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" -#include "hash.h" -#include "hard-interface.h" -#include "originator.h" #include "bridge_loop_avoidance.h" -#include "translation-table.h" -#include "send.h" +#include "main.h"
-#include <linux/etherdevice.h> +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/compiler.h> #include <linux/crc16.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> #include <linux/if_arp.h> -#include <net/arp.h> +#include <linux/if_ether.h> #include <linux/if_vlan.h> +#include <linux/jhash.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/lockdep.h> +#include <linux/netdevice.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/seq_file.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/workqueue.h> +#include <net/arp.h> + +#include "hard-interface.h" +#include "hash.h" +#include "originator.h" +#include "packet.h" +#include "translation-table.h"
static const uint8_t batadv_announce_mac[4] = {0x43, 0x05, 0x43, 0x05};
diff --git a/bridge_loop_avoidance.h b/bridge_loop_avoidance.h index 43c985d..1318805 100644 --- a/bridge_loop_avoidance.h +++ b/bridge_loop_avoidance.h @@ -18,6 +18,16 @@ #ifndef _NET_BATMAN_ADV_BLA_H_ #define _NET_BATMAN_ADV_BLA_H_
+#include "main.h" + +#include <linux/types.h> + +struct batadv_hard_iface; +struct batadv_orig_node; +struct batadv_priv; +struct seq_file; +struct sk_buff; + #ifdef CONFIG_BATMAN_ADV_BLA int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, unsigned short vid, bool is_bcast); diff --git a/debugfs.c b/debugfs.c index 9d337b5..e7d6f1a 100644 --- a/debugfs.c +++ b/debugfs.c @@ -15,21 +15,42 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
+#include "debugfs.h" #include "main.h"
+#include <linux/compiler.h> #include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/export.h> +#include <linux/fcntl.h> +#include <linux/fs.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netdevice.h> +#include <linux/poll.h> +#include <linux/printk.h> +#include <linux/sched.h> /* for linux/wait.h */ +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stat.h> +#include <linux/stddef.h> +#include <linux/stringify.h> +#include <linux/sysfs.h> +#include <linux/types.h> +#include <linux/uaccess.h> +#include <linux/wait.h> +#include <stdarg.h>
-#include "debugfs.h" -#include "translation-table.h" -#include "originator.h" -#include "hard-interface.h" -#include "gateway_common.h" -#include "gateway_client.h" -#include "soft-interface.h" -#include "icmp_socket.h" #include "bridge_loop_avoidance.h" #include "distributed-arp-table.h" +#include "gateway_client.h" +#include "icmp_socket.h" #include "network-coding.h" +#include "originator.h" +#include "translation-table.h"
static struct dentry *batadv_debugfs;
diff --git a/debugfs.h b/debugfs.h index 421f092..ce085b8 100644 --- a/debugfs.h +++ b/debugfs.h @@ -18,6 +18,13 @@ #ifndef _NET_BATMAN_ADV_DEBUGFS_H_ #define _NET_BATMAN_ADV_DEBUGFS_H_
+#include "main.h" + +#include <linux/kconfig.h> + +struct batadv_hard_iface; +struct net_device; + #define BATADV_DEBUGFS_SUBDIR "batman_adv"
#if IS_ENABLED(CONFIG_DEBUG_FS) diff --git a/distributed-arp-table.c b/distributed-arp-table.c index 107ad62..0b3d13d 100644 --- a/distributed-arp-table.c +++ b/distributed-arp-table.c @@ -15,18 +15,36 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include <linux/if_ether.h> +#include "distributed-arp-table.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> #include <linux/if_arp.h> +#include <linux/if_ether.h> #include <linux/if_vlan.h> +#include <linux/in.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/seq_file.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/workqueue.h> #include <net/arp.h>
-#include "main.h" -#include "hash.h" -#include "distributed-arp-table.h" #include "hard-interface.h" +#include "hash.h" #include "originator.h" #include "send.h" -#include "types.h" #include "translation-table.h"
static void batadv_dat_purge(struct work_struct *work); diff --git a/distributed-arp-table.h b/distributed-arp-table.h index 2fe0764..7fe6cd9 100644 --- a/distributed-arp-table.h +++ b/distributed-arp-table.h @@ -18,12 +18,19 @@ #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
-#ifdef CONFIG_BATMAN_ADV_DAT +#include "main.h" + +#include <linux/compiler.h> +#include <linux/netdevice.h> +#include <linux/types.h>
-#include "types.h" #include "originator.h" +#include "packet.h"
-#include <linux/if_arp.h> +struct seq_file; +struct sk_buff; + +#ifdef CONFIG_BATMAN_ADV_DAT
/* BATADV_DAT_ADDR_MAX - maximum address value in the DHT space */ #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0) diff --git a/fragmentation.c b/fragmentation.c index 9e06457..124356a 100644 --- a/fragmentation.c +++ b/fragmentation.c @@ -15,12 +15,28 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "fragmentation.h" -#include "send.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/pkt_sched.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/string.h> + +#include "hard-interface.h" #include "originator.h" +#include "packet.h" #include "routing.h" -#include "hard-interface.h" +#include "send.h" #include "soft-interface.h"
/** diff --git a/fragmentation.h b/fragmentation.h index d848cf6..7436a57 100644 --- a/fragmentation.h +++ b/fragmentation.h @@ -18,6 +18,15 @@ #ifndef _NET_BATMAN_ADV_FRAGMENTATION_H_ #define _NET_BATMAN_ADV_FRAGMENTATION_H_
+#include "main.h" + +#include <linux/compiler.h> +#include <linux/list.h> +#include <linux/stddef.h> +#include <linux/types.h> + +struct sk_buff; + void batadv_frag_purge_orig(struct batadv_orig_node *orig, bool (*check_cb)(struct batadv_frag_table_entry *)); bool batadv_frag_skb_fwd(struct sk_buff *skb, diff --git a/gateway_client.c b/gateway_client.c index 090828c..9b2ef82 100644 --- a/gateway_client.c +++ b/gateway_client.c @@ -15,18 +15,38 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" -#include "sysfs.h" #include "gateway_client.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/if_vlan.h> +#include <linux/in.h> +#include <linux/ip.h> +#include <linux/ipv6.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/netdevice.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/seq_file.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/udp.h> + #include "gateway_common.h" #include "hard-interface.h" #include "originator.h" -#include "translation-table.h" +#include "packet.h" #include "routing.h" -#include <linux/ip.h> -#include <linux/ipv6.h> -#include <linux/udp.h> -#include <linux/if_vlan.h> +#include "sysfs.h" +#include "translation-table.h"
/* These are the offsets of the "hw type" and "hw address length" in the dhcp * packet starting at the beginning of the dhcp header diff --git a/gateway_client.h b/gateway_client.h index 7ee53bb..60a52d5 100644 --- a/gateway_client.h +++ b/gateway_client.h @@ -18,6 +18,14 @@ #ifndef _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ #define _NET_BATMAN_ADV_GATEWAY_CLIENT_H_
+#include "main.h" + +#include <linux/types.h> + +struct batadv_tvlv_gateway_data; +struct seq_file; +struct sk_buff; + void batadv_gw_check_client_stop(struct batadv_priv *bat_priv); void batadv_gw_reselect(struct batadv_priv *bat_priv); void batadv_gw_election(struct batadv_priv *bat_priv); diff --git a/gateway_common.c b/gateway_common.c index 88a1bc3..f5d6734 100644 --- a/gateway_common.c +++ b/gateway_common.c @@ -15,9 +15,18 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "gateway_common.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/stddef.h> +#include <linux/string.h> + #include "gateway_client.h" +#include "packet.h"
/** * batadv_parse_gw_bandwidth - parse supplied string buffer to extract download diff --git a/gateway_common.h b/gateway_common.h index aa51165..2020c0f 100644 --- a/gateway_common.h +++ b/gateway_common.h @@ -18,6 +18,13 @@ #ifndef _NET_BATMAN_ADV_GATEWAY_COMMON_H_ #define _NET_BATMAN_ADV_GATEWAY_COMMON_H_
+#include "main.h" + +#include <linux/types.h> + +struct batadv_priv; +struct net_device; + enum batadv_gw_modes { BATADV_GW_MODE_OFF, BATADV_GW_MODE_CLIENT, diff --git a/hard-interface.c b/hard-interface.c index baf1f98..a05cf66 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -15,22 +15,36 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" -#include "distributed-arp-table.h" #include "hard-interface.h" -#include "soft-interface.h" -#include "send.h" -#include "translation-table.h" -#include "routing.h" -#include "sysfs.h" -#include "debugfs.h" -#include "originator.h" -#include "hash.h" -#include "bridge_loop_avoidance.h" -#include "gateway_client.h" +#include "main.h"
+#include <linux/bug.h> +#include <linux/byteorder/generic.h> +#include <linux/errno.h> +#include <linux/fs.h> #include <linux/if_arp.h> #include <linux/if_ether.h> +#include <linux/if.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/netdevice.h> +#include <linux/printk.h> +#include <linux/rculist.h> +#include <linux/rtnetlink.h> +#include <linux/slab.h> +#include <linux/workqueue.h> +#include <net/net_namespace.h> + +#include "bridge_loop_avoidance.h" +#include "debugfs.h" +#include "distributed-arp-table.h" +#include "gateway_client.h" +#include "originator.h" +#include "packet.h" +#include "send.h" +#include "soft-interface.h" +#include "sysfs.h" +#include "translation-table.h"
void batadv_hardif_free_rcu(struct rcu_head *rcu) { diff --git a/hard-interface.h b/hard-interface.h index 1918cd5..1012a5b 100644 --- a/hard-interface.h +++ b/hard-interface.h @@ -18,6 +18,17 @@ #ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_ #define _NET_BATMAN_ADV_HARD_INTERFACE_H_
+#include "main.h" + +#include <linux/atomic.h> +#include <linux/compiler.h> +#include <linux/notifier.h> +#include <linux/rcupdate.h> +#include <linux/stddef.h> +#include <linux/types.h> + +struct net_device; + enum batadv_hard_if_state { BATADV_IF_NOT_IN_USE, BATADV_IF_TO_BE_REMOVED, diff --git a/hash.c b/hash.c index 7c1c630..0532dc9 100644 --- a/hash.c +++ b/hash.c @@ -15,8 +15,12 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "hash.h" +#include "main.h" + +#include <linux/fs.h> +#include <linux/lockdep.h> +#include <linux/slab.h>
/* clears the hash */ static void batadv_hash_init(struct batadv_hashtable *hash) diff --git a/hash.h b/hash.h index a1d0980..b7cc418 100644 --- a/hash.h +++ b/hash.h @@ -18,7 +18,16 @@ #ifndef _NET_BATMAN_ADV_HASH_H_ #define _NET_BATMAN_ADV_HASH_H_
+#include "main.h" + +#include <linux/compiler.h> #include <linux/list.h> +#include <linux/rculist.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/types.h> + +struct lock_class_key;
/* callback to a compare function. should compare 2 element datas for their * keys, return 0 if same and not 0 if not same diff --git a/icmp_socket.c b/icmp_socket.c index 161ef8f..c09342c 100644 --- a/icmp_socket.c +++ b/icmp_socket.c @@ -15,14 +15,39 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
+#include "icmp_socket.h" #include "main.h" + +#include <linux/atomic.h> +#include <linux/compiler.h> #include <linux/debugfs.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/export.h> +#include <linux/fcntl.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/netdevice.h> +#include <linux/pkt_sched.h> +#include <linux/poll.h> +#include <linux/printk.h> +#include <linux/sched.h> /* for linux/wait.h */ +#include <linux/skbuff.h> #include <linux/slab.h> -#include "icmp_socket.h" -#include "send.h" -#include "hash.h" -#include "originator.h" +#include <linux/spinlock.h> +#include <linux/stat.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/uaccess.h> +#include <linux/wait.h> + #include "hard-interface.h" +#include "originator.h" +#include "packet.h" +#include "send.h"
static struct batadv_socket_client *batadv_socket_client_hash[256];
diff --git a/icmp_socket.h b/icmp_socket.h index 0c33950..0189910 100644 --- a/icmp_socket.h +++ b/icmp_socket.h @@ -18,6 +18,13 @@ #ifndef _NET_BATMAN_ADV_ICMP_SOCKET_H_ #define _NET_BATMAN_ADV_ICMP_SOCKET_H_
+#include "main.h" + +#include <linux/types.h> + +struct batadv_icmp_header; +struct batadv_priv; + #define BATADV_ICMP_SOCKET "socket"
void batadv_socket_init(void); diff --git a/main.c b/main.c index 766ab33..0cbbd6f 100644 --- a/main.c +++ b/main.c @@ -15,31 +15,53 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
+#include "main.h" + +#include <linux/atomic.h> +#include <linux/bug.h> +#include <linux/byteorder/generic.h> #include <linux/crc32c.h> -#include <linux/highmem.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/if_ether.h> #include <linux/if_vlan.h> -#include <net/ip.h> -#include <net/ipv6.h> +#include <linux/init.h> +#include <linux/ip.h> +#include <linux/ipv6.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/netdevice.h> +#include <linux/pkt_sched.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/seq_file.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/workqueue.h> #include <net/dsfield.h> -#include "main.h" -#include "sysfs.h" +#include <net/rtnetlink.h> + +#include "bat_algo.h" +#include "bridge_loop_avoidance.h" #include "debugfs.h" +#include "distributed-arp-table.h" +#include "gateway_client.h" +#include "gateway_common.h" +#include "hard-interface.h" +#include "icmp_socket.h" +#include "multicast.h" +#include "network-coding.h" +#include "originator.h" +#include "packet.h" #include "routing.h" #include "send.h" -#include "originator.h" #include "soft-interface.h" -#include "icmp_socket.h" #include "translation-table.h" -#include "hard-interface.h" -#include "gateway_client.h" -#include "bridge_loop_avoidance.h" -#include "distributed-arp-table.h" -#include "multicast.h" -#include "gateway_common.h" -#include "hash.h" -#include "bat_algo.h" -#include "network-coding.h" -#include "fragmentation.h"
/* List manipulations on hardif_list have to be rtnl_lock()'ed, * list traversals just rcu-locked diff --git a/main.h b/main.h index 1d5340c..dee8072 100644 --- a/main.h +++ b/main.h @@ -163,29 +163,25 @@ enum batadv_uev_type {
/* Kernel headers */
-#include <linux/mutex.h> /* mutex */ -#include <linux/module.h> /* needed by all modules */ -#include <linux/netdevice.h> /* netdevice */ -#include <linux/etherdevice.h> /* ethernet address classification */ -#include <linux/if_ether.h> /* ethernet header */ -#include <linux/poll.h> /* poll_table */ -#include <linux/kthread.h> /* kernel threads */ -#include <linux/pkt_sched.h> /* schedule types */ -#include <linux/workqueue.h> /* workqueue */ +#include <linux/atomic.h> +#include <linux/bitops.h> /* for packet.h */ +#include <linux/compiler.h> +#include <linux/cpumask.h> +#include <linux/etherdevice.h> +#include <linux/if_ether.h> /* for packet.h */ +#include <linux/netdevice.h> +#include <linux/printk.h> +#include <linux/types.h> #include <linux/percpu.h> -#include <linux/slab.h> -#include <linux/jhash.h> -#include <net/sock.h> /* struct sock */ -#include <net/addrconf.h> /* ipv6 address stuff */ -#include <linux/ip.h> -#include <net/rtnetlink.h> #include <linux/jiffies.h> -#include <linux/seq_file.h> #include <linux/if_vlan.h> -#include <linux/printk.h>
#include "types.h"
+struct batadv_ogm_packet; +struct seq_file; +struct sk_buff; + #define BATADV_PRINT_VID(vid) (vid & BATADV_VLAN_HAS_TAG ? \ (int)(vid & VLAN_VID_MASK) : -1)
diff --git a/multicast.c b/multicast.c index b24e4bb..70ce652 100644 --- a/multicast.c +++ b/multicast.c @@ -15,10 +15,33 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "multicast.h" -#include "originator.h" -#include "hard-interface.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/in6.h> +#include <linux/in.h> +#include <linux/ip.h> +#include <linux/ipv6.h> +#include <linux/list.h> +#include <linux/netdevice.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/types.h> +#include <net/addrconf.h> +#include <net/ipv6.h> + +#include "packet.h" #include "translation-table.h"
/** diff --git a/multicast.h b/multicast.h index 3a44ebd..ae04f1e 100644 --- a/multicast.h +++ b/multicast.h @@ -18,6 +18,12 @@ #ifndef _NET_BATMAN_ADV_MULTICAST_H_ #define _NET_BATMAN_ADV_MULTICAST_H_
+#include "main.h" + +struct batadv_orig_node; +struct batadv_priv; +struct sk_buff; + /** * batadv_forw_mode - the way a packet should be forwarded as * @BATADV_FORW_ALL: forward the packet to all nodes (currently via classic diff --git a/network-coding.c b/network-coding.c index d128c3b..b3b3c4e 100644 --- a/network-coding.c +++ b/network-coding.c @@ -15,15 +15,44 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
+#include "network-coding.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/compiler.h> #include <linux/debugfs.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/if_packet.h> +#include <linux/init.h> +#include <linux/jhash.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/lockdep.h> +#include <linux/netdevice.h> +#include <linux/printk.h> +#include <linux/random.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/seq_file.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stat.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/workqueue.h>
-#include "main.h" +#include "hard-interface.h" #include "hash.h" -#include "network-coding.h" -#include "send.h" #include "originator.h" -#include "hard-interface.h" +#include "packet.h" #include "routing.h" +#include "send.h"
static struct lock_class_key batadv_nc_coding_hash_lock_class_key; static struct lock_class_key batadv_nc_decoding_hash_lock_class_key; diff --git a/network-coding.h b/network-coding.h index 358c0d6..4008ec2 100644 --- a/network-coding.h +++ b/network-coding.h @@ -18,6 +18,19 @@ #ifndef _NET_BATMAN_ADV_NETWORK_CODING_H_ #define _NET_BATMAN_ADV_NETWORK_CODING_H_
+#include "main.h" + +#include <linux/types.h> + +struct batadv_nc_node; +struct batadv_neigh_node; +struct batadv_ogm_packet; +struct batadv_orig_node; +struct batadv_priv; +struct net_device; +struct seq_file; +struct sk_buff; + #ifdef CONFIG_BATMAN_ADV_NC
void batadv_nc_status_update(struct net_device *net_dev); diff --git a/originator.c b/originator.c index 9e04e60..684536e 100644 --- a/originator.c +++ b/originator.c @@ -15,19 +15,31 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
+#include "originator.h" #include "main.h" + +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/lockdep.h> +#include <linux/netdevice.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/workqueue.h> + #include "distributed-arp-table.h" -#include "originator.h" -#include "hash.h" -#include "translation-table.h" -#include "routing.h" +#include "fragmentation.h" #include "gateway_client.h" #include "hard-interface.h" -#include "soft-interface.h" -#include "bridge_loop_avoidance.h" -#include "network-coding.h" -#include "fragmentation.h" +#include "hash.h" #include "multicast.h" +#include "network-coding.h" +#include "routing.h" +#include "translation-table.h"
/* hash class keys */ static struct lock_class_key batadv_orig_hash_lock_class_key; diff --git a/originator.h b/originator.h index a179c03..39085cc 100644 --- a/originator.h +++ b/originator.h @@ -18,8 +18,21 @@ #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_ #define _NET_BATMAN_ADV_ORIGINATOR_H_
+#include "main.h" + +#include <linux/atomic.h> +#include <linux/compiler.h> +#include <linux/if_ether.h> +#include <linux/jhash.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/stddef.h> +#include <linux/types.h> + #include "hash.h"
+struct seq_file; + int batadv_compare_orig(const struct hlist_node *node, const void *data2); int batadv_originator_init(struct batadv_priv *bat_priv); void batadv_originator_free(struct batadv_priv *bat_priv); diff --git a/packet.h b/packet.h index b81fbbf..7a9cb7a 100644 --- a/packet.h +++ b/packet.h @@ -18,6 +18,9 @@ #ifndef _NET_BATMAN_ADV_PACKET_H_ #define _NET_BATMAN_ADV_PACKET_H_
+#include <asm/byteorder.h> +#include <linux/types.h> + /** * enum batadv_packettype - types for batman-adv encapsulated packets * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV diff --git a/routing.c b/routing.c index da83982..db68ae4 100644 --- a/routing.c +++ b/routing.c @@ -15,20 +15,36 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "routing.h" -#include "send.h" -#include "soft-interface.h" -#include "hard-interface.h" -#include "icmp_socket.h" -#include "translation-table.h" -#include "originator.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/compiler.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/if_ether.h> +#include <linux/jiffies.h> +#include <linux/netdevice.h> +#include <linux/printk.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/skbuff.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> + +#include "bitarray.h" #include "bridge_loop_avoidance.h" #include "distributed-arp-table.h" -#include "network-coding.h" #include "fragmentation.h" - -#include <linux/if_vlan.h> +#include "hard-interface.h" +#include "icmp_socket.h" +#include "network-coding.h" +#include "originator.h" +#include "packet.h" +#include "send.h" +#include "soft-interface.h" +#include "translation-table.h"
static int batadv_route_unicast_packet(struct sk_buff *skb, struct batadv_hard_iface *recv_if); diff --git a/routing.h b/routing.h index 557d3d1..f8a9e14 100644 --- a/routing.h +++ b/routing.h @@ -18,6 +18,16 @@ #ifndef _NET_BATMAN_ADV_ROUTING_H_ #define _NET_BATMAN_ADV_ROUTING_H_
+#include "main.h" + +#include <linux/types.h> + +struct batadv_hard_iface; +struct batadv_neigh_node; +struct batadv_orig_node; +struct batadv_priv; +struct sk_buff; + bool batadv_check_management_packet(struct sk_buff *skb, struct batadv_hard_iface *hard_iface, int header_len); diff --git a/send.c b/send.c index 3d64ed2..2b5e7a9 100644 --- a/send.c +++ b/send.c @@ -15,19 +15,37 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
+#include "send.h" #include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/if.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/netdevice.h> +#include <linux/printk.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/workqueue.h> + #include "distributed-arp-table.h" -#include "send.h" -#include "routing.h" -#include "translation-table.h" -#include "soft-interface.h" -#include "hard-interface.h" -#include "gateway_common.h" +#include "fragmentation.h" #include "gateway_client.h" -#include "originator.h" +#include "hard-interface.h" #include "network-coding.h" -#include "fragmentation.h" -#include "multicast.h" +#include "originator.h" +#include "routing.h" +#include "soft-interface.h" +#include "translation-table.h"
static void batadv_send_outstanding_bcast_packet(struct work_struct *work);
diff --git a/send.h b/send.h index 38d0ec1..de85f2f 100644 --- a/send.h +++ b/send.h @@ -18,6 +18,19 @@ #ifndef _NET_BATMAN_ADV_SEND_H_ #define _NET_BATMAN_ADV_SEND_H_
+#include "main.h" + +#include <linux/compiler.h> +#include <linux/types.h> + +#include "packet.h" + +struct batadv_hard_iface; +struct batadv_orig_node; +struct batadv_priv; +struct sk_buff; +struct work_struct; + int batadv_send_skb_packet(struct sk_buff *skb, struct batadv_hard_iface *hard_iface, const uint8_t *dst_addr); diff --git a/soft-interface.c b/soft-interface.c index 99d455c..310031f 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -15,26 +15,50 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "soft-interface.h" -#include "hard-interface.h" -#include "distributed-arp-table.h" -#include "routing.h" -#include "send.h" -#include "debugfs.h" -#include "translation-table.h" -#include "hash.h" -#include "gateway_common.h" -#include "gateway_client.h" -#include "sysfs.h" -#include "originator.h" -#include <linux/slab.h> -#include <linux/ethtool.h> +#include "main.h" + +#include <linux/atomic.h> +#include <linux/byteorder/generic.h> +#include <linux/cache.h> +#include <linux/compiler.h> +#include <linux/errno.h> #include <linux/etherdevice.h> +#include <linux/ethtool.h> +#include <linux/fs.h> +#include <linux/if_ether.h> #include <linux/if_vlan.h> -#include "multicast.h" +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/lockdep.h> +#include <linux/netdevice.h> +#include <linux/percpu.h> +#include <linux/printk.h> +#include <linux/random.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/socket.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/types.h> +#include <linux/workqueue.h> + #include "bridge_loop_avoidance.h" +#include "debugfs.h" +#include "distributed-arp-table.h" +#include "gateway_client.h" +#include "gateway_common.h" +#include "hard-interface.h" +#include "multicast.h" #include "network-coding.h" +#include "packet.h" +#include "send.h" +#include "sysfs.h" +#include "translation-table.h"
static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd); static void batadv_get_drvinfo(struct net_device *dev, diff --git a/soft-interface.h b/soft-interface.h index dbab22f..e1e8bb9 100644 --- a/soft-interface.h +++ b/soft-interface.h @@ -18,6 +18,17 @@ #ifndef _NET_BATMAN_ADV_SOFT_INTERFACE_H_ #define _NET_BATMAN_ADV_SOFT_INTERFACE_H_
+#include "main.h" + +#include <net/rtnetlink.h> + +struct batadv_hard_iface; +struct batadv_orig_node; +struct batadv_priv; +struct batadv_softif_vlan; +struct net_device; +struct sk_buff; + int batadv_skb_head_push(struct sk_buff *skb, unsigned int len); void batadv_interface_rx(struct net_device *soft_iface, struct sk_buff *skb, struct batadv_hard_iface *recv_if, diff --git a/sysfs.c b/sysfs.c index c3c4b9c..ddfa989 100644 --- a/sysfs.c +++ b/sysfs.c @@ -15,16 +15,35 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "sysfs.h" -#include "translation-table.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/compiler.h> +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/if.h> +#include <linux/if_vlan.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/printk.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/rtnetlink.h> +#include <linux/slab.h> +#include <linux/stat.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/stringify.h> + #include "distributed-arp-table.h" -#include "network-coding.h" -#include "originator.h" +#include "gateway_client.h" +#include "gateway_common.h" #include "hard-interface.h" +#include "network-coding.h" +#include "packet.h" #include "soft-interface.h" -#include "gateway_common.h" -#include "gateway_client.h"
static struct net_device *batadv_kobj_to_netdev(struct kobject *obj) { diff --git a/sysfs.h b/sysfs.h index b715b60..bc1f6df 100644 --- a/sysfs.h +++ b/sysfs.h @@ -18,6 +18,16 @@ #ifndef _NET_BATMAN_ADV_SYSFS_H_ #define _NET_BATMAN_ADV_SYSFS_H_
+#include "main.h" + +#include <linux/sysfs.h> +#include <linux/types.h> + +struct batadv_priv; +struct batadv_softif_vlan; +struct kobject; +struct net_device; + #define BATADV_SYSFS_IF_MESH_SUBDIR "mesh" #define BATADV_SYSFS_IF_BAT_SUBDIR "batman_adv" /** diff --git a/translation-table.c b/translation-table.c index b20812b..5551ecc 100644 --- a/translation-table.c +++ b/translation-table.c @@ -15,18 +15,41 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */
-#include "main.h" #include "translation-table.h" -#include "soft-interface.h" +#include "main.h" + +#include <linux/atomic.h> +#include <linux/bug.h> +#include <linux/byteorder/generic.h> +#include <linux/compiler.h> +#include <linux/crc32c.h> +#include <linux/errno.h> +#include <linux/etherdevice.h> +#include <linux/fs.h> +#include <linux/if_ether.h> +#include <linux/jhash.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/lockdep.h> +#include <linux/netdevice.h> +#include <linux/rculist.h> +#include <linux/rcupdate.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/string.h> +#include <linux/workqueue.h> +#include <net/net_namespace.h> + +#include "bridge_loop_avoidance.h" #include "hard-interface.h" -#include "send.h" #include "hash.h" -#include "originator.h" -#include "routing.h" -#include "bridge_loop_avoidance.h" #include "multicast.h" - -#include <linux/crc32c.h> +#include "originator.h" +#include "packet.h" +#include "soft-interface.h"
/* hash class keys */ static struct lock_class_key batadv_tt_local_hash_lock_class_key; diff --git a/translation-table.h b/translation-table.h index ad84d7b..3c2b868 100644 --- a/translation-table.h +++ b/translation-table.h @@ -18,6 +18,15 @@ #ifndef _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ #define _NET_BATMAN_ADV_TRANSLATION_TABLE_H_
+#include "main.h" + +#include <linux/types.h> + +struct batadv_orig_node; +struct batadv_priv; +struct net_device; +struct seq_file; + int batadv_tt_init(struct batadv_priv *bat_priv); bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, unsigned short vid, int ifindex, uint32_t mark); diff --git a/types.h b/types.h index b72fa7b..1d4781e 100644 --- a/types.h +++ b/types.h @@ -18,9 +18,23 @@ #ifndef _NET_BATMAN_ADV_TYPES_H_ #define _NET_BATMAN_ADV_TYPES_H_
+#ifndef _NET_BATMAN_ADV_MAIN_H_ +#error only "main.h" can be included directly +#endif + +#include <linux/bitops.h> +#include <linux/compiler.h> +#include <linux/if_ether.h> +#include <linux/netdevice.h> +#include <linux/sched.h> /* for linux/wait.h */ +#include <linux/spinlock.h> +#include <linux/types.h> +#include <linux/wait.h> +#include <linux/workqueue.h> + #include "packet.h" -#include "bitarray.h" -#include <linux/kernel.h> + +struct seq_file;
#ifdef CONFIG_BATMAN_ADV_DAT
Hi,
Just noticed that the first "to" in the subject has to be removed. I will not resend the patchset because of that... unless someone really wants it.
Kind regards, Sven
On Friday, April 17, 2015 19:40:28 Sven Eckelmann wrote:
The header files could not be build indepdent from each other. This is happened because headers didn't include the files for things they've used. This was problematic because the success of a build depended on the knowledge about the right order of local includes.
Also source files were not including everything they've used explicitly. Instead they required that transitive includes are always stable. This is problematic because some transitive includes are not obvious, depend on config settings and may not be stable in the future.
The order for include blocks are:
- primary headers (main.h and the *.h file of a *.c file)
- global linux headers
- required local headers
- extra forward declarations for pointers in function/struct declarations
The only exceptions are linux/bitops.h and linux/if_ether.h in packet.h. This header file is shared with userspace applications like batctl and must therefore build together with userspace applications. The header linux/bitops.h is not part of the uapi headers and linux/if_ether.h conflicts with the musl implementation of netinet/if_ether.h. The maintainers rejected the use of __KERNEL__ preprocessor checks and thus these two headers are only in main.h. All files using packet.h first have to include main.h to work correctly.
Reported-by: Markus Pargmann mpa@pengutronix.de Signed-off-by: Sven Eckelmann sven@narfation.org
Applied in revision 960339d.
Thanks, Marek
Signed-off-by: Sven Eckelmann sven@narfation.org --- v4: * rebased on top of master with merged patches from https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.html v3: no change v2: no change
compat.h | 2 -- 1 file changed, 2 deletions(-)
diff --git a/compat.h b/compat.h index 35e3dbd..9871a23 100644 --- a/compat.h +++ b/compat.h @@ -59,8 +59,6 @@
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
-#define IFF_BRIDGE_PORT 0 || (hard_iface->net_dev->br_port ? 1 : 0) - /* hack for dev->addr_assign_type &= ~NET_ADDR_RANDOM; */ #define addr_assign_type ifindex
On Friday, April 17, 2015 19:40:29 Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven@narfation.org
v4:
- rebased on top of master with merged patches from https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.html
v3: no change v2: no change
compat.h | 2 -- 1 file changed, 2 deletions(-)
diff --git a/compat.h b/compat.h index 35e3dbd..9871a23 100644 --- a/compat.h +++ b/compat.h @@ -59,8 +59,6 @@
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
-#define IFF_BRIDGE_PORT 0 || (hard_iface->net_dev->br_port ? 1 : 0)
/* hack for dev->addr_assign_type &= ~NET_ADDR_RANDOM; */ #define addr_assign_type ifindex
The macro is used in compat.h line 55, is it not ?
Cheers, Marek
diff --git a/compat.h b/compat.h index 35e3dbd..9871a23 100644 --- a/compat.h +++ b/compat.h @@ -59,8 +59,6 @@
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
-#define IFF_BRIDGE_PORT 0 || (hard_iface->net_dev->br_port ? 1 : 0)
/* hack for dev->addr_assign_type &= ~NET_ADDR_RANDOM; */ #define addr_assign_type ifindex
The macro is used in compat.h line 55, is it not ?
IFF_BRIDGE_PORT appears in this line but here is the context:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
HERE IT IS *NOT* USED
#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
HERE IT IS USED
#endif /* < KERNEL_VERSION(2, 6, 36) */
The IFF_BRIDGE_PORT (which I call unused( is only required in this other compat hack when the kernel is >= 2.6.36 and < 3.9.0. But the one I want to remove is only for kernels < 2.6.36.
Kind regards, Sven
On Tuesday, April 21, 2015 08:04:41 Sven Eckelmann wrote:
The macro is used in compat.h line 55, is it not ?
IFF_BRIDGE_PORT appears in this line but here is the context:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
HERE IT IS *NOT* USED
#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
HERE IT IS USED
#endif /* < KERNEL_VERSION(2, 6, 36) */
The IFF_BRIDGE_PORT (which I call unused( is only required in this other compat hack when the kernel is >= 2.6.36 and < 3.9.0. But the one I want to remove is only for kernels < 2.6.36.
Good point. The patch was applied in revision 312ea8a.
Thanks, Marek
The kfree_rcu compat helper for old kernels require a special function that knows how to calculate the offsets to the actual data pointer to call kfree. These can either be manually provided or the GCC extension for nested functions can be used to automatically create a local function using a macro.
Signed-off-by: Sven Eckelmann sven@narfation.org --- v4: * rebased on top of master with merged patches from https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.html v3: no change v2: no change
Makefile | 1 - compat-include/linux/rcupdate.h | 15 +++++ compat.c | 120 ---------------------------------------- compat.h | 20 ------- 4 files changed, 15 insertions(+), 141 deletions(-) delete mode 100644 compat.c
diff --git a/Makefile b/Makefile index fd7ae8d..e57fcb3 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,6 @@ NOSTDINC_FLAGS := \ $(CFLAGS)
CONFIG_BATMAN_ADV=m -batman-adv-y += compat.o ifneq ($(REVISION),) ccflags-y += -DBATADV_SOURCE_VERSION="$(REVISION)" endif diff --git a/compat-include/linux/rcupdate.h b/compat-include/linux/rcupdate.h index f3ed948..12a1c2a 100644 --- a/compat-include/linux/rcupdate.h +++ b/compat-include/linux/rcupdate.h @@ -36,4 +36,19 @@
#endif /* < KERNEL_VERSION(2, 6, 34) */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) + +#define kfree_rcu(ptr, rcuhead_name) \ + do { \ + void batadv_free_rcu_##ptr(struct rcu_head *rcu) \ + { \ + void *container_ptr; \ + container_ptr = container_of(rcu, typeof(*(ptr)), rcuhead_name); \ + kfree(container_ptr); \ + } \ + call_rcu(&(ptr)->rcuhead_name, batadv_free_rcu_##ptr); \ + } while (0) + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + #endif /* _NET_BATMAN_ADV_COMPAT_LINUX_RCUPDATE_H_ */ diff --git a/compat.c b/compat.c deleted file mode 100644 index 516d06c..0000000 --- a/compat.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: - * - * Marek Lindner, Simon Wunderlich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see http://www.gnu.org/licenses/. - * - * This file contains macros for maintaining compatibility with older versions - * of the Linux kernel. - */ - -#include <linux/in.h> -#include <linux/version.h> -#include "main.h" - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) - -void batadv_free_rcu_orig_vlan(struct rcu_head *rcu) -{ - struct batadv_orig_node_vlan *vlan; - - vlan = container_of(rcu, struct batadv_orig_node_vlan, rcu); - - kfree(vlan); -} - -void batadv_free_rcu_softif_vlan(struct rcu_head *rcu) -{ - struct batadv_softif_vlan *vlan; - - vlan = container_of(rcu, struct batadv_softif_vlan, rcu); - - kfree(vlan); -} - -void batadv_free_rcu_vlan(struct rcu_head *rcu) -{ - struct batadv_softif_vlan *vlan; - - vlan = container_of(rcu, struct batadv_softif_vlan, rcu); - - kfree(vlan); -} - -void batadv_free_rcu_tt_global_entry(struct rcu_head *rcu) -{ - struct batadv_tt_global_entry *global; - - global = container_of(rcu, struct batadv_tt_global_entry, common.rcu); - - kfree(global); -} - -void batadv_free_rcu_gw_node(struct rcu_head *rcu) -{ - struct batadv_gw_node *gw_node; - - gw_node = container_of(rcu, struct batadv_gw_node, rcu); - kfree(gw_node); -} - -void batadv_free_rcu_tt_local_entry(struct rcu_head *rcu) -{ - struct batadv_tt_common_entry *tt_common_entry; - struct batadv_tt_local_entry *tt_local_entry; - - tt_common_entry = container_of(rcu, struct batadv_tt_common_entry, rcu); - tt_local_entry = container_of(tt_common_entry, - struct batadv_tt_local_entry, common); - kfree(tt_local_entry); -} - -#ifdef CONFIG_BATMAN_ADV_BLA -void batadv_free_rcu_backbone_gw(struct rcu_head *rcu) -{ - struct batadv_bla_backbone_gw *backbone_gw; - - backbone_gw = container_of(rcu, struct batadv_bla_backbone_gw, rcu); - kfree(backbone_gw); -} -#endif - -#ifdef CONFIG_BATMAN_ADV_DAT -void batadv_free_rcu_dat_entry(struct rcu_head *rcu) -{ - struct batadv_dat_entry *dat_entry; - - dat_entry = container_of(rcu, struct batadv_dat_entry, rcu); - kfree(dat_entry); -} -#endif - -#ifdef CONFIG_BATMAN_ADV_NC -void batadv_free_rcu_nc_path(struct rcu_head *rcu) -{ - struct batadv_nc_path *nc_path; - - nc_path = container_of(rcu, struct batadv_nc_path, rcu); - kfree(nc_path); -} -#endif - -void batadv_free_rcu_tvlv_handler(struct rcu_head *rcu) -{ - struct batadv_tvlv_handler *tvlv_handler; - - tvlv_handler = container_of(rcu, struct batadv_tvlv_handler, rcu); - kfree(tvlv_handler); -} - -#endif /* < KERNEL_VERSION(3, 0, 0) */ diff --git a/compat.h b/compat.h index 9871a23..99e75c5 100644 --- a/compat.h +++ b/compat.h @@ -88,26 +88,6 @@ static const struct { \ #endif /* < KERNEL_VERSION(2, 6, 39) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) - -#define kfree_rcu(ptr, rcu_head) call_rcu(&ptr->rcu_head, batadv_free_rcu_##ptr) - -struct rcu_head; - -void batadv_free_rcu_orig_vlan(struct rcu_head *rcu); -void batadv_free_rcu_softif_vlan(struct rcu_head *rcu); -void batadv_free_rcu_tt_global_entry(struct rcu_head *rcu); -void batadv_free_rcu_gw_node(struct rcu_head *rcu); -void batadv_free_rcu_tt_local_entry(struct rcu_head *rcu); -void batadv_free_rcu_backbone_gw(struct rcu_head *rcu); -void batadv_free_rcu_dat_entry(struct rcu_head *rcu); -void batadv_free_rcu_nc_path(struct rcu_head *rcu); -void batadv_free_rcu_tvlv_handler(struct rcu_head *rcu); -void batadv_free_rcu_vlan(struct rcu_head *rcu); - -#endif /* < KERNEL_VERSION(3, 0, 0) */ - - #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
#define batadv_interface_add_vid(x, y, z) \
On Friday, April 17, 2015 19:40:30 Sven Eckelmann wrote:
The kfree_rcu compat helper for old kernels require a special function that knows how to calculate the offsets to the actual data pointer to call kfree. These can either be manually provided or the GCC extension for nested functions can be used to automatically create a local function using a macro.
Signed-off-by: Sven Eckelmann sven@narfation.org
v4:
- rebased on top of master with merged patches from https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.html
v3: no change v2: no change
Makefile | 1 - compat-include/linux/rcupdate.h | 15 +++++ compat.c | 120
compat.h | 20 ------- 4 files changed, 15 insertions(+), 141 deletions(-) delete mode 100644 compat.c
Applied in revision 082c888.
Thanks, Marek
On Tuesday 21 April 2015 11:52:16 Marek Lindner wrote:
On Friday, April 17, 2015 19:40:30 Sven Eckelmann wrote:
The kfree_rcu compat helper for old kernels require a special function that knows how to calculate the offsets to the actual data pointer to call kfree. These can either be manually provided or the GCC extension for nested functions can be used to automatically create a local function using a macro.
Signed-off-by: Sven Eckelmann sven@narfation.org
v4:
rebased on top of master with merged patches from
https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.htm l
v3: no change v2: no change
Makefile | 1 - compat-include/linux/rcupdate.h | 15 +++++ compat.c | 120
compat.h | 20 -------
4 files changed, 15 insertions(+), 141 deletions(-) delete mode 100644 compat.c
Applied in revision 082c888.
The commit is also not the patch I've send you. compat-includes/ is also missing in this commit.
Kind regards, Sven
On Tuesday, April 21, 2015 08:35:37 Sven Eckelmann wrote:
4 files changed, 15 insertions(+), 141 deletions(-) delete mode 100644 compat.c
Applied in revision 082c888.
The commit is also not the patch I've send you. compat-includes/ is also missing in this commit.
Thanks for letting me know! Should be fixed now.
Cheers, Marek
The current approach for the compat layer is to include the compat.h file at exactly the right time to provide additional functionality and to live patch the batman-adv sources. This has the problem that the compat.h file becomes harder to read over time. Also live patching and adding of missing functionality partially conflict. This becomes obvious when the include order in some files is different compared to the one the author of an compat.h entry expected.
A different approach is to inject intermediate header files which add additional features. This allows to reduce the size of compat.h and only leaves the live patching part in it. The compat.h can then added automatically to each compile run before anything else is included. compat.h has therefore the control which headers must be included before the live patching of the batman-adv source can begin.
Signed-off-by: Sven Eckelmann sven@narfation.org --- v5: rebased on top of 9f01c16a4409e43e86629418fae9184fabb59da5 v4: * rebased on top of master with merged patches from https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2015-April/012985.html * moved newly added dev_get_iflink to compat-include/linux/netdevice.h v3: no change v2: no change
Makefile | 4 + compat-include/linux/atomic.h | 29 +++ compat-include/linux/bug.h | 38 ++++ compat-include/linux/compiler.h | 40 ++++ compat-include/linux/etherdevice.h | 45 +++++ compat-include/linux/export.h | 29 +++ compat-include/linux/if_ether.h | 33 ++++ compat-include/linux/if_vlan.h | 44 +++++ compat-include/linux/kconfig.h | 42 ++++ compat-include/linux/kernel.h | 44 +++++ compat-include/linux/list.h | 54 ++++++ compat-include/linux/moduleparam.h | 72 +++++++ compat-include/linux/net.h | 39 ++++ compat-include/linux/netdev_features.h | 35 ++++ compat-include/linux/netdevice.h | 120 ++++++++++++ compat-include/linux/percpu.h | 48 +++++ compat-include/linux/printk.h | 39 ++++ compat-include/linux/random.h | 33 ++++ compat-include/linux/rculist.h | 49 +++++ compat-include/linux/rcupdate.h | 39 ++++ compat-include/linux/seq_file.h | 36 ++++ compat-include/linux/skbuff.h | 94 +++++++++ compat-include/linux/slab.h | 33 ++++ compat.h | 342 ++------------------------------- main.h | 2 +- 25 files changed, 1056 insertions(+), 327 deletions(-) create mode 100644 compat-include/linux/atomic.h create mode 100644 compat-include/linux/bug.h create mode 100644 compat-include/linux/compiler.h create mode 100644 compat-include/linux/etherdevice.h create mode 100644 compat-include/linux/export.h create mode 100644 compat-include/linux/if_ether.h create mode 100644 compat-include/linux/if_vlan.h create mode 100644 compat-include/linux/kconfig.h create mode 100644 compat-include/linux/kernel.h create mode 100644 compat-include/linux/list.h create mode 100644 compat-include/linux/moduleparam.h create mode 100644 compat-include/linux/net.h create mode 100644 compat-include/linux/netdev_features.h create mode 100644 compat-include/linux/netdevice.h create mode 100644 compat-include/linux/percpu.h create mode 100644 compat-include/linux/printk.h create mode 100644 compat-include/linux/random.h create mode 100644 compat-include/linux/rculist.h create mode 100644 compat-include/linux/rcupdate.h create mode 100644 compat-include/linux/seq_file.h create mode 100644 compat-include/linux/skbuff.h create mode 100644 compat-include/linux/slab.h
diff --git a/Makefile b/Makefile index 4f6c30a..fd7ae8d 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,10 @@ RM ?= rm -f REVISION= $(shell if [ -d "$(PWD)/.git" ]; then \ echo $$(git --git-dir="$(PWD)/.git" describe --always --dirty --match "v*" |sed 's/^v//' 2> /dev/null || echo "[unknown]"); \ fi) +NOSTDINC_FLAGS := \ + -I$(PWD)/compat-include/ \ + -include $(PWD)/compat.h \ + $(CFLAGS)
CONFIG_BATMAN_ADV=m batman-adv-y += compat.o diff --git a/compat-include/linux/atomic.h b/compat-include/linux/atomic.h new file mode 100644 index 0000000..304af51 --- /dev/null +++ b/compat-include/linux/atomic.h @@ -0,0 +1,29 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_ATOMIC_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_ATOMIC_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37) +#include_next <linux/atomic.h> +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_ATOMIC_H_ */ diff --git a/compat-include/linux/bug.h b/compat-include/linux/bug.h new file mode 100644 index 0000000..66f79f8 --- /dev/null +++ b/compat-include/linux/bug.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_BUG_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_BUG_H_ + +#include <linux/version.h> +#include_next <linux/bug.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) + +#undef BUILD_BUG_ON +#ifdef __CHECKER__ +#define BUILD_BUG_ON(condition) (0) +#else /* __CHECKER__ */ +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)])) +#endif /* __CHECKER__ */ + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_BUG_H_ */ diff --git a/compat-include/linux/compiler.h b/compat-include/linux/compiler.h new file mode 100644 index 0000000..1717105 --- /dev/null +++ b/compat-include/linux/compiler.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_COMPILER_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_COMPILER_H_ + +#include <linux/version.h> +#include_next <linux/compiler.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define __always_unused __attribute__((unused)) +#define __percpu + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) + +#define __rcu + +#endif /* < KERNEL_VERSION(2, 6, 36) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_COMPILER_H_ */ diff --git a/compat-include/linux/etherdevice.h b/compat-include/linux/etherdevice.h new file mode 100644 index 0000000..c20b43c --- /dev/null +++ b/compat-include/linux/etherdevice.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_ETHERDEVICE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_ETHERDEVICE_H_ + +#include <linux/version.h> +#include_next <linux/etherdevice.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) + +#define eth_hw_addr_random(dev) batadv_eth_hw_addr_random(dev) + +static inline void batadv_eth_hw_addr_random(struct net_device *dev) +{ + random_ether_addr(dev->dev_addr); +} + +#endif /* < KERNEL_VERSION(3, 4, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) + +#define ether_addr_equal_unaligned(_a, _b) (memcmp(_a, _b, ETH_ALEN) == 0) +#define ether_addr_copy(_a, _b) memcpy(_a, _b, ETH_ALEN) + +#endif /* < KERNEL_VERSION(3, 14, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_ETHERDEVICE_H_ */ diff --git a/compat-include/linux/export.h b/compat-include/linux/export.h new file mode 100644 index 0000000..3b31a2d --- /dev/null +++ b/compat-include/linux/export.h @@ -0,0 +1,29 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_EXPORT_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_EXPORT_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0) +#include_next <linux/export.h> +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_EXPORT_H_ */ diff --git a/compat-include/linux/if_ether.h b/compat-include/linux/if_ether.h new file mode 100644 index 0000000..5ea164f --- /dev/null +++ b/compat-include/linux/if_ether.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_IF_ETHER_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_IF_ETHER_H_ + +#include <linux/version.h> +#include_next <linux/if_ether.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) + +#define ETH_P_BATMAN 0x4305 + +#endif /* < KERNEL_VERSION(3, 8, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_IF_ETHER_H_ */ diff --git a/compat-include/linux/if_vlan.h b/compat-include/linux/if_vlan.h new file mode 100644 index 0000000..3b146b4 --- /dev/null +++ b/compat-include/linux/if_vlan.h @@ -0,0 +1,44 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ + +#include <linux/version.h> +#include_next <linux/if_vlan.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ +#define VLAN_PRIO_SHIFT 13 + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) + +#define vlan_insert_tag(skb, proto, vid) __vlan_put_tag(skb, vid) + +#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) + +#define vlan_insert_tag(skb, proto, vid) vlan_insert_tag(skb, vid) + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_IF_VLAN_H_ */ diff --git a/compat-include/linux/kconfig.h b/compat-include/linux/kconfig.h new file mode 100644 index 0000000..be8aa02 --- /dev/null +++ b/compat-include/linux/kconfig.h @@ -0,0 +1,42 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_KCONFIG_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_KCONFIG_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0) +#include_next <linux/kconfig.h> +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) + +#define __ARG_PLACEHOLDER_1 0, +#define config_enabled(cfg) _config_enabled(cfg) +#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) +#define ___config_enabled(__ignored, val, ...) val + +#define IS_ENABLED(option) \ + (config_enabled(option) || config_enabled(option##_MODULE)) + +#endif /* < KERNEL_VERSION(3, 1, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_KCONFIG_H_ */ diff --git a/compat-include/linux/kernel.h b/compat-include/linux/kernel.h new file mode 100644 index 0000000..81b2862 --- /dev/null +++ b/compat-include/linux/kernel.h @@ -0,0 +1,44 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_KERNEL_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_KERNEL_H_ + +#include <linux/version.h> +#include_next <linux/kernel.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) + +#define kstrtou32(cp, base, v)\ +({\ + unsigned long _v;\ + int _r;\ + _r = strict_strtoul(cp, base, &_v);\ + *(v) = (uint32_t)_v;\ + if ((unsigned long)*(v) != _v)\ + _r = -ERANGE;\ + _r;\ +}) +#define kstrtoul strict_strtoul +#define kstrtol strict_strtol + +#endif /* < KERNEL_VERSION(2, 6, 39) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_KERNEL_H_ */ diff --git a/compat-include/linux/list.h b/compat-include/linux/list.h new file mode 100644 index 0000000..dcd604c --- /dev/null +++ b/compat-include/linux/list.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_LIST_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_LIST_H_ + +#include <linux/version.h> +#include_next <linux/list.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +#undef hlist_for_each_entry +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +#undef hlist_for_each_entry_safe +#define hlist_for_each_entry_safe(pos, n, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ + pos && ({ n = pos->member.next; 1; }); \ + pos = hlist_entry_safe(n, typeof(*pos), member)) + +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) + +#define hlist_add_behind(n, prev) hlist_add_after(prev, n) + +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_LIST_H_ */ diff --git a/compat-include/linux/moduleparam.h b/compat-include/linux/moduleparam.h new file mode 100644 index 0000000..fd8ac41 --- /dev/null +++ b/compat-include/linux/moduleparam.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_MODULEPARAM_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_MODULEPARAM_H_ + +#include <linux/version.h> +#include_next <linux/moduleparam.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) + +#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ + __module_param_call(p1, p2, p3, p4, p5, p7) + +#else + +#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ + __module_param_call(p1, p2, p3, p4, p5, p6, p7) + +#endif /* < KERNEL_VERSION(2, 6, 31) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) + +struct kernel_param_ops { + /* Returns 0, or -errno. arg is in kp->arg. */ + int (*set)(const char *val, const struct kernel_param *kp); + /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ + int (*get)(char *buffer, struct kernel_param *kp); + /* Optional function to free kp->arg when module unloaded. */ + void (*free)(void *arg); +}; + +#define module_param_cb(name, ops, arg, perm) \ + static int __compat_set_param_##name(const char *val, \ + struct kernel_param *kp) \ + { return (ops)->set(val, kp); } \ + static int __compat_get_param_##name(char *buffer, \ + struct kernel_param *kp) \ + { return (ops)->get(buffer, kp); } \ + __compat__module_param_call(MODULE_PARAM_PREFIX, name, \ + __compat_set_param_##name, \ + __compat_get_param_##name, arg, \ + __same_type((arg), bool *), perm) + +static inline int batadv_param_set_copystring(const char *val, + const struct kernel_param *kp) +{ + return param_set_copystring(val, (struct kernel_param *)kp); +} + +#define param_set_copystring batadv_param_set_copystring + +#endif /* < KERNEL_VERSION(2, 6, 36) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_MODULEPARAM_H_ */ diff --git a/compat-include/linux/net.h b/compat-include/linux/net.h new file mode 100644 index 0000000..fcd7873 --- /dev/null +++ b/compat-include/linux/net.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NET_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NET_H_ + +#include <linux/version.h> +#include_next <linux/net.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) + +#ifndef net_ratelimited_function +#define net_ratelimited_function(func, ...) \ + do { \ + if (net_ratelimit()) \ + func(__VA_ARGS__); \ + } while (0) +#endif /* ifndef net_ratelimited_function */ + +#endif /* < KERNEL_VERSION(3, 5, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NET_H_ */ diff --git a/compat-include/linux/netdev_features.h b/compat-include/linux/netdev_features.h new file mode 100644 index 0000000..36c9c2f --- /dev/null +++ b/compat-include/linux/netdev_features.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETDEV_FEATURES_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETDEV_FEATURES_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0) +#include_next <linux/netdev_features.h> +#endif /* >= KERNEL_VERSION(3, 3, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) + +#define NETIF_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_FILTER + +#endif /* < KERNEL_VERSION(3, 10, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETDEV_FEATURES_H_ */ diff --git a/compat-include/linux/netdevice.h b/compat-include/linux/netdevice.h new file mode 100644 index 0000000..8d77bd8 --- /dev/null +++ b/compat-include/linux/netdevice.h @@ -0,0 +1,120 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETDEVICE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETDEVICE_H_ + +#include <linux/version.h> +#include_next <linux/netdevice.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) + +#include <linux/netdev_features.h> + +#endif /* < KERNEL_VERSION(3, 3, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev) + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) + +#include <linux/etherdevice.h> + +#undef netdev_for_each_mc_addr +#define netdev_for_each_mc_addr(mclist, dev) \ + for (mclist = (struct batadv_dev_addr_list *)dev->mc_list; mclist; \ + mclist = (struct batadv_dev_addr_list *)mclist->next) + +/* Note, that this breaks the usage of the normal 'struct netdev_hw_addr' + * for kernels < 2.6.35 in batman-adv! + */ +#define netdev_hw_addr batadv_dev_addr_list +struct batadv_dev_addr_list { + struct dev_addr_list *next; + u8 addr[MAX_ADDR_LEN]; + u8 da_addrlen; + u8 da_synced; + int da_users; + int da_gusers; +}; + +#endif /* < KERNEL_VERSION(2, 6, 35) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) + +#define NET_ADDR_RANDOM 0 + +#endif /* < KERNEL_VERSION(2, 6, 36) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) + +/* On older kernels net_dev->master is reserved for iface bonding. */ +static inline int batadv_netdev_set_master(struct net_device *slave, + struct net_device *master) +{ + return 0; +} + +#define netdev_set_master batadv_netdev_set_master + +#endif /* < KERNEL_VERSION(2, 6, 39) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#define netdev_master_upper_dev_link netdev_set_master +#define netdev_upper_dev_unlink(slave, master) netdev_set_master(slave, NULL) +#define netdev_master_upper_dev_get(dev) \ +({\ + ASSERT_RTNL();\ + dev->master;\ +}) + +#endif /* < KERNEL_VERSION(3, 9, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) + +#define netdev_notifier_info_to_dev(ptr) ptr + +#endif /* < KERNEL_VERSION(3, 11, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) + +/* alloc_netdev() was defined differently before 2.6.38 */ +#undef alloc_netdev +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) +#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ + alloc_netdev_mq(sizeof_priv, name, setup, 1) +#else +#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ + alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1) +#endif /* nested < KERNEL_VERSION(2, 6, 38) */ + +#endif /* < KERNEL_VERSION(3, 17, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0) + +#define dev_get_iflink(_net_dev) ((_net_dev)->iflink) + +#endif /* < KERNEL_VERSION(3, 19, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETDEVICE_H_ */ diff --git a/compat-include/linux/percpu.h b/compat-include/linux/percpu.h new file mode 100644 index 0000000..82355e4 --- /dev/null +++ b/compat-include/linux/percpu.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_PERCPU_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_PERCPU_H_ + +#include <linux/version.h> +#include_next <linux/percpu.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) + +#undef __alloc_percpu +#define __alloc_percpu(size, align) \ + percpu_alloc_mask((size), GFP_KERNEL, cpu_possible_map) + +#endif /* < KERNEL_VERSION(2, 6, 30) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +#define this_cpu_add(x, c) batadv_this_cpu_add(&(x), c) + +static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count) +{ + int cpu = get_cpu(); + *per_cpu_ptr(count_ptr, cpu) += count; + put_cpu(); +} + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_PERCPU_H_ */ diff --git a/compat-include/linux/printk.h b/compat-include/linux/printk.h new file mode 100644 index 0000000..c69c406 --- /dev/null +++ b/compat-include/linux/printk.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_PRINTK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_PRINTK_H_ + +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37) +#include_next <linux/printk.h> +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) + +#define pr_warn pr_warning + +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_PRINTK_H_ */ + +#ifndef pr_fmt +#define pr_fmt(fmt) fmt +#endif diff --git a/compat-include/linux/random.h b/compat-include/linux/random.h new file mode 100644 index 0000000..ce12f1a --- /dev/null +++ b/compat-include/linux/random.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_RANDOM_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_RANDOM_H_ + +#include <linux/version.h> +#include_next <linux/random.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#define prandom_u32() random32() + +#endif /* < KERNEL_VERSION(3, 9, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_RANDOM_H_ */ diff --git a/compat-include/linux/rculist.h b/compat-include/linux/rculist.h new file mode 100644 index 0000000..4736db1 --- /dev/null +++ b/compat-include/linux/rculist.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_RCULIST_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_RCULIST_H_ + +#include <linux/version.h> +#include_next <linux/rculist.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) + +#define hlist_first_rcu(head) \ + (*((struct hlist_node __rcu **)(&(head)->first))) + +#define hlist_next_rcu(node) \ + (*((struct hlist_node __rcu **)(&(node)->next))) + +#endif /* < KERNEL_VERSION(2, 6, 37) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) + +#undef hlist_for_each_entry_rcu +#define hlist_for_each_entry_rcu(pos, head, member) \ + for (pos = hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(head)),\ + typeof(*(pos)), member); \ + pos; \ + pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ + &(pos)->member)), typeof(*(pos)), member)) + +#endif + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_RCULIST_H_ */ diff --git a/compat-include/linux/rcupdate.h b/compat-include/linux/rcupdate.h new file mode 100644 index 0000000..f3ed948 --- /dev/null +++ b/compat-include/linux/rcupdate.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_RCUPDATE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_RCUPDATE_H_ + +#include <linux/version.h> +#include_next <linux/rcupdate.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) + +#define rcu_dereference_protected(p, c) (p) + +#define rcu_dereference_raw(p) ({ \ + typeof(p) _________p1 = ACCESS_ONCE(p); \ + smp_read_barrier_depends(); \ + (_________p1); \ + }) + +#endif /* < KERNEL_VERSION(2, 6, 34) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_RCUPDATE_H_ */ diff --git a/compat-include/linux/seq_file.h b/compat-include/linux/seq_file.h new file mode 100644 index 0000000..5eaaec8 --- /dev/null +++ b/compat-include/linux/seq_file.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_SEQ_FILE_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_SEQ_FILE_H_ + +#include <linux/version.h> +#include_next <linux/seq_file.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) + +static inline bool seq_has_overflowed(struct seq_file *m) +{ + return m->count == m->size; +} + +#endif /* < KERNEL_VERSION(3, 19, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_SEQ_FILE_H_ */ diff --git a/compat-include/linux/skbuff.h b/compat-include/linux/skbuff.h new file mode 100644 index 0000000..ed911ef --- /dev/null +++ b/compat-include/linux/skbuff.h @@ -0,0 +1,94 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_SKBUFF_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_SKBUFF_H_ + +#include <linux/version.h> +#include_next <linux/skbuff.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) + +#define consume_skb(_skb) kfree_skb(_skb) + +#endif /* < KERNEL_VERSION(2, 6, 30) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) + +static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, + unsigned int length) +{ + struct sk_buff *skb = netdev_alloc_skb(dev, length + NET_IP_ALIGN); + + if (NET_IP_ALIGN && skb) + skb_reserve(skb, NET_IP_ALIGN); + return skb; +} + +#endif /* < KERNEL_VERSION(2, 6, 33) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) + +static inline void skb_reset_mac_len(struct sk_buff *skb) +{ + skb->mac_len = skb->network_header - skb->mac_header; +} + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) + +/* hack for not correctly set mac_len. This may happen for some special + * configurations like batman-adv on VLANs. + * + * This is pretty dirty, but we only use skb_share_check() in main.c right + * before mac_len is checked, and the recomputation shouldn't hurt too much. + */ +#define skb_share_check(skb, b) \ + ({ \ + struct sk_buff *_t_skb; \ + _t_skb = skb_share_check(skb, b); \ + if (_t_skb) \ + skb_reset_mac_len(_t_skb); \ + _t_skb; \ + }) + +#endif /* < KERNEL_VERSION(3, 8, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) + +/* older kernels still need to call skb_abort_seq_read() */ +#define skb_seq_read(consumed, data, st) \ + ({ \ + int __len = skb_seq_read(consumed, data, st); \ + if (__len == 0) \ + skb_abort_seq_read(st); \ + __len; \ + }) + +#endif /* < KERNEL_VERSION(3, 11, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) + +#define pskb_copy_for_clone pskb_copy + +#endif /* < KERNEL_VERSION(3, 16, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_SKBUFF_H_ */ diff --git a/compat-include/linux/slab.h b/compat-include/linux/slab.h new file mode 100644 index 0000000..569c5aa --- /dev/null +++ b/compat-include/linux/slab.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see http://www.gnu.org/licenses/. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_ + +#include <linux/version.h> +#include_next <linux/slab.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) + +#define kmalloc_array(n, size, flags) kmalloc(n * size, flags) + +#endif /* < KERNEL_VERSION(3, 4, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_ */ diff --git a/compat.h b/compat.h index 98b9612..35e3dbd 100644 --- a/compat.h +++ b/compat.h @@ -22,30 +22,7 @@ #define _NET_BATMAN_ADV_COMPAT_H_
#include <linux/version.h> /* LINUX_VERSION_CODE */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) - -#define consume_skb(_skb) kfree_skb(_skb) - -#undef __alloc_percpu -#define __alloc_percpu(size, align) \ - percpu_alloc_mask((size), GFP_KERNEL, cpu_possible_map) - -#endif /* < KERNEL_VERSION(2, 6, 30) */ - - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) - -#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ - __module_param_call(p1, p2, p3, p4, p5, p7) - -#else - -#define __compat__module_param_call(p1, p2, p3, p4, p5, p6, p7) \ - __module_param_call(p1, p2, p3, p4, p5, p6, p7) - -#endif /* < KERNEL_VERSION(2, 6, 31) */ - +#include <linux/kconfig.h>
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) #include <linux/autoconf.h> @@ -56,154 +33,47 @@
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
-#define __always_unused __attribute__((unused)) -#define __percpu - #define skb_iif iif
-#define this_cpu_add(x, c) batadv_this_cpu_add(&(x), c) - -static inline void batadv_this_cpu_add(uint64_t *count_ptr, size_t count) -{ - int cpu = get_cpu(); - *per_cpu_ptr(count_ptr, cpu) += count; - put_cpu(); -} - #define batadv_softif_destroy_netlink(dev, head) batadv_softif_destroy_netlink(dev) -#define unregister_netdevice_queue(dev, head) unregister_netdevice(dev) - -static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, - unsigned int length) -{ - struct sk_buff *skb = netdev_alloc_skb(dev, length + NET_IP_ALIGN); - - if (NET_IP_ALIGN && skb) - skb_reserve(skb, NET_IP_ALIGN); - return skb; -} - -#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ -#define VLAN_PRIO_SHIFT 13
#endif /* < KERNEL_VERSION(2, 6, 33) */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) - -#define rcu_dereference_protected(p, c) (p) - -#define rcu_dereference_raw(p) ({ \ - typeof(p) _________p1 = ACCESS_ONCE(p); \ - smp_read_barrier_depends(); \ - (_________p1); \ - }) - -#endif /* < KERNEL_VERSION(2, 6, 34) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) +#include <linux/netdevice.h>
-#define pr_warn pr_warning +#define netdev_master_upper_dev_get_rcu(dev) \ + (dev->br_port ? dev : NULL); \ + break;
-#undef netdev_for_each_mc_addr -#define netdev_for_each_mc_addr(mclist, dev) \ - for (mclist = (struct batadv_dev_addr_list *)dev->mc_list; mclist; \ - mclist = (struct batadv_dev_addr_list *)mclist->next) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
-/* Note, that this breaks the usage of the normal 'struct netdev_hw_addr' - * for kernels < 2.6.35 in batman-adv! - */ -#define netdev_hw_addr batadv_dev_addr_list -struct batadv_dev_addr_list { - struct dev_addr_list *next; - u8 addr[MAX_ADDR_LEN]; - u8 da_addrlen; - u8 da_synced; - int da_users; - int da_gusers; -}; +#include <linux/netdevice.h>
-#endif /* < KERNEL_VERSION(2, 6, 35) */ +#define netdev_master_upper_dev_get_rcu(dev) \ + (dev->priv_flags & IFF_BRIDGE_PORT ? dev : NULL); \ + break;
+#endif /* < KERNEL_VERSION(2, 6, 36) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
-#define __rcu #define IFF_BRIDGE_PORT 0 || (hard_iface->net_dev->br_port ? 1 : 0)
-struct kernel_param_ops { - /* Returns 0, or -errno. arg is in kp->arg. */ - int (*set)(const char *val, const struct kernel_param *kp); - /* Returns length written or -errno. Buffer is 4k (ie. be short!) */ - int (*get)(char *buffer, struct kernel_param *kp); - /* Optional function to free kp->arg when module unloaded. */ - void (*free)(void *arg); -}; - -#define module_param_cb(name, ops, arg, perm) \ - static int __compat_set_param_##name(const char *val, \ - struct kernel_param *kp) \ - { return (ops)->set(val, kp); } \ - static int __compat_get_param_##name(char *buffer, \ - struct kernel_param *kp) \ - { return (ops)->get(buffer, kp); } \ - __compat__module_param_call(MODULE_PARAM_PREFIX, name, \ - __compat_set_param_##name, \ - __compat_get_param_##name, arg, \ - __same_type((arg), bool *), perm) - -static inline int batadv_param_set_copystring(const char *val, - const struct kernel_param *kp) -{ - return param_set_copystring(val, (struct kernel_param *)kp); -} -#define param_set_copystring batadv_param_set_copystring - /* hack for dev->addr_assign_type &= ~NET_ADDR_RANDOM; */ #define addr_assign_type ifindex -#define NET_ADDR_RANDOM 0 - -#define netdev_master_upper_dev_get_rcu(dev) \ - (dev->br_port ? dev : NULL); \ - break;
#endif /* < KERNEL_VERSION(2, 6, 36) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) - -#define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first))) -#define hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next))) - -#endif /* < KERNEL_VERSION(2, 6, 37) */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
-#define kstrtou32(cp, base, v)\ -({\ - unsigned long _v;\ - int _r;\ - _r = strict_strtoul(cp, base, &_v);\ - *(v) = (uint32_t)_v;\ - if ((unsigned long)*(v) != _v)\ - _r = -ERANGE;\ - _r;\ -}) -#define kstrtoul strict_strtoul -#define kstrtol strict_strtol - -/* On older kernels net_dev->master is reserved for iface bonding. */ -static inline int batadv_netdev_set_master(struct net_device *slave, - struct net_device *master) -{ - return 0; -} - -#define netdev_set_master batadv_netdev_set_master - /* Hack for removing ndo_add/del_slave at the end of net_device_ops. * This is somewhat ugly because it requires that ndo_validate_addr * is at the end of this struct in soft-interface.c. */ +#include <linux/netdevice.h> + #define ndo_validate_addr \ ndo_validate_addr = eth_validate_addr, \ }; \ @@ -223,7 +93,8 @@ static const struct { \ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0)
#define kfree_rcu(ptr, rcu_head) call_rcu(&ptr->rcu_head, batadv_free_rcu_##ptr) -#define vlan_insert_tag(skb, proto, vid) __vlan_put_tag(skb, vid) + +struct rcu_head;
void batadv_free_rcu_orig_vlan(struct rcu_head *rcu); void batadv_free_rcu_softif_vlan(struct rcu_head *rcu); @@ -236,32 +107,8 @@ void batadv_free_rcu_nc_path(struct rcu_head *rcu); void batadv_free_rcu_tvlv_handler(struct rcu_head *rcu); void batadv_free_rcu_vlan(struct rcu_head *rcu);
-static inline void skb_reset_mac_len(struct sk_buff *skb) -{ - skb->mac_len = skb->network_header - skb->mac_header; -} - -#undef BUILD_BUG_ON -#ifdef __CHECKER__ -#define BUILD_BUG_ON(condition) (0) -#else /* __CHECKER__ */ -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) -#endif /* __CHECKER__ */ - #endif /* < KERNEL_VERSION(3, 0, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) - -#define __ARG_PLACEHOLDER_1 0, -#define config_enabled(cfg) _config_enabled(cfg) -#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) -#define ___config_enabled(__ignored, val, ...) val - -#define IS_ENABLED(option) \ - (config_enabled(option) || config_enabled(option##_MODULE)) - -#endif /* < KERNEL_VERSION(3, 1, 0) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
@@ -288,56 +135,8 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
#endif /* < KERNEL_VERSION(3, 3, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) - -#define eth_hw_addr_random(dev) batadv_eth_hw_addr_random(dev) - -static inline void batadv_eth_hw_addr_random(struct net_device *dev) -{ - random_ether_addr(dev->dev_addr); -} - -#define kmalloc_array(n, size, flags) kmalloc(n * size, flags) - -#endif /* < KERNEL_VERSION(3, 4, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) - -#ifndef net_ratelimited_function -#define net_ratelimited_function(func, ...) \ - do { \ - if (net_ratelimit()) \ - func(__VA_ARGS__); \ - } while (0) -#endif /* ifndef net_ratelimited_function */ - -#endif /* < KERNEL_VERSION(3, 5, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) - -#define ETH_P_BATMAN 0x4305 - -/* hack for not correctly set mac_len. This may happen for some special - * configurations like batman-adv on VLANs. - * - * This is pretty dirty, but we only use skb_share_check() in main.c right - * before mac_len is checked, and the recomputation shouldn't hurt too much. - */ -#define skb_share_check(skb, b) \ - ({ \ - struct sk_buff *_t_skb; \ - _t_skb = skb_share_check(skb, b); \ - if (_t_skb) \ - skb_reset_mac_len(_t_skb); \ - _t_skb; \ - }) - -#endif /* < KERNEL_VERSION(3, 8, 0) */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
-#define prandom_u32() random32() - #define batadv_interface_set_mac_addr(x, y) \ __batadv_interface_set_mac_addr(struct net_device *dev, void *p);\ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p) \ @@ -362,61 +161,10 @@ static int batadv_interface_tx(struct sk_buff *skb, \ static int __batadv_interface_tx(struct sk_buff *skb, \ struct net_device *soft_iface)
-#define netdev_master_upper_dev_link netdev_set_master -#define netdev_upper_dev_unlink(slave, master) netdev_set_master(slave, NULL) -#define netdev_master_upper_dev_get(dev) \ -({\ - ASSERT_RTNL();\ - dev->master;\ -}) -#define hlist_entry_safe(ptr, type, member) \ - ({ typeof(ptr) ____ptr = (ptr); \ - ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ - }) - -#undef hlist_for_each_entry -#define hlist_for_each_entry(pos, head, member) \ - for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ - pos; \ - pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) - -#undef hlist_for_each_entry_rcu -#define hlist_for_each_entry_rcu(pos, head, member) \ - for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ - typeof(*(pos)), member); \ - pos; \ - pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ - &(pos)->member)), typeof(*(pos)), member)) - -#undef hlist_for_each_entry_safe -#define hlist_for_each_entry_safe(pos, n, head, member) \ - for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ - pos && ({ n = pos->member.next; 1; }); \ - pos = hlist_entry_safe(n, typeof(*pos), member)) - -#ifndef netdev_master_upper_dev_get_rcu -#define netdev_master_upper_dev_get_rcu(dev) \ - (dev->priv_flags & IFF_BRIDGE_PORT ? dev : NULL); \ - break; - -#endif /* netdev_master_upper_dev_get_rcu */ - #endif /* < KERNEL_VERSION(3, 9, 0) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
-#ifndef vlan_insert_tag - -/* include this header early to let the following define - * not mess up the original function prototype. - */ -#include <linux/if_vlan.h> -#define vlan_insert_tag(skb, proto, vid) vlan_insert_tag(skb, vid) - -#endif /* vlan_insert_tag */ - -#define NETIF_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_FILTER - #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
#define batadv_interface_add_vid(x, y, z) \ @@ -444,62 +192,4 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
#endif /* < KERNEL_VERSION(3, 10, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) - -#define netdev_notifier_info_to_dev(ptr) ptr - -/* older kernels still need to call skb_abort_seq_read() */ -#define skb_seq_read(consumed, data, st) \ - ({ \ - int __len = skb_seq_read(consumed, data, st); \ - if (__len == 0) \ - skb_abort_seq_read(st); \ - __len; \ - }) -#endif /* < KERNEL_VERSION(3, 11, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) - -#define ether_addr_equal_unaligned(_a, _b) (memcmp(_a, _b, ETH_ALEN) == 0) -#define ether_addr_copy(_a, _b) memcpy(_a, _b, ETH_ALEN) - -#endif /* < KERNEL_VERSION(3, 14, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) - -#define pskb_copy_for_clone pskb_copy - -#endif /* < KERNEL_VERSION(3, 16, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) - -#define hlist_add_behind(n, prev) hlist_add_after(prev, n) - -/* alloc_netdev() was defined differently before 2.6.38 */ -#undef alloc_netdev -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) -#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ - alloc_netdev_mq(sizeof_priv, name, setup, 1) -#else -#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \ - alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1) -#endif /* nested < KERNEL_VERSION(2, 6, 38) */ - -#endif /* < KERNEL_VERSION(3, 17, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) - -static inline bool seq_has_overflowed(struct seq_file *m) -{ - return m->count == m->size; -} - -#endif /* < KERNEL_VERSION(3, 19, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0) - -#define dev_get_iflink(_net_dev) ((_net_dev)->iflink) - -#endif /* < KERNEL_VERSION(4, 1, 0) */ - #endif /* _NET_BATMAN_ADV_COMPAT_H_ */ diff --git a/main.h b/main.h index 569846b..1d5340c 100644 --- a/main.h +++ b/main.h @@ -182,7 +182,7 @@ enum batadv_uev_type { #include <linux/jiffies.h> #include <linux/seq_file.h> #include <linux/if_vlan.h> -#include "compat.h" +#include <linux/printk.h>
#include "types.h"
On Friday, April 17, 2015 19:40:27 Sven Eckelmann wrote:
The current approach for the compat layer is to include the compat.h file at exactly the right time to provide additional functionality and to live patch the batman-adv sources. This has the problem that the compat.h file becomes harder to read over time. Also live patching and adding of missing functionality partially conflict. This becomes obvious when the include order in some files is different compared to the one the author of an compat.h entry expected.
A different approach is to inject intermediate header files which add additional features. This allows to reduce the size of compat.h and only leaves the live patching part in it. The compat.h can then added automatically to each compile run before anything else is included. compat.h has therefore the control which headers must be included before the live patching of the batman-adv source can begin.
Signed-off-by: Sven Eckelmann sven@narfation.org
Applied in revision 8746f0f.
Thanks, Marek
On Tuesday 21 April 2015 11:41:48 Marek Lindner wrote:
On Friday, April 17, 2015 19:40:27 Sven Eckelmann wrote:
The current approach for the compat layer is to include the compat.h file at exactly the right time to provide additional functionality and to live patch the batman-adv sources. This has the problem that the compat.h file becomes harder to read over time. Also live patching and adding of missing functionality partially conflict. This becomes obvious when the include order in some files is different compared to the one the author of an compat.h entry expected.
A different approach is to inject intermediate header files which add additional features. This allows to reduce the size of compat.h and only leaves the live patching part in it. The compat.h can then added automatically to each compile run before anything else is included. compat.h has therefore the control which headers must be included before the live patching of the batman-adv source can begin.
Signed-off-by: Sven Eckelmann sven@narfation.org
Applied in revision 8746f0f.
The patch you've added is not the one I've send. All files in compat-include are missing now in your commit.
Btw. I had prepared a patch v5 which fixed some merge conflicts with the state of the next from yesterday.
Kind regards, Sven
On Tuesday, April 21, 2015 08:19:56 Sven Eckelmann wrote:
A different approach is to inject intermediate header files which add additional features. This allows to reduce the size of compat.h and only leaves the live patching part in it. The compat.h can then added automatically to each compile run before anything else is included. compat.h has therefore the control which headers must be included before the live patching of the batman-adv source can begin.
Signed-off-by: Sven Eckelmann sven@narfation.org
Applied in revision 8746f0f.
The patch you've added is not the one I've send. All files in compat-include are missing now in your commit.
Btw. I had prepared a patch v5 which fixed some merge conflicts with the state of the next from yesterday.
I had seen that patch only after I had fought my way through the merge conflicts. Not without side effects it seems. Should be fixed now.
Cheers, Marek
b.a.t.m.a.n@lists.open-mesh.org