Compare commits

..

24 Commits

Author SHA1 Message Date
Jan Engelhardt
1b4b4347c5 geoip: apply consistent style to xt_geoip_build 2018-02-12 13:58:18 +01:00
Philip Prindeville
2f37af43c5 geoip: selective endianness catalog generation 2018-02-12 13:56:48 +01:00
Jan Engelhardt
56e5970c64 xt_pknock: don't split function heads 2018-01-05 01:36:12 +01:00
Marcelo Henrique Cerri
2b76b68c65 build: support for Linux 4.15
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
2018-01-05 01:35:12 +01:00
Seth Forshee
d2eeac4c32 build: (additional) support for Linux 4.14
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2018-01-05 01:35:07 +01:00
Jan Engelhardt
0e9037b000 Xtables-addons 2.14 2017-11-22 18:29:25 +01:00
Jan Engelhardt
0a6091b64a DNETMAP: remove NF_CT_ASSERT use
The hooks are already checked by the xtables core (due to struct
xt_target::hooks).
2017-11-22 18:27:36 +01:00
Jan Engelhardt
b565a85fb6 DNETMAP: fix write past end of buffer 2017-11-22 18:24:10 +01:00
Jan Engelhardt
89c80f5981 DELUDE: fix PVSStudio reports
V560 A part of conditional expression is always true: !oth->rst.
2017-07-23 19:59:36 +02:00
Jan Engelhardt
8579fd2b3b ipp2p: fix PVSStudio reports
V666 Consider inspecting fourth argument of the function 'HX_memmem'.
It is possible that the value does not correspond with the length of
a string which was passed with the third argument.
2017-07-23 19:56:42 +02:00
Jan Engelhardt
0a836e9677 pknock: fix PVSStudio static analyzer reports
V595 The 'peer' pointer was utilized before it was verified against
nullptr.
2017-07-23 19:55:06 +02:00
Jan Engelhardt
90b0f3a51f Xtables-addons 2.13 2017-06-29 14:46:37 +02:00
Grzegorz Kuczyński
89d1b808b9 xt_condition: namespace support #2 2017-06-27 13:36:03 +02:00
Jan Engelhardt
c839e87bbb xt_geoip: check for allocation overflow 2017-06-26 22:03:53 +02:00
Jan Engelhardt
a587f9526d compat_xtables: use more accurate printf format for NIPQUAD
We never expect to emit values greater than 255 here, so use %hhu to
address more sprintf warnings.
2017-06-15 12:18:41 +02:00
Jan Engelhardt
1874fcd519 xt_DNETMAP: fix a buffer overflow
prefix_str was only 16 bytes, but the largest emitted string could be
"255.255.255.255/32" (19 bytes).

xt_DNETMAP.c: In function "dnetmap_tg_check":
compat_xtables.h:46:22: warning: "%u" directive writing between 1 and 10
bytes into a region of size between 0 and 8 [-Wformat-overflow=]
 # define NIPQUAD_FMT "%u.%u.%u.%u"
xt_DNETMAP.c:296:2: note: "sprintf" output between 10 and 27 bytes into
a destination of size 16
  sprintf(p->prefix_str, NIPQUAD_FMT "/%u", NIPQUAD(mr->min_addr.ip),
   33 - ffs(~(ip_min ^ ip_max)));
2017-06-15 12:15:48 +02:00
Jan Engelhardt
21ea7b76ec xt_LOGMARK: resolve new gcc7 warnings
xt_LOGMARK.c:56:32: warning: increment of a boolean expression [-Wbool-operation]
   printk("%s""SEEN_REPLY", prev++ ? "," : "");
xt_LOGMARK.c:58:29: warning: increment of a boolean expression [-Wbool-operation]
   printk("%s""ASSURED", prev++ ? "," : "");
xt_LOGMARK.c:60:31: warning: increment of a boolean expression [-Wbool-operation]
   printk("%s""CONFIRMED", prev++ ? "," : "");
2017-06-15 12:00:09 +02:00
Ralph Sennhauser
ee8da2b1ac build: support for Linux 4.12
As a result of commit cc41c84b7e7f ("netfilter: kill the fake untracked
conntrack objects") the helper nf_ct_is_untracked always returns false
and commit ab8bc7ed864b ("netfilter: remove nf_ct_is_untracked") removes
it all together.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2017-06-15 11:57:23 +02:00
Grzegorz Kuczyński
19a4359368 xt_condition: add support for namespaces 2017-06-15 10:45:37 +02:00
Jan Engelhardt
1b379667d3 xt_psd: resolve compiler warning
xt_psd.c:53:0: warning: "HASH_SIZE" redefined
 #define HASH_SIZE   (1 << HASH_LOG)
linux-4.10.10/include/linux/hashtable.h:26:0:
note: this is the location of the previous definition
 #define HASH_SIZE(name) (ARRAY_SIZE(name))
2017-04-13 11:38:00 +02:00
Jan Engelhardt
cd410aefe7 Xtables-addons 2.12 2017-01-11 01:39:53 +01:00
Jan Engelhardt
e4b5cef8f0 build: mark Linux 4.10 as supported 2017-01-04 02:44:43 +01:00
Ralph Sennhauser
a8af97b8fa build: support for Linux 4.10
Commit 613dbd95723aee7abd16860745691b6c7bda20dc (netfilter:
x_tables: move hook state into xt_action_param structure) changes the
struct xt_action_param, accommodate for it.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2017-01-04 02:40:41 +01:00
Ralph Sennhauser
db234c30cd build: support for Linux 4.9
Commit f330a7fdbe1611104622faff7e614a246a7d20f0 (netfilter: conntrack:
get rid of conntrack timer) replaces timer_list with an u32, use helper
from commit c8607e020014cf11a61601a0005270bad81cabdf (netfilter: nft_ct:
fix expiration getter).

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2017-01-04 02:04:14 +01:00
19 changed files with 287 additions and 78 deletions

View File

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

View File

@@ -1,6 +1,32 @@
HEAD HEAD
==== ====
Enhancements:
- support for Linux up to 4.15
v2.14 (2017-11-22)
==================
Enhancements:
- support for Linux up to 4.14
Fixes:
- xt_DNETMAP: fix some reports from PVSStudio (a static checker)
v2.13 (2017-06-29)
==================
Enhancements:
- support for Linux up to 4.12
- xt_condition: namespace support
Fixes:
- xt_geoip: check for allocation overflow
- xt_DNETMAP: fix a buffer overflow
v2.12 (2017-01-11)
==================
Enhancements:
- support for Linux up to 4.10
v2.11 (2016-05-20) v2.11 (2016-05-20)

View File

@@ -482,11 +482,15 @@ static void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8,
static unsigned int static unsigned int
ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par) ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
{ {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
struct ipt_acc_net *ian = net_generic(par->state->net, ipt_acc_net_id);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0)
struct ipt_acc_net *ian = net_generic(par->net, ipt_acc_net_id); struct ipt_acc_net *ian = net_generic(par->net, ipt_acc_net_id);
#else #else
struct net *net = dev_net(par->in ? par->in : par->out); struct net *net = dev_net(par->in ? par->in : par->out);
struct ipt_acc_net *ian = net_generic(net, ipt_acc_net_id); struct ipt_acc_net *ian = net_generic(net, ipt_acc_net_id);
#endif
#endif #endif
struct ipt_acc_table *ipt_acc_tables = ian->ipt_acc_tables; struct ipt_acc_table *ipt_acc_tables = ian->ipt_acc_tables;
const struct ipt_acc_info *info = const struct ipt_acc_info *info =

View File

@@ -35,7 +35,7 @@
ntohs((addr).s6_addr16[5]), \ ntohs((addr).s6_addr16[5]), \
ntohs((addr).s6_addr16[6]), \ ntohs((addr).s6_addr16[6]), \
ntohs((addr).s6_addr16[7]) ntohs((addr).s6_addr16[7])
# define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x" # define NIP6_FMT "%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx"
#endif #endif
#if !defined(NIPQUAD) && !defined(NIPQUAD_FMT) #if !defined(NIPQUAD) && !defined(NIPQUAD_FMT)
# define NIPQUAD(addr) \ # define NIPQUAD(addr) \
@@ -43,7 +43,7 @@
((const unsigned char *)&addr)[1], \ ((const unsigned char *)&addr)[1], \
((const unsigned char *)&addr)[2], \ ((const unsigned char *)&addr)[2], \
((const unsigned char *)&addr)[3] ((const unsigned char *)&addr)[3]
# define NIPQUAD_FMT "%u.%u.%u.%u" # define NIPQUAD_FMT "%hhu.%hhu.%hhu.%hhu"
#endif #endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
@@ -82,11 +82,19 @@ static inline void proc_remove(struct proc_dir_entry *de)
static inline struct net *par_net(const struct xt_action_param *par) static inline struct net *par_net(const struct xt_action_param *par)
{ {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
return par->state->net;
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
return par->net; return par->net;
#else #else
return dev_net((par->in != NULL) ? par->in : par->out); return dev_net((par->in != NULL) ? par->in : par->out);
#endif #endif
#endif
} }
#ifndef NF_CT_ASSERT
# define NF_CT_ASSERT(x) WARN_ON(!(x))
#endif
#endif /* _XTABLES_COMPAT_H */ #endif /* _XTABLES_COMPAT_H */

View File

@@ -357,11 +357,18 @@ has_logged_during_this_minute(const struct peer *peer)
* *
* @r: rule * @r: rule
*/ */
static void #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
peer_gc(unsigned long r) static void peer_gc(struct timer_list *tl)
#else
static void peer_gc(unsigned long r)
#endif
{ {
unsigned int i; unsigned int i;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
struct xt_pknock_rule *rule = from_timer(rule, tl, timer);
#else
struct xt_pknock_rule *rule = (struct xt_pknock_rule *)r; struct xt_pknock_rule *rule = (struct xt_pknock_rule *)r;
#endif
struct peer *peer; struct peer *peer;
struct list_head *pos, *n; struct list_head *pos, *n;
@@ -469,9 +476,13 @@ add_rule(struct xt_pknock_mtinfo *info)
if (rule->peer_head == NULL) if (rule->peer_head == NULL)
goto out; goto out;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
timer_setup(&rule->timer, peer_gc, 0);
#else
init_timer(&rule->timer); init_timer(&rule->timer);
rule->timer.function = peer_gc; rule->timer.function = peer_gc;
rule->timer.data = (unsigned long)rule; rule->timer.data = (unsigned long)rule;
#endif
rule->status_proc = proc_create_data(info->rule_name, 0, pde, rule->status_proc = proc_create_data(info->rule_name, 0, pde,
&pknock_proc_ops, rule); &pknock_proc_ops, rule);
@@ -619,8 +630,9 @@ static void add_peer(struct peer *peer, struct xt_pknock_rule *rule)
*/ */
static void remove_peer(struct peer *peer) static void remove_peer(struct peer *peer)
{ {
if (peer == NULL)
return;
list_del(&peer->head); list_del(&peer->head);
if (peer != NULL)
kfree(peer); kfree(peer);
} }

View File

@@ -58,8 +58,12 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par)
{ {
struct xt_action_param local_par; struct xt_action_param local_par;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
local_par.state = par->state;
#else
local_par.in = par->in, local_par.in = par->in,
local_par.out = par->out, local_par.out = par->out,
#endif
local_par.match = xm_tcp; local_par.match = xm_tcp;
local_par.matchinfo = &tcp_params; local_par.matchinfo = &tcp_params;
local_par.fragoff = fragoff; local_par.fragoff = fragoff;
@@ -74,12 +78,16 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par)
destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude; destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude;
{ {
struct xt_action_param local_par; struct xt_action_param local_par;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
local_par.state = par->state;
#else
local_par.in = par->in; local_par.in = par->in;
local_par.out = par->out; local_par.out = par->out;
local_par.hooknum = par->hooknum; local_par.hooknum = par->hooknum;
local_par.family = par->family;
#endif
local_par.target = destiny; local_par.target = destiny;
local_par.targinfo = par->targinfo; local_par.targinfo = par->targinfo;
local_par.family = par->family;
destiny->target(skb, &local_par); destiny->target(skb, &local_par);
} }
} }
@@ -100,9 +108,13 @@ chaos_tg(struct sk_buff *skb, const struct xt_action_param *par)
if ((unsigned int)prandom_u32() <= reject_percentage) { if ((unsigned int)prandom_u32() <= reject_percentage) {
struct xt_action_param local_par; struct xt_action_param local_par;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
local_par.state = par->state;
#else
local_par.in = par->in; local_par.in = par->in;
local_par.out = par->out; local_par.out = par->out;
local_par.hooknum = par->hooknum; local_par.hooknum = par->hooknum;
#endif
local_par.target = xt_reject; local_par.target = xt_reject;
local_par.targinfo = &reject_params; local_par.targinfo = &reject_params;
return xt_reject->target(skb, &local_par); return xt_reject->target(skb, &local_par);
@@ -111,7 +123,12 @@ chaos_tg(struct sk_buff *skb, const struct xt_action_param *par)
/* TARPIT/DELUDE may not be called from the OUTPUT chain */ /* TARPIT/DELUDE may not be called from the OUTPUT chain */
if (iph->protocol == IPPROTO_TCP && if (iph->protocol == IPPROTO_TCP &&
info->variant != XTCHAOS_NORMAL && info->variant != XTCHAOS_NORMAL &&
par->hooknum != NF_INET_LOCAL_OUT) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
par->state->hook
#else
par->hooknum
#endif
!= NF_INET_LOCAL_OUT)
xt_chaos_total(skb, par); xt_chaos_total(skb, par);
return NF_DROP; return NF_DROP;

View File

@@ -79,7 +79,7 @@ static void delude_send_reset(struct net *net, struct sk_buff *oldskb,
tcph->doff = sizeof(struct tcphdr) / 4; tcph->doff = sizeof(struct tcphdr) / 4;
/* DELUDE essential part */ /* DELUDE essential part */
if (oth->syn && !oth->ack && !oth->rst && !oth->fin) { if (oth->syn && !oth->ack && !oth->fin) {
tcph->syn = true; tcph->syn = true;
tcph->seq = 0; tcph->seq = 0;
tcph->ack = true; tcph->ack = true;
@@ -151,7 +151,13 @@ delude_tg(struct sk_buff *skb, const struct xt_action_param *par)
* a problem, as that is supported since Linux 2.6.35. But since we do not * a problem, as that is supported since Linux 2.6.35. But since we do not
* actually want to have a connection open, we are still going to drop it. * actually want to have a connection open, we are still going to drop it.
*/ */
delude_send_reset(par_net(par), skb, par->hooknum); delude_send_reset(par_net(par), skb,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
par->state->hook
#else
par->hooknum
#endif
);
return NF_DROP; return NF_DROP;
} }

View File

@@ -81,7 +81,7 @@ struct dnetmap_entry {
struct dnetmap_prefix { struct dnetmap_prefix {
struct nf_nat_range prefix; struct nf_nat_range prefix;
char prefix_str[16]; char prefix_str[20];
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
char proc_str_data[20]; char proc_str_data[20];
char proc_str_stat[25]; char proc_str_stat[25];
@@ -356,7 +356,11 @@ out:
static unsigned int static unsigned int
dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par) dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
{ {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
struct net *net = dev_net(par->state->in ? par->state->in : par->state->out);
#else
struct net *net = dev_net(par->in ? par->in : par->out); struct net *net = dev_net(par->in ? par->in : par->out);
#endif
struct dnetmap_net *dnetmap_net = dnetmap_pernet(net); struct dnetmap_net *dnetmap_net = dnetmap_pernet(net);
struct nf_conn *ct; struct nf_conn *ct;
enum ip_conntrack_info ctinfo; enum ip_conntrack_info ctinfo;
@@ -367,16 +371,17 @@ dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
struct dnetmap_entry *e; struct dnetmap_entry *e;
struct dnetmap_prefix *p; struct dnetmap_prefix *p;
__s32 jttl; __s32 jttl;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
NF_CT_ASSERT(par->hooknum == NF_INET_POST_ROUTING || unsigned int hooknum = par->state->hook;
par->hooknum == NF_INET_LOCAL_OUT || #else
par->hooknum == NF_INET_PRE_ROUTING); unsigned int hooknum = par->hooknum;
#endif
ct = nf_ct_get(skb, &ctinfo); ct = nf_ct_get(skb, &ctinfo);
jttl = tginfo->flags & XT_DNETMAP_TTL ? tginfo->ttl * HZ : jtimeout; jttl = tginfo->flags & XT_DNETMAP_TTL ? tginfo->ttl * HZ : jtimeout;
/* in prerouting we try to map postnat-ip to prenat-ip */ /* in prerouting we try to map postnat-ip to prenat-ip */
if (par->hooknum == NF_INET_PRE_ROUTING) { if (hooknum == NF_INET_PRE_ROUTING) {
postnat_ip = ip_hdr(skb)->daddr; postnat_ip = ip_hdr(skb)->daddr;
spin_lock_bh(&dnetmap_lock); spin_lock_bh(&dnetmap_lock);
@@ -389,7 +394,7 @@ dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
/* if prefix is specified, we check if /* if prefix is specified, we check if
it matches lookedup entry */ it matches lookedup entry */
if (tginfo->flags & XT_DNETMAP_PREFIX) if (tginfo->flags & XT_DNETMAP_PREFIX)
if (memcmp(mr, &e->prefix, sizeof(*mr))) if (memcmp(mr, &e->prefix->prefix, sizeof(*mr)))
goto no_rev_map; goto no_rev_map;
/* don't reset ttl if flag is set */ /* don't reset ttl if flag is set */
if (jttl >= 0 && (! (e->flags & XT_DNETMAP_STATIC) ) ) { if (jttl >= 0 && (! (e->flags & XT_DNETMAP_STATIC) ) ) {
@@ -407,7 +412,7 @@ dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
newrange.min_proto = mr->min_proto; newrange.min_proto = mr->min_proto;
newrange.max_proto = mr->max_proto; newrange.max_proto = mr->max_proto;
return nf_nat_setup_info(ct, &newrange, return nf_nat_setup_info(ct, &newrange,
HOOK2MANIP(par->hooknum)); HOOK2MANIP(hooknum));
} }
prenat_ip = ip_hdr(skb)->saddr; prenat_ip = ip_hdr(skb)->saddr;
@@ -495,7 +500,11 @@ bind_new_prefix:
newrange.max_addr.ip = postnat_ip; newrange.max_addr.ip = postnat_ip;
newrange.min_proto = mr->min_proto; newrange.min_proto = mr->min_proto;
newrange.max_proto = mr->max_proto; newrange.max_proto = mr->max_proto;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(par->state->hook));
#else
return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(par->hooknum)); return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(par->hooknum));
#endif
no_rev_map: no_rev_map:
no_free_ip: no_free_ip:

View File

@@ -35,7 +35,11 @@ echo_tg6(struct sk_buff *oldskb, const struct xt_action_param *par)
void *payload; void *payload;
struct flowi6 fl; struct flowi6 fl;
struct dst_entry *dst = NULL; struct dst_entry *dst = NULL;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
struct net *net = dev_net((par->state->in != NULL) ? par->state->in : par->state->out);
#else
struct net *net = dev_net((par->in != NULL) ? par->in : par->out); struct net *net = dev_net((par->in != NULL) ? par->in : par->out);
#endif
/* This allows us to do the copy operation in fewer lines of code. */ /* This allows us to do the copy operation in fewer lines of code. */
if (skb_linearize(oldskb) < 0) if (skb_linearize(oldskb) < 0)

View File

@@ -52,14 +52,24 @@ static void logmark_ct(const struct nf_conn *ct, enum ip_conntrack_info ctinfo)
printk("EXPECTED"); printk("EXPECTED");
prev = true; prev = true;
} }
if (ct->status & IPS_SEEN_REPLY) if (ct->status & IPS_SEEN_REPLY) {
printk("%s""SEEN_REPLY", prev++ ? "," : ""); printk("%s""SEEN_REPLY", prev ? "," : "");
if (ct->status & IPS_ASSURED) prev = true;
printk("%s""ASSURED", prev++ ? "," : ""); }
if (ct->status & IPS_CONFIRMED) if (ct->status & IPS_ASSURED) {
printk("%s""CONFIRMED", prev++ ? "," : ""); printk("%s""ASSURED", prev ? "," : "");
prev = true;
}
if (ct->status & IPS_CONFIRMED) {
printk("%s""CONFIRMED", prev ? "," : "");
prev = true;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0)
printk(" lifetime=%lus", nf_ct_expires(ct) / HZ);
#else
printk(" lifetime=%lus", printk(" lifetime=%lus",
(jiffies - ct->timeout.expires) / HZ); (jiffies - ct->timeout.expires) / HZ);
#endif
} }
static unsigned int static unsigned int
@@ -72,15 +82,21 @@ logmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
printk("<%u>%.*s""iif=%d hook=%s nfmark=0x%x " printk("<%u>%.*s""iif=%d hook=%s nfmark=0x%x "
"secmark=0x%x classify=0x%x", "secmark=0x%x classify=0x%x",
info->level, (unsigned int)sizeof(info->prefix), info->prefix, info->level, (unsigned int)sizeof(info->prefix), info->prefix,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
skb_ifindex(skb), hook_names[par->state->hook],
#else
skb_ifindex(skb), hook_names[par->hooknum], skb_ifindex(skb), hook_names[par->hooknum],
#endif
skb_nfmark(skb), skb_secmark(skb), skb->priority); skb_nfmark(skb), skb_secmark(skb), skb->priority);
ct = nf_ct_get(skb, &ctinfo); ct = nf_ct_get(skb, &ctinfo);
printk(" ctdir=%s", dir_names[ctinfo >= IP_CT_IS_REPLY]); printk(" ctdir=%s", dir_names[ctinfo >= IP_CT_IS_REPLY]);
if (ct == NULL) if (ct == NULL)
printk(" ct=NULL ctmark=NULL ctstate=INVALID ctstatus=NONE"); printk(" ct=NULL ctmark=NULL ctstate=INVALID ctstatus=NONE");
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
else if (nf_ct_is_untracked(ct)) else if (nf_ct_is_untracked(ct))
printk(" ct=UNTRACKED ctmark=NULL ctstate=UNTRACKED ctstatus=NONE"); printk(" ct=UNTRACKED ctmark=NULL ctstate=UNTRACKED ctstatus=NONE");
#endif
else else
logmark_ct(ct, ctinfo); logmark_ct(ct, ctinfo);

View File

@@ -455,7 +455,11 @@ tarpit_tg4(struct sk_buff *skb, const struct xt_action_param *par)
if (iph->frag_off & htons(IP_OFFSET)) if (iph->frag_off & htons(IP_OFFSET))
return NF_DROP; return NF_DROP;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
tarpit_tcp4(par_net(par), skb, par->state->hook, info->variant);
#else
tarpit_tcp4(par_net(par), skb, par->hooknum, info->variant); tarpit_tcp4(par_net(par), skb, par->hooknum, info->variant);
#endif
return NF_DROP; return NF_DROP;
} }
@@ -497,7 +501,11 @@ tarpit_tg6(struct sk_buff *skb, const struct xt_action_param *par)
return NF_DROP; return NF_DROP;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
tarpit_tcp6(par_net(par), skb, par->state->hook, info->variant);
#else
tarpit_tcp6(par_net(par), skb, par->hooknum, info->variant); tarpit_tcp6(par_net(par), skb, par->hooknum, info->variant);
#endif
return NF_DROP; return NF_DROP;
} }
#endif #endif

View File

@@ -7,6 +7,7 @@
* Authors: * Authors:
* Stephane Ouellette <ouellettes [at] videotron ca>, 2002-10-22 * Stephane Ouellette <ouellettes [at] videotron ca>, 2002-10-22
* Massimiliano Hofer <max [at] nucleus it>, 2006-05-15 * Massimiliano Hofer <max [at] nucleus it>, 2006-05-15
* Grzegorz Kuczyński <grzegorz.kuczynski [at] koba pl>, 2017-02-27
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License; either version 2 * under the terms of the GNU General Public License; either version 2
@@ -21,6 +22,8 @@
#include <linux/version.h> #include <linux/version.h>
#include <linux/netfilter/x_tables.h> #include <linux/netfilter/x_tables.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>
#include "xt_condition.h" #include "xt_condition.h"
#include "compat_xtables.h" #include "compat_xtables.h"
@@ -59,8 +62,18 @@ struct condition_variable {
/* to the conditions' list. */ /* to the conditions' list. */
static DEFINE_MUTEX(proc_lock); static DEFINE_MUTEX(proc_lock);
static LIST_HEAD(conditions_list); struct condition_net {
static struct proc_dir_entry *proc_net_condition; struct list_head conditions_list;
struct proc_dir_entry *proc_net_condition;
bool after_clear;
};
static int condition_net_id;
static inline struct condition_net *condition_pernet(struct net *net)
{
return net_generic(net, condition_net_id);
}
static int condition_proc_show(struct seq_file *m, void *data) static int condition_proc_show(struct seq_file *m, void *data)
{ {
@@ -119,6 +132,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
{ {
struct xt_condition_mtinfo *info = par->matchinfo; struct xt_condition_mtinfo *info = par->matchinfo;
struct condition_variable *var; struct condition_variable *var;
struct condition_net *condition_net = condition_pernet(par->net);
/* Forbid certain names */ /* Forbid certain names */
if (*info->name == '\0' || *info->name == '.' || if (*info->name == '\0' || *info->name == '.' ||
@@ -134,7 +148,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
* or increase the reference counter. * or increase the reference counter.
*/ */
mutex_lock(&proc_lock); mutex_lock(&proc_lock);
list_for_each_entry(var, &conditions_list, list) { list_for_each_entry(var, &condition_net->conditions_list, list) {
if (strcmp(info->name, var->name) == 0) { if (strcmp(info->name, var->name) == 0) {
var->refcount++; var->refcount++;
mutex_unlock(&proc_lock); mutex_unlock(&proc_lock);
@@ -153,7 +167,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
memcpy(var->name, info->name, sizeof(info->name)); memcpy(var->name, info->name, sizeof(info->name));
/* Create the condition variable's proc file entry. */ /* Create the condition variable's proc file entry. */
var->status_proc = proc_create_data(info->name, condition_list_perms, var->status_proc = proc_create_data(info->name, condition_list_perms,
proc_net_condition, &condition_proc_fops, var); condition_net->proc_net_condition, &condition_proc_fops, var);
if (var->status_proc == NULL) { if (var->status_proc == NULL) {
kfree(var); kfree(var);
mutex_unlock(&proc_lock); mutex_unlock(&proc_lock);
@@ -166,7 +180,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
var->refcount = 1; var->refcount = 1;
var->enabled = false; var->enabled = false;
wmb(); wmb();
list_add(&var->list, &conditions_list); list_add(&var->list, &condition_net->conditions_list);
mutex_unlock(&proc_lock); mutex_unlock(&proc_lock);
info->condvar = var; info->condvar = var;
return 0; return 0;
@@ -176,11 +190,15 @@ static void condition_mt_destroy(const struct xt_mtdtor_param *par)
{ {
const struct xt_condition_mtinfo *info = par->matchinfo; const struct xt_condition_mtinfo *info = par->matchinfo;
struct condition_variable *var = info->condvar; struct condition_variable *var = info->condvar;
struct condition_net *cnet = condition_pernet(par->net);
if (cnet->after_clear)
return;
mutex_lock(&proc_lock); mutex_lock(&proc_lock);
if (--var->refcount == 0) { if (--var->refcount == 0) {
list_del(&var->list); list_del(&var->list);
proc_remove(var->status_proc); remove_proc_entry(var->name, cnet->proc_net_condition);
mutex_unlock(&proc_lock); mutex_unlock(&proc_lock);
kfree(var); kfree(var);
return; return;
@@ -213,18 +231,54 @@ static struct xt_match condition_mt_reg[] __read_mostly = {
static const char *const dir_name = "nf_condition"; static const char *const dir_name = "nf_condition";
static int __net_init condition_net_init(struct net *net)
{
struct condition_net *condition_net = condition_pernet(net);
INIT_LIST_HEAD(&condition_net->conditions_list);
condition_net->proc_net_condition = proc_mkdir(dir_name, net->proc_net);
if (condition_net->proc_net_condition == NULL)
return -EACCES;
condition_net->after_clear = 0;
return 0;
}
static void __net_exit condition_net_exit(struct net *net)
{
struct condition_net *condition_net = condition_pernet(net);
struct list_head *pos, *q;
struct condition_variable *var = NULL;
remove_proc_subtree(dir_name, net->proc_net);
mutex_lock(&proc_lock);
list_for_each_safe(pos, q, &condition_net->conditions_list) {
var = list_entry(pos, struct condition_variable, list);
list_del(pos);
kfree(var);
}
mutex_unlock(&proc_lock);
condition_net->after_clear = true;
}
static struct pernet_operations condition_net_ops = {
.init = condition_net_init,
.exit = condition_net_exit,
.id = &condition_net_id,
.size = sizeof(struct condition_net),
};
static int __init condition_mt_init(void) static int __init condition_mt_init(void)
{ {
int ret; int ret;
mutex_init(&proc_lock); mutex_init(&proc_lock);
proc_net_condition = proc_mkdir(dir_name, init_net.proc_net); ret = register_pernet_subsys(&condition_net_ops);
if (proc_net_condition == NULL) if (ret != 0)
return -EACCES; return ret;
ret = xt_register_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg)); ret = xt_register_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
if (ret < 0) { if (ret < 0) {
remove_proc_entry(dir_name, init_net.proc_net); unregister_pernet_subsys(&condition_net_ops);
return ret; return ret;
} }
@@ -234,7 +288,7 @@ static int __init condition_mt_init(void)
static void __exit condition_mt_exit(void) static void __exit condition_mt_exit(void)
{ {
xt_unregister_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg)); xt_unregister_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
remove_proc_entry(dir_name, init_net.proc_net); unregister_pernet_subsys(&condition_net_ops);
} }
module_init(condition_mt_init); module_init(condition_mt_init);

View File

@@ -75,7 +75,8 @@ geoip_add_node(const struct geoip_country_user __user *umem_ptr,
if (copy_from_user(&umem, umem_ptr, sizeof(umem)) != 0) if (copy_from_user(&umem, umem_ptr, sizeof(umem)) != 0)
return ERR_PTR(-EFAULT); return ERR_PTR(-EFAULT);
if (umem.count > SIZE_MAX / geoproto_size[proto])
return ERR_PTR(-E2BIG);
p = kmalloc(sizeof(struct geoip_country_kernel), GFP_KERNEL); p = kmalloc(sizeof(struct geoip_country_kernel), GFP_KERNEL);
if (p == NULL) if (p == NULL)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);

View File

@@ -45,9 +45,17 @@ static const struct net_device *iface_get(const struct xt_iface_mtinfo *info,
const struct xt_action_param *par, struct net_device **put) const struct xt_action_param *par, struct net_device **put)
{ {
if (info->flags & XT_IFACE_DEV_IN) if (info->flags & XT_IFACE_DEV_IN)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
return par->state->in;
#else
return par->in; return par->in;
#endif
else if (info->flags & XT_IFACE_DEV_OUT) else if (info->flags & XT_IFACE_DEV_OUT)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
return par->state->out;
#else
return par->out; return par->out;
#endif
return *put = dev_get_by_name(&init_net, info->ifname); return *put = dev_get_by_name(&init_net, info->ifname);
} }

View File

@@ -511,7 +511,7 @@ search_bittorrent(const unsigned char *payload, const unsigned int plen)
* but *must have* one (or more) of strings listed below (true for scrape and announce) * but *must have* one (or more) of strings listed below (true for scrape and announce)
*/ */
if (memcmp(payload, "GET /", 5) == 0) { if (memcmp(payload, "GET /", 5) == 0) {
if (HX_memmem(payload, plen, "info_hash=", 9) != NULL) if (HX_memmem(payload, plen, "info_hash=", 10) != NULL)
return IPP2P_BIT * 100 + 1; return IPP2P_BIT * 100 + 1;
if (HX_memmem(payload, plen, "peer_id=", 8) != NULL) if (HX_memmem(payload, plen, "peer_id=", 8) != NULL)
return IPP2P_BIT * 100 + 2; return IPP2P_BIT * 100 + 2;

View File

@@ -204,7 +204,11 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par)
unsigned int n; unsigned int n;
n = lscan_mt_full(ctdata->mark & connmark_mask, ctstate, n = lscan_mt_full(ctdata->mark & connmark_mask, ctstate,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
par->state->in == init_net.loopback_dev, tcph,
#else
par->in == init_net.loopback_dev, tcph, par->in == init_net.loopback_dev, tcph,
#endif
skb->len - par->thoff - 4 * tcph->doff); skb->len - par->thoff - 4 * tcph->doff);
ctdata->mark = (ctdata->mark & ~connmark_mask) | n; ctdata->mark = (ctdata->mark & ~connmark_mask) | n;

View File

@@ -45,12 +45,12 @@ MODULE_ALIAS("ip6t_psd");
/* /*
* Keep track of up to LIST_SIZE source addresses, using a hash table of * Keep track of up to LIST_SIZE source addresses, using a hash table of
* HASH_SIZE entries for faster lookups, but limiting hash collisions to * PSD_HASH_SIZE entries for faster lookups, but limiting hash collisions to
* HASH_MAX source addresses per the same hash value. * HASH_MAX source addresses per the same hash value.
*/ */
#define LIST_SIZE 0x100 #define LIST_SIZE 0x100
#define HASH_LOG 9 #define HASH_LOG 9
#define HASH_SIZE (1 << HASH_LOG) #define PSD_HASH_SIZE (1 << HASH_LOG)
#define HASH_MAX 0x10 #define HASH_MAX 0x10
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
@@ -108,7 +108,7 @@ struct host6 {
static struct { static struct {
spinlock_t lock; spinlock_t lock;
struct host4 list[LIST_SIZE]; struct host4 list[LIST_SIZE];
struct host *hash[HASH_SIZE]; struct host *hash[PSD_HASH_SIZE];
int index; int index;
} state; } state;
@@ -143,13 +143,12 @@ static bool state6_alloc_mem(void)
if (state6.list == NULL) if (state6.list == NULL)
return false; return false;
memset(state6.list, 0, LIST_SIZE * sizeof(struct host6)); memset(state6.list, 0, LIST_SIZE * sizeof(struct host6));
state6.hash = vmalloc(PSD_HASH_SIZE * sizeof(struct host *));
state6.hash = vmalloc(HASH_SIZE * sizeof(struct host*));
if (state6.hash == NULL) { if (state6.hash == NULL) {
vfree(state6.list); vfree(state6.list);
return false; return false;
} }
memset(state6.hash, 0, HASH_SIZE * sizeof(struct host *)); memset(state6.hash, 0, PSD_HASH_SIZE * sizeof(struct host *));
return true; return true;
} }
#endif #endif
@@ -167,8 +166,7 @@ static unsigned int hashfunc(__be32 addr)
do { do {
hash ^= value; hash ^= value;
} while ((value >>= HASH_LOG) != 0); } while ((value >>= HASH_LOG) != 0);
return hash & (PSD_HASH_SIZE - 1);
return hash & (HASH_SIZE - 1);
} }
static inline unsigned int hashfunc6(const struct in6_addr *addr) static inline unsigned int hashfunc6(const struct in6_addr *addr)

View File

@@ -8,23 +8,45 @@ use IO::Handle;
use Text::CSV_XS; # or trade for Text::CSV use Text::CSV_XS; # or trade for Text::CSV
use strict; use strict;
my $le32 = pack("V", 0x10000000);
my $be32 = pack("N", 0x10000000);
my $u32 = undef;
sub wantBE { return !$u32 || $u32 eq $be32; }
sub wantLE { return !$u32 || $u32 eq $le32; }
my $csv = Text::CSV_XS->new({ my $csv = Text::CSV_XS->new({
allow_whitespace => 1, allow_whitespace => 1,
binary => 1, binary => 1,
eol => $/, eol => $/,
}); # or Text::CSV }); # or Text::CSV
my $target_dir = "."; my $target_dir = ".";
my $native_only = 0;
&Getopt::Long::Configure(qw(bundling)); &Getopt::Long::Configure(qw(bundling));
&GetOptions( &GetOptions(
"D=s" => \$target_dir, "D=s" => \$target_dir,
"n" => \$native_only,
); );
if (!-d $target_dir) { if (!-d $target_dir) {
print STDERR "Target directory $target_dir does not exist.\n"; print STDERR "Target directory $target_dir does not exist.\n";
exit 1; exit 1;
} }
foreach (qw(LE BE)) { my @dbs = qw(LE BE);
if ($native_only) {
$u32 = pack("L", 0x10000000);
if ($u32 eq $le32) {
@dbs = qw(LE);
} elsif ($u32 eq $be32) {
@dbs = qw(BE);
} else {
print STDERRR "Cannot determine endianness.\n";
exit 1;
}
}
foreach (@dbs) {
my $dir = "$target_dir/$_"; my $dir = "$target_dir/$_";
if (!-e $dir && !mkdir($dir)) { if (!-e $dir && !mkdir($dir)) {
print STDERR "Could not mkdir $dir: $!\n"; print STDERR "Could not mkdir $dir: $!\n";
@@ -80,11 +102,18 @@ sub dump_one
scalar(@{$country->{pool_v6}}), scalar(@{$country->{pool_v6}}),
$iso_code, $country->{name}; $iso_code, $country->{name};
if (wantLE) {
$file = "$target_dir/LE/".uc($iso_code).".iv6"; $file = "$target_dir/LE/".uc($iso_code).".iv6";
if (!open($fh_le, "> $file")) { if (!open($fh_le, "> $file")) {
print STDERR "Error opening $file: $!\n"; print STDERR "Error opening $file: $!\n";
exit 1; exit 1;
} }
foreach my $range (@{$country->{pool_v6}}) {
print $fh_le &ip6_swap($range->[0]), &ip6_swap($range->[1]);
}
close $fh_le;
}
if (wantBE) {
$file = "$target_dir/BE/".uc($iso_code).".iv6"; $file = "$target_dir/BE/".uc($iso_code).".iv6";
if (!open($fh_be, "> $file")) { if (!open($fh_be, "> $file")) {
print STDERR "Error opening $file: $!\n"; print STDERR "Error opening $file: $!\n";
@@ -92,31 +121,36 @@ sub dump_one
} }
foreach my $range (@{$country->{pool_v6}}) { foreach my $range (@{$country->{pool_v6}}) {
print $fh_be $range->[0], $range->[1]; print $fh_be $range->[0], $range->[1];
print $fh_le &ip6_swap($range->[0]), &ip6_swap($range->[1]);
} }
close $fh_le;
close $fh_be; close $fh_be;
}
printf "%5u IPv4 ranges for %s %s\n", printf "%5u IPv4 ranges for %s %s\n",
scalar(@{$country->{pool_v4}}), scalar(@{$country->{pool_v4}}),
$iso_code, $country->{name}; $iso_code, $country->{name};
if (wantLE) {
$file = "$target_dir/LE/".uc($iso_code).".iv4"; $file = "$target_dir/LE/".uc($iso_code).".iv4";
if (!open($fh_le, "> $file")) { if (!open($fh_le, "> $file")) {
print STDERR "Error opening $file: $!\n"; print STDERR "Error opening $file: $!\n";
exit 1; exit 1;
} }
foreach my $range (@{$country->{pool_v4}}) {
print $fh_le pack("VV", $range->[0], $range->[1]);
}
close $fh_le;
}
if (wantBE) {
$file = "$target_dir/BE/".uc($iso_code).".iv4"; $file = "$target_dir/BE/".uc($iso_code).".iv4";
if (!open($fh_be, "> $file")) { if (!open($fh_be, "> $file")) {
print STDERR "Error opening $file: $!\n"; print STDERR "Error opening $file: $!\n";
exit 1; exit 1;
} }
foreach my $range (@{$country->{pool_v4}}) { foreach my $range (@{$country->{pool_v4}}) {
print $fh_le pack("VV", $range->[0], $range->[1]);
print $fh_be pack("NN", $range->[0], $range->[1]); print $fh_be pack("NN", $range->[0], $range->[1]);
} }
close $fh_le;
close $fh_be; close $fh_be;
}
} }
sub ip6_pack sub ip6_pack

View File

@@ -1,4 +1,4 @@
.TH xtables-addons 8 "For Workgroups?" "" "v2.11 (2016-05-20)" .TH xtables-addons 8 "" "" "v2.14 (2017-11-22)"
.SH Name .SH Name
Xtables-addons \(em additional extensions for iptables, ip6tables, etc. Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
.SH Targets .SH Targets