1da295319SPatrick WilliamsSUMMARY = "Tools for managing kernel packet filtering capabilities"
2da295319SPatrick WilliamsDESCRIPTION = "iptables is the userspace command line program used to configure and control network packet \
3da295319SPatrick Williamsfiltering code in Linux."
4da295319SPatrick WilliamsHOMEPAGE = "http://www.netfilter.org/"
5da295319SPatrick WilliamsBUGTRACKER = "http://bugzilla.netfilter.org/"
6da295319SPatrick WilliamsLICENSE = "GPL-2.0-or-later"
7da295319SPatrick WilliamsLIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
8da295319SPatrick Williams                    file://iptables/iptables.c;beginline=13;endline=25;md5=c5cffd09974558cf27d0f763df2a12dc \
9da295319SPatrick Williams"
10da295319SPatrick Williams
11da295319SPatrick WilliamsSRC_URI = "http://netfilter.org/projects/iptables/files/iptables-${PV}.tar.xz \
12da295319SPatrick Williams           file://iptables.service \
13da295319SPatrick Williams           file://iptables.rules \
14da295319SPatrick Williams           file://ip6tables.service \
15da295319SPatrick Williams           file://ip6tables.rules \
16da295319SPatrick Williams           file://0001-configure-Add-option-to-enable-disable-libnfnetlink.patch \
17da295319SPatrick Williams           "
18da295319SPatrick WilliamsSRC_URI[sha256sum] = "5cc255c189356e317d070755ce9371eb63a1b783c34498fb8c30264f3cc59c9c"
19da295319SPatrick Williams
20da295319SPatrick WilliamsSYSTEMD_SERVICE:${PN} = "\
21da295319SPatrick Williams    iptables.service \
22da295319SPatrick Williams    ${@bb.utils.contains('PACKAGECONFIG', 'ipv6', 'ip6tables.service', '', d)} \
23da295319SPatrick Williams"
24da295319SPatrick Williams
25da295319SPatrick Williamsinherit autotools pkgconfig systemd
26da295319SPatrick Williams
27da295319SPatrick WilliamsEXTRA_OECONF = "--with-kernel=${STAGING_INCDIR}"
28da295319SPatrick Williams
29da295319SPatrick WilliamsCFLAGS:append:libc-musl = " -D__UAPI_DEF_ETHHDR=0"
30da295319SPatrick Williams
31da295319SPatrick WilliamsPACKAGECONFIG ?= "${@bb.utils.filter('DISTRO_FEATURES', 'ipv6', d)}"
32da295319SPatrick WilliamsPACKAGECONFIG[ipv6] = "--enable-ipv6,--disable-ipv6,"
33da295319SPatrick Williams
34da295319SPatrick Williams# libnfnetlink recipe is in meta-networking layer
35*edff4923SAndrew GeisslerPACKAGECONFIG[libnfnetlink] = "--enable-libnfnetlink --enable-connlabel,--disable-libnfnetlink --disable-connlabel,libnfnetlink libnetfilter-conntrack"
36da295319SPatrick Williams
37da295319SPatrick Williams# libnftnl recipe is in meta-networking layer(previously known as libnftables)
38da295319SPatrick WilliamsPACKAGECONFIG[libnftnl] = "--enable-nftables,--disable-nftables,libnftnl"
39da295319SPatrick Williams
40da295319SPatrick Williamsdo_configure:prepend() {
41da295319SPatrick Williams    # Remove some libtool m4 files
42da295319SPatrick Williams    # Keep ax_check_linker_flags.m4 which belongs to autoconf-archive.
43da295319SPatrick Williams    rm -f libtool.m4 lt~obsolete.m4 ltoptions.m4 ltsugar.m4 ltversion.m4
44da295319SPatrick Williams
45da295319SPatrick Williams    # Copy a header to fix out of tree builds
46da295319SPatrick Williams    cp -f ${S}/libiptc/linux_list.h ${S}/include/libiptc/
47da295319SPatrick Williams}
48da295319SPatrick Williams
49da295319SPatrick WilliamsIPTABLES_RULES_DIR ?= "${sysconfdir}/${BPN}"
50da295319SPatrick Williams
51da295319SPatrick Williamsdo_install:append() {
52da295319SPatrick Williams    install -d ${D}${IPTABLES_RULES_DIR}
53*edff4923SAndrew Geissler    install -m 0644 ${UNPACKDIR}/iptables.rules ${D}${IPTABLES_RULES_DIR}
54da295319SPatrick Williams
55da295319SPatrick Williams    install -d ${D}${systemd_system_unitdir}
56*edff4923SAndrew Geissler    install -m 0644 ${UNPACKDIR}/iptables.service ${D}${systemd_system_unitdir}
57da295319SPatrick Williams
58da295319SPatrick Williams    sed -i \
59da295319SPatrick Williams        -e 's,@SBINDIR@,${sbindir},g' \
60da295319SPatrick Williams        -e 's,@RULESDIR@,${IPTABLES_RULES_DIR},g' \
61da295319SPatrick Williams        ${D}${systemd_system_unitdir}/iptables.service
62da295319SPatrick Williams
63da295319SPatrick Williams    if ${@bb.utils.contains('PACKAGECONFIG', 'ipv6', 'true', 'false', d)} ; then
64*edff4923SAndrew Geissler        install -m 0644 ${UNPACKDIR}/ip6tables.rules ${D}${IPTABLES_RULES_DIR}
65*edff4923SAndrew Geissler        install -m 0644 ${UNPACKDIR}/ip6tables.service ${D}${systemd_system_unitdir}
66da295319SPatrick Williams
67da295319SPatrick Williams        sed -i \
68da295319SPatrick Williams            -e 's,@SBINDIR@,${sbindir},g' \
69da295319SPatrick Williams            -e 's,@RULESDIR@,${IPTABLES_RULES_DIR},g' \
70da295319SPatrick Williams            ${D}${systemd_system_unitdir}/ip6tables.service
71da295319SPatrick Williams    fi
72da295319SPatrick Williams
73da295319SPatrick Williams    # if libnftnl is included, make the iptables symlink point to the nft-based binary by default
74da295319SPatrick Williams    if ${@bb.utils.contains('PACKAGECONFIG', 'libnftnl', 'true', 'false', d)} ; then
75da295319SPatrick Williams        ln -sf ${sbindir}/xtables-nft-multi ${D}${sbindir}/iptables
76*edff4923SAndrew Geissler        ln -sf ${sbindir}/xtables-nft-multi ${D}${sbindir}/iptables-save
77*edff4923SAndrew Geissler        ln -sf ${sbindir}/xtables-nft-multi ${D}${sbindir}/iptables-restore
78da295319SPatrick Williams    fi
79da295319SPatrick Williams}
80da295319SPatrick Williams
81da295319SPatrick WilliamsPACKAGES =+ "${PN}-modules ${PN}-apply"
82da295319SPatrick WilliamsPACKAGES_DYNAMIC += "^${PN}-module-.*"
83da295319SPatrick Williams
84da295319SPatrick Williamspython populate_packages:prepend() {
85da295319SPatrick Williams    modules = do_split_packages(d, '${libdir}/xtables', r'lib(.*)\.so$', '${PN}-module-%s', '${PN} module %s', extra_depends='')
86da295319SPatrick Williams    if modules:
87da295319SPatrick Williams        metapkg = d.getVar('PN') + '-modules'
88da295319SPatrick Williams        d.appendVar('RDEPENDS:' + metapkg, ' ' + ' '.join(modules))
89da295319SPatrick Williams}
90da295319SPatrick Williams
91da295319SPatrick WilliamsRDEPENDS:${PN} = "${PN}-module-xt-standard"
92da295319SPatrick WilliamsRRECOMMENDS:${PN} = " \
93da295319SPatrick Williams    ${PN}-modules \
94da295319SPatrick Williams    kernel-module-x-tables \
95da295319SPatrick Williams    kernel-module-ip-tables \
96da295319SPatrick Williams    kernel-module-iptable-filter \
97da295319SPatrick Williams    kernel-module-iptable-nat \
98da295319SPatrick Williams    kernel-module-nf-defrag-ipv4 \
99da295319SPatrick Williams    kernel-module-nf-conntrack \
100da295319SPatrick Williams    kernel-module-nf-conntrack-ipv4 \
101da295319SPatrick Williams    kernel-module-nf-nat \
102da295319SPatrick Williams    kernel-module-ipt-masquerade \
103da295319SPatrick Williams    ${@bb.utils.contains('PACKAGECONFIG', 'ipv6', '\
104da295319SPatrick Williams        kernel-module-ip6table-filter \
105da295319SPatrick Williams        kernel-module-ip6-tables \
106da295319SPatrick Williams    ', '', d)} \
107da295319SPatrick Williams"
108da295319SPatrick Williams
109da295319SPatrick WilliamsFILES:${PN} += "${datadir}/xtables"
110da295319SPatrick Williams
111da295319SPatrick WilliamsFILES:${PN}-apply = "${sbindir}/ip*-apply"
112da295319SPatrick WilliamsRDEPENDS:${PN}-apply = "${PN} bash"
113da295319SPatrick Williams
114da295319SPatrick Williams# Include the symlinks as well in respective packages
115da295319SPatrick WilliamsFILES:${PN}-module-xt-conntrack += "${libdir}/xtables/libxt_state.so"
116da295319SPatrick WilliamsFILES:${PN}-module-xt-ct += "${libdir}/xtables/libxt_NOTRACK.so ${libdir}/xtables/libxt_REDIRECT.so"
117da295319SPatrick WilliamsFILES:${PN}-module-xt-nat += "${libdir}/xtables/libxt_SNAT.so ${libdir}/xtables/libxt_DNAT.so ${libdir}/xtables/libxt_MASQUERADE.so"
118da295319SPatrick Williams
119da295319SPatrick WilliamsALLOW_EMPTY:${PN}-modules = "1"
120da295319SPatrick Williams
121da295319SPatrick WilliamsINSANE_SKIP:${PN}-module-xt-conntrack = "dev-so"
122da295319SPatrick WilliamsINSANE_SKIP:${PN}-module-xt-ct = "dev-so"
123da295319SPatrick WilliamsINSANE_SKIP:${PN}-module-xt-nat = "dev-so"
124