1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit autotools linux-info systemd
8 DESCRIPTION="Linux kernel (3.13+) firewall, NAT and packet mangling tools"
9 HOMEPAGE="https://netfilter.org/projects/nftables/"
10 SRC_URI="https://git.netfilter.org/nftables/snapshot/v${PV}.tar.gz -> ${P}.tar.gz"
14 KEYWORDS="~amd64 ~arm ~arm64 ~ia64 ~x86"
15 IUSE="debug doc +gmp json +modern-kernel +readline"
17 RDEPEND=">=net-libs/libmnl-1.0.3:0=
18 gmp? ( dev-libs/gmp:0= )
19 json? ( dev-libs/jansson )
20 readline? ( sys-libs/readline:0= )
21 >=net-libs/libnftnl-1.1.1:0="
24 >=app-text/docbook2X-0.8.8-r4
25 doc? ( >=app-text/dblatex-0.3.7 )
33 if kernel_is ge 3 13; then
34 if use modern-kernel && kernel_is lt 3 18; then
35 eerror "The modern-kernel USE flag requires kernel version 3.18 or newer to work properly."
37 CONFIG_CHECK="~NF_TABLES"
40 eerror "This package requires kernel version 3.13 or newer to work properly."
51 --sbindir="${EPREFIX}"/sbin
53 $(use_enable doc pdf-doc)
54 $(use_with !gmp mini_gmp)
56 $(use_with readline cli)
58 econf "${myeconfargs[@]}"
65 use modern-kernel && mksuffix="-mk"
67 exeinto /usr/libexec/${PN}
68 newexe "${FILESDIR}"/libexec/${PN}${mksuffix}.sh ${PN}.sh
69 newconfd "${FILESDIR}"/${PN}${mksuffix}.confd ${PN}
70 newinitd "${FILESDIR}"/${PN}${mksuffix}.init ${PN}
71 keepdir /var/lib/nftables
73 systemd_dounit "${FILESDIR}"/systemd/${PN}-restore.service
76 dodoc "${D}"/etc/nftables/*
77 rm -R "${D}"/etc/nftables
82 save_file="${EROOT%/}/var/lib/nftables/rules-save"
84 # In order for the nftables-restore systemd service to start
85 # the save_file must exist.
86 if [[ ! -f "${save_file}" ]]; then
87 ( umask 177; touch "${save_file}" )
88 elif [[ $(( "$( stat --printf '%05a' "${save_file}" )" & 07177 )) -ne 0 ]]; then
89 ewarn "Your system has dangerous permissions for ${save_file}"
90 ewarn "It is probably affected by bug #691326."
91 ewarn "You may need to fix the permissions of the file. To do so,"
92 ewarn "you can run the command in the line below as root."
93 ewarn " 'chmod 600 \"${save_file}\"'"
96 elog "If you wish to enable the firewall rules on boot (on systemd) you"
97 elog "will need to enable the nftables-restore service."
98 elog " 'systemd_enable_service basic.target ${PN}-restore.service'"
100 elog "If you are creating firewall rules before the next system restart "
101 elog "the nftables-restore service must be manually started in order to "
102 elog "save those rules on shutdown."