Skip to content

Commit 2ccba54

Browse files
committed
Merge branch 'master' of git://1984.lsi.us.es/nf-next
Pablo Neira Ayuso says: ==================== The following patchset contain updates for your net-next tree, they are: * Fix (for just added) connlabel dependencies, from Florian Westphal. * Add aliasing support for conntrack, thus users can either use -m state or -m conntrack from iptables while using the same kernel module, from Jozsef Kadlecsik. * Some code refactoring for the CT target to merge common code in revision 0 and 1, from myself. * Add aliasing support for CT, based on patch from Jozsef Kadlecsik. * Add one mutex per nfnetlink subsystem, from myself. * Improved logging for packets that are dropped by helpers, from myself. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 6338a53 + b20ab9c commit 2ccba54

25 files changed

Lines changed: 310 additions & 200 deletions

‎include/linux/netfilter/nfnetlink.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ extern int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigne
3434
extern int nfnetlink_set_err(struct net *net, u32 pid, u32 group, int error);
3535
extern int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u_int32_t pid, int flags);
3636

37-
extern void nfnl_lock(void);
38-
extern void nfnl_unlock(void);
37+
extern void nfnl_lock(__u8 subsys_id);
38+
extern void nfnl_unlock(__u8 subsys_id);
3939

4040
#define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
4141
MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))

‎include/net/netfilter/nf_conntrack_helper.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ struct nf_ct_helper_expectfn {
100100
void (*expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
101101
};
102102

103+
__printf(3,4)
104+
void nf_ct_helper_log(struct sk_buff *skb, const struct nf_conn *ct,
105+
const char *fmt, ...);
106+
103107
void nf_ct_helper_expectfn_register(struct nf_ct_helper_expectfn *n);
104108
void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n);
105109
struct nf_ct_helper_expectfn *

‎include/uapi/linux/netfilter/xt_CT.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
#include <linux/types.h>
55

6-
#define XT_CT_NOTRACK 0x1
6+
enum {
7+
XT_CT_NOTRACK = 1 << 0,
8+
XT_CT_NOTRACK_ALIAS = 1 << 1,
9+
XT_CT_MASK = XT_CT_NOTRACK | XT_CT_NOTRACK_ALIAS,
10+
};
711

812
struct xt_ct_target_info {
913
__u16 flags;

‎include/uapi/linux/netfilter/xt_conntrack.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum {
3131
XT_CONNTRACK_REPLSRC_PORT = 1 << 10,
3232
XT_CONNTRACK_REPLDST_PORT = 1 << 11,
3333
XT_CONNTRACK_DIRECTION = 1 << 12,
34+
XT_CONNTRACK_STATE_ALIAS = 1 << 13,
3435
};
3536

3637
struct xt_conntrack_mtinfo1 {

‎net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ static unsigned int ipv4_helper(unsigned int hooknum,
100100
enum ip_conntrack_info ctinfo;
101101
const struct nf_conn_help *help;
102102
const struct nf_conntrack_helper *helper;
103-
unsigned int ret;
104103

105104
/* This is where we call the helper: as the packet goes out. */
106105
ct = nf_ct_get(skb, &ctinfo);
@@ -116,13 +115,8 @@ static unsigned int ipv4_helper(unsigned int hooknum,
116115
if (!helper)
117116
return NF_ACCEPT;
118117

119-
ret = helper->help(skb, skb_network_offset(skb) + ip_hdrlen(skb),
120-
ct, ctinfo);
121-
if (ret != NF_ACCEPT && (ret & NF_VERDICT_MASK) != NF_QUEUE) {
122-
nf_log_packet(NFPROTO_IPV4, hooknum, skb, in, out, NULL,
123-
"nf_ct_%s: dropping packet", helper->name);
124-
}
125-
return ret;
118+
return helper->help(skb, skb_network_offset(skb) + ip_hdrlen(skb),
119+
ct, ctinfo);
126120
}
127121

128122
static unsigned int ipv4_confirm(unsigned int hooknum,

‎net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ static unsigned int ipv6_helper(unsigned int hooknum,
104104
const struct nf_conn_help *help;
105105
const struct nf_conntrack_helper *helper;
106106
enum ip_conntrack_info ctinfo;
107-
unsigned int ret;
108107
__be16 frag_off;
109108
int protoff;
110109
u8 nexthdr;
@@ -130,12 +129,7 @@ static unsigned int ipv6_helper(unsigned int hooknum,
130129
return NF_ACCEPT;
131130
}
132131

133-
ret = helper->help(skb, protoff, ct, ctinfo);
134-
if (ret != NF_ACCEPT && (ret & NF_VERDICT_MASK) != NF_QUEUE) {
135-
nf_log_packet(NFPROTO_IPV6, hooknum, skb, in, out, NULL,
136-
"nf_ct_%s: dropping packet", helper->name);
137-
}
138-
return ret;
132+
return helper->help(skb, protoff, ct, ctinfo);
139133
}
140134

141135
static unsigned int ipv6_confirm(unsigned int hooknum,

‎net/netfilter/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ config NETFILTER_XT_MATCH_CONNBYTES
860860
config NETFILTER_XT_MATCH_CONNLABEL
861861
tristate '"connlabel" match support'
862862
select NF_CONNTRACK_LABELS
863+
depends on NF_CONNTRACK
863864
depends on NETFILTER_ADVANCED
864865
---help---
865866
This match allows you to test and assign userspace-defined labels names

‎net/netfilter/ipset/ip_set_core.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ find_set_type(const char *name, u8 family, u8 revision)
8888
static bool
8989
load_settype(const char *name)
9090
{
91-
nfnl_unlock();
91+
nfnl_unlock(NFNL_SUBSYS_IPSET);
9292
pr_debug("try to load ip_set_%s\n", name);
9393
if (request_module("ip_set_%s", name) < 0) {
9494
pr_warning("Can't find ip_set type %s\n", name);
95-
nfnl_lock();
95+
nfnl_lock(NFNL_SUBSYS_IPSET);
9696
return false;
9797
}
98-
nfnl_lock();
98+
nfnl_lock(NFNL_SUBSYS_IPSET);
9999
return true;
100100
}
101101

@@ -532,7 +532,7 @@ ip_set_nfnl_get(const char *name)
532532
ip_set_id_t i, index = IPSET_INVALID_ID;
533533
struct ip_set *s;
534534

535-
nfnl_lock();
535+
nfnl_lock(NFNL_SUBSYS_IPSET);
536536
for (i = 0; i < ip_set_max; i++) {
537537
s = nfnl_set(i);
538538
if (s != NULL && STREQ(s->name, name)) {
@@ -541,7 +541,7 @@ ip_set_nfnl_get(const char *name)
541541
break;
542542
}
543543
}
544-
nfnl_unlock();
544+
nfnl_unlock(NFNL_SUBSYS_IPSET);
545545

546546
return index;
547547
}
@@ -561,13 +561,13 @@ ip_set_nfnl_get_byindex(ip_set_id_t index)
561561
if (index > ip_set_max)
562562
return IPSET_INVALID_ID;
563563

564-
nfnl_lock();
564+
nfnl_lock(NFNL_SUBSYS_IPSET);
565565
set = nfnl_set(index);
566566
if (set)
567567
__ip_set_get(set);
568568
else
569569
index = IPSET_INVALID_ID;
570-
nfnl_unlock();
570+
nfnl_unlock(NFNL_SUBSYS_IPSET);
571571

572572
return index;
573573
}
@@ -584,11 +584,11 @@ void
584584
ip_set_nfnl_put(ip_set_id_t index)
585585
{
586586
struct ip_set *set;
587-
nfnl_lock();
587+
nfnl_lock(NFNL_SUBSYS_IPSET);
588588
set = nfnl_set(index);
589589
if (set != NULL)
590590
__ip_set_put(set);
591-
nfnl_unlock();
591+
nfnl_unlock(NFNL_SUBSYS_IPSET);
592592
}
593593
EXPORT_SYMBOL_GPL(ip_set_nfnl_put);
594594

@@ -1763,10 +1763,10 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
17631763
goto done;
17641764
}
17651765
req_get->set.name[IPSET_MAXNAMELEN - 1] = '\0';
1766-
nfnl_lock();
1766+
nfnl_lock(NFNL_SUBSYS_IPSET);
17671767
find_set_and_id(req_get->set.name, &id);
17681768
req_get->set.index = id;
1769-
nfnl_unlock();
1769+
nfnl_unlock(NFNL_SUBSYS_IPSET);
17701770
goto copy;
17711771
}
17721772
case IP_SET_OP_GET_BYINDEX: {
@@ -1778,11 +1778,11 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
17781778
ret = -EINVAL;
17791779
goto done;
17801780
}
1781-
nfnl_lock();
1781+
nfnl_lock(NFNL_SUBSYS_IPSET);
17821782
set = nfnl_set(req_get->set.index);
17831783
strncpy(req_get->set.name, set ? set->name : "",
17841784
IPSET_MAXNAMELEN);
1785-
nfnl_unlock();
1785+
nfnl_unlock(NFNL_SUBSYS_IPSET);
17861786
goto copy;
17871787
}
17881788
default:

‎net/netfilter/nf_conntrack_amanda.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ static int amanda_help(struct sk_buff *skb,
145145

146146
exp = nf_ct_expect_alloc(ct);
147147
if (exp == NULL) {
148+
nf_ct_helper_log(skb, ct, "cannot alloc expectation");
148149
ret = NF_DROP;
149150
goto out;
150151
}
@@ -158,8 +159,10 @@ static int amanda_help(struct sk_buff *skb,
158159
if (nf_nat_amanda && ct->status & IPS_NAT_MASK)
159160
ret = nf_nat_amanda(skb, ctinfo, protoff,
160161
off - dataoff, len, exp);
161-
else if (nf_ct_expect_related(exp) != 0)
162+
else if (nf_ct_expect_related(exp) != 0) {
163+
nf_ct_helper_log(skb, ct, "cannot add expectation");
162164
ret = NF_DROP;
165+
}
163166
nf_ct_expect_put(exp);
164167
}
165168

‎net/netfilter/nf_conntrack_ftp.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ static int help(struct sk_buff *skb,
435435
connection tracking, not packet filtering.
436436
However, it is necessary for accurate tracking in
437437
this case. */
438-
pr_debug("conntrack_ftp: partial %s %u+%u\n",
439-
search[dir][i].pattern, ntohl(th->seq), datalen);
438+
nf_ct_helper_log(skb, ct, "partial matching of `%s'",
439+
search[dir][i].pattern);
440440
ret = NF_DROP;
441441
goto out;
442442
} else if (found == 0) { /* No match */
@@ -450,6 +450,7 @@ static int help(struct sk_buff *skb,
450450

451451
exp = nf_ct_expect_alloc(ct);
452452
if (exp == NULL) {
453+
nf_ct_helper_log(skb, ct, "cannot alloc expectation");
453454
ret = NF_DROP;
454455
goto out;
455456
}
@@ -500,9 +501,10 @@ static int help(struct sk_buff *skb,
500501
protoff, matchoff, matchlen, exp);
501502
else {
502503
/* Can't expect this? Best to drop packet now. */
503-
if (nf_ct_expect_related(exp) != 0)
504+
if (nf_ct_expect_related(exp) != 0) {
505+
nf_ct_helper_log(skb, ct, "cannot add expectation");
504506
ret = NF_DROP;
505-
else
507+
} else
506508
ret = NF_ACCEPT;
507509
}
508510

0 commit comments

Comments
 (0)