Compare commits

...

5 Commits
v2.4 ... v2.5

Author SHA1 Message Date
Jan Engelhardt
431062c6ec Xtables-addons 2.5 2014-04-18 19:14:59 +02:00
Jan Engelhardt
87adf3461f build: resolve compile error with Linux 3.15
Commit v3.15-rc1~141^2~97 changed the signature for cn_netlink_send.
2014-04-18 19:12:51 +02:00
Jan Engelhardt
f2e21e67a5 build: resolve compile error with Linux 3.13
net_random has been removed in commit v3.14-rc1~94^2~191 and replaced
by its definition, prandom_u32.

prandom_u32 was only introduced in v3.8-rc1~74^2~22, so we will have
an extra ifdef for 3.7 support.
2014-04-18 19:12:40 +02:00
Daniel Golle
ae307c0bf3 xt_quota2: introduce support for network namespaces
Initialize a separate xt_quota2 instance for each network
namespace so data limit can be set and enforced per container.
2014-04-18 15:10:05 +02:00
Jan Engelhardt
ec8c6b8732 doc: add xt_quota2 changelog items 2014-01-18 12:29:09 +01:00
8 changed files with 92 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
AC_INIT([xtables-addons], [2.4])
AC_INIT([xtables-addons], [2.5])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
@@ -63,7 +63,7 @@ if test -n "$kbuilddir"; then
echo "WARNING: Version detection did not succeed. Continue at own luck.";
else
echo "$kmajor.$kminor.$kmicro.$kstable in $kbuilddir";
if test "$kmajor" -gt 3 -o "$kmajor" -eq 3 -a "$kminor" -gt 13; then
if test "$kmajor" -gt 3 -o "$kmajor" -eq 3 -a "$kminor" -gt 15; then
echo "WARNING: That kernel version is not officially supported yet. Continue at own luck.";
elif test "$kmajor" -eq 3 -a "$kminor" -ge 7; then
:;

View File

@@ -3,6 +3,13 @@ HEAD
====
v2.5 (2014-04-18)
=================
Enhancements:
- Support for Linux 3.14 and 3.15
- xt_quota2: introduce support for network namespaces
v2.4 (2014-01-09)
=================
Enhancements:
@@ -10,6 +17,9 @@ Enhancements:
Changes:
- remove unmaintained RAWSNAT/RAWDNAT code
- remove unused parts of compat_xtables that served Linux <3.7
Fixes:
- xt_quota2: --no-change should not alter quota to zero ever
- xt_quota2: --packet should not be set to zero based on skb->len
v2.3 (2013-06-18)

View File

@@ -12,6 +12,10 @@
# warning Kernels below 3.7 not supported.
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)
# define prandom_u32() random32()
#endif
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
# if !defined(CONFIG_NF_CONNTRACK_MARK)
# warning You have CONFIG_NF_CONNTRACK enabled, but CONFIG_NF_CONNTRACK_MARK is not (please enable).

View File

@@ -701,7 +701,11 @@ msg_to_userspace_nl(const struct xt_pknock_mtinfo *info,
memcpy(m + 1, &msg, m->len);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0)
cn_netlink_send(m, 0, multicast_group, GFP_ATOMIC);
#else
cn_netlink_send(m, multicast_group, GFP_ATOMIC);
#endif
kfree(m);
#endif

View File

@@ -68,7 +68,7 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par)
ret = xm_tcp->match(skb, &local_par);
hotdrop = local_par.hotdrop;
}
if (!ret || hotdrop || (unsigned int)net_random() > delude_percentage)
if (!ret || hotdrop || (unsigned int)prandom_u32() > delude_percentage)
return;
destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude;
@@ -98,7 +98,7 @@ chaos_tg(struct sk_buff *skb, const struct xt_action_param *par)
const struct xt_chaos_tginfo *info = par->targinfo;
const struct iphdr *iph = ip_hdr(skb);
if ((unsigned int)net_random() <= reject_percentage) {
if ((unsigned int)prandom_u32() <= reject_percentage) {
struct xt_action_param local_par;
local_par.in = par->in;
local_par.out = par->out;

View File

@@ -107,8 +107,8 @@ static bool xttarpit_honeypot(struct tcphdr *tcph, const struct tcphdr *oth,
tcph->syn = true;
tcph->ack = true;
tcph->window = oth->window &
((net_random() & 0x1f) - 0xf);
tcph->seq = htonl(net_random() & ~oth->seq);
((prandom_u32() & 0x1f) - 0xf);
tcph->seq = htonl(prandom_u32() & ~oth->seq);
tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn);
}
@@ -117,7 +117,7 @@ static bool xttarpit_honeypot(struct tcphdr *tcph, const struct tcphdr *oth,
tcph->syn = false;
tcph->ack = true;
tcph->window = oth->window &
((net_random() & 0x1f) - 0xf);
((prandom_u32() & 0x1f) - 0xf);
tcph->ack_seq = payload > 100 ?
htonl(ntohl(oth->seq) + payload) :
oth->seq;

View File

@@ -13,6 +13,7 @@
*/
#include <linux/list.h>
#include <linux/module.h>
#include <linux/nsproxy.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/skbuff.h>
@@ -20,6 +21,9 @@
#include <linux/uidgid.h>
#include <linux/version.h>
#include <asm/atomic.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>
#include <net/dst.h>
#include <linux/netfilter/x_tables.h>
#include "xt_quota2.h"
@@ -37,10 +41,19 @@ struct xt_quota_counter {
struct proc_dir_entry *procfs_entry;
};
static LIST_HEAD(counter_list);
struct quota2_net {
struct list_head counter_list;
struct proc_dir_entry *proc_xt_quota;
};
static int quota2_net_id;
static inline struct quota2_net *quota2_pernet(struct net *net)
{
return net_generic(net, quota2_net_id);
}
static DEFINE_SPINLOCK(counter_list_lock);
static struct proc_dir_entry *proc_xt_quota;
static unsigned int quota_list_perms = S_IRUGO | S_IWUSR;
static unsigned int quota_list_uid = 0;
static unsigned int quota_list_gid = 0;
@@ -120,16 +133,17 @@ q2_new_counter(const struct xt_quota_mtinfo2 *q, bool anon)
* @name: name of counter
*/
static struct xt_quota_counter *
q2_get_counter(const struct xt_quota_mtinfo2 *q)
q2_get_counter(struct net *net, const struct xt_quota_mtinfo2 *q)
{
struct proc_dir_entry *p;
struct xt_quota_counter *e;
struct quota2_net *quota2_net = quota2_pernet(net);
if (*q->name == '\0')
return q2_new_counter(q, true);
spin_lock_bh(&counter_list_lock);
list_for_each_entry(e, &counter_list, list)
list_for_each_entry(e, &quota2_net->counter_list, list)
if (strcmp(e->name, q->name) == 0) {
atomic_inc(&e->ref);
spin_unlock_bh(&counter_list_lock);
@@ -140,7 +154,8 @@ q2_get_counter(const struct xt_quota_mtinfo2 *q)
if (e == NULL)
goto out;
p = proc_create_data(e->name, quota_list_perms, proc_xt_quota,
p = proc_create_data(e->name, quota_list_perms,
quota2_net->proc_xt_quota,
&quota_proc_fops, e);
if (p == NULL || IS_ERR(p))
goto out;
@@ -148,7 +163,7 @@ q2_get_counter(const struct xt_quota_mtinfo2 *q)
e->procfs_entry = p;
proc_set_user(p, make_kuid(&init_user_ns, quota_list_uid),
make_kgid(&init_user_ns, quota_list_gid));
list_add_tail(&e->list, &counter_list);
list_add_tail(&e->list, &quota2_net->counter_list);
spin_unlock_bh(&counter_list_lock);
return e;
@@ -171,7 +186,7 @@ static int quota_mt2_check(const struct xt_mtchk_param *par)
return -EINVAL;
}
q->master = q2_get_counter(q);
q->master = q2_get_counter(par->net, q);
if (q->master == NULL) {
printk(KERN_ERR "xt_quota.3: memory alloc failure\n");
return -ENOMEM;
@@ -184,6 +199,7 @@ static void quota_mt2_destroy(const struct xt_mtdtor_param *par)
{
struct xt_quota_mtinfo2 *q = par->matchinfo;
struct xt_quota_counter *e = q->master;
struct quota2_net *quota2_net = quota2_pernet(par->net);
if (*q->name == '\0') {
kfree(e);
@@ -197,7 +213,7 @@ static void quota_mt2_destroy(const struct xt_mtdtor_param *par)
}
list_del(&e->list);
remove_proc_entry(e->name, proc_xt_quota);
remove_proc_entry(e->name, quota2_net->proc_xt_quota);
spin_unlock_bh(&counter_list_lock);
kfree(e);
}
@@ -259,24 +275,60 @@ static struct xt_match quota_mt2_reg[] __read_mostly = {
},
};
static int __net_init quota2_net_init(struct net *net)
{
struct quota2_net *quota2_net = quota2_pernet(net);
INIT_LIST_HEAD(&quota2_net->counter_list);
quota2_net->proc_xt_quota = proc_mkdir("xt_quota", net->proc_net);
if (quota2_net->proc_xt_quota == NULL)
return -EACCES;
return 0;
}
static void __net_exit quota2_net_exit(struct net *net)
{
struct quota2_net *quota2_net = quota2_pernet(net);
struct xt_quota_counter *e = NULL;
struct list_head *pos, *q;
remove_proc_entry("xt_quota", net->proc_net);
/* destroy counter_list while freeing it's content */
spin_lock_bh(&counter_list_lock);
list_for_each_safe(pos, q, &quota2_net->counter_list) {
e = list_entry(pos, struct xt_quota_counter, list);
list_del(pos);
kfree(e);
}
spin_unlock_bh(&counter_list_lock);
}
static struct pernet_operations quota2_net_ops = {
.init = quota2_net_init,
.exit = quota2_net_exit,
.id = &quota2_net_id,
.size = sizeof(struct quota2_net),
};
static int __init quota_mt2_init(void)
{
int ret;
proc_xt_quota = proc_mkdir("xt_quota", init_net.proc_net);
if (proc_xt_quota == NULL)
return -EACCES;
ret = register_pernet_subsys(&quota2_net_ops);
if (ret < 0)
return ret;
ret = xt_register_matches(quota_mt2_reg, ARRAY_SIZE(quota_mt2_reg));
if (ret < 0)
remove_proc_entry("xt_quota", init_net.proc_net);
unregister_pernet_subsys(&quota2_net_ops);
return ret;
}
static void __exit quota_mt2_exit(void)
{
xt_unregister_matches(quota_mt2_reg, ARRAY_SIZE(quota_mt2_reg));
remove_proc_entry("xt_quota", init_net.proc_net);
unregister_pernet_subsys(&quota2_net_ops);
}
module_init(quota_mt2_init);

View File

@@ -1,4 +1,4 @@
.TH xtables-addons 8 "US Hoarding All The Cold Edition" "" "v2.4 (2014-01-09)"
.TH xtables-addons 8 "SFUAN" "" "v2.5 (2014-04-18)"
.SH Name
Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
.SH Targets