1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 inherit eutils linux-info linux-mod multilib
9 DESCRIPTION="iptables extensions not yet accepted in the main kernel"
10 HOMEPAGE="http://xtables-addons.sourceforge.net/"
11 SRC_URI="mirror://sourceforge/xtables-addons/${P}.tar.xz"
15 KEYWORDS="~amd64 ~x86"
18 MODULES="quota2 psd pknock lscan length2 ipv4options ipp2p iface gradm geoip fuzzy condition tarpit sysrq logmark ipmark echo dnetmap dhcpmac delude chaos account"
20 for mod in ${MODULES}; do
21 IUSE="${IUSE} xtables_addons_${mod}"
24 DEPEND=">=net-firewall/iptables-1.4.5"
27 xtables_addons_geoip? (
30 virtual/perl-Getopt-Long
35 virtual/linux-sources"
39 XA_check4internal_module() {
42 local kconfigname=${3}
44 if use xtables_addons_${mod} && kernel_is -gt ${version}; then
45 ewarn "${kconfigname} should be provided by the kernel. Skipping its build..."
46 if ! linux_chkconfig_present ${kconfigname}; then
47 ewarn "Please enable ${kconfigname} target in your kernel
48 configuration or disable checksum module in ${PN}."
50 # SKIP_MODULES in case we need to disable building of everything
51 # like having this USE disabled
52 SKIP_MODULES+=" ${mod}"
59 check_modules_supported
60 CONFIG_CHECK="NF_CONNTRACK NF_CONNTRACK_MARK ~CONNECTOR"
61 ERROR_CONNECTOR="Please, enable CONFIG_CONNECTOR if you wish to receive userspace notifications from pknock through netlink/connector"
64 if ! linux_chkconfig_present IPV6; then
65 SKIP_IPV6_MODULES="ip6table_rawpost"
66 ewarn "No IPV6 support in kernel. Disabling: ${SKIP_IPV6_MODULES}"
68 kernel_is -lt 3 7 && die "${P} requires kernel version >= 3.7, if you have older kernel please use 1.x version instead"
72 # Helper for maintainer: cheks if all possible MODULES are listed.
75 all_modules=$(sed -n '/^build_/{s/build_\(.*\)=.*/\L\1/;G;s/\n/ /;s/ $//;h}; ${x;p}' "${S}/mconfig")
76 if [[ ${all_modules} != ${MODULES} ]]; then
77 ewarn "QA: Modules in mconfig differ from \$MODULES in ebuild."
78 ewarn "Please, update MODULES in ebuild."
79 ewarn "'${all_modules}'"
83 # Is there any use flag set?
84 XA_has_something_to_build() {
86 for mod in ${MODULES}; do
87 use xtables_addons_${mod} && return
90 eerror "All modules are disabled. What do you want me to build?"
91 eerror "Please, set XTABLES_ADDONS to any combination of"
93 die "All modules are disabled."
96 # Parse Kbuid files and generates list of sources
97 XA_get_module_name() {
98 [[ $# != 1 ]] && die "XA_get_sources_for_mod: needs exactly one argument."
99 local mod objdir build_mod sources_list
101 objdir=${S}/extensions
102 # Take modules name from mconfig
103 build_mod=$(sed -n "s/\(build_${mod}\)=.*/\1/Ip" "${S}/mconfig")
104 # strip .o, = and everything before = and print
105 sources_list=$(sed -n "/^obj-[$][{]${build_mod}[}]/\
106 {s:obj-[^+]\+ [+]=[[:space:]]*::;s:[.]o::g;p}" \
109 if [[ -d ${S}/extensions/${sources_list} ]]; then
110 objdir=${S}/extensions/${sources_list}
111 sources_list=$(sed -n "/^obj-m/\
112 {s:obj-[^+]\+ [+]=[[:space:]]*::;s:[.]o::g;p}" \
115 for mod_src in ${sources_list}; do
116 has ${mod_src} ${SKIP_IPV6_MODULES} || \
117 echo " ${mod_src}(xtables_addons:${S}/extensions:${objdir})"
121 # Die on modules known to fail on certain kernel version.
126 if use xtables_addons_${module_name} && kernel_is ge ${KV_max//./ }; then
128 eerror "XTABLES_ADDONS=${module_name} fails to build on linux ${KV_max} or above."
129 eerror "Either remove XTABLES_ADDONS=${module_name} or use an earlier version of the kernel."
137 XA_has_something_to_build
139 # Bug #553630#c2. echo fails on linux-4 and above.
140 # This appears to be fixed, at least as of linux-4.2
141 # XA_known_failure "echo" 4
143 local mod module_name
145 MODULE_NAMES="compat_xtables(xtables_addons:${S}/extensions:)"
147 for mod in ${MODULES}; do
148 if ! has ${mod} ${SKIP_MODULES} && use xtables_addons_${mod}; then
149 sed "s/\(build_${mod}=\).*/\1m/I" -i mconfig || die
151 for module_name in $(XA_get_module_name ${mod}); do
152 MODULE_NAMES+=" ${module_name}"
156 sed "s/\(build_${mod}=\).*/\1n/I" -i mconfig || die
159 einfo "${MODULE_NAMES}" # for debugging
161 sed -e 's/depmod -a/true/' -i Makefile.in || die
162 sed -e '/^all-local:/{s: modules::}' \
163 -e '/^install-exec-local:/{s: modules_install::}' \
164 -i extensions/Makefile.in || die
166 use xtables_addons_geoip || sed -e '/^SUBDIRS/{s/geoip//}' -i Makefile.in
170 set_arch_to_kernel # .. or it'll look for /arch/amd64/Makefile
171 econf --prefix="${EPREFIX}/" \
172 --libexecdir="${EPREFIX}/$(get_libdir)/" \
173 --with-kbuild="${KV_DIR}"
177 emake CFLAGS="${CFLAGS}" CC="$(tc-getCC)" V=1
178 use modules && BUILD_PARAMS="V=1" BUILD_TARGETS="modules" linux-mod_src_compile
182 emake DESTDIR="${D}" install
183 use modules && linux-mod_src_install
184 dodoc -r README doc/*
185 find "${ED}" -type f -name '*.la' -exec rm -rf '{}' '+'