]> granicus.if.org Git - ipset/log
ipset
5 years agoipset: update my email address
Jozsef Kadlecsik [Tue, 4 Jun 2019 18:47:34 +0000 (20:47 +0200)]
ipset: update my email address

It's better to use my kadlec@netfilter.org email address in
the source code. I might not be able to use
kadlec@blackhole.kfki.hu in the future.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoipset: Fix memory accounting for hash types on resize
Stefano Brivio [Sun, 26 May 2019 21:14:06 +0000 (23:14 +0200)]
ipset: Fix memory accounting for hash types on resize

If a fresh array block is allocated during resize, the current in-memory
set size should be increased by the size of the block, not replaced by it.

Before the fix, adding entries to a hash set type, leading to a table
resize, caused an inconsistent memory size to be reported. This becomes
more obvious when swapping sets with similar sizes:

  # cat hash_ip_size.sh
  #!/bin/sh
  FAIL_RETRIES=10

  tries=0
  while [ ${tries} -lt ${FAIL_RETRIES} ]; do
   ipset create t1 hash:ip
   for i in `seq 1 4345`; do
   ipset add t1 1.2.$((i / 255)).$((i % 255))
   done
   t1_init="$(ipset list t1|sed -n 's/Size in memory: \(.*\)/\1/p')"

   ipset create t2 hash:ip
   for i in `seq 1 4360`; do
   ipset add t2 1.2.$((i / 255)).$((i % 255))
   done
   t2_init="$(ipset list t2|sed -n 's/Size in memory: \(.*\)/\1/p')"

   ipset swap t1 t2
   t1_swap="$(ipset list t1|sed -n 's/Size in memory: \(.*\)/\1/p')"
   t2_swap="$(ipset list t2|sed -n 's/Size in memory: \(.*\)/\1/p')"

   ipset destroy t1
   ipset destroy t2
   tries=$((tries + 1))

   if [ ${t1_init} -lt 10000 ] || [ ${t2_init} -lt 10000 ]; then
   echo "FAIL after ${tries} tries:"
   echo "T1 size ${t1_init}, after swap ${t1_swap}"
   echo "T2 size ${t2_init}, after swap ${t2_swap}"
   exit 1
   fi
  done
  echo "PASS"
  # echo -n 'func hash_ip4_resize +p' > /sys/kernel/debug/dynamic_debug/control
  # ./hash_ip_size.sh
  [ 2035.018673] attempt to resize set t1 from 10 to 11, t 00000000fe6551fa
  [ 2035.078583] set t1 resized from 10 (00000000fe6551fa) to 11 (00000000172a0163)
  [ 2035.080353] Table destroy by resize 00000000fe6551fa
  FAIL after 4 tries:
  T1 size 9064, after swap 71128
  T2 size 71128, after swap 9064

Reported-by: NOYB <JunkYardMail1@Frontier.com>
Fixes: 9e41f26a505c ("netfilter: ipset: Count non-static extension memory for userspace")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoFix error path in set_target_v3_checkentry()
Jozsef Kadlecsik [Fri, 18 Jan 2019 17:16:55 +0000 (18:16 +0100)]
Fix error path in set_target_v3_checkentry()

Fix error path and release the references properly.

5 years agoFix the last missing check of nla_parse()
Jozsef Kadlecsik [Thu, 10 Jan 2019 20:00:16 +0000 (21:00 +0100)]
Fix the last missing check of nla_parse()

In dump_init() the outdated comment was incorrect and we had a missing
validation check of nla_parse().

5 years agonetfilter: ipset: fix a missing check of nla_parse
Aditya Pakki [Tue, 8 Jan 2019 20:00:33 +0000 (21:00 +0100)]
netfilter: ipset: fix a missing check of nla_parse

When nla_parse fails, we should not use the results (the first
argument). The fix checks if it fails, and if so, returns its error code
upstream.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agonetfilter: ipset: merge uadd and udel functions
Florent Fourcot [Tue, 8 Jan 2019 19:55:55 +0000 (20:55 +0100)]
netfilter: ipset: merge uadd and udel functions

Both functions are using exactly the same code, except the command value
passed to call_ad function.

Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agonetfilter: ipset: remove useless memset() calls
Florent Fourcot [Tue, 8 Jan 2019 19:37:33 +0000 (20:37 +0100)]
netfilter: ipset: remove useless memset() calls

One of the memset call is buggy: it does not erase full array, but only
pointer size.
Moreover, after a check, first step of nla_parse_nested/nla_parse is to
erase tb array as well. We can remove both calls safely.

Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoipset 7.1 released v7.1
Jozsef Kadlecsik [Mon, 10 Dec 2018 17:35:31 +0000 (18:35 +0100)]
ipset 7.1 released

5 years agoAdd compatibility support for strscpy()
Jozsef Kadlecsik [Mon, 10 Dec 2018 17:29:48 +0000 (18:29 +0100)]
Add compatibility support for strscpy()

5 years agonetfilter/ipset: replace a strncpy() with strscpy()
Qian Cai [Sun, 2 Dec 2018 04:06:01 +0000 (23:06 -0500)]
netfilter/ipset: replace a strncpy() with strscpy()

To make overflows as obvious as possible and to prevent code from blithely
proceeding with a truncated string. This also has a side-effect to fix a
compilation warning when using GCC 8.2.1.

net/netfilter/ipset/ip_set_core.c: In function 'ip_set_sockfn_get':
net/netfilter/ipset/ip_set_core.c:2027:3: warning: 'strncpy' writing 32
bytes into a region of size 2 overflows the destination
[-Wstringop-overflow=]

Signed-off-by: Qian Cai <cai@gmx.us>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoCorrect the manpage about the sort option, supported since 3713072d
Jozsef Kadlecsik [Fri, 30 Nov 2018 20:43:51 +0000 (21:43 +0100)]
Correct the manpage about the sort option, supported since 3713072d

5 years agoAdd missing functions to libipset.map
Jozsef Kadlecsik [Wed, 28 Nov 2018 17:45:50 +0000 (18:45 +0100)]
Add missing functions to libipset.map

Some new functions was not added to libipset.map at the previous
release, fix it.

5 years agonetfilter: ipset: fix ip_set_byindex function
Florent Fourcot [Tue, 27 Nov 2018 16:15:56 +0000 (17:15 +0100)]
netfilter: ipset: fix ip_set_byindex function

New function added by "Introduction of new commands and protocol
version 7" is not working, since we return skb2 to user

Signed-off-by: Victorien Molle <victorien.molle@wifirst.fr>
Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agonetfilter: ipset: do not call ipset_nest_end after nla_nest_cancel
Pan Bian [Mon, 26 Nov 2018 10:42:10 +0000 (18:42 +0800)]
netfilter: ipset: do not call ipset_nest_end after nla_nest_cancel

In the error handling block, nla_nest_cancel(skb, atd) is called to
cancel the nest operation. But then, ipset_nest_end(skb, atd) is
unexpected called to end the nest operation. This patch calls the
ipset_nest_end only on the branch that nla_nest_cancel is
not called.

Fixes: 45040978c89("netfilter: ipset: Fix set:list type crash when
flush/dump set in parallel")

Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoconfigure.ac: Fix build regression on RHEL/CentOS/SL
Serhey Popovych [Sun, 18 Nov 2018 19:08:23 +0000 (21:08 +0200)]
configure.ac: Fix build regression on RHEL/CentOS/SL

This was introduced with commit 0f82228387ae ("Use more robust awk
patterns to check for backward compatibility") on RHEL 7.3+ because
it's kernel contains backported upstream commit 633c9a840d0b
("netfilter: nfnetlink: avoid recurrent netns lookups in call_batch")
that introduces @net of @struct net type parameter matched with $GREP
after $AWK returns whole @struct nfnl_callback.

This causes incorrect IPSET_CBFN() prototype choose for ->call()
of @struct nfnl_callback producing following warnings during the build:

  .../ipset/ip_set_core.c:2007:3: warning: initialization from
  incompatible pointer type [enabled by default]
     .call  = ip_set_destroy,
     ^
  ../ipset/ip_set_core.c:2007:3: warning: (near initialization
  for ‘ip_set_netlink_subsys_cb[3].call’) [enabled by default]

Fix by matching pattern to the end of first function pointer in
@struct nfnl_callback instead of end of struct.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 years agoImplement sorting for hash types in the ipset tool
Jozsef Kadlecsik [Mon, 26 Nov 2018 09:54:36 +0000 (10:54 +0100)]
Implement sorting for hash types in the ipset tool

Support listing/saving with sorted entries for the hash types.
(bitmap and list types are automatically sorted.)

6 years agoFix to list/save into file specified by option
Jozsef Kadlecsik [Sat, 10 Nov 2018 16:34:57 +0000 (17:34 +0100)]
Fix to list/save into file specified by option

list/save into file given by "-f filename" did not work in 7.0,
reported by Isaac Good.

6 years agoCorrect workaround in patch "Fix calling ip_set() macro at dumping"
Jozsef Kadlecsik [Tue, 30 Oct 2018 21:30:30 +0000 (22:30 +0100)]
Correct workaround in patch "Fix calling ip_set() macro at dumping"

As Pablo pointed out, in order to fix the bogus warnings, there's
no need for the non-useful rcu_read_lock/unlock dancing. Call
rcu_dereference_raw() instead, the ref_netlink protects the set.

6 years agoipset 7.0 released v7.0
Jozsef Kadlecsik [Sat, 27 Oct 2018 16:09:10 +0000 (18:09 +0200)]
ipset 7.0 released

6 years agoIntroduction of new commands and protocol version 7
Jozsef Kadlecsik [Mon, 22 Oct 2018 20:25:09 +0000 (22:25 +0200)]
Introduction of new commands and protocol version 7

Two new commands (IPSET_CMD_GET_BYNAME, IPSET_CMD_GET_BYINDEX) are
introduced. The new commands makes possible to eliminate the getsockopt
operation (in iptables set/SET match/target) and thus use only netlink
communication between userspace and kernel for ipset. With the new
protocol version, userspace can exactly know which functionality is
supported by the running kernel.

Both the kernel and userspace is fully backward compatible.

6 years agoLicense cleanup: add SPDX license identifier to uapi header files with no license
Greg Kroah-Hartman [Mon, 22 Oct 2018 19:01:58 +0000 (21:01 +0200)]
License cleanup: add SPDX license identifier to uapi header files with no license

Many user space API headers are missing licensing information, which
makes it hard for compliance tools to determine the correct license.

By default are files without license information under the default
license of the kernel, which is GPLV2.  Marking them GPLV2 would exclude
them from being included in non GPLV2 code, which is obviously not
intended. The user space API headers fall under the syscall exception
which is in the kernels COPYING file:

   NOTE! This copyright does *not* cover user programs that use kernel
   services by normal system calls - this is merely considered normal use
   of the kernel, and does *not* fall under the heading of "derived work".

otherwise syscall usage would not be possible.

Update the files which contain no license information with an SPDX
license identifier.  The chosen identifier is 'GPL-2.0 WITH
Linux-syscall-note' which is the officially assigned identifier for the
Linux syscall exception.  SPDX license identifiers are a legally binding
shorthand, which can be used instead of the full boiler plate text.

This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.  See the previous patch in this series for the
methodology of how this patch was researched.

Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoAdd compatibility support for async in pernet_operations.
Jozsef Kadlecsik [Mon, 22 Oct 2018 18:47:35 +0000 (20:47 +0200)]
Add compatibility support for async in pernet_operations.

6 years agonet: Convert ip_set_net_ops
Kirill Tkhai [Mon, 22 Oct 2018 18:46:53 +0000 (20:46 +0200)]
net: Convert ip_set_net_ops

These pernet_operations initialize and destroy
net_generic(net, ip_set_net_id)-related data.
Since ip_set is under CONFIG_IP_SET, it's easy
to watch drivers, which depend on this config.
All of them are in net/netfilter/ipset directory,
except of net/netfilter/xt_set.c. There are no
more drivers, which use ip_set, and all of
the above don't register another pernet_operations.
Also, there are is no indirect users, as header
file include/linux/netfilter/ipset/ip_set.h does
not define indirect users by something like this:

        #ifdef CONFIG_IP_SET
        extern func(void);
        #else
        static inline func(void);
        #endif

So, there are no more pernet operations, dereferencing
net_generic(net, ip_set_net_id).

ip_set_net_ops are OK to be executed in parallel
for several net, so we mark them as async.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoUse more robust awk patterns to check for backward compatibility
Jozsef Kadlecsik [Mon, 22 Oct 2018 18:38:55 +0000 (20:38 +0200)]
Use more robust awk patterns to check for backward compatibility

6 years agonetfilter: Replace spin_is_locked() with lockdep
Lance Roy [Wed, 3 Oct 2018 05:39:00 +0000 (22:39 -0700)]
netfilter: Replace spin_is_locked() with lockdep

lockdep_assert_held() is better suited to checking locking requirements,
since it won't get confused when someone else holds the lock. This is
also a step towards possibly removing spin_is_locked().

Signed-off-by: Lance Roy <ldr709@gmail.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Cc: Florian Westphal <fw@strlen.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: <netfilter-devel@vger.kernel.org>
Cc: <coreteam@netfilter.org>
Cc: <netdev@vger.kernel.org>
Acked-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoPrepare the ipset tool to handle multiple protocol versions
Jozsef Kadlecsik [Mon, 22 Oct 2018 18:01:14 +0000 (20:01 +0200)]
Prepare the ipset tool to handle multiple protocol versions

From now on the "version" command asks the kernel protocol version too
and reports if the userspace - kernel protocols do not match.

6 years agoFix warning message handling
Jozsef Kadlecsik [Mon, 22 Oct 2018 17:12:14 +0000 (19:12 +0200)]
Fix warning message handling

Warning messages were not printed and handled properly, the patch
fixes the issue.

6 years agoCorrect to test null valued entry in hash:net6,port,net6 test
Jozsef Kadlecsik [Fri, 19 Oct 2018 17:41:26 +0000 (19:41 +0200)]
Correct to test null valued entry in hash:net6,port,net6 test

6 years agoFix calling ip_set() macro at dumping
Jozsef Kadlecsik [Fri, 19 Oct 2018 17:37:28 +0000 (19:37 +0200)]
Fix calling ip_set() macro at dumping

The ip_set() macro is called when either ip_set_ref_lock held only
or no lock/nfnl mutex is held at dumping. Take this into account
properly.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoCorrect rcu_dereference() call in ip_set_put_comment()
Jozsef Kadlecsik [Fri, 19 Oct 2018 17:35:19 +0000 (19:35 +0200)]
Correct rcu_dereference() call in ip_set_put_comment()

The function is called when rcu_read_lock() is held and not
when rcu_read_lock_bh() is held.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoLibrary reworked to support embedding ipset completely
Jozsef Kadlecsik [Thu, 18 Oct 2018 15:27:49 +0000 (17:27 +0200)]
Library reworked to support embedding ipset completely

The ipset library is rewritten/extended to support embedding
ipset, so that sets can fully be managed without calling the ipset
binary. The ipset binary relies completely on the new library.

The libipset.3 manpage was written about the library functions
and usage.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoAdd compatibility to support kvcalloc()
Jozsef Kadlecsik [Mon, 24 Sep 2018 16:28:53 +0000 (18:28 +0200)]
Add compatibility to support kvcalloc()

6 years agonetfilter: ipset: fix ip_set_list allocation failure
Andrey Ryabinin [Mon, 24 Sep 2018 16:20:42 +0000 (18:20 +0200)]
netfilter: ipset: fix ip_set_list allocation failure

ip_set_create() and ip_set_net_init() attempt to allocate physically
contiguous memory for ip_set_list. If memory is fragmented, the
allocations could easily fail:

        vzctl: page allocation failure: order:7, mode:0xc0d0

        Call Trace:
         dump_stack+0x19/0x1b
         warn_alloc_failed+0x110/0x180
         __alloc_pages_nodemask+0x7bf/0xc60
         alloc_pages_current+0x98/0x110
         kmalloc_order+0x18/0x40
         kmalloc_order_trace+0x26/0xa0
         __kmalloc+0x279/0x290
         ip_set_net_init+0x4b/0x90 [ip_set]
         ops_init+0x3b/0xb0
         setup_net+0xbb/0x170
         copy_net_ns+0xf1/0x1c0
         create_new_namespaces+0xf9/0x180
         copy_namespaces+0x8e/0xd0
         copy_process+0xb61/0x1a00
         do_fork+0x91/0x320

Use kvcalloc() to fallback to 0-order allocations if high order
page isn't available.

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoValidate string type attributes in attr2data()
Stefano Brivio [Fri, 31 Aug 2018 09:43:39 +0000 (11:43 +0200)]
Validate string type attributes in attr2data()

Otherwise, we are missing checks in some paths, e.g. we might
overrun the buffer used to save the set name in callback_list()
when we strcpy() to it.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agomanpage: Add comment about matching on destination MAC address
Stefano Brivio [Wed, 29 Aug 2018 17:51:12 +0000 (19:51 +0200)]
manpage: Add comment about matching on destination MAC address

Patch "ipset: Allow matching on destination MAC address for mac
and ipmac sets" allows the user to match on destination MAC
addresses in some selected cases. Add a comment to the manpage
detailing in which cases it makes sense.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoAdd compatibility to support is_zero_ether_addr()
Jozsef Kadlecsik [Thu, 30 Aug 2018 08:46:18 +0000 (10:46 +0200)]
Add compatibility to support is_zero_ether_addr()

6 years agoipset: Make invalid MAC address checks consistent
Stefano Brivio [Fri, 17 Aug 2018 19:09:48 +0000 (21:09 +0200)]
ipset: Make invalid MAC address checks consistent

Set types bitmap:ipmac and hash:ipmac check that MAC addresses
are not all zeroes.

Introduce one missing check, and make the remaining ones
consistent, using is_zero_ether_addr() instead of comparing
against an array containing zeroes.

This was already done for hash:mac sets in commit 26c97c5d8dac
("netfilter: ipset: Use is_zero_ether_addr instead of static and
memcmp").

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoipset: Allow matching on destination MAC address for mac and ipmac sets
Stefano Brivio [Fri, 17 Aug 2018 19:09:47 +0000 (21:09 +0200)]
ipset: Allow matching on destination MAC address for mac and ipmac sets

There doesn't seem to be any reason to restrict MAC address
matching to source MAC addresses in set types bitmap:ipmac,
hash:ipmac and hash:mac. With this patch, and this setup:

  ip netns add A
  ip link add veth1 type veth peer name veth2 netns A
  ip addr add 192.0.2.1/24 dev veth1
  ip -net A addr add 192.0.2.2/24 dev veth2
  ip link set veth1 up
  ip -net A link set veth2 up

  ip netns exec A ipset create test hash:mac
  dst=$(ip netns exec A cat /sys/class/net/veth2/address)
  ip netns exec A ipset add test ${dst}
  ip netns exec A iptables -P INPUT DROP
  ip netns exec A iptables -I INPUT -m set --match-set test dst -j ACCEPT

ipset will match packets based on destination MAC address:

  # ping -c1 192.0.2.2 >/dev/null
  # echo $?
  0

Reported-by: Yi Chen <yiche@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agonetfilter: ipset: actually allow allowable CIDR 0 in hash:net,port,net
Eric Westbrook [Tue, 28 Aug 2018 21:14:42 +0000 (15:14 -0600)]
netfilter: ipset: actually allow allowable CIDR 0 in hash:net,port,net

Allow /0 as advertised for hash:net,port,net sets.

For "hash:net,port,net", ipset(8) says that "either subnet
is permitted to be a /0 should you wish to match port
between all destinations."

Make that statement true.

Before:

    # ipset create cidrzero hash:net,port,net
    # ipset add cidrzero 0.0.0.0/0,12345,0.0.0.0/0
    ipset v6.34: The value of the CIDR parameter of the IP address is invalid

    # ipset create cidrzero6 hash:net,port,net family inet6
    # ipset add cidrzero6 ::/0,12345,::/0
    ipset v6.34: The value of the CIDR parameter of the IP address is invalid

After:

    # ipset create cidrzero hash:net,port,net
    # ipset add cidrzero 0.0.0.0/0,12345,0.0.0.0/0
    # ipset test cidrzero 192.168.205.129,12345,172.16.205.129
    192.168.205.129,tcp:12345,172.16.205.129 is in set cidrzero.

    # ipset create cidrzero6 hash:net,port,net family inet6
    # ipset add cidrzero6 ::/0,12345,::/0
    # ipset test cidrzero6 fe80::1,12345,ff00::1
    fe80::1,tcp:12345,ff00::1 is in set cidrzero6.

See also:

  https://bugzilla.kernel.org/show_bug.cgi?id=200897
  https://github.com/ewestbrook/linux/commit/df7ff6efb0934ab6acc11f003ff1a7580d6c1d9c

Signed-off-by: Eric Westbrook <linux@westbrook.io>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoFix use-after-free in ipset_parse_name_compat()
Stefano Brivio [Wed, 22 Aug 2018 09:22:53 +0000 (11:22 +0200)]
Fix use-after-free in ipset_parse_name_compat()

When check_setname is used in ipset_parse_name_compat(), the
'str' and 'saved' macro arguments point in fact to the same
buffer. Free the 'saved' argument only after using it.

While at it, remove a useless NULL check on 'saved'.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoFix leak in build_argv() on line parsing error
Stefano Brivio [Wed, 22 Aug 2018 09:22:56 +0000 (11:22 +0200)]
Fix leak in build_argv() on line parsing error

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoSimplify return statement in ipset_mnl_query()
Stefano Brivio [Wed, 22 Aug 2018 09:22:54 +0000 (11:22 +0200)]
Simplify return statement in ipset_mnl_query()

As we loop as long as 'ret' is greater than zero, and break only
if we get an error in mnl_cb_run2 (with ret <= 0), we can just
return ret without checking once more if it's greater than zero.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoipset: list:set: Decrease refcount synchronously on deletion and replace
Stefano Brivio [Sat, 14 Jul 2018 19:59:43 +0000 (21:59 +0200)]
ipset: list:set: Decrease refcount synchronously on deletion and replace

Commit 45040978c899 ("netfilter: ipset: Fix set:list type crash
when flush/dump set in parallel") postponed decreasing set
reference counters to the RCU callback.

An 'ipset del' command can terminate before the RCU grace period
is elapsed, and if sets are listed before then, the reference
counter shown in userspace will be wrong:

 # ipset create h hash:ip; ipset create l list:set; ipset add l
 # ipset del l h; ipset list h
 Name: h
 Type: hash:ip
 Revision: 4
 Header: family inet hashsize 1024 maxelem 65536
 Size in memory: 88
 References: 1
 Number of entries: 0
 Members:
 # sleep 1; ipset list h
 Name: h
 Type: hash:ip
 Revision: 4
 Header: family inet hashsize 1024 maxelem 65536
 Size in memory: 88
 References: 0
 Number of entries: 0
 Members:

Fix this by making the reference count update synchronous again.

As a result, when sets are listed, ip_set_name_byindex() might
now fetch a set whose reference count is already zero. Instead
of relying on the reference count to protect against concurrent
set renaming, grab ip_set_ref_lock as reader and copy the name,
while holding the same lock in ip_set_rename() as writer
instead.

Reported-by: Li Shuang <shuali@redhat.com>
Fixes: 45040978c899 ("netfilter: ipset: Fix set:list type crash when flush/dump set in parallel")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agonetfilter: ipset: forbid family for hash:mac sets
Florent Fourcot [Mon, 4 Jun 2018 14:51:19 +0000 (16:51 +0200)]
netfilter: ipset: forbid family for hash:mac sets

Userspace `ipset` command forbids family option for hash:mac type:

ipset create test hash:mac family inet4
ipset v6.30: Unknown argument: `family'

However, this check is not done in kernel itself. When someone use
external netlink applications (pyroute2 python library for example), one
can create hash:mac with invalid family and inconsistant results from
userspace (`ipset` command cannot read set content anymore).

This patch enforce the logic in kernel, and forbids insertion of
hash:mac with a family set.

Since IP_SET_PROTO_UNDEF is defined only for hash:mac, this patch has no
impact on other hash:* sets

Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Victorien Molle <victorien.molle@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoLimit max timeout value to (UINT_MAX >> 1)/MSEC_PER_SEC
Jozsef Kadlecsik [Fri, 1 Jun 2018 18:59:14 +0000 (20:59 +0200)]
Limit max timeout value to (UINT_MAX >> 1)/MSEC_PER_SEC

Due to the negative value condition in msecs_to_jiffies(), the real
max possible timeout value must be set to (UINT_MAX >> 1)/MSEC_PER_SEC.

Neutron Soutmun proposed the proper fix, but an insufficient one was
applied, see https://patchwork.ozlabs.org/patch/400405/.

6 years agoList timing out entries with "timeout 1" instead of zero timeout value
Jozsef Kadlecsik [Thu, 31 May 2018 16:45:21 +0000 (18:45 +0200)]
List timing out entries with "timeout 1" instead of zero timeout value

When listing sets with timeout support, there's a probability that
just timing out entries with "0" timeout value is listed/saved.
However when restoring the saved list, the zero timeout value means
permanent elelements.

The new behaviour is that timing out entries are listed with "timeout 1"
instead of zero.

Fixes bugzilla #1258.

6 years agotests/check_klog.sh: Try dmesg too, don't let shell terminate script
Stefano Brivio [Tue, 8 May 2018 15:43:30 +0000 (17:43 +0200)]
tests/check_klog.sh: Try dmesg too, don't let shell terminate script

Some hosts might not use /var/log/kern.log for kernel messages,
so if we can't find a match there, try dmesg next.

If no matches are found, don't let the shell terminate the
script, so that we have a chance to try dmesg and actually echo
"no match!" if no matches are found: set +e before the setname
loop.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agonetfilter: xt_set: Check hook mask correctly
Serhey Popovych [Mon, 30 Apr 2018 18:26:02 +0000 (21:26 +0300)]
netfilter: xt_set: Check hook mask correctly

Inserting rule before one with SET target we get error with warning in
dmesg(1) output:

  # iptables -A FORWARD -t mangle -j SET --map-set test src --map-prio
  # iptables -I FORWARD 1 -t mangle -j ACCEPT
  iptables: Invalid argument. Run `dmesg' for more information.
  # dmesg |tail -n1
  [268578.026643] mapping of prio or/and queue is allowed only from \
  OUTPUT/FORWARD/POSTROUTING chains

Rather than checking for supported hook bits for SET target check for
unsupported one as done in all rest of matches and targets.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoipset 6.38 released v6.38
Jozsef Kadlecsik [Tue, 10 Apr 2018 21:36:27 +0000 (23:36 +0200)]
ipset 6.38 released

6 years agoFix API version number (reported by Jan Engelhardt)
Jozsef Kadlecsik [Tue, 10 Apr 2018 21:35:21 +0000 (23:35 +0200)]
Fix API version number (reported by Jan Engelhardt)

6 years agoipset 6.37 released v6.37
Jozsef Kadlecsik [Tue, 10 Apr 2018 18:53:25 +0000 (20:53 +0200)]
ipset 6.37 released

6 years agoFix parsing service names for ports
Jozsef Kadlecsik [Tue, 10 Apr 2018 18:48:35 +0000 (20:48 +0200)]
Fix parsing service names for ports

Parsing is attempted both for numbers and service names and
the temporary stored error message triggered to reset the state
parameters about the set. Reported by Yuri D'Elia.

6 years agonetfilter: ipset: Use is_zero_ether_addr instead of static and memcmp
Joe Perches [Tue, 20 Mar 2018 17:35:47 +0000 (10:35 -0700)]
netfilter: ipset: Use is_zero_ether_addr instead of static and memcmp

To make the test a bit clearer and to reduce object size a little.

Miscellanea:

o remove now unnecessary static const array

$ size ip_set_hash_mac.o*
   text    data     bss     dec     hex filename
  22822    4619      64   27505    6b71 ip_set_hash_mac.o.allyesconfig.new
  22932    4683      64   27679    6c1f ip_set_hash_mac.o.allyesconfig.old
  10443    1040       0   11483    2cdb ip_set_hash_mac.o.defconfig.new
  10507    1040       0   11547    2d1b ip_set_hash_mac.o.defconfig.old

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoipset 6.36 released v6.36
Jozsef Kadlecsik [Sat, 3 Mar 2018 13:04:02 +0000 (14:04 +0100)]
ipset 6.36 released

6 years agoUse 'ss' in runtest.sh but fall back to deprecated 'net-tools' command
Jozsef Kadlecsik [Sat, 3 Mar 2018 12:59:05 +0000 (13:59 +0100)]
Use 'ss' in runtest.sh but fall back to deprecated 'net-tools' command

Fixes bugzilla id #1209.

6 years agoRemove duplicate module description
Jozsef Kadlecsik [Mon, 29 Jan 2018 20:28:32 +0000 (21:28 +0100)]
Remove duplicate module description

6 years agonetfilter: remove messages print and boot/module load time
Pablo Neira Ayuso [Fri, 19 Jan 2018 12:47:02 +0000 (13:47 +0100)]
netfilter: remove messages print and boot/module load time

Several reasons for this:

* Several modules maintain internal version numbers, that they print at
  boot/module load time, that are not exposed to userspace, as a
  primitive mechanism to make revision number control from the earlier
  days of Netfilter.

* IPset shows the protocol version at boot/module load time, instead
  display this via module description, as Jozsef suggested.

* Remove copyright notice at boot/module load time in two spots, the
  Netfilter codebase is a collective development effort, if we would
  have to display copyrights for each contributor at boot/module load
  time for each extensions we have, we would probably fill up logs with
  lots of useless information - from a technical standpoint.

So let's be consistent and remove them all.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agobuild: do install libipset/args.h
Jan Engelhardt [Mon, 22 Jan 2018 21:50:33 +0000 (22:50 +0100)]
build: do install libipset/args.h

libipset/types.h includes args.h, therefore args.h must be installed
too.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoAdd test to verify wraparound fix
Jozsef Kadlecsik [Fri, 12 Jan 2018 09:42:40 +0000 (10:42 +0100)]
Add test to verify wraparound fix

6 years agoFix wraparound bug introduced in commit 48596a8ddc46
Jozsef Kadlecsik [Fri, 12 Jan 2018 09:36:25 +0000 (10:36 +0100)]
Fix wraparound bug introduced in commit 48596a8ddc46

The patch "netfilter: ipset: Fix adding an IPv4 range containing
more than 2^31 addresses" introduced a wraparound bug, which could
lead to memory exhaustion when adding an x.x.x.x-255.255.255.255
range to any hash:*net* types.

Fixes Netfilter's bugzilla id #1212, reported by Thomas Schwark.

6 years agoipset 6.35 released v6.35
Jozsef Kadlecsik [Sat, 6 Jan 2018 16:00:25 +0000 (17:00 +0100)]
ipset 6.35 released

6 years agonetfilter: mark expected switch fall-throughs
Gustavo A. R. Silva [Sat, 6 Jan 2018 15:53:35 +0000 (16:53 +0100)]
netfilter: mark expected switch fall-throughs

In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoLicense cleanup: add SPDX GPL-2.0 license identifier to files with no license
Greg Kroah-Hartman [Wed, 1 Nov 2017 14:07:57 +0000 (15:07 +0100)]
License cleanup: add SPDX GPL-2.0 license identifier to files with no license

Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.

By default all files without license information are under the default
license of the kernel, which is GPL version 2.

Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier.  The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.

This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.

How this work was done:

Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
 - file had no licensing information it it.
 - file was a */uapi/* one with no licensing information in it,
 - file was a */uapi/* one with existing licensing information,

Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.

The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne.  Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.

The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed.  Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.

Criteria used to select files for SPDX license identifier tagging was:
 - Files considered eligible had to be source code files.
 - Make and config files were included as candidates if they contained >5
   lines of source
 - File already had some variant of a license header in it (even if <5
   lines).

All documentation files were explicitly excluded.

The following heuristics were used to determine which SPDX license
identifiers to apply.

 - when both scanners couldn't find any license traces, file was
   considered to have no license information in it, and the top level
   COPYING file license applied.

   For non */uapi/* files that summary was:

   SPDX license identifier                            # files
   ---------------------------------------------------|-------
   GPL-2.0                                              11139

   and resulted in the first patch in this series.

   If that file was a */uapi/* path one, it was "GPL-2.0 WITH
   Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:

   SPDX license identifier                            # files
   ---------------------------------------------------|-------
   GPL-2.0 WITH Linux-syscall-note                        930

   and resulted in the second patch in this series.

 - if a file had some form of licensing information in it, and was one
   of the */uapi/* ones, it was denoted with the Linux-syscall-note if
   any GPL family license was found in the file or had no licensing in
   it (per prior point).  Results summary:

   SPDX license identifier                            # files
   ---------------------------------------------------|------
   GPL-2.0 WITH Linux-syscall-note                       270
   GPL-2.0+ WITH Linux-syscall-note                      169
   ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
   ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
   LGPL-2.1+ WITH Linux-syscall-note                      15
   GPL-1.0+ WITH Linux-syscall-note                       14
   ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
   LGPL-2.0+ WITH Linux-syscall-note                       4
   LGPL-2.1 WITH Linux-syscall-note                        3
   ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
   ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1

   and that resulted in the third patch in this series.

 - when the two scanners agreed on the detected license(s), that became
   the concluded license(s).

 - when there was disagreement between the two scanners (one detected a
   license but the other didn't, or they both detected different
   licenses) a manual inspection of the file occurred.

 - In most cases a manual inspection of the information in the file
   resulted in a clear resolution of the license that should apply (and
   which scanner probably needed to revisit its heuristics).

 - When it was not immediately clear, the license identifier was
   confirmed with lawyers working with the Linux Foundation.

 - If there was any question as to the appropriate license identifier,
   the file was flagged for further research and to be revisited later
   in time.

In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.

Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights.  The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.

Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.

In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.

Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
 - a full scancode scan run, collecting the matched texts, detected
   license ids and scores
 - reviewing anything where there was a license detected (about 500+
   files) to ensure that the applied SPDX license was correct
 - reviewing anything where there was no detection but the patch license
   was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
   SPDX license was correct

This produced a worksheet with 20 files needing minor correction.  This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.

These .csv files were then reviewed by Greg.  Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected.  This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.)  Finally Greg ran the script using the .csv files to
generate the patches.

Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agoBackport patch: netfilter: ipset: use nfnl_mutex_is_locked
Jozsef Kadlecsik [Thu, 4 Jan 2018 13:16:47 +0000 (14:16 +0100)]
Backport patch: netfilter: ipset: use nfnl_mutex_is_locked

6 years agoMissing nfnl_lock()/nfnl_unlock() is added to ip_set_net_exit()
Jozsef Kadlecsik [Thu, 4 Jan 2018 13:15:22 +0000 (14:15 +0100)]
Missing nfnl_lock()/nfnl_unlock() is added to ip_set_net_exit()

Patch "netfilter: ipset: use nfnl_mutex_is_locked" is added the real
mutex locking check, which revealed the missing locking in ip_set_net_exit().

6 years agonetfilter: ipset: use nfnl_mutex_is_locked
Florian Westphal [Thu, 30 Nov 2017 20:07:32 +0000 (21:07 +0100)]
netfilter: ipset: use nfnl_mutex_is_locked

Check that we really hold nfnl mutex here instead of relying on correct
usage alone.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 years agonetfilter: ipset: add resched points during set listing
Florian Westphal [Thu, 4 Jan 2018 12:24:44 +0000 (13:24 +0100)]
netfilter: ipset: add resched points during set listing

When sets are extremely large we can get softlockup during ipset -L.
We could fix this by adding cond_resched_rcu() at the right location
during iteration, but this only works if RCU nesting depth is 1.

At this time entire variant->list() is called under under rcu_read_lock_bh.
This used to be a read_lock_bh() but as rcu doesn't really lock anything,
it does not appear to be needed, so remove it (ipset increments set
reference count before this, so a set deletion should not be possible).

Reported-by: Li Shuang <shuali@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoFix "don't update counters" mode when counters used at the matching
Jozsef Kadlecsik [Thu, 4 Jan 2018 12:21:26 +0000 (13:21 +0100)]
Fix "don't update counters" mode when counters used at the matching

The matching of the counters was not taken into account, fixed.

6 years agoBackport patch: netfilter: ipset: Convert timers to use timer_setup()
Jozsef Kadlecsik [Wed, 3 Jan 2018 09:57:31 +0000 (10:57 +0100)]
Backport patch: netfilter: ipset: Convert timers to use timer_setup()

6 years agoUserspace revision handling is reworked
Jozsef Kadlecsik [Mon, 9 Oct 2017 16:43:04 +0000 (18:43 +0200)]
Userspace revision handling is reworked

In order to make it simpler and more straightforward to express
the revisions of the set type, all keywords and their parsing
are separated from the individual set types.

All backward compatibility arguments are recognized and ignored
arguments are supported.

Recognized but ignored arguments will be removed in a later release.

7 years agonetfilter: ipset: use swap macro instead of _manually_ swapping values
Gustavo A. R. Silva [Mon, 30 Oct 2017 22:19:25 +0000 (17:19 -0500)]
netfilter: ipset: use swap macro instead of _manually_ swapping values

Make use of the swap macro and remove unnecessary variables tmp.
This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agonetfilter: ipset: Fix race between dump and swap
Ross Lagerwall [Wed, 27 Sep 2017 09:06:27 +0000 (10:06 +0100)]
netfilter: ipset: Fix race between dump and swap

Fix a race between ip_set_dump_start() and ip_set_swap().
The race is as follows:
* Without holding the ref lock, ip_set_swap() checks ref_netlink of the
  set and it is 0.
* ip_set_dump_start() takes a reference on the set.
* ip_set_swap() does the swap (even though it now has a non-zero
  reference count).
* ip_set_dump_start() gets the set from ip_set_list again which is now a
  different set since it has been swapped.
* ip_set_dump_start() calls __ip_set_put_netlink() and hits a BUG_ON due
  to the reference count being 0.

Fix this race by extending the critical region in which the ref lock is
held to include checking the ref counts.

The race can be reproduced with the following script:
  while :; do
    ipset destroy hash_ip1
    ipset destroy hash_ip2
    ipset create hash_ip1 hash:ip family inet hashsize 1024 \
        maxelem 500000
    ipset create hash_ip2 hash:ip family inet hashsize 300000 \
        maxelem 500000
    ipset create hash_ip3 hash:ip family inet hashsize 1024 \
        maxelem 500000
    ipset save &
    ipset swap hash_ip3 hash_ip2
    ipset destroy hash_ip3
    wait
  done

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agonetfilter: ipset: pernet ops must be unregistered last
Florian Westphal [Tue, 26 Sep 2017 17:52:58 +0000 (19:52 +0200)]
netfilter: ipset: pernet ops must be unregistered last

Removing the ipset module leaves a small window where one cpu performs
module removal while another runs a command like 'ipset flush'.

ipset uses net_generic(), unregistering the pernet ops frees this
storage area.

Fix it by first removing the user-visible api handlers and the pernet
ops last.

Fixes: 1785e8f473082 ("netfiler: ipset: Add net namespace for ipset")
Reported-by: Li Shuang <shuali@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoReplace the last reference to u_int8_t with uint8_t.
Jozsef Kadlecsik [Tue, 26 Sep 2017 05:00:13 +0000 (07:00 +0200)]
Replace the last reference to u_int8_t with uint8_t.

7 years agoRevert "ipset: fix build with musl"
Jozsef Kadlecsik [Tue, 26 Sep 2017 04:57:34 +0000 (06:57 +0200)]
Revert "ipset: fix build with musl"

This reverts commit 992723e3712a09037338aa9e5506a080e24d1642.

The single u_int8_t usage was a leftover.

7 years agoipset: fix build with musl
Stijn Tintel [Mon, 25 Sep 2017 05:09:01 +0000 (08:09 +0300)]
ipset: fix build with musl

Include sys/types.h for u_int8_t and define _GNU_SOURCE for musl to
expose it.

Fixes: 54802b2c2826 ("Report if the option is supported by a newer kernel release")
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoipset 6.34 released v6.34
Jozsef Kadlecsik [Sat, 23 Sep 2017 18:44:37 +0000 (20:44 +0200)]
ipset 6.34 released

7 years agotestsuite: Make sure it can be run over ssh :-)
Jozsef Kadlecsik [Sat, 23 Sep 2017 18:37:16 +0000 (20:37 +0200)]
testsuite: Make sure it can be run over ssh :-)

7 years agoReset state after a command failed, when multiple ones are issued.
Jozsef Kadlecsik [Tue, 19 Sep 2017 20:06:50 +0000 (22:06 +0200)]
Reset state after a command failed, when multiple ones are issued.

Fixes bugzilla id #1158 reported by Dimitri Grischin.

7 years agoHandle padding attribute properly in userspace.
Jozsef Kadlecsik [Tue, 19 Sep 2017 19:43:29 +0000 (21:43 +0200)]
Handle padding attribute properly in userspace.

7 years agoAdd test file missing from patch previous patch.
Jozsef Kadlecsik [Tue, 19 Sep 2017 19:42:41 +0000 (21:42 +0200)]
Add test file missing from patch previous patch.

7 years agoTest to check the fix to add an IPv4 range containing more than 2^31 addresses
Jozsef Kadlecsik [Mon, 18 Sep 2017 19:46:42 +0000 (21:46 +0200)]
Test to check the fix to add an IPv4 range containing more than 2^31 addresses

7 years agoFix adding an IPv4 range containing more than 2^31 addresses
Jozsef Kadlecsik [Mon, 18 Sep 2017 19:43:30 +0000 (21:43 +0200)]
Fix adding an IPv4 range containing more than 2^31 addresses

Wrong comparison prevented the hash types to add a range with
more than 2^31 addresses but reported as a success.

Fixes bugzilla id #1005, reported by Oleg Serditov and Oliver Ford.

7 years agoFix the include guards on the include/libipset/linux_ip_set*.h
Jozsef Kadlecsik [Thu, 14 Sep 2017 17:48:03 +0000 (19:48 +0200)]
Fix the include guards on the include/libipset/linux_ip_set*.h

The include guards did not prevent including the "same" userspace
and kernel header files.

Fixes bugzilla id #1139, reported and solution suggested by Quentin Armitage.

7 years agoNew function added in commit 54802b2c is missing from libipset.map
Jozsef Kadlecsik [Thu, 14 Sep 2017 17:29:55 +0000 (19:29 +0200)]
New function added in commit 54802b2c is missing from libipset.map
The patch title was "Report if the option is supported by a newer kernel release"

Fixes bugzilla id #1182, reported by irherder@gmail.com.

7 years agoipset 6.33 released v6.33
Jozsef Kadlecsik [Tue, 12 Sep 2017 05:26:58 +0000 (07:26 +0200)]
ipset 6.33 released

7 years agoBackport patch: sctp: remove the typedef sctp_sctphdr_t
Jozsef Kadlecsik [Mon, 11 Sep 2017 19:12:13 +0000 (21:12 +0200)]
Backport patch: sctp: remove the typedef sctp_sctphdr_t

7 years agoBackport patch: netfilter: nfnetlink: extended ACK reporting
Jozsef Kadlecsik [Mon, 11 Sep 2017 19:04:59 +0000 (21:04 +0200)]
Backport patch: netfilter: nfnetlink: extended ACK reporting

7 years agoipset: remove unused function __ip_set_get_netlink
Aaron Conole [Mon, 11 Sep 2017 18:47:53 +0000 (20:47 +0200)]
ipset: remove unused function __ip_set_get_netlink

There are no in-tree callers.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Acked-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoBackport patch: netlink: pass extended ACK struct to parsing functions
Jozsef Kadlecsik [Mon, 11 Sep 2017 18:45:44 +0000 (20:45 +0200)]
Backport patch: netlink: pass extended ACK struct to parsing functions

7 years agoBackport patch netlink: extended ACK reporting
Jozsef Kadlecsik [Mon, 11 Sep 2017 18:30:21 +0000 (20:30 +0200)]
Backport patch netlink: extended ACK reporting

7 years agonetfilter: Remove exceptional & on function name
Arushi Singhal [Mon, 11 Sep 2017 18:20:00 +0000 (20:20 +0200)]
netfilter: Remove exceptional & on function name

Remove & from function pointers to conform to the style found elsewhere
in the file. Done using the following semantic patch

// <smpl>
@r@
identifier f;
@@

f(...) { ... }
@@
identifier r.f;
@@

- &f
+ f
// </smpl>

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoBackport missing part of patch: netfilter: Remove unnecessary cast on void pointer
Jozsef Kadlecsik [Mon, 11 Sep 2017 18:18:08 +0000 (20:18 +0200)]
Backport missing part of patch: netfilter: Remove unnecessary cast on void pointer

7 years agoBackport nfnl_msg_type()
Jozsef Kadlecsik [Mon, 11 Sep 2017 18:14:25 +0000 (20:14 +0200)]
Backport nfnl_msg_type()

7 years agoReport if the option is supported by a newer kernel release
Jozsef Kadlecsik [Mon, 11 Sep 2017 18:07:40 +0000 (20:07 +0200)]
Report if the option is supported by a newer kernel release

Instead ot printing "Unknown argument: foo", if foo option is
supported by a newer kernel release, report that.

7 years agonetfilter: ipset: ipset list may return wrong member count for set with timeout
Vishwanath Pai [Thu, 17 Aug 2017 05:23:55 +0000 (01:23 -0400)]
netfilter: ipset: ipset list may return wrong member count for set with timeout

Simple testcase:

$ ipset create test hash:ip timeout 5
$ ipset add test 1.2.3.4
$ ipset add test 1.2.2.2
$ sleep 5

$ ipset l
Name: test
Type: hash:ip
Revision: 5
Header: family inet hashsize 1024 maxelem 65536 timeout 5
Size in memory: 296
References: 0
Number of entries: 2
Members:

We return "Number of entries: 2" but no members are listed. That is
because mtype_list runs "ip_set_timeout_expired" and does not list the
expired entries, but set->elements is never upated (until mtype_gc
cleans it up later).

Reviewed-by: Joshua Hunt <johunt@akamai.com>
Signed-off-by: Vishwanath Pai <vpai@akamai.com>
7 years agonetfilter: ipset: deduplicate prefixlen maps
Aaron Conole [Thu, 20 Jul 2017 18:13:00 +0000 (14:13 -0400)]
netfilter: ipset: deduplicate prefixlen maps

The prefixlen maps used here are identical, and have been since
introduction.  It seems to make sense to use a single large map,
that the preprocessor will fill appropriately.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
7 years agoipset: Fix ipset command replacement in runtest.sh
Neutron Soutmun [Tue, 30 May 2017 10:46:33 +0000 (17:46 +0700)]
ipset: Fix ipset command replacement in runtest.sh

  Fix the ipset command replacement.

  For ipset="/sbin/ipset"

  Actual:
    /sbin//sbin/ipset 2>.foo.err | ... | xargs -n1 ipset
  Expected:
    /sbin/ipset 2>.foo.err | ... | xargs -n1 /sbin/ipset

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoFix sparse warnings
Jozsef Kadlecsik [Thu, 23 Mar 2017 21:10:40 +0000 (22:10 +0100)]
Fix sparse warnings

7 years agoCorrect a test: number of entries may be outdated
Jozsef Kadlecsik [Thu, 23 Mar 2017 20:28:11 +0000 (21:28 +0100)]
Correct a test: number of entries may be outdated

At listing, timed out entries are not listed but the number of entries
counter is updated at garbage collection.