]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
6 years agoxtables: Don't use native nftables comments
Phil Sutter [Tue, 27 Nov 2018 19:07:11 +0000 (20:07 +0100)] 
xtables: Don't use native nftables comments

The problem with converting libxt_comment into nftables comment is that
rules change when parsing from kernel due to comment match being moved
to the end of the match list. And since match ordering matters, the rule
may not be found anymore when checking or deleting. Apart from that,
iptables-nft didn't support multiple comments per rule anymore. This is
a compatibility issue without technical reason.

Leave conversion from nftables comment to libxt_comment in place so we
don't break running systems during an update.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoebtables: Use xtables_exit_err()
Phil Sutter [Fri, 23 Nov 2018 14:32:53 +0000 (15:32 +0100)] 
ebtables: Use xtables_exit_err()

When e.g. ebtables-nft detects an incompatible table, a stray '.' was
printed as last line of output:

| # ebtables-nft -L
| table `filter' is incompatible, use 'nft' tool.
| .

This comes from ebtables' own exit_err callback. Instead use the common
one which also provides useful version information.

While being at it, align the final error message in xtables_eb_main()
with how the others print it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoarptables: Support --set-counters option
Phil Sutter [Thu, 22 Nov 2018 19:50:13 +0000 (20:50 +0100)] 
arptables: Support --set-counters option

Relevant code for this was already present (short option '-c'), just the
long option definition was missing.

While being at it, add '-c' to help text.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: libip6t_mh: fix bogus translation error
Pablo Neira Ayuso [Mon, 19 Nov 2018 13:09:20 +0000 (14:09 +0100)] 
extensions: libip6t_mh: fix bogus translation error

 libip6t_mh.txlate: Fail
 src: ip6tables-translate -A INPUT -p mh --mh-type 1 -j ACCEPT
 exp: nft add rule ip6 filter INPUT meta l4proto 135 mh type 1 counter accept
 res: nft add rule ip6 filter INPUT meta l4proto mobility-header mh type 1 counter accept

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: make all nft_parse_ helpers static
Florian Westphal [Sun, 18 Nov 2018 18:26:51 +0000 (19:26 +0100)] 
xtables: make all nft_parse_ helpers static

no more external callers.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: rename opcodes to arp_opcodes
Florian Westphal [Fri, 8 Jun 2018 13:19:18 +0000 (15:19 +0200)] 
xtables: rename opcodes to arp_opcodes

way too generic name.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: constify struct builtin_table and struct builtin_chain
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:25:58 +0000 (18:25 +0100)] 
xtables: constify struct builtin_table and struct builtin_chain

These definitions should be const, propagate this to all existing users.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: move initialize to struct nft_handle
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:38:30 +0000 (18:38 +0100)] 
nft: move initialize to struct nft_handle

Move this to the structure that stores, stateful information. Introduce
nft_table_initialized() and use it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: move chain_cache back to struct nft_handle
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:16:45 +0000 (18:16 +0100)] 
nft: move chain_cache back to struct nft_handle

Place this back into the structure that stores the state information.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: add type field to builtin_table
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:10:15 +0000 (18:10 +0100)] 
nft: add type field to builtin_table

Use enum nft_table_type to set the new type field in the structure that
define tables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoarptables-nft: use generic expression parsing function
Florian Westphal [Sun, 18 Nov 2018 11:31:33 +0000 (12:31 +0100)] 
arptables-nft: use generic expression parsing function

since commit d9c6a5d0977a6d8bbe772dbc31a2c4f58eec1708
("xtables: merge {ip,arp}tables_command_state structs") arptables
uses the shared representation.

With only minor changes (e.g., use generic counters in command_state),
in print/save functions we can use the shared nftnl expression parser
too.

arptables-legacy prints (-L) the jump target first, i.e.:
-j MARK -d 0.0.0.0/8 --h-length 6 ...

... so keep that here too.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables-monitor: fix build with musl libc
Baruch Siach [Sat, 17 Nov 2018 20:20:08 +0000 (22:20 +0200)] 
xtables-monitor: fix build with musl libc

Commit 7c8791edac3 ("xtables-monitor: fix build with older glibc")
changed the code to use GNU style tcphdr fields. Unfortunately, musl
libc requires _GNU_SOURCE definition to expose these fields.

Fix the following build failure:

xtables-monitor.c: In function ‘trace_print_packet’:
xtables-monitor.c:406:43: error: ‘const struct tcphdr’ has no member named ‘source’
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->source), ntohs(tcph->dest));
                                           ^~
xtables-monitor.c:406:64: error: ‘const struct tcphdr’ has no member named ‘dest’
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->source), ntohs(tcph->dest));
                                                                ^~
...

Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoinclude: fix build with kernel headers before 4.2
Baruch Siach [Fri, 16 Nov 2018 07:30:33 +0000 (09:30 +0200)] 
include: fix build with kernel headers before 4.2

Commit 672accf1530 (include: update kernel netfilter header files)
updated linux/netfilter.h and brought with it the update from kernel
commit a263653ed798 (netfilter: don't pull include/linux/netfilter.h
from netns headers). This triggers conflict of headers that is fixed in
kernel commit 279c6c7fa64f (api: fix compatibility of linux/in.h with
netinet/in.h) included in kernel version 4.2. For earlier kernel headers
we need a workaround that prevents the headers conflict.

Fixes the following build failure:

In file included from .../sysroot/usr/include/netinet/ip.h:25:0,
                 from ../include/libiptc/ipt_kernel_headers.h:8,
                 from ../include/libiptc/libiptc.h:6,
                 from libip4tc.c:29:
.../sysroot/usr/include/linux/in.h:26:3: error: redeclaration of enumerator ‘IPPROTO_IP’
   IPPROTO_IP = 0,  /* Dummy protocol for TCP  */
   ^
.../sysroot/usr/include/netinet/in.h:33:5: note: previous definition of ‘IPPROTO_IP’ was here
     IPPROTO_IP = 0,    /* Dummy protocol for TCP.  */
     ^~~~~~~~~~

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Introduce per table chain caches
Phil Sutter [Thu, 15 Nov 2018 13:53:02 +0000 (14:53 +0100)] 
xtables: Introduce per table chain caches

Being able to omit the previously obligatory table name check when
iterating over the chain cache might help restore performance with large
rulesets in xtables-save and -restore.

There is one subtle quirk in the code: flush_chain_cache() did free the
global chain cache if not called with a table name but didn't if a table
name was given even if it emptied the chain cache. In other places,
chain_cache being non-NULL prevented a cache update from happening, so
this patch establishes the same behaviour (for each individual chain
cache) since otherwise unexpected cache updates lead to weird problems.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables-monitor: fix build with older glibc
Baruch Siach [Fri, 16 Nov 2018 05:23:32 +0000 (07:23 +0200)] 
xtables-monitor: fix build with older glibc

glibc older than 2.19 only expose BSD style fields of struct tcphdr when
_BSD_SOURCE is define. Current glibc however, warn that _BSD_SOURCE is
deprecated. Migrate to the GNU style of tcphdr fields to make the code
compatible with any glibc version.

Fix the following build failure:

xtables-monitor.c: In function 'trace_print_packet':
xtables-monitor.c:406:43: error: 'const struct tcphdr' has no member named 'th_sport'
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
                                           ^
xtables-monitor.c:406:66: error: 'const struct tcphdr' has no member named 'th_dport'
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
                                                                  ^
...

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: format-security fixes in libip[6]t_icmp
Adam Gołębiowski [Wed, 14 Nov 2018 06:35:28 +0000 (07:35 +0100)] 
extensions: format-security fixes in libip[6]t_icmp

commit 61d6c3834de3 ("xtables: add 'printf' attribute to xlate_add")
introduced support for gcc feature to check format string against passed
argument.  This commit adds missing bits to extenstions's libipt_icmp.c
and libip6t_icmp6.c that were causing build to fail.

Fixes: 61d6c3834de3 ("xtables: add 'printf' attribute to xlate_add")
Signed-off-by: Adam Gołębiowski <adamg@pld-linux.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoebtables: vlan: fix userspace/kernel headers collision
Baruch Siach [Tue, 13 Nov 2018 17:22:08 +0000 (19:22 +0200)] 
ebtables: vlan: fix userspace/kernel headers collision

Build with musl libc fails because of conflicting struct ethhdr
definitions:

In file included from .../sysroot/usr/include/net/ethernet.h:10:0,
                 from ../iptables/nft-bridge.h:8,
                 from libebt_vlan.c:18:
.../sysroot/usr/include/netinet/if_ether.h:107:8: error: redefinition of ‘struct ethhdr’
 struct ethhdr {
        ^~~~~~
In file included from libebt_vlan.c:16:0:
.../sysroot/usr/include/linux/if_ether.h:160:8: note: originally defined here
 struct ethhdr {
        ^~~~~~

Include the userspace header first for the definition suppression logic
to do the right thing.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoip6tables-save: Merge into iptables-save.c
Phil Sutter [Wed, 19 Sep 2018 14:25:58 +0000 (16:25 +0200)] 
ip6tables-save: Merge into iptables-save.c

Both implementations were very similar already. Differences were mostly
in which libiptc functions were called. Therefore introduce struct
iptables_save_cb to point to the right functions for each variant.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoip6tables-restore: Merge into iptables-restore.c
Phil Sutter [Wed, 19 Sep 2018 14:25:57 +0000 (16:25 +0200)] 
ip6tables-restore: Merge into iptables-restore.c

Introduce struct iptables_restore_cb and merge ip6tables-restore with
iptables-restore.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibiptc: Extend struct xtc_ops
Phil Sutter [Wed, 19 Sep 2018 14:25:56 +0000 (16:25 +0200)] 
libiptc: Extend struct xtc_ops

Add a few more callbacks used by iptables-save.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoconfigure: bump versions for 1.8.2 release v1.8.2
Florian Westphal [Tue, 13 Nov 2018 05:45:21 +0000 (06:45 +0100)] 
configure: bump versions for 1.8.2 release

this release also adds xtables_print_mac* functions to libxtables, so
current and age are incremented again.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: add 'printf' attribute to xlate_add
Florian Westphal [Mon, 12 Nov 2018 13:40:41 +0000 (14:40 +0100)] 
xtables: add 'printf' attribute to xlate_add

This allows gcc to check format string vs. passed arguments.
Fix the fallout from this as well, typical warning produced is:

libebt_mark_m.c:112:28: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int' [-Wformat=]
   xt_xlate_add(xl, "and 0x%x %s0 ", info->mask, ...
                           ~^        ~~~~~~~~~~

so add the required casts or fixup format strings as needed.
libxt_conntrack also passed an unneeded argument (port), so remove that.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: xlate: init buffer to zero
Florian Westphal [Mon, 12 Nov 2018 17:04:45 +0000 (18:04 +0100)] 
libxtables: xlate: init buffer to zero

Doesn't affect iptables-xlate, but nft (when built w. xtables support).

Without this, nft can print random content if an extension doesn't
add anything to the output xlate buffer, e.g.

-p mh -m mh

can cause nft to print random data after "meta l4proto mobility",
as mh ->xlate doesn't do anything in this case.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: fix expected arptables-save output
Florian Westphal [Mon, 5 Nov 2018 16:51:18 +0000 (17:51 +0100)] 
tests: shell: fix expected arptables-save output

forgot to squash this before pushing arptables fixes.

Fixes: 5aecb2d8bfd ("arptables: pre-init hlen and ethertype")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix --version info
Florian Westphal [Wed, 7 Nov 2018 09:32:42 +0000 (10:32 +0100)] 
arptables: fix --version info

old: arptables vlibxtables.so.12 (nf_tables)
now: arptables 1.8.1 (nf_tables)

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: ignore --table argument.
Florian Westphal [Wed, 7 Nov 2018 09:16:24 +0000 (10:16 +0100)] 
arptables: ignore --table argument.

You can run 'arptables-legacy -t foobar' and commands work fine,
as it still operates on filter table (the only table that exists).

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: make uni/multicast mac masks static
Florian Westphal [Tue, 6 Nov 2018 17:39:16 +0000 (18:39 +0100)] 
arptables: make uni/multicast mac masks static

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: add test cases
Florian Westphal [Mon, 5 Nov 2018 16:51:37 +0000 (17:51 +0100)] 
arptables: add test cases

Unicast being shown as '00:00:00:00:00:00/01:00:00:00:00:00' looks like
broken output, however, arptables classic did not pretty-print either.

Also add test cases for all targets supported by the original
arptables tool:

-j CLASSIFY
-j MARK
-j mangle

[ yes, mangle target is lower-case 8-( ]

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: pre-init hlen and ethertype
Florian Westphal [Mon, 5 Nov 2018 16:51:18 +0000 (17:51 +0100)] 
arptables: pre-init hlen and ethertype

to check -s 1.2.3.4, we need to add the size of the hardware address
to the arp header to obtain the offset where the ipv4 address begins:

base_arphdr
HW_ADDR
IP_ADDR (src)
IP_ADDR (target)

In arptables-classic, the kernel will add dev->addr_len to the
arp header base address to obtain the correct location, but we cannot
do this in nf_tables, at least not at this time (we need a fixed offset
value).

code does:

  op = nft_invflags2cmp(fw->arp.invflags, ARPT_INV_TGTIP);
  add_addr(r, sizeof(struct arphdr) + fw->arp.arhln + ...

but if user did not provide "--h-length 6" argument, then this won't
work even for ethernet, as the payload expression will be told to load
the first 4 bytes of arp header source mac address (sender hw address).

Fix this by pre-initialising arhlen to 6.
We also need to set up arhrd.  Otherwise, src/dst mac can't be used:

arptables -A INPUT -i lo --destination-mac 11:22:33:44:55:66
arptables v1.8.1 (nf_tables):  RULE_APPEND failed (Invalid argument): rule in chain INPUT

This means that matching won't work for AX25, NETROM etc, however,
arptables "classic" can't  parse non-ethernet addresses, and makes
ETH_ALEN assumptions in several spots, so this should be fine from
compatibility point of view.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix src/dst mac handling
Florian Westphal [Tue, 6 Nov 2018 16:52:10 +0000 (17:52 +0100)] 
arptables: fix src/dst mac handling

1. check both address and mask, not just first byte of mac
2. use add_addr() for this so mask is also handled via bitwise expr.
3. use the correct offsets.
4. add dissector so we can reverse translate the payload expressions
   generated for this.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix target ip offset
Florian Westphal [Tue, 6 Nov 2018 16:48:24 +0000 (17:48 +0100)] 
arptables: fix target ip offset

--dst-ip checks the first four octets of the target mac.

Format of ipv4 arp is:
arphdr (htype, ptype...)
src mac
src ip
target mac
target ip

So we need to add hlen (6 bytes) a second time
(arphdr + 6 + 4 + 6) to get correct offset.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix -s/-d handling for negation and mask
Florian Westphal [Mon, 5 Nov 2018 16:05:12 +0000 (17:05 +0100)] 
arptables: fix -s/-d handling for negation and mask

also handle negations in other cases.
Still to be resolved: mask handling for other options such as hlen.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: add basic test infra for arptables-nft
Florian Westphal [Mon, 5 Nov 2018 16:03:07 +0000 (17:03 +0100)] 
arptables: add basic test infra for arptables-nft

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix rule deletion/compare
Florian Westphal [Mon, 5 Nov 2018 16:01:36 +0000 (17:01 +0100)] 
arptables: fix rule deletion/compare

arptables -D fails most of the time, as we compared
source mask with target mask.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: remove code that is also commented-out in original arptables
Florian Westphal [Mon, 5 Nov 2018 22:53:31 +0000 (23:53 +0100)] 
arptables: remove code that is also commented-out in original arptables

This isn't a missing feature in the -nft version,
neither plen and -m were ever implemented in arptables-legacy.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables-save: add -c option, like xtables-save
Florian Westphal [Mon, 5 Nov 2018 12:38:08 +0000 (13:38 +0100)] 
arptables-save: add -c option, like xtables-save

arptables classic doesn't have arptables-save, it only has a perl
script that attempts to emulate iptables-save.  It supports no options,
and thus has no way to dump counters.  Add -c option, like iptables to
enable this.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: use ->save for arptables-save, like xtables
Florian Westphal [Wed, 7 Nov 2018 12:57:16 +0000 (13:57 +0100)] 
arptables: use ->save for arptables-save, like xtables

arptables-save will show
-A OUTPUT --h-length 6 --h-type 1 -j MARK --set-xmark 0x1/0xffffffff
as
--h-length 6 --h-type Ethernet -j MARK MARK set 0x1

Because it uses ->print() instead of ->save().
Switch it to use ->save, we can then also drop special handling of
CLASSIFY target.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: test protocol and interface negation
Florian Westphal [Mon, 5 Nov 2018 17:58:42 +0000 (18:58 +0100)] 
extensions: test protocol and interface negation

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Fix error return code in nft_chain_user_rename()
Phil Sutter [Mon, 12 Nov 2018 13:29:47 +0000 (14:29 +0100)] 
xtables: Fix error return code in nft_chain_user_rename()

If the chain to rename wasn't found, the function would return -1 which
got interpreted as success.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoxtables: Clarify error message when deleting by index
Phil Sutter [Mon, 12 Nov 2018 13:29:46 +0000 (14:29 +0100)] 
xtables: Clarify error message when deleting by index

Trying to delete a rule by index from a non-existent chain leads to a
somewhat confusing error message:

| # iptables-nft -D foobar 1
| iptables: Index of deletion too big.

Fix this by performing chain existence checks for CMD_DELETE_NUM, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoxtables: Fix typo in do_command() error message
Phil Sutter [Mon, 12 Nov 2018 13:29:45 +0000 (14:29 +0100)] 
xtables: Fix typo in do_command() error message

This checks p->chain for existence, not cs->jumpto. Fixes this bogus
error message:

| # iptables-nft -t nat -A FORWARD -j ACCEPT
| iptables v1.8.1 (nf_tables): Chain 'ACCEPT' does not exist

Fixes: b6a06c1a215f8 ("xtables: Align return codes with legacy iptables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoebtables: use extrapositioned negation consistently
Florian Westphal [Mon, 12 Nov 2018 11:49:11 +0000 (12:49 +0100)] 
ebtables: use extrapositioned negation consistently

in the iptables universe, we enforce extrapositioned negation:

! -i foo

"-i ! foo" is not even supported anymore.

At least make sure that ebtables prints the former syntax everywhere as
well so we don't have a mix of both ways.
Parsing of --option ! 42 will still work for backwards compat reasons.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables-save: add -c option, using xtables-style counters
Florian Westphal [Mon, 12 Nov 2018 11:49:10 +0000 (12:49 +0100)] 
ebtables-save: add -c option, using xtables-style counters

The 'original' ebtables-save was a perl script that supported no option.
Add minimal options, like ip(6)tables save.

Retain the old way of formatiing counters via environment variable,
but allow overriding this using the -c option.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonft: add NFT_TABLE_* enumeration
Pablo Neira Ayuso [Mon, 12 Nov 2018 11:44:56 +0000 (12:44 +0100)] 
nft: add NFT_TABLE_* enumeration

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: replace nft_chain_dump() by nft_chain_list_get()
Pablo Neira Ayuso [Mon, 12 Nov 2018 11:03:57 +0000 (12:03 +0100)] 
nft: replace nft_chain_dump() by nft_chain_list_get()

So we can remove nft_chain_dump() and replace nftnl_chain_get_list().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoiptables-nft: fix -f fragment option
Florian Westphal [Sun, 11 Nov 2018 21:02:39 +0000 (22:02 +0100)] 
iptables-nft: fix -f fragment option

This needs to be passed in network byte order.

Reported-by: Arno van Amersfoort <arnova@rocky.eld.leidenuniv.nl>
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1292
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: add and use mac print helpers
Florian Westphal [Sat, 3 Nov 2018 22:43:49 +0000 (23:43 +0100)] 
libxtables: add and use mac print helpers

This changes ebtables-nft to consistently print mac
address with two characters, i.e.
00:01:02:03:04:0a, not 0:1:2:3:4:a.

Will require another bump of vcurrent/vage.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: libebt_ip: fix tos negation
Florian Westphal [Mon, 5 Nov 2018 10:46:02 +0000 (11:46 +0100)] 
extensions: libebt_ip: fix tos negation

passing ->tos as uintmax_t will clear adjacent fields in the structure,
including invflags.

Fixes: 49479aa12a15 ("ebtables-compat: add 'ip' match extension")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: libebt_ip6: fix ip6-dport negation
Florian Westphal [Mon, 5 Nov 2018 10:30:57 +0000 (11:30 +0100)] 
extensions: libebt_ip6: fix ip6-dport negation

Fixes: 5c8ce9c6aede0 ("ebtables-compat: add 'ip6' match extension")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables-nft: make -Z option work
Florian Westphal [Mon, 5 Nov 2018 09:44:20 +0000 (10:44 +0100)] 
xtables-nft: make -Z option work

-Z doesn't just zero base counters, it zeroes out all rule
counters, or, optionally, all counters of a chain (-Z FOO).

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1286
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonft: add missing error string
Florian Westphal [Sat, 3 Nov 2018 22:45:13 +0000 (23:45 +0100)] 
nft: add missing error string

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-tests: add % to run iptables commands
Pablo Neira Ayuso [Sat, 3 Nov 2018 13:40:26 +0000 (14:40 +0100)] 
iptables-tests: add % to run iptables commands

Lines starting by % allows you to run iptables commands, use it for
rateest test.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoiptables-tests: do not append xtables-multi to external commands
Pablo Neira Ayuso [Sat, 3 Nov 2018 13:40:26 +0000 (14:40 +0100)] 
iptables-tests: do not append xtables-multi to external commands

Lines starting by @ can be used to invoke an external command of any
kind. Do not add xtables-multi here since we may want to execute a
non-iptables command.

Fixes: 9ff99156b63e ("iptables-test: fix netns test")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoebtables-nft: add arpreply target
Florian Westphal [Tue, 9 Oct 2018 15:21:37 +0000 (17:21 +0200)] 
ebtables-nft: add arpreply target

Unfortunately no nft translation available so far.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: add redirect test case
Florian Westphal [Fri, 2 Nov 2018 15:19:42 +0000 (16:19 +0100)] 
ebtables: add redirect test case

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: add test cases
Florian Westphal [Fri, 2 Nov 2018 15:19:20 +0000 (16:19 +0100)] 
ebtables: add test cases

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: relax -t table restriction, add snat/dnat test cases
Florian Westphal [Fri, 2 Nov 2018 15:24:24 +0000 (16:24 +0100)] 
ebtables: relax -t table restriction, add snat/dnat test cases

Its artificial and prevents test cases that need to add rules
to a different table from working.

The test script generates:
-A PREROUTING -t nat

... which works fine for iptables and ip6tables.
Just accept it for ebtables too and add test cases
for snat and dnat.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: fix -j CONTINUE handling for add/delete
Florian Westphal [Fri, 2 Nov 2018 13:36:54 +0000 (14:36 +0100)] 
ebtables: fix -j CONTINUE handling for add/delete

-j CONTINUE can be added, but it can't be removed:
extensions/libebt_standard.t: ERROR: line 5 (cannot find: ebtables -I INPUT -d de:ad:be:ef:00:00 -j CONTINUE)

This problem stems from silly ambiguity in ebtables-nft vs. iptables.

In iptables, you can do
iptables -A INPUT
(no -j)
in ebtables, you can do either
ebtables -A INPUT
or
ebtables -A INPUT -j CONTINUE

both are *supposed* to be the same (and they do the same even
in ebtables-nft on netlink side).

However, the temprary binary representation within ebtables-nft is not
the same: when parsing -j CONTINUE, we add a standard target, then omit
it later in _add_target().

When translating netlink representation to ebt binary one,
we do not add a standard target and instead just print '-j CONTINUE'
when listing rules.

So when doing
-I INPUT -j CONTINUE
-D INPUT -j CONTINUE

the -D operation fails because it has a standard target in the binary
representation, whereas the rule we obtained from translating
nftables netlink back to ebtables' binary represenation doesn't.

Fix it by ignoring 'CONTINUE' on parser side.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: add basic ebtables test support
Florian Westphal [Fri, 2 Nov 2018 11:06:30 +0000 (12:06 +0100)] 
tests: add basic ebtables test support

now that we have ebtables-save, lets add test cases for ebtables-nft
as well.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-nft: fix bogus handling of zero saddr/daddr
Florian Westphal [Fri, 2 Nov 2018 09:47:25 +0000 (10:47 +0100)] 
iptables-nft: fix bogus handling of zero saddr/daddr

rule for 0.0.0.0/8 is added as 0.0.0.0/0, because we did not check
mask (or negation, for that matter).

Fix this and add test cases too.

This also revealed an ip6tables-nft-save bug, it would print
' !-d', not '! -d'.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1287
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-test: fix netns test
Taehee Yoo [Thu, 1 Nov 2018 14:32:50 +0000 (23:32 +0900)] 
iptables-test: fix netns test

The libxt_rateest test always fails because dependent command is not
executed in netns.

(@iptables -I INPUT -j RATEEST --rateest-name RE1 --rateest-interval \
 250.0ms --rateest-ewmalog 500.0ms)

After this path, adding netns command is executed first.
Then test commands are executed.

Fixes: 0123183f43a9 ("iptables-test: add -N option to exercise netns removal path")
Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Fix for matching rules with wildcard interfaces
Phil Sutter [Wed, 31 Oct 2018 19:13:34 +0000 (20:13 +0100)] 
xtables: Fix for matching rules with wildcard interfaces

Due to xtables_parse_interface() and parse_ifname() being misaligned
regarding interface mask setting, rules containing a wildcard interface
added with iptables-nft could neither be checked nor deleted.

As suggested, introduce extensions/iptables.t to hold checks for
built-in selectors. This file is picked up by iptables-test.py as-is.
The only limitation is that iptables is being used for it, so no
ip6tables-specific things can be tested with it (for now).

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoextensions: limit: unbreak build without libnftnl
Florian Westphal [Wed, 24 Oct 2018 10:00:11 +0000 (12:00 +0200)] 
extensions: limit: unbreak build without libnftnl

Lars Wendler reported 1.8.1 build failure when trying to build without nft backend:

  In file included from ../iptables/nft.h:5, from libxt_limit.c:18: libnftnl/rule.h: No such file or directory

Reported-by: Lars Wendler <polynomial-c@gentoo.org>
Fixes: 02b80972c43 ("ebtables: Merge libebt_limit.c into libxt_limit.c")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Fix for spurious errors from iptables-translate
Phil Sutter [Tue, 23 Oct 2018 14:59:14 +0000 (16:59 +0200)] 
xtables: Fix for spurious errors from iptables-translate

When aligning iptables-nft error messages with legacy ones, I missed
that translate tools shouldn't check for missing or duplicated chains.

Introduce a boolean in struct nft_xt_cmd_parse indicating we're "just"
translating and do_parse() should skip the checks.

Fixes: b6a06c1a215f8 ("xtables: Align return codes with legacy iptables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoconfigure: bump versions for 1.8.1 release v1.8.1
Florian Westphal [Mon, 22 Oct 2018 16:48:53 +0000 (18:48 +0200)] 
configure: bump versions for 1.8.1 release

this release also adds xtables_getether* functions to libxtables, so
current and age are incremented as well.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoiptables-test: add -N option to exercise netns removal path
Pablo Neira Ayuso [Fri, 19 Oct 2018 10:13:37 +0000 (12:13 +0200)] 
iptables-test: add -N option to exercise netns removal path

We are getting bug reports lately from the netns path, add a new option
to exercise this path.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agolibxtables: expose new etherdb lookup function through libxtables API
Pablo Neira Ayuso [Fri, 19 Oct 2018 11:06:53 +0000 (13:06 +0200)] 
libxtables: expose new etherdb lookup function through libxtables API

This is used from extensions and included in libxtables, so we have to
make them public.

Fixes: 31f1434dfe37 ("libxtables: Integrate getethertype.c from xtables core")
Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
6 years agolibxtables: prefix exported new functions for etherdb lookups
Pablo Neira Ayuso [Fri, 19 Oct 2018 10:55:16 +0000 (12:55 +0200)] 
libxtables: prefix exported new functions for etherdb lookups

To avoid symbol pollution, place them under the xt_ and xtables_ prefix
name.

Fixes: 31f1434dfe37 ("libxtables: Integrate getethertype.c from xtables core")
Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
6 years agoRevert "extensions: libxt_quota: Allow setting the remaining quota"
Pablo Neira Ayuso [Fri, 19 Oct 2018 09:48:59 +0000 (11:48 +0200)] 
Revert "extensions: libxt_quota: Allow setting the remaining quota"

This reverts commit 0a8f2bcadff157489a737f8cc8846adcb750b91f.

Google folks are reporting some issues with 32-bits arch, let's revert
this until we have a new version for this.

6 years agoxtables: Remove target_maxnamelen field
Phil Sutter [Thu, 11 Oct 2018 11:30:38 +0000 (13:30 +0200)] 
xtables: Remove target_maxnamelen field

This is a partial revert of commit 9f075031a1973 ("Combine
parse_target() and command_jump() implementations"): Upstream prefers to
reduce max chain name length of arptables by two characters instead of
the introduced struct xtables_globals field which requires to bump
library API version.

Fixes: 9f075031a1973 ("Combine parse_target() and command_jump() implementations")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoextensions: cgroup: fix option parsing for v2
Pablo Neira Ayuso [Tue, 9 Oct 2018 18:36:36 +0000 (20:36 +0200)] 
extensions: cgroup: fix option parsing for v2

Structure layout is different, therefore a new struct xt_option_entry is
needed.

Fixes: f9efc8cb79c0 ("extensions: add cgroup revision 2")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoextensions: libxt_quota: Allow setting the remaining quota
Chenbo Feng [Tue, 2 Oct 2018 01:23:07 +0000 (18:23 -0700)] 
extensions: libxt_quota: Allow setting the remaining quota

The current xt_quota module cannot track the current remaining quota
of a specific rule. Everytime an unrelated rule is updated in the same
iptables table, the quota will be reset. This is not a very useful
function for iptables that get changed at run time. This patch fixes the
above problem by adding a new field in the struct that records the
current remaining quota.

Fixed a print out bug in verbose print out wrt. inversion.

Signed-off-by: Chenbo Feng <fengc@google.com>
Suggested-by: Maciej Żenczykowski <maze@google.com>
Reviewed-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft-shared: Use xtables_calloc()
Phil Sutter [Mon, 24 Sep 2018 17:25:26 +0000 (19:25 +0200)] 
nft-shared: Use xtables_calloc()

This simplifies code a bit since it takes care of checking for
out-of-memory conditions.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: Use the shared nft_ipv46_parse_target()
Phil Sutter [Mon, 24 Sep 2018 17:25:25 +0000 (19:25 +0200)] 
arptables: Use the shared nft_ipv46_parse_target()

No point in having a dedicated implementation for 'parse_target'
callback since it is identical with the shared one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoCombine parse_target() and command_jump() implementations
Phil Sutter [Mon, 24 Sep 2018 17:25:24 +0000 (19:25 +0200)] 
Combine parse_target() and command_jump() implementations

Merge these two functions from xtables, iptables, ip6tables and
arptables. Both functions were basically identical in the first three,
only the last one required a bit more attention.

To eliminate access to 'invflags' in variant-specific location, move the
call to set_option() into callers. This is actually consistent with
parsing of other options in them.

As with command_match(), use xt_params instead of the different
*_globals objects to refer to 'opts' and 'orig_opts'.

It was necessary to rename parse_target() as it otherwise clashes with a
static function of same name in libxt_SET.

In arptables, the maximum allowed target name is a bit larger, so
introduce xtables_globals.target_maxnamelen defining the value. It is
used in the shared xt_parse_target() implementation.

Implementation of command_jump() in arptables diverted from the others
for no obvious reason. The call to parse_target() was done outside of it
and a pointer to cs->arp was passed but not used inside.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoCombine command_match() implementations
Phil Sutter [Mon, 24 Sep 2018 17:25:23 +0000 (19:25 +0200)] 
Combine command_match() implementations

This merges the basically identical implementations of command_match()
from xtables, iptables and ip6tables into one. The only required
adjustment was to make use of xt_params instead of the different
*_globals objects.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibiptc: NULL-terminate errorname
Phil Sutter [Mon, 24 Sep 2018 17:25:22 +0000 (19:25 +0200)] 
libiptc: NULL-terminate errorname

In struct chain_head, field 'name' is of size TABLE_MAXNAMELEN, hence
copying its content into 'error_name' field of struct xt_error_target
which is two bytes shorter may overflow. Make sure this doesn't happen
by using strncpy() and set the last byte to zero.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: Check extension real_name length
Phil Sutter [Mon, 24 Sep 2018 17:25:21 +0000 (19:25 +0200)] 
libxtables: Check extension real_name length

Just like with 'name', if given check 'real_name' to not exceed max length.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables: Gitignore xtables-{legacy, nft}-multi scripts
Phil Sutter [Wed, 19 Sep 2018 13:17:09 +0000 (15:17 +0200)] 
iptables: Gitignore xtables-{legacy, nft}-multi scripts

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Drop pointless check
Phil Sutter [Wed, 19 Sep 2018 13:17:08 +0000 (15:17 +0200)] 
xtables: Drop pointless check

All commands this block handles set p->chain. Also the pointer is
dereferenced before, so no point in checking for it to be non-NULL.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: Fix incorrect strcmp() in nft_arp_rule_find()
Phil Sutter [Wed, 19 Sep 2018 13:17:07 +0000 (15:17 +0200)] 
arptables: Fix incorrect strcmp() in nft_arp_rule_find()

Since nft_arp_rule_to_cs() may not set cs->jumpto, later call to
strcmp() may be passed a NULL pointer. Therefore check if the pointer is
valid before doing so.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Don't read garbage in nft_ipv4_parse_payload()
Phil Sutter [Wed, 19 Sep 2018 13:17:06 +0000 (15:17 +0200)] 
xtables: Don't read garbage in nft_ipv4_parse_payload()

The problem here is that get_frag() does not set 'inv' in any case, so
when later checking its value, garbage may be read. Sanitize this case
by setting 'inv' to false before calling get_frag().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: Use posix_spawn() instead of vfork()
Phil Sutter [Wed, 19 Sep 2018 13:17:05 +0000 (15:17 +0200)] 
libxtables: Use posix_spawn() instead of vfork()

According to covscan, vfork() may lead to a deadlock in the parent
process. It suggests to use posix_spawn() instead. Since the latter
combines vfork() and exec() calls, use it for xtables_insmod().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoFix a few cases of pointless assignments
Phil Sutter [Wed, 19 Sep 2018 13:17:04 +0000 (15:17 +0200)] 
Fix a few cases of pointless assignments

This gets rid of a number of assignments which are either redundant or
not used afterwards.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: libebt_ip{, 6}: Drop pointless error checking
Phil Sutter [Wed, 19 Sep 2018 13:17:03 +0000 (15:17 +0200)] 
extensions: libebt_ip{, 6}: Drop pointless error checking

Since info->protocol is of type __u8, its value will never become -1.
Apart from that, xtables_parse_protocol() calls xt_params->exit_err() in
case of error, so this code is dead anyway.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonft-arp: Drop ineffective conditional
Phil Sutter [Wed, 19 Sep 2018 13:17:02 +0000 (15:17 +0200)] 
nft-arp: Drop ineffective conditional

Since fw->arp.arhln is of type __u8, its value will never become less
than zero.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables: Use print_ifaces() from xtables
Phil Sutter [Wed, 19 Sep 2018 13:17:00 +0000 (15:17 +0200)] 
iptables: Use print_ifaces() from xtables

Move the function to xshared.c for common use between legacy and xtables
sources. While being at it, silence a covscan warning triggered by that
function as it couldn't verify input buffers won't exceed IFNAMSIZ.
Therefore use snprintf() when writing to the local buffer.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoShare print_ipv{4,6}_addr() from xtables
Phil Sutter [Wed, 19 Sep 2018 13:16:59 +0000 (15:16 +0200)] 
Share print_ipv{4,6}_addr() from xtables

These functions contain code which occurs in legacy's print_firewall()
functions, so use them there.

Rename them to at least make clear they print more than a single
address.

Also introduce ipv{4,6}_addr_to_string() which take care of converting
an address/netmask pair into string representation in a way which
doesn't upset covscan (since that didn't detect that 'buf' may not be
exceeded by the strings written into it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-apply: Replace signal numbers by names
Phil Sutter [Wed, 19 Sep 2018 13:16:58 +0000 (15:16 +0200)] 
iptables-apply: Replace signal numbers by names

As covscan stated: "Trapping signals by number is not well defined.
Prefer signal names."

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-apply: Quote strings passed to echo
Phil Sutter [Wed, 19 Sep 2018 13:16:57 +0000 (15:16 +0200)] 
iptables-apply: Quote strings passed to echo

Not a real problem here, but covscan got confused by one string
containing 'then' keyword.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonfnl_osf: Replace deprecated nfnl_talk() by nfnl_query()
Phil Sutter [Wed, 19 Sep 2018 13:16:56 +0000 (15:16 +0200)] 
nfnl_osf: Replace deprecated nfnl_talk() by nfnl_query()

This eliminates the deprecation warning when compiling the sources.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: Don't read garbage in xtables_strtoui()
Phil Sutter [Wed, 19 Sep 2018 13:16:55 +0000 (15:16 +0200)] 
libxtables: Don't read garbage in xtables_strtoui()

If xtables_strtoul() fails, it returns false and data pointed to by
parameter 'value' is undefined. Hence avoid copying that data in
xtables_strtoui() if the call failed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: Avoid calling memcpy() with NULL source
Phil Sutter [Wed, 19 Sep 2018 13:16:54 +0000 (15:16 +0200)] 
libxtables: Avoid calling memcpy() with NULL source

Both affected functions check if 'oldopts' is NULL once but later seem
to ignore that possibility. To catch up on that, increment the pointer
only if it isn't NULL, also don't copy its content into the merged
options buffer in that case.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibiptc: Simplify alloc_handle() function signature
Phil Sutter [Wed, 19 Sep 2018 13:16:53 +0000 (15:16 +0200)] 
libiptc: Simplify alloc_handle() function signature

This change originated from covscan complaining about the strcpy() call
with an unknown size source buffer. But in fact, the size is known (and
equal to the destination size), so pass a pointer to STRUCT_GETINFO to
alloc_handle() instead of it's fields separately. Hopefully this will
silence covscan.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxt_time: Drop initialization of variable 'year'
Phil Sutter [Wed, 19 Sep 2018 13:16:52 +0000 (15:16 +0200)] 
libxt_time: Drop initialization of variable 'year'

The variable is not read before being assigned the return value of
strtoul(), thefore the initialization is useless. And since after this
change parameter 'end' becomes unused, drop it as well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxt_ipvs: Avoid potential buffer overrun
Phil Sutter [Wed, 19 Sep 2018 13:16:51 +0000 (15:16 +0200)] 
libxt_ipvs: Avoid potential buffer overrun

Just like with libxt_conntrack, get rid of the temporary buffer. The
comment even states that it was copied from there, so just make them
identical again.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxt_conntrack: Avoid potential buffer overrun
Phil Sutter [Wed, 19 Sep 2018 13:16:50 +0000 (15:16 +0200)] 
libxt_conntrack: Avoid potential buffer overrun

In print_addr(), a resolved hostname is written into a buffer without
size check. Since BUFSIZ is typically 8192 bytes, this shouldn't be an
issue, though covscan complained about it. Fix the code by using
conntrack_dump_addr() as an example.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxt_conntrack: Version 0 does not support XT_CONNTRACK_DIRECTION
Phil Sutter [Wed, 19 Sep 2018 13:16:49 +0000 (15:16 +0200)] 
libxt_conntrack: Version 0 does not support XT_CONNTRACK_DIRECTION

Since sinfo->flags is only 8 bytes large, checking for
XT_CONNTRACK_DIRECTION bit (which has value 1 << 12) will always return
false, so drop this dead code.

Fixes: c7fc1dae1e8f8 ("libxt_conntrack: dump ctdir")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxt_LED: Avoid string overrun while parsing led-trigger-id
Phil Sutter [Wed, 19 Sep 2018 13:16:48 +0000 (15:16 +0200)] 
libxt_LED: Avoid string overrun while parsing led-trigger-id

Instead of using strcat() and assuming the name will fit, print into the
buffer using snprintf() which truncates the string as needed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Remove unused variable in nft_is_table_compatible()
Phil Sutter [Wed, 19 Sep 2018 13:16:47 +0000 (15:16 +0200)] 
xtables: Remove unused variable in nft_is_table_compatible()

This is a leftover from previous cleanup.

Fixes: 098ee2e91756c ("xtables-save: Ignore uninteresting tables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>