Skip to content

Commit 4e7a84b

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== netfilter updates for net-next The following patchset contains netfilter updates for net-next, just a bunch of cleanups and small enhancement to selectively flush conntracks in ctnetlink, more specifically the patches are: 1) Rise default number of buckets in conntrack from 16384 to 65536 in systems with >= 4GBytes, patch from Marcelo Leitner. 2) Small refactor to save one level on indentation in xt_osf, from Joe Perches. 3) Remove unnecessary sizeof(char) in nf_log, from Fabian Frederick. 4) Another small cleanup to remove redundant variable in nfnetlink, from Duan Jiong. 5) Fix compilation warning in nfnetlink_cthelper on parisc, from Chen Gang. 6) Fix wrong format in debugging for ctseqadj, from Gao feng. 7) Selective conntrack flushing through the mark for ctnetlink, patch from Kristian Evensen. 8) Remove nf_ct_conntrack_flush_report() exported symbol now that is not required anymore after the selective flushing patch, again from Kristian. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 2e62fa6 + ae406bd commit 4e7a84b

File tree

9 files changed

+172
-136
lines changed

9 files changed

+172
-136
lines changed

Documentation/networking/nf_conntrack-sysctl.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ nf_conntrack_buckets - INTEGER (read-only)
1111
Size of hash table. If not specified as parameter during module
1212
loading, the default size is calculated by dividing total memory
1313
by 16384 to determine the number of buckets but the hash table will
14-
never have fewer than 32 or more than 16384 buckets.
14+
never have fewer than 32 and limited to 16384 buckets. For systems
15+
with more than 4GB of memory it will be 65536 buckets.
1516

1617
nf_conntrack_checksum - BOOLEAN
1718
0 - disabled

include/net/netfilter/nf_conntrack.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ __nf_conntrack_find(struct net *net, u16 zone,
191191
int nf_conntrack_hash_check_insert(struct nf_conn *ct);
192192
bool nf_ct_delete(struct nf_conn *ct, u32 pid, int report);
193193

194-
void nf_conntrack_flush_report(struct net *net, u32 portid, int report);
195-
196194
bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,
197195
u_int16_t l3num, struct nf_conntrack_tuple *tuple);
198196
bool nf_ct_invert_tuplepr(struct nf_conntrack_tuple *inverse,

net/netfilter/nf_conntrack_core.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,12 +1424,6 @@ void nf_ct_free_hashtable(void *hash, unsigned int size)
14241424
}
14251425
EXPORT_SYMBOL_GPL(nf_ct_free_hashtable);
14261426

1427-
void nf_conntrack_flush_report(struct net *net, u32 portid, int report)
1428-
{
1429-
nf_ct_iterate_cleanup(net, kill_all, NULL, portid, report);
1430-
}
1431-
EXPORT_SYMBOL_GPL(nf_conntrack_flush_report);
1432-
14331427
static int untrack_refs(void)
14341428
{
14351429
int cnt = 0, cpu;
@@ -1622,13 +1616,18 @@ int nf_conntrack_init_start(void)
16221616
for (i = 0; i < CONNTRACK_LOCKS; i++)
16231617
spin_lock_init(&nf_conntrack_locks[i]);
16241618

1625-
/* Idea from tcp.c: use 1/16384 of memory. On i386: 32MB
1626-
* machine has 512 buckets. >= 1GB machines have 16384 buckets. */
16271619
if (!nf_conntrack_htable_size) {
1620+
/* Idea from tcp.c: use 1/16384 of memory.
1621+
* On i386: 32MB machine has 512 buckets.
1622+
* >= 1GB machines have 16384 buckets.
1623+
* >= 4GB machines have 65536 buckets.
1624+
*/
16281625
nf_conntrack_htable_size
16291626
= (((totalram_pages << PAGE_SHIFT) / 16384)
16301627
/ sizeof(struct hlist_head));
1631-
if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
1628+
if (totalram_pages > (4 * (1024 * 1024 * 1024 / PAGE_SIZE)))
1629+
nf_conntrack_htable_size = 65536;
1630+
else if (totalram_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
16321631
nf_conntrack_htable_size = 16384;
16331632
if (nf_conntrack_htable_size < 32)
16341633
nf_conntrack_htable_size = 32;

net/netfilter/nf_conntrack_netlink.c

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,47 @@ static int ctnetlink_done(struct netlink_callback *cb)
749749
return 0;
750750
}
751751

752-
struct ctnetlink_dump_filter {
752+
struct ctnetlink_filter {
753753
struct {
754754
u_int32_t val;
755755
u_int32_t mask;
756756
} mark;
757757
};
758758

759+
static struct ctnetlink_filter *
760+
ctnetlink_alloc_filter(const struct nlattr * const cda[])
761+
{
762+
#ifdef CONFIG_NF_CONNTRACK_MARK
763+
struct ctnetlink_filter *filter;
764+
765+
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
766+
if (filter == NULL)
767+
return ERR_PTR(-ENOMEM);
768+
769+
filter->mark.val = ntohl(nla_get_be32(cda[CTA_MARK]));
770+
filter->mark.mask = ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
771+
772+
return filter;
773+
#else
774+
return ERR_PTR(-EOPNOTSUPP);
775+
#endif
776+
}
777+
778+
static int ctnetlink_filter_match(struct nf_conn *ct, void *data)
779+
{
780+
struct ctnetlink_filter *filter = data;
781+
782+
if (filter == NULL)
783+
return 1;
784+
785+
#ifdef CONFIG_NF_CONNTRACK_MARK
786+
if ((ct->mark & filter->mark.mask) == filter->mark.val)
787+
return 1;
788+
#endif
789+
790+
return 0;
791+
}
792+
759793
static int
760794
ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
761795
{
@@ -768,10 +802,6 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
768802
int res;
769803
spinlock_t *lockp;
770804

771-
#ifdef CONFIG_NF_CONNTRACK_MARK
772-
const struct ctnetlink_dump_filter *filter = cb->data;
773-
#endif
774-
775805
last = (struct nf_conn *)cb->args[1];
776806

777807
local_bh_disable();
@@ -798,12 +828,9 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
798828
continue;
799829
cb->args[1] = 0;
800830
}
801-
#ifdef CONFIG_NF_CONNTRACK_MARK
802-
if (filter && !((ct->mark & filter->mark.mask) ==
803-
filter->mark.val)) {
831+
if (!ctnetlink_filter_match(ct, cb->data))
804832
continue;
805-
}
806-
#endif
833+
807834
rcu_read_lock();
808835
res =
809836
ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).portid,
@@ -1001,6 +1028,25 @@ static const struct nla_policy ct_nla_policy[CTA_MAX+1] = {
10011028
.len = NF_CT_LABELS_MAX_SIZE },
10021029
};
10031030

1031+
static int ctnetlink_flush_conntrack(struct net *net,
1032+
const struct nlattr * const cda[],
1033+
u32 portid, int report)
1034+
{
1035+
struct ctnetlink_filter *filter = NULL;
1036+
1037+
if (cda[CTA_MARK] && cda[CTA_MARK_MASK]) {
1038+
filter = ctnetlink_alloc_filter(cda);
1039+
if (IS_ERR(filter))
1040+
return PTR_ERR(filter);
1041+
}
1042+
1043+
nf_ct_iterate_cleanup(net, ctnetlink_filter_match, filter,
1044+
portid, report);
1045+
kfree(filter);
1046+
1047+
return 0;
1048+
}
1049+
10041050
static int
10051051
ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
10061052
const struct nlmsghdr *nlh,
@@ -1024,11 +1070,9 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
10241070
else if (cda[CTA_TUPLE_REPLY])
10251071
err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
10261072
else {
1027-
/* Flush the whole table */
1028-
nf_conntrack_flush_report(net,
1029-
NETLINK_CB(skb).portid,
1030-
nlmsg_report(nlh));
1031-
return 0;
1073+
return ctnetlink_flush_conntrack(net, cda,
1074+
NETLINK_CB(skb).portid,
1075+
nlmsg_report(nlh));
10321076
}
10331077

10341078
if (err < 0)
@@ -1076,21 +1120,16 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
10761120
.dump = ctnetlink_dump_table,
10771121
.done = ctnetlink_done,
10781122
};
1079-
#ifdef CONFIG_NF_CONNTRACK_MARK
1123+
10801124
if (cda[CTA_MARK] && cda[CTA_MARK_MASK]) {
1081-
struct ctnetlink_dump_filter *filter;
1125+
struct ctnetlink_filter *filter;
10821126

1083-
filter = kzalloc(sizeof(struct ctnetlink_dump_filter),
1084-
GFP_ATOMIC);
1085-
if (filter == NULL)
1086-
return -ENOMEM;
1127+
filter = ctnetlink_alloc_filter(cda);
1128+
if (IS_ERR(filter))
1129+
return PTR_ERR(filter);
10871130

1088-
filter->mark.val = ntohl(nla_get_be32(cda[CTA_MARK]));
1089-
filter->mark.mask =
1090-
ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
10911131
c.data = filter;
10921132
}
1093-
#endif
10941133
return netlink_dump_start(ctnl, skb, nlh, &c);
10951134
}
10961135

net/netfilter/nf_conntrack_seqadj.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ static void nf_ct_sack_block_adjust(struct sk_buff *skb,
9898
new_end_seq = htonl(ntohl(sack->end_seq) -
9999
seq->offset_before);
100100

101-
pr_debug("sack_adjust: start_seq: %d->%d, end_seq: %d->%d\n",
102-
ntohl(sack->start_seq), new_start_seq,
103-
ntohl(sack->end_seq), new_end_seq);
101+
pr_debug("sack_adjust: start_seq: %u->%u, end_seq: %u->%u\n",
102+
ntohl(sack->start_seq), ntohl(new_start_seq),
103+
ntohl(sack->end_seq), ntohl(new_end_seq));
104104

105105
inet_proto_csum_replace4(&tcph->check, skb,
106106
sack->start_seq, new_start_seq, 0);

net/netfilter/nf_log.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ static int netfilter_log_sysctl_init(struct net *net)
425425
nf_log_sysctl_table[i].procname =
426426
nf_log_sysctl_fnames[i];
427427
nf_log_sysctl_table[i].data = NULL;
428-
nf_log_sysctl_table[i].maxlen =
429-
NFLOGGER_NAME_LEN * sizeof(char);
428+
nf_log_sysctl_table[i].maxlen = NFLOGGER_NAME_LEN;
430429
nf_log_sysctl_table[i].mode = 0644;
431430
nf_log_sysctl_table[i].proc_handler =
432431
nf_log_proc_dostring;

net/netfilter/nfnetlink.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static void nfnl_err_deliver(struct list_head *err_list, struct sk_buff *skb)
272272
static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
273273
u_int16_t subsys_id)
274274
{
275-
struct sk_buff *nskb, *oskb = skb;
275+
struct sk_buff *oskb = skb;
276276
struct net *net = sock_net(skb->sk);
277277
const struct nfnetlink_subsystem *ss;
278278
const struct nfnl_callback *nc;
@@ -283,12 +283,11 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
283283
if (subsys_id >= NFNL_SUBSYS_COUNT)
284284
return netlink_ack(skb, nlh, -EINVAL);
285285
replay:
286-
nskb = netlink_skb_clone(oskb, GFP_KERNEL);
287-
if (!nskb)
286+
skb = netlink_skb_clone(oskb, GFP_KERNEL);
287+
if (!skb)
288288
return netlink_ack(oskb, nlh, -ENOMEM);
289289

290-
nskb->sk = oskb->sk;
291-
skb = nskb;
290+
skb->sk = oskb->sk;
292291

293292
nfnl_lock(subsys_id);
294293
ss = rcu_dereference_protected(table[subsys_id].subsys,
@@ -305,7 +304,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
305304
{
306305
nfnl_unlock(subsys_id);
307306
netlink_ack(skb, nlh, -EOPNOTSUPP);
308-
return kfree_skb(nskb);
307+
return kfree_skb(skb);
309308
}
310309
}
311310

@@ -386,7 +385,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
386385
nfnl_err_reset(&err_list);
387386
ss->abort(oskb);
388387
nfnl_unlock(subsys_id);
389-
kfree_skb(nskb);
388+
kfree_skb(skb);
390389
goto replay;
391390
}
392391
}
@@ -427,7 +426,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
427426

428427
nfnl_err_deliver(&err_list, oskb);
429428
nfnl_unlock(subsys_id);
430-
kfree_skb(nskb);
429+
kfree_skb(skb);
431430
}
432431

433432
static void nfnetlink_rcv(struct sk_buff *skb)

net/netfilter/nfnetlink_cthelper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ nfnl_cthelper_parse_tuple(struct nf_conntrack_tuple *tuple,
8686
static int
8787
nfnl_cthelper_from_nlattr(struct nlattr *attr, struct nf_conn *ct)
8888
{
89-
const struct nf_conn_help *help = nfct_help(ct);
89+
struct nf_conn_help *help = nfct_help(ct);
9090

9191
if (attr == NULL)
9292
return -EINVAL;
9393

9494
if (help->helper->data_len == 0)
9595
return -EINVAL;
9696

97-
memcpy(&help->data, nla_data(attr), help->helper->data_len);
97+
memcpy(help->data, nla_data(attr), help->helper->data_len);
9898
return 0;
9999
}
100100

0 commit comments

Comments
 (0)