gentoo/net-firewall/iptables/iptables-9999.ebuild

180 lines
4.3 KiB
Bash
Raw Permalink Normal View History

2023-05-02 17:50:48 +02:00
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
2022-07-15 16:44:57 +02:00
EAPI=8
2022-07-15 16:44:57 +02:00
inherit systemd toolchain-funcs autotools flag-o-matic usr-ldscript git-r3
2015-08-21 15:17:46 +02:00
DESCRIPTION="Linux kernel (2.4+) firewall, NAT and packet mangling tools"
HOMEPAGE="https://www.netfilter.org/projects/iptables/"
EGIT_REPO_URI="git://git.netfilter.org/iptables.git"
LICENSE="GPL-2"
# Subslot reflects PV when libxtables and/or libip*tc was changed
# the last time.
SLOT="0/1.8.3"
KEYWORDS=""
2022-07-15 16:44:57 +02:00
IUSE="conntrack netlink nftables pcap static-libs"
2018-03-07 21:04:02 +01:00
COMMON_DEPEND="
conntrack? ( >=net-libs/libnetfilter_conntrack-1.0.6 )
netlink? ( net-libs/libnfnetlink )
nftables? (
2022-07-15 16:44:57 +02:00
>=net-libs/libmnl-1.0:=
>=net-libs/libnftnl-1.1.6:=
)
2015-08-21 15:17:46 +02:00
pcap? ( net-libs/libpcap )
"
2022-07-15 16:44:57 +02:00
DEPEND="
${COMMON_DEPEND}
virtual/os-headers
>=sys-kernel/linux-headers-4.4:0
"
BDEPEND="
virtual/pkgconfig
nftables? (
sys-devel/flex
2023-05-02 17:50:48 +02:00
app-alternatives/yacc
)
"
2022-07-15 16:44:57 +02:00
RDEPEND="
${COMMON_DEPEND}
2018-03-07 21:04:02 +01:00
nftables? ( net-misc/ethertypes )
2022-07-15 16:44:57 +02:00
!<net-firewall/ebtables-2.0.11-r1
!<net-firewall/arptables-0.0.5-r1
2018-03-07 21:04:02 +01:00
"
2022-07-15 16:44:57 +02:00
IDEPEND=">=app-eselect/eselect-iptables-20220320"
PATCHES=(
2023-05-02 17:50:48 +02:00
"${FILESDIR}"/${PN}-1.8.4-no-symlinks.patch
2022-07-15 16:44:57 +02:00
)
src_prepare() {
2022-07-15 16:44:57 +02:00
# Use the saner headers from the kernel
rm include/linux/{kernel,types}.h || die
2022-07-15 16:44:57 +02:00
default
eautoreconf
}
src_configure() {
2022-07-15 16:44:57 +02:00
# Some libs use $(AR) rather than libtool to build, bug #444282
tc-export AR
2022-07-15 16:44:57 +02:00
# Hack around struct mismatches between userland & kernel for some ABIs
# bug #472388
2015-08-21 15:17:46 +02:00
use amd64 && [[ ${ABI} == "x32" ]] && append-flags -fpack-struct
sed -i \
-e "/nfnetlink=[01]/s:=[01]:=$(usex netlink 1 0):" \
2015-08-21 15:17:46 +02:00
-e "/nfconntrack=[01]/s:=[01]:=$(usex conntrack 1 0):" \
configure || die
2018-03-07 21:04:02 +01:00
local myeconfargs=(
--sbindir="${EPREFIX}/sbin"
--libexecdir="${EPREFIX}/$(get_libdir)"
--enable-devel
2022-07-15 16:44:57 +02:00
--enable-ipv6
2018-03-07 21:04:02 +01:00
--enable-shared
$(use_enable nftables)
$(use_enable pcap bpf-compiler)
$(use_enable pcap nfsynproxy)
$(use_enable static-libs static)
)
2022-07-15 16:44:57 +02:00
2018-03-07 21:04:02 +01:00
econf "${myeconfargs[@]}"
}
src_compile() {
emake V=1
}
src_install() {
default
2022-07-15 16:44:57 +02:00
2023-05-02 17:50:48 +02:00
# Managed by eselect-iptables
# https://bugs.gentoo.org/881295
rm "${ED}/usr/bin/iptables-xml" || die
dodoc iptables/iptables.xslt
2022-07-15 16:44:57 +02:00
# All the iptables binaries are in /sbin, so might as well
# put these small files in with them
into /
dosbin iptables/iptables-apply
dosym iptables-apply /sbin/ip6tables-apply
doman iptables/iptables-apply.8
insinto /usr/include
2022-07-15 16:44:57 +02:00
doins include/ip{,6}tables.h
insinto /usr/include/iptables
doins include/iptables/internal.h
2022-07-15 16:44:57 +02:00
keepdir /var/lib/ip{,6}tables
newinitd "${FILESDIR}"/${PN}-r3.init iptables
newconfd "${FILESDIR}"/${PN}-r1.confd iptables
2022-07-15 16:44:57 +02:00
dosym iptables /etc/init.d/ip6tables
newconfd "${FILESDIR}"/ip6tables-r1.confd ip6tables
2018-03-07 21:04:02 +01:00
if use nftables; then
2022-07-15 16:44:57 +02:00
# Bug #647458
rm "${ED}"/etc/ethertypes || die
2022-07-15 16:44:57 +02:00
# Bugs #660886 and #669894
rm "${ED}"/sbin/{arptables,ebtables}{,-{save,restore}} || die
2018-03-07 21:04:02 +01:00
fi
2022-07-15 16:44:57 +02:00
systemd_dounit "${FILESDIR}"/systemd/ip{,6}tables-{re,}store.service
2022-07-15 16:44:57 +02:00
# Move important libs to /lib, bug #332175
2020-02-14 04:30:12 +01:00
gen_usr_ldscript -a ip{4,6}tc xtables
find "${ED}" -type f -name "*.la" -delete || die
}
2022-07-15 16:44:57 +02:00
pkg_postinst() {
local default_iptables="xtables-legacy-multi"
if ! eselect iptables show &>/dev/null; then
elog "Current iptables implementation is unset, setting to ${default_iptables}"
eselect iptables set "${default_iptables}"
fi
if use nftables; then
local tables
for tables in {arp,eb}tables; do
if ! eselect ${tables} show &>/dev/null; then
elog "Current ${tables} implementation is unset, setting to ${default_iptables}"
eselect ${tables} set xtables-nft-multi
fi
done
fi
eselect iptables show
}
pkg_prerm() {
if [[ -z ${REPLACED_BY_VERSION} ]]; then
elog "Unsetting iptables symlinks before removal"
eselect iptables unset
fi
if ! has_version 'net-firewall/ebtables'; then
elog "Unsetting ebtables symlinks before removal"
eselect ebtables unset
elif [[ -z ${REPLACED_BY_VERSION} ]]; then
elog "Resetting ebtables symlinks to ebtables-legacy"
eselect ebtables set ebtables-legacy
fi
if ! has_version 'net-firewall/arptables'; then
elog "Unsetting arptables symlinks before removal"
eselect arptables unset
elif [[ -z ${REPLACED_BY_VERSION} ]]; then
elog "Resetting arptables symlinks to arptables-legacy"
eselect arptables set arptables-legacy
fi
# The eselect module failing should not be fatal
return 0
}