Diff xtables-addons-3.24 with a xtables-addons-3.24-r1

/usr/portage/net-firewall/xtables-addons/xtables-addons-3.24-r1.ebuild 2023-10-09 14:52:34.428368475 +0300
1
# Copyright 1999-2023 Gentoo Authors
1
# Copyright 2023 Gentoo Authors
2 2
# Distributed under the terms of the GNU General Public License v2
3 3

  
4 4
EAPI=8
5 5

  
6
MODULES_OPTIONAL_USE=modules
7
MODULES_OPTIONAL_USE_IUSE_DEFAULT=1
8
inherit linux-info linux-mod multilib toolchain-funcs
6
MODULES_OPTIONAL_IUSE="+modules"
7
inherit flag-o-matic linux-mod-r1
8

  
9
XTABLES_MODULES=(
10
	account chaos delude dhcpmac dnetmap echo ipmark logmark
11
	proto sysrq tarpit asn condition fuzzy geoip gradm iface
12
	ipp2p ipv4options length2 lscan pknock psd quota2
13
)
14

  
15
MODULES_KERNEL_MIN=4.15
9 16

  
10 17
DESCRIPTION="iptables extensions not yet accepted in the main kernel"
11
HOMEPAGE="https://inai.de/projects/xtables-addons/ https://codeberg.org/jengelh/xtables-addons"
18
HOMEPAGE="
19
	https://inai.de/projects/xtables-addons/
20
	https://codeberg.org/jengelh/xtables-addons/
21
"
12 22
SRC_URI="https://inai.de/files/xtables-addons/${P}.tar.xz"
13 23

  
14
LICENSE="GPL-2"
24
LICENSE="GPL-2+"
15 25
SLOT="0"
16
KEYWORDS="amd64 x86"
26
KEYWORDS="~amd64 ~x86"
27
IUSE="${XTABLES_MODULES[*]/#/xtables_addons_}"
17 28

  
18
MODULES="quota2 psd pknock lscan length2 ipv4options ipp2p iface gradm geoip fuzzy condition tarpit sysrq proto logmark ipmark echo dnetmap dhcpmac delude chaos account"
19

  
20
for mod in ${MODULES}; do
21
	IUSE="${IUSE} xtables_addons_${mod}"
22
done
23

  
24
DEPEND=">=net-firewall/iptables-1.6.0"
25

  
26
RDEPEND="${DEPEND}
27
	xtables_addons_geoip? (
28
		app-arch/unzip
29
		dev-perl/Net-CIDR-Lite
30
		dev-perl/Text-CSV_XS
31
		virtual/perl-Getopt-Long
32
	)
29
XTABLES_SCRIPTS_DEPEND="
30
	app-arch/unzip
31
	dev-perl/Net-CIDR-Lite
32
	dev-perl/Text-CSV_XS
33
	virtual/perl-Getopt-Long
34
"
35
DEPEND="net-firewall/iptables:="
36
RDEPEND="
37
	${DEPEND}
38
	xtables_addons_asn? ( ${XTABLES_SCRIPTS_DEPEND} )
39
	xtables_addons_geoip? ( ${XTABLES_SCRIPTS_DEPEND} )
33 40
"
34

  
35
DEPEND="${DEPEND}
36
	virtual/linux-sources"
37

  
38
SKIP_MODULES=""
39

  
40
XA_check4internal_module() {
41
	local mod=${1}
42
	local version=${3}
43
	local kconfigname=${3}
44

  
45
	if use xtables_addons_${mod} && kernel_is -gt ${version}; then
46
		ewarn "${kconfigname} should be provided by the kernel. Skipping its build..."
47
		if ! linux_chkconfig_present ${kconfigname}; then
48
			ewarn "Please enable ${kconfigname} target in your kernel
49
			configuration or disable checksum module in ${PN}."
50
		fi
51
		# SKIP_MODULES in case we need to disable building of everything
52
		# like having this USE disabled
53
		SKIP_MODULES+=" ${mod}"
54
	fi
55
}
56 41

  
57 42
pkg_setup() {
58
	if use modules; then
59
		get_version
60
		check_modules_supported
61
		CONFIG_CHECK="NF_CONNTRACK NF_CONNTRACK_MARK ~CONNECTOR"
62
		ERROR_CONNECTOR="Please, enable CONFIG_CONNECTOR if you wish to receive userspace notifications from pknock through netlink/connector"
63
		linux-mod_pkg_setup
64

  
65
		if ! linux_chkconfig_present IPV6; then
66
			SKIP_IPV6_MODULES="ip6table_rawpost"
67
			ewarn "No IPV6 support in kernel. Disabling: ${SKIP_IPV6_MODULES}"
68
		fi
69
		kernel_is -lt 4 18 && die "${P} requires kernel version >= 4.18"
70
	fi
71
}
72

  
73
# Helper for maintainer: cheks if all possible MODULES are listed.
74
XA_qa_check() {
75
	local all_modules
76
	all_modules=$(sed -n '/^build_/{s/build_\(.*\)=.*/\L\1/;G;s/\n/ /;s/ $//;h}; ${x;p}' "${S}/mconfig")
77
	if [[ ${all_modules} != ${MODULES} ]]; then
78
		ewarn "QA: Modules in mconfig differ from \$MODULES in ebuild."
79
		ewarn "Please, update MODULES in ebuild."
80
		ewarn "'${all_modules}'"
81
	fi
82
}
83

  
84
# Is there any use flag set?
85
XA_has_something_to_build() {
86
	local mod
87
	for mod in ${MODULES}; do
88
		use xtables_addons_${mod} && return
89
	done
43
	local CONFIG_CHECK="NF_CONNTRACK NF_CONNTRACK_MARK"
90 44

  
91
	eerror "All modules are disabled. What do you want me to build?"
92
	eerror "Please, set XTABLES_ADDONS to any combination of"
93
	eerror "${MODULES}"
94
	die "All modules are disabled."
95
}
96

  
97
# Parse Kbuid files and generates list of sources
98
XA_get_module_name() {
99
	[[ $# != 1 ]] && die "XA_get_sources_for_mod: needs exactly one argument."
100
	local mod objdir build_mod sources_list
101
	mod=${1}
102
	objdir=${S}/extensions
103
	# Take modules name from mconfig
104
	build_mod=$(sed -n "s/\(build_${mod}\)=.*/\1/Ip" "${S}/mconfig")
105
	# strip .o, = and everything before = and print
106
	sources_list=$(sed -n "/^obj-[$][{]${build_mod}[}]/\
107
		{s:obj-[^+]\+ [+]=[[:space:]]*::;s:[.]o::g;p}" \
108
				"${objdir}/Kbuild")
109

  
110
	if [[ -d ${S}/extensions/${sources_list} ]]; then
111
		objdir=${S}/extensions/${sources_list}
112
		sources_list=$(sed -n "/^obj-m/\
113
			{s:obj-[^+]\+ [+]=[[:space:]]*::;s:[.]o::g;p}" \
114
				"${objdir}/Kbuild")
45
	if use xtables_addons_pknock; then
46
		CONFIG_CHECK+=" ~CONNECTOR"
47
		local ERROR_CONNECTOR="CONFIG_CONNECTOR: is not set but is needed to receive userspace
48
		notifications from pknock through netlink/connector"
115 49
	fi
116
	for mod_src in ${sources_list}; do
117
		has ${mod_src} ${SKIP_IPV6_MODULES} || \
118
			echo " ${mod_src}(xtables_addons:${S}/extensions:${objdir})"
119
	done
120
}
121 50

  
122
# Die on modules known to fail on certain kernel version.
123
XA_known_failure() {
124
	local module_name=$1
125
	local KV_max=$2
126

  
127
	if use xtables_addons_${module_name} && kernel_is ge ${KV_max//./ }; then
128
		eerror
129
		eerror "XTABLES_ADDONS=${module_name} fails to build on linux ${KV_max} or above."
130
		eerror "Either remove XTABLES_ADDONS=${module_name} or use an earlier version of the kernel."
131
		eerror
132
		die
133
	fi
51
	linux-mod-r1_pkg_setup
134 52
}
135 53

  
136 54
src_prepare() {
137
	XA_qa_check
138
	XA_has_something_to_build
139

  
140
	# Bug #553630#c2.  echo fails on linux-4 and above.
141
	# This appears to be fixed, at least as of linux-4.2
142
	# XA_known_failure "echo" 4
143

  
144
	local mod module_name
145
	if use modules; then
146
		MODULE_NAMES="compat_xtables(xtables_addons:${S}/extensions:)"
147
	fi
148
	for mod in ${MODULES}; do
149
		if ! has ${mod} ${SKIP_MODULES} && use xtables_addons_${mod}; then
150
			sed "s/\(build_${mod}=\).*/\1m/I" -i mconfig || die
151
			if use modules; then
152
				for module_name in $(XA_get_module_name ${mod}); do
153
					MODULE_NAMES+=" ${module_name}"
154
				done
155
			fi
156
		else
157
			sed "s/\(build_${mod}=\).*/\1n/I" -i mconfig || die
158
		fi
159
	done
160
	einfo "${MODULE_NAMES}" # for debugging
161

  
162
	sed -e 's/depmod -a/true/' -i Makefile.in || die
163
	sed -e '/^all-local:/{s: modules::}' \
164
		-e '/^install-exec-local:/{s: modules_install::}' \
165
			-i extensions/Makefile.in || die
55
	default
166 56

  
167
	use xtables_addons_geoip || sed  -e '/^SUBDIRS/{s/geoip//}' -i Makefile.in
57
	local mod modules
58
	mapfile -t modules < <(sed -En 's/^build_(.+)=.*/\L\1/p' mconfig || die)
59
	[[ ${modules[*]} == "${XTABLES_MODULES[*]}" ]] ||
60
		die "XTABLES_MODULES needs to be updated to: '${modules[*]}'"
168 61

  
169
	eapply_user
62
	for mod in "${modules[@]}"; do
63
		use xtables_addons_${mod} || sed -i "/^build_${mod}=/Id" mconfig || die
64
	done
170 65
}
171 66

  
172 67
src_configure() {
173
	set_arch_to_kernel # .. or it'll look for /arch/amd64/Makefile
174
	econf --prefix="${EPREFIX}/" \
175
		--libexecdir="${EPREFIX}/$(get_libdir)/" \
176
		--with-kbuild="${KV_OUT_DIR}"
68
	# Uses CFLAGS for tools, and it may mismatch with the kernel's CC
69
	# FIXME?: ideally would want to build tools with normal CC
70
	use modules && CC=${KERNEL_CC} strip-unsupported-flags
71

  
72
	local econfargs=(
73
		# TODO?: should move to ${EPREFIX}/usr + use default libexecdir by now
74
		# (matching documentation), but could be a disruptive change for users
75
		# with xt_asn/geoip_* paths they may have hardcoded in scripts
76
		--prefix="${EPREFIX:-/}"
77
		--libexecdir="${EPREFIX}"/$(get_libdir)
78
		$(usex modules --with-kbuild="${KV_OUT_DIR}" --without-kbuild)
79
	)
80

  
81
	econf "${econfargs[@]}"
177 82
}
178 83

  
179 84
src_compile() {
180
	emake CFLAGS="${CFLAGS}" CC="$(tc-getCC)" V=1
181
	use modules && BUILD_PARAMS="V=1" BUILD_TARGETS="modules" linux-mod_src_compile
85
	use modules || MODULES_MAKEARGS=()
86

  
87
	emake "${MODULES_MAKEARGS[@]}"
182 88
}
183 89

  
184 90
src_install() {
185
	emake DESTDIR="${D}" install
186
	use modules && linux-mod_src_install
187
	dodoc -r README.rst doc/*
188
	find "${ED}" -type f -name '*.la' -exec rm -rf '{}' '+'
91
	MODULES_MAKEARGS+=(
92
		DESTDIR="${D}"
93
		INSTALL_MOD_DIR=xtables_addons
94
	)
95

  
96
	emake "${MODULES_MAKEARGS[@]}" install
97
	modules_post_process
98

  
99
	dodoc -r README.rst doc/.
100

  
101
	use xtables_addons_asn ||
102
		find "${ED}" -type f -name '*_asn*' -delete || die
103
	use xtables_addons_geoip ||
104
		find "${ED}" -type f -name '*_geoip*' -delete || die
105

  
106
	find "${ED}" -type f -name '*.la' -delete || die
189 107
}
Thank you!