]> granicus.if.org Git - ipset/log
ipset
6 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.

6 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.

6 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

6 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.

6 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.

6 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.

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

6 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

6 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

6 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>
6 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

6 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

6 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>
6 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

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

6 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.

6 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>
6 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.

7 years agonetfilter: ipset: Compress return logic
simran singhal [Tue, 21 Mar 2017 13:30:07 +0000 (19:00 +0530)]
netfilter: ipset: Compress return logic

Simplify function returns by merging assignment and return into one
command line.

Signed-off-by: simran singhal <singhalsimran0@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agonetfilter: ipset: Remove unnecessary cast on void pointer
simran singhal [Tue, 21 Mar 2017 12:19:53 +0000 (17:49 +0530)]
netfilter: ipset: Remove unnecessary cast on void pointer

The following Coccinelle script was used to detect this:
@r@
expression x;
void* e;
type T;
identifier f;
@@
(
  *((T *)e)
|
  ((T *)x)[...]
|
  ((T*)x)->f
|

- (T*)
  e
)

Signed-off-by: simran singhal <singhalsimran0@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoCompatibility: handle changes in 4.10 kernel tree
Jozsef Kadlecsik [Thu, 23 Mar 2017 15:13:16 +0000 (16:13 +0100)]
Compatibility: handle changes in 4.10 kernel tree

Handle changes in struct xt_action_param and the new xt_family(),
xt_net() interfaces (reported by Jan Engelhardt).

7 years agoipset 6.32 released v6.32
Jozsef Kadlecsik [Sun, 12 Mar 2017 17:41:03 +0000 (18:41 +0100)]
ipset 6.32 released

7 years agoFix possible truncated output in ipset output buffer handling
Jozsef Kadlecsik [Sun, 12 Mar 2017 17:27:45 +0000 (18:27 +0100)]
Fix possible truncated output in ipset output buffer handling

Omri Bahumi and Yoni Lavi discovered that due to the inproper
handling of the ipset output buffer, the output may be truncated.
So for example in an "ipset save" output, instead of 192.168.0.0/24,
just 192.168.0.0 printed. If one use "ipset save" and then "ipset restore"
to restore the sets, this may lead to wrong firewall rules at the end.

The patch fixes the bug in the ipset code.

7 years agoMissing prototype added in ipset_hash_ipmac.c (debugging)
Jozsef Kadlecsik [Sun, 12 Mar 2017 17:26:43 +0000 (18:26 +0100)]
Missing prototype added in ipset_hash_ipmac.c (debugging)

7 years agoipset 6.31 released v6.31
Jozsef Kadlecsik [Sun, 19 Feb 2017 17:52:52 +0000 (18:52 +0100)]
ipset 6.31 released

7 years agoUpdate manpage about the size parameter of list:set types.
Jozsef Kadlecsik [Sun, 19 Feb 2017 17:51:29 +0000 (18:51 +0100)]
Update manpage about the size parameter of list:set types.

The parameter is ignored since ipset version 6.24.

7 years agonetfilter: ipset: Null pointer exception in ipset list:set
Vishwanath Pai [Thu, 16 Feb 2017 19:55:45 +0000 (20:55 +0100)]
netfilter: ipset: Null pointer exception in ipset list:set

If we use before/after to add an element to an empty list it will cause
a kernel panic.

$> cat crash.restore
create a hash:ip
create b hash:ip
create test list:set timeout 5 size 4
add test b before a

$> ipset -R < crash.restore

Executing the above will crash the kernel.

Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Reviewed-by: Josh Hunt <johunt@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoNew test to verify that only the intended entries are deleted at hash types.
Jozsef Kadlecsik [Thu, 16 Feb 2017 19:52:04 +0000 (20:52 +0100)]
New test to verify that only the intended entries are deleted at hash types.

7 years agoFix bug: sometimes valid entries in hash:* types of sets were evicted
Jozsef Kadlecsik [Thu, 16 Feb 2017 19:47:30 +0000 (20:47 +0100)]
Fix bug: sometimes valid entries in hash:* types of sets were evicted

Wrong index was used and therefore when shrinking a hash bucket at
deleting an entry, valid entries could be evicted as well.
Thanks to Eric Ewanco for the thorough bugreport.

Fixes netfilter bugzilla #1119

7 years agoCorrect copyright owner
Jozsef Kadlecsik [Thu, 10 Nov 2016 10:51:37 +0000 (11:51 +0100)]
Correct copyright owner

The functions was not introduced by Sergey Popovich, he proposed
only separating them into individual extension header files.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoRevert patch "Correct rcu_dereference_bh_nfnl() usage"
Jozsef Kadlecsik [Thu, 10 Nov 2016 10:11:32 +0000 (11:11 +0100)]
Revert patch "Correct rcu_dereference_bh_nfnl() usage"

The susbsystem param cannot be used to rely on subsystem mutex locking
because the call is used in netlink dump context as well.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoipset 6.30 released v6.30
Jozsef Kadlecsik [Mon, 17 Oct 2016 11:50:14 +0000 (13:50 +0200)]
ipset 6.30 released

7 years agoipset: Drop extra comma from error message
Neutron Soutmun [Mon, 17 Oct 2016 04:51:06 +0000 (11:51 +0700)]
ipset: Drop extra comma from error message

* The "by userspace." should be concat with the error message instead.

Signed-off-by: Neutron Soutmun <neo.neutron@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoipset: Fix the incorrect dynamic/static modules list
Neutron Soutmun [Mon, 17 Oct 2016 04:48:33 +0000 (11:48 +0700)]
ipset: Fix the incorrect dynamic/static modules list

* The module's name should not be partial matched.

  SETTYPE_MODLIST="ipset_hash_ipmac"
  It shoud not be matched with "ipset_hash_ip".

Signed-off-by: Neutron Soutmun <neo.neutron@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agonetfilter: ipset: hash: fix boolreturn.cocci warnings
kbuild test robot [Sat, 15 Oct 2016 01:13:14 +0000 (09:13 +0800)]
netfilter: ipset: hash: fix boolreturn.cocci warnings

net/netfilter/ipset/ip_set_hash_ipmac.c:70:8-9: WARNING: return of 0/1 in function 'hash_ipmac4_data_list' with return type bool
net/netfilter/ipset/ip_set_hash_ipmac.c:178:8-9: WARNING: return of 0/1 in function 'hash_ipmac6_data_list' with return type bool

 Return statements in functions returning bool should use
 true/false instead of 1/0.
Generated by: scripts/coccinelle/misc/boolreturn.cocci

CC: Tomasz Chilinski <tomasz.chilinski@chilan.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoCorrect tests to check the number of entries too
Jozsef Kadlecsik [Fri, 14 Oct 2016 21:38:30 +0000 (23:38 +0200)]
Correct tests to check the number of entries too

Give enough time for the entries to timeout before listing, so that
we get the correct number of entries.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoFix the nla_put_net64() API changes backport
Jozsef Kadlecsik [Fri, 14 Oct 2016 21:36:46 +0000 (23:36 +0200)]
Fix the nla_put_net64() API changes backport

We must call nla_put_net64() because ipset uses net order in the netlink
communication.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agonetfilter: ipset: Fixing unnamed union init
Elad Raz [Thu, 13 Oct 2016 18:52:54 +0000 (20:52 +0200)]
netfilter: ipset: Fixing unnamed union init

In continue to proposed Vinson Lee's post [1], this patch fixes compilation
issues founded at gcc 4.4.7. The initialization of .cidr field of unnamed
unions causes compilation error in gcc 4.4.x.

References

Visible links
[1] https://lkml.org/lkml/2015/7/5/74

Signed-off-by: Elad Raz <eladr@mellanox.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agonetfilter: x_tables: Use par->net instead of computing from the passed net devices
Eric W. Biederman [Thu, 13 Oct 2016 18:40:39 +0000 (20:40 +0200)]
netfilter: x_tables: Use par->net instead of computing from the passed net devices

Backported from kernel tree.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoCorrect the reported memory size for bitmap:* types
Jozsef Kadlecsik [Thu, 13 Oct 2016 17:38:53 +0000 (19:38 +0200)]
Correct the reported memory size for bitmap:* types

The patch "Fix extension alignmen" (c7cf6f3b) removed counting
the non-dynamic extensions into the used up memory area, fixed.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoFix coding styles reported by checkpatch.pl, already in kernel
Jozsef Kadlecsik [Tue, 11 Oct 2016 20:37:18 +0000 (22:37 +0200)]
Fix coding styles reported by checkpatch.pl, already in kernel

7 years agonetfilter: x_tables: Pass struct net in xt_action_param
Eric W. Biederman [Tue, 11 Oct 2016 20:19:51 +0000 (22:19 +0200)]
netfilter: x_tables: Pass struct net in xt_action_param

As xt_action_param lives on the stack this does not bloat any
persistent data structures.

This is a first step in making netfilter code that needs to know
which network namespace it is executing in simpler.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonet: sched: fix skb->protocol use in case of accelerated vlan path
Jiri Pirko [Tue, 11 Oct 2016 20:09:08 +0000 (22:09 +0200)]
net: sched: fix skb->protocol use in case of accelerated vlan path

tc code implicitly considers skb->protocol even in case of accelerated
vlan paths and expects vlan protocol type here. However, on rx path,
if the vlan header was already stripped, skb->protocol contains value
of next header. Similar situation is on tx path.

So for skbs that use skb->vlan_tci for tagging, use skb->vlan_proto instead.

Reported-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
7 years agoCheck IPSET_ATTR_ETHER netlink attribute length in hash:ipmac too
Jozsef Kadlecsik [Tue, 11 Oct 2016 06:02:14 +0000 (08:02 +0200)]
Check IPSET_ATTR_ETHER netlink attribute length in hash:ipmac too

The explicit length checking was missing, added.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agonetfilter: fix include files for compilation
Mikko Rapeli [Tue, 11 Oct 2016 06:00:03 +0000 (08:00 +0200)]
netfilter: fix include files for compilation

Add missing header dependencies and other small changes so that each file
compiles alone in userspace.

Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
7 years agoipset: Backports for the nla_put_net64() API changes
Neutron Soutmun [Thu, 23 Jun 2016 10:22:11 +0000 (17:22 +0700)]
ipset: Backports for the nla_put_net64() API changes

* Backports the patch "libnl: nla_put_net64():align on a 64-bit area" [1]
  by Nicolas Dichtel <nicolas.dichtel@6wind.com>

* Since the nla_put_net64() API has been changed, therefore, the
  ip_set_compat.h.in should provides the macro IPSET_NLA_PUT_NET64 that
  point to the nla_put_net64() with appropriate number of arguments.

  The build script should distinguish the API changes by detect for
  the existence of nla_put_64bit() function in include/net/netlink.h.
  This function was added in the same patches set and called by
  the nla_put_be64() that called by nla_put_net64() respectively.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit?id=e9bbe898cbe89b17ad3993c136aa13d0431cd537

Signed-off-by: Neutron Soutmun <neo.neutron@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agonetfilter: ipset: use setup_timer() and mod_timer().
Muhammad Falak R Wani [Fri, 13 May 2016 20:58:54 +0000 (02:28 +0530)]
netfilter: ipset: use setup_timer() and mod_timer().

Use setup_timer() and instead of init_timer(), being the preferred way
of setting up a timer.

Also, quoting the mod_timer() function comment:
-> mod_timer() is a more efficient way to update the expire field of an
   active timer (if the timer is inactive it will be activated).

Use setup_timer() and mod_timer() to setup and arm a timer, making the
code compact and easier to read.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agonetfilter: ipset: use setup_timer() and mod_timer().
Muhammad Falak R Wani [Fri, 13 May 2016 20:58:53 +0000 (02:28 +0530)]
netfilter: ipset: use setup_timer() and mod_timer().

Use setup_timer() and instead of init_timer(), being the preferred way
of setting up a timer.

Also, quoting the mod_timer() function comment:
-> mod_timer() is a more efficient way to update the expire field of an
   active timer (if the timer is inactive it will be activated).

Use setup_timer() and mod_timer() to setup and arm a timer, making the
code compact and easier to read.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agonetfilter: ipset: use setup_timer() and mod_timer().
Muhammad Falak R Wani [Fri, 13 May 2016 20:58:52 +0000 (02:28 +0530)]
netfilter: ipset: use setup_timer() and mod_timer().

Use setup_timer() and instead of init_timer(), being the preferred way
of setting up a timer.

Also, quoting the mod_timer() function comment:
-> mod_timer() is a more efficient way to update the expire field of an
   active timer (if the timer is inactive it will be activated).

Use setup_timer() and mod_timer() to setup and arm a timer, making the
code compact and easier to read.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agohash:ipmac type support added to ipset, userspace part
Tomasz Chilinski [Thu, 5 May 2016 05:32:19 +0000 (07:32 +0200)]
hash:ipmac type support added to ipset, userspace part

Signed-off-by: Tomasz Chili??ski <tomasz.chilinski@chilan.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agohash:ipmac type support added to ipset
Tomasz Chilinski [Thu, 5 May 2016 05:21:26 +0000 (07:21 +0200)]
hash:ipmac type support added to ipset

Signed-off-by: Tomasz Chili??ski <tomasz.chilinski@chilan.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoipset 6.29 released v6.29
Jozsef Kadlecsik [Wed, 16 Mar 2016 08:07:18 +0000 (09:07 +0100)]
ipset 6.29 released

8 years agonetfilter: ipset: fix race condition in ipset save, swap and delete
Vishwanath Pai [Wed, 16 Mar 2016 08:03:30 +0000 (09:03 +0100)]
netfilter: ipset: fix race condition in ipset save, swap and delete

This fix adds a new reference counter (ref_netlink) for the struct ip_set.
The other reference counter (ref) can be swapped out by ip_set_swap and we
need a separate counter to keep track of references for netlink events
like dump. Using the same ref counter for dump causes a race condition
which can be demonstrated by the following script:

ipset create hash_ip1 hash:ip family inet hashsize 1024 maxelem 500000 \
counters
ipset create hash_ip2 hash:ip family inet hashsize 300000 maxelem 500000 \
counters
ipset create hash_ip3 hash:ip family inet hashsize 1024 maxelem 500000 \
counters

ipset save &

ipset swap hash_ip3 hash_ip2
ipset destroy hash_ip3 /* will crash the machine */

Swap will exchange the values of ref so destroy will see ref = 0 instead of
ref = 1. With this fix in place swap will not succeed because ipset save
still has ref_netlink on the set (ip_set_swap doesn't swap ref_netlink).

Both delete and swap will error out if ref_netlink != 0 on the set.

Note: The changes to *_head functions is because previously we would
increment ref whenever we called these functions, we don't do that
anymore.

Reviewed-by: Joshua Hunt <johunt@akamai.com>
Signed-off-by: Vishwanath Pai <vpai@akamai.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoSuppress unnecessary stderr in command loop for resize and list
Jozsef Kadlecsik [Wed, 16 Mar 2016 08:01:56 +0000 (09:01 +0100)]
Suppress unnecessary stderr in command loop for resize and list

8 years agoCorrection in comment test
Jozsef Kadlecsik [Wed, 16 Mar 2016 08:01:42 +0000 (09:01 +0100)]
Correction in comment test

8 years agoSupport chroot buildroots
Jozsef Kadlecsik [Sun, 13 Mar 2016 14:18:58 +0000 (15:18 +0100)]
Support chroot buildroots

The calling of modinfo at `make modules_install` did not take into
account chroot buildroots (reported by Jan Engelhardt).

8 years agoFix "configure" breakage due to pkg-config related changes
Jozsef Kadlecsik [Sun, 13 Mar 2016 11:10:47 +0000 (12:10 +0100)]
Fix "configure" breakage due to pkg-config related changes

The support for older pkg-config packages broke the "configure" script
(reported by Jan Engelhardt).

8 years agoipset 6.28 released v6.28
Jozsef Kadlecsik [Sat, 12 Mar 2016 21:01:00 +0000 (22:01 +0100)]
ipset 6.28 released

8 years agonetfilter: ipset: Check IPSET_ATTR_ETHER netlink attribute length
Jozsef Kadlecsik [Tue, 8 Mar 2016 19:29:10 +0000 (20:29 +0100)]
netfilter: ipset: Check IPSET_ATTR_ETHER netlink attribute length

Julia Lawall pointed out that IPSET_ATTR_ETHER netlink attribute length
was not checked explicitly, just for the maximum possible size. Malicious
netlink clients could send shorter attribute and thus resulting a kernel
read after the buffer.

The patch adds the explicit length checkings.

Reported-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoFix __aligned_u64 compatibility support for older kernel releases
Jozsef Kadlecsik [Mon, 29 Feb 2016 12:04:53 +0000 (13:04 +0100)]
Fix __aligned_u64 compatibility support for older kernel releases

The issue was reported by Mart Frauenlob.

8 years agoSupport older pkg-config packages
Jozsef Kadlecsik [Mon, 29 Feb 2016 12:02:08 +0000 (13:02 +0100)]
Support older pkg-config packages

Resolve the pkg-config 0.28 or greater dependency introduced by
the patch "Add bash completion to the install routine."

8 years agoAdd bash completion to the install routine.
Mart Frauenlob [Thu, 25 Feb 2016 15:01:40 +0000 (16:01 +0100)]
Add bash completion to the install routine.

Add the configure option --enable-bashcompl (default disabled).
The PKG_CHECK_VAR requires pkg-config 0.28 or greater.

Signed-off-by: Mart Frauenlob <mart.frauenlob@chello.at>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoAdd compatibility to support EXPORT_SYMBOL_GPL in module.h
Jozsef Kadlecsik [Wed, 24 Feb 2016 21:07:40 +0000 (22:07 +0100)]
Add compatibility to support EXPORT_SYMBOL_GPL in module.h

Fixes netfilter bugzilla id #1008

8 years agoFix misleading error message with comment extension
Jozsef Kadlecsik [Wed, 24 Feb 2016 20:10:19 +0000 (21:10 +0100)]
Fix misleading error message with comment extension

Error message was totally misleading when comment
extension was used when the set was defined without
the extension. Reported by Drunkard Zhang.

8 years agoFix set:list type crash when flush/dump set in parallel
Jozsef Kadlecsik [Wed, 24 Feb 2016 19:22:51 +0000 (20:22 +0100)]
Fix set:list type crash when flush/dump set in parallel

Flushing/listing entries was not RCU safe, so parallel flush/dump
could lead to kernel crash. Bug reported by Deniz Eren.

Fixes netfilter bugzilla id #1050.

8 years agonetfilter: nfnetlink: pass down netns pointer to call() and call_rcu()
Jozsef Kadlecsik [Tue, 16 Feb 2016 06:50:22 +0000 (07:50 +0100)]
netfilter: nfnetlink: pass down netns pointer to call() and call_rcu()

Backport patch from Pablo Neira Ayuso <pablo@netfilter.org>

8 years agoTest added to check 0.0.0.0/0,iface to be matched in hash:net,iface type
Jozsef Kadlecsik [Wed, 13 Jan 2016 08:28:07 +0000 (09:28 +0100)]
Test added to check 0.0.0.0/0,iface to be matched in hash:net,iface type

8 years agonetfilter: ipset: allow a 0 netmask with hash_netiface type
Florian Westphal [Tue, 12 Jan 2016 16:07:05 +0000 (17:07 +0100)]
netfilter: ipset: allow a 0 netmask with hash_netiface type

Jozsef says:
 The correct behaviour is that if we have
 ipset create test1 hash:net,iface
 ipset add test1 0.0.0.0/0,eth0
 iptables -A INPUT -m set --match-set test1 src,src

 then the rule should match for any traffic coming in through eth0.

This removes the -EINVAL runtime test to make matching work
in case packet arrived via the specified interface.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1297092
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoFix link with libtool >= 2.4.4
Olivier Blin [Wed, 6 Jan 2016 23:21:09 +0000 (00:21 +0100)]
Fix link with libtool >= 2.4.4

As of libtool-2.4.4, -ldl is no longer prepended to LIBS.
Since types.c needs dlopen() and dlerror(), use LIBADD_DLOPEN, as
suggested in libtool-2.4.4 release notes.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoipset 6.27 released v6.27
Jozsef Kadlecsik [Sat, 7 Nov 2015 12:25:38 +0000 (13:25 +0100)]
ipset 6.27 released

8 years agoFix reported memory size for hash:* types
Jozsef Kadlecsik [Wed, 4 Nov 2015 08:44:29 +0000 (09:44 +0100)]
Fix reported memory size for hash:* types

The calculation of the full allocated memory did not take
into account the size of the base hash bucket structure at some
places.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoFix hash type expire: release empty hash bucket block
Jozsef Kadlecsik [Wed, 4 Nov 2015 08:48:39 +0000 (09:48 +0100)]
Fix hash type expire: release empty hash bucket block

When all entries are expired/all slots are empty, release the bucket.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoFix hash:* type expiration
Jozsef Kadlecsik [Wed, 4 Nov 2015 08:28:29 +0000 (09:28 +0100)]
Fix hash:* type expiration

Incorrect index was used when the data blob was shrinked at expiration,
which could lead to falsely expired entries and memory leak when
the comment extension was used too.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoCollapse same condition body to a single one
Jozsef Kadlecsik [Mon, 2 Nov 2015 19:27:58 +0000 (20:27 +0100)]
Collapse same condition body to a single one

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoFix extension alignment
Jozsef Kadlecsik [Sat, 7 Nov 2015 09:44:57 +0000 (10:44 +0100)]
Fix extension alignment

The data extensions in ipset lacked the proper memory alignment and
thus could lead to kernel crash on several architectures. Therefore
the structures have been reorganized and alignment attributes added
where needed. The patch was tested on armv7h by Gerhard Wiesinger and
on x86_64, sparc64 by Jozsef Kadlecsik.

Reported-by: Gerhard Wiesinger <lists@wiesinger.com>
Tested-by: Gerhard Wiesinger <lists@wiesinger.com>
Tested-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoCompatibility: include linux/export.h when needed
Jozsef Kadlecsik [Wed, 28 Oct 2015 16:14:28 +0000 (17:14 +0100)]
Compatibility: include linux/export.h when needed

8 years agoHandle uint64_t alignment issue in ipset tool
Jozsef Kadlecsik [Wed, 28 Oct 2015 16:13:31 +0000 (17:13 +0100)]
Handle uint64_t alignment issue in ipset tool

8 years agoCompatibility: make sure vmalloc.h is included for kvfree()
Jozsef Kadlecsik [Mon, 26 Oct 2015 17:54:19 +0000 (18:54 +0100)]
Compatibility: make sure vmalloc.h is included for kvfree()

8 years agoFix detecting 'struct net' in 'struct tcf_ematch'
Jozsef Kadlecsik [Mon, 19 Oct 2015 18:20:19 +0000 (20:20 +0200)]
Fix detecting 'struct net' in 'struct tcf_ematch'

Nikolay Borisov reported that the detection is broken. Fix checking in the
right sctructure and wrap the call to dev_get_by_index_rcu() too.

8 years agoProtect definition of RCU_INIT_POINTER in compatibility header file
Jozsef Kadlecsik [Mon, 19 Oct 2015 17:58:35 +0000 (19:58 +0200)]
Protect definition of RCU_INIT_POINTER in compatibility header file

Nikolay Borisov reported that in 3.12.47 RCU_INIT_POINTER is redefined
in ip_set_compat.h.in due to not protecting it individually.

8 years agonetfilter: ipset: Fix sleeping memory allocation in atomic context
Nikolay Borisov [Fri, 16 Oct 2015 06:40:28 +0000 (09:40 +0300)]
netfilter: ipset: Fix sleeping memory allocation in atomic context

Commit 00590fdd5be0 introduced RCU locking in list type and in
doing so introduced a memory allocation in list_set_add, which
is done in an atomic context, due to the fact that ipset rcu
list modifications are serialised with a spin lock. The reason
why we can't use a mutex is that in addition to modifying the
list with ipset commands, it's also being modified when a
particular ipset rule timeout expires aka garbage collection.
This gc is triggered from set_cleanup_entries, which in turn
is invoked from a timer thus requiring the lock to be bh-safe.

Concretely the following call chain can lead to "sleeping function
called in atomic context" splat:
call_ad -> list_set_uadt -> list_set_uadd -> kzalloc(, GFP_KERNEL).
And since GFP_KERNEL allows initiating direct reclaim thus
potentially sleeping in the allocation path.

To fix the issue change the allocation type to GFP_ATOMIC, to
correctly reflect that it is occuring in an atomic context.

Fixes: 00590fdd5be0 ("netfilter: ipset: Introduce RCU locking in list type")
Acked-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Nikolay Borisov <kernel@kyup.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoipset 6.26 released v6.26
Jozsef Kadlecsik [Fri, 28 Aug 2015 17:01:12 +0000 (19:01 +0200)]
ipset 6.26 released

8 years agoOut of bound access in hash:net* types fixed
Jozsef Kadlecsik [Tue, 25 Aug 2015 09:11:57 +0000 (11:11 +0200)]
Out of bound access in hash:net* types fixed

Dave Jones reported that KASan detected out of bounds access in hash:net*
types:

[   23.139532] ==================================================================
[   23.146130] BUG: KASan: out of bounds access in hash_net4_add_cidr+0x1db/0x220 at addr ffff8800d4844b58
[   23.152937] Write of size 4 by task ipset/457
[   23.159742] =============================================================================
[   23.166672] BUG kmalloc-512 (Not tainted): kasan: bad access detected
[   23.173641] -----------------------------------------------------------------------------
[   23.194668] INFO: Allocated in hash_net_create+0x16a/0x470 age=7 cpu=1 pid=456
[   23.201836]  __slab_alloc.constprop.66+0x554/0x620
[   23.208994]  __kmalloc+0x2f2/0x360
[   23.216105]  hash_net_create+0x16a/0x470
[   23.223238]  ip_set_create+0x3e6/0x740
[   23.230343]  nfnetlink_rcv_msg+0x599/0x640
[   23.237454]  netlink_rcv_skb+0x14f/0x190
[   23.244533]  nfnetlink_rcv+0x3f6/0x790
[   23.251579]  netlink_unicast+0x272/0x390
[   23.258573]  netlink_sendmsg+0x5a1/0xa50
[   23.265485]  SYSC_sendto+0x1da/0x2c0
[   23.272364]  SyS_sendto+0xe/0x10
[   23.279168]  entry_SYSCALL_64_fastpath+0x12/0x6f

The bug is fixed in the patch and the testsuite is extended in ipset
to check cidr handling more thoroughly.

8 years agoWarn about loaded in ip_set modules at module installation
Jozsef Kadlecsik [Tue, 25 Aug 2015 08:48:37 +0000 (10:48 +0200)]
Warn about loaded in ip_set modules at module installation

8 years agoUse IPSET_BIN in resize-and-list.sh and suppress echoing of loop variable
Jozsef Kadlecsik [Mon, 24 Aug 2015 15:12:23 +0000 (17:12 +0200)]
Use IPSET_BIN in resize-and-list.sh and suppress echoing of loop variable

8 years agoManpage typo corrections
David Wittman [Mon, 20 Jul 2015 12:05:13 +0000 (14:05 +0200)]
Manpage typo corrections

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoFix grammar error in manpage
Neutron Soutmun [Mon, 20 Jul 2015 10:21:56 +0000 (17:21 +0700)]
Fix grammar error in manpage

Refer to: https://bugs.launchpad.net/ubuntu/+source/lintian/+bug/608231

The "allows to" is a common grammar error which it will probably be
replaced by "allows one to" as a suggestion in above bug report page.

Signed-off-by: Neutron Soutmun <neo.neutron@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoMake struct htype per ipset family
Jozsef Kadlecsik [Fri, 26 Jun 2015 13:13:18 +0000 (15:13 +0200)]
Make struct htype per ipset family

Before this patch struct htype created at the first source
of ip_set_hash_gen.h and it is common for both IPv4 and IPv6
set variants.

Make struct htype per ipset family and use NLEN to make
nets array fixed size to simplify struct htype allocation.

Ported from a patch proposed by Sergey Popovich <popovich_sergei@mail.ua>.

8 years agoOptimize hash creation routine
Jozsef Kadlecsik [Fri, 26 Jun 2015 09:45:09 +0000 (11:45 +0200)]
Optimize hash creation routine

Exit as easly as possible on error and use RCU_INIT_POINTER()
as set is not seen at creation time.

Ported from a patch proposed by Sergey Popovich <popovich_sergei@mail.ua>.

8 years agoMake sure element data size is a multiple of u32
Jozsef Kadlecsik [Fri, 26 Jun 2015 09:16:28 +0000 (11:16 +0200)]
Make sure element data size is a multiple of u32

Data for hashing required to be array of u32. Make sure that
element data always multiple of u32.

Ported from a patch proposed by Sergey Popovich <popovich_sergei@mail.ua>.

8 years agoMake NLEN compile time constant for hash types
Jozsef Kadlecsik [Fri, 26 Jun 2015 09:05:54 +0000 (11:05 +0200)]
Make NLEN compile time constant for hash types

Hash types define HOST_MASK before inclusion of ip_set_hash_gen.h
and the only place where NLEN needed to be calculated at runtime
is *_create() method.

Ported from a patch proposed by Sergey Popovich <popovich_sergei@mail.ua>.

8 years agoSimplify mtype_expire() for hash types
Jozsef Kadlecsik [Fri, 26 Jun 2015 08:14:47 +0000 (10:14 +0200)]
Simplify mtype_expire() for hash types

Remove redundant parameters nets_length and dsize:
they could be get from other parameters.

Remove one leve of intendation by using continue while
iterating over elements in bucket.

Ported from a patch proposed by Sergey Popovich <popovich_sergei@mail.ua>.

8 years agoCount non-static extension memory into the set memory size for userspace
Jozsef Kadlecsik [Fri, 26 Jun 2015 07:40:14 +0000 (09:40 +0200)]
Count non-static extension memory into the set memory size for userspace

Non-static (i.e. comment) extension was not counted into the memory
size. A new internal counter is introduced for this. In the case of
the hash types the sizes of the arrays are counted there as well so
that we can avoid to scan the whole set when just the header data
is requested.

8 years agonet: sched: Simplify em_ipset_match
Eric W. Biederman [Thu, 25 Jun 2015 09:48:23 +0000 (11:48 +0200)]
net: sched: Simplify em_ipset_match

em->net is always set and always available, use it in preference
to dev_net(skb->dev).

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoipset 6.25.1 released v6.25.1
Jozsef Kadlecsik [Thu, 25 Jun 2015 09:19:08 +0000 (11:19 +0200)]
ipset 6.25.1 released

8 years agonet/netfilter/ipset: work around gcc-4.4.4 initializer bug
Andrew Morton [Thu, 25 Jun 2015 09:15:39 +0000 (11:15 +0200)]
net/netfilter/ipset: work around gcc-4.4.4 initializer bug

gcc-4.4.4 (at least) isn't able to handle the mixture of anonymous unions
and declaration-time intializers.  Work around this.

net/netfilter/ipset/ip_set_hash_netnet.c: In function 'hash_netnet4_uadt':
net/netfilter/ipset/ip_set_hash_netnet.c:163: error: unknown field 'cidr' specified in initializer
net/netfilter/ipset/ip_set_hash_netnet.c:163: warning: missing braces around initializer
net/netfilter/ipset/ip_set_hash_netnet.c:163: warning: (near initialization for 'e.<anonymous>.ip')
...

Fixes: ea53ac5b630e813ae ("netfilter: ipset: Add hash:net,net module to kernel.)
Cc: Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 years agoipset manpage: refer to iptables-extensions
Jozsef Kadlecsik [Thu, 25 Jun 2015 08:49:24 +0000 (10:49 +0200)]
ipset manpage: refer to iptables-extensions