Skip to content

Commit 90d0e08

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== Netfilter/IPVS updates for net-next This small patchset contains three accumulated Netfilter/IPVS updates, they are: 1) Refactorize common NAT code by encapsulating it into a helper function, similarly to what we do in other conntrack extensions, from Florian Westphal. 2) A minor format string mismatch fix for IPVS, from Masanari Iida. 3) Add quota support to the netfilter accounting infrastructure, now you can add quotas to accounting objects via the nfnetlink interface and use them from iptables. You can also listen to quota notifications from userspace. This enhancement from Mathieu Poirier. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 648d4fe + f768e5b commit 90d0e08

12 files changed

Lines changed: 138 additions & 51 deletions

File tree

‎include/linux/netfilter/nfnetlink_acct.h‎

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

44
#include <uapi/linux/netfilter/nfnetlink_acct.h>
55

6+
enum {
7+
NFACCT_NO_QUOTA = -1,
8+
NFACCT_UNDERQUOTA,
9+
NFACCT_OVERQUOTA,
10+
};
611

712
struct nf_acct;
813

914
struct nf_acct *nfnl_acct_find_get(const char *filter_name);
1015
void nfnl_acct_put(struct nf_acct *acct);
1116
void nfnl_acct_update(const struct sk_buff *skb, struct nf_acct *nfacct);
12-
17+
extern int nfnl_acct_overquota(const struct sk_buff *skb,
18+
struct nf_acct *nfacct);
1319
#endif /* _NFNL_ACCT_H */

‎include/net/netfilter/nf_nat.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ unsigned int nf_nat_setup_info(struct nf_conn *ct,
4848
extern unsigned int nf_nat_alloc_null_binding(struct nf_conn *ct,
4949
unsigned int hooknum);
5050

51+
struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct);
52+
5153
/* Is this tuple already taken? (not by us)*/
5254
int nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,
5355
const struct nf_conn *ignored_conntrack);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ enum nfnetlink_groups {
2020
#define NFNLGRP_CONNTRACK_EXP_DESTROY NFNLGRP_CONNTRACK_EXP_DESTROY
2121
NFNLGRP_NFTABLES,
2222
#define NFNLGRP_NFTABLES NFNLGRP_NFTABLES
23+
NFNLGRP_ACCT_QUOTA,
24+
#define NFNLGRP_ACCT_QUOTA NFNLGRP_ACCT_QUOTA
2325
__NFNLGRP_MAX,
2426
};
2527
#define NFNLGRP_MAX (__NFNLGRP_MAX - 1)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ enum nfnl_acct_msg_types {
1010
NFNL_MSG_ACCT_GET,
1111
NFNL_MSG_ACCT_GET_CTRZERO,
1212
NFNL_MSG_ACCT_DEL,
13+
NFNL_MSG_ACCT_OVERQUOTA,
1314
NFNL_MSG_ACCT_MAX
1415
};
1516

17+
enum nfnl_acct_flags {
18+
NFACCT_F_QUOTA_PKTS = (1 << 0),
19+
NFACCT_F_QUOTA_BYTES = (1 << 1),
20+
NFACCT_F_OVERQUOTA = (1 << 2), /* can't be set from userspace */
21+
};
22+
1623
enum nfnl_acct_type {
1724
NFACCT_UNSPEC,
1825
NFACCT_NAME,
1926
NFACCT_PKTS,
2027
NFACCT_BYTES,
2128
NFACCT_USE,
29+
NFACCT_FLAGS,
30+
NFACCT_QUOTA,
2231
__NFACCT_MAX
2332
};
2433
#define NFACCT_MAX (__NFACCT_MAX - 1)

‎net/ipv4/netfilter/iptable_nat.c‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,9 @@ nf_nat_ipv4_fn(const struct nf_hook_ops *ops,
9191
if (nf_ct_is_untracked(ct))
9292
return NF_ACCEPT;
9393

94-
nat = nfct_nat(ct);
95-
if (!nat) {
96-
/* NAT module was loaded late. */
97-
if (nf_ct_is_confirmed(ct))
98-
return NF_ACCEPT;
99-
nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
100-
if (nat == NULL) {
101-
pr_debug("failed to add NAT extension\n");
102-
return NF_ACCEPT;
103-
}
104-
}
94+
nat = nf_ct_nat_ext_add(ct);
95+
if (nat == NULL)
96+
return NF_ACCEPT;
10597

10698
switch (ctinfo) {
10799
case IP_CT_RELATED:

‎net/ipv4/netfilter/nft_chain_nat_ipv4.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,9 @@ static unsigned int nf_nat_fn(const struct nf_hook_ops *ops,
4848

4949
NF_CT_ASSERT(!(ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)));
5050

51-
nat = nfct_nat(ct);
52-
if (nat == NULL) {
53-
/* Conntrack module was loaded late, can't add extension. */
54-
if (nf_ct_is_confirmed(ct))
55-
return NF_ACCEPT;
56-
nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
57-
if (nat == NULL)
58-
return NF_ACCEPT;
59-
}
51+
nat = nf_ct_nat_ext_add(ct);
52+
if (nat == NULL)
53+
return NF_ACCEPT;
6054

6155
switch (ctinfo) {
6256
case IP_CT_RELATED:

‎net/ipv6/netfilter/ip6table_nat.c‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,9 @@ nf_nat_ipv6_fn(const struct nf_hook_ops *ops,
9090
if (nf_ct_is_untracked(ct))
9191
return NF_ACCEPT;
9292

93-
nat = nfct_nat(ct);
94-
if (!nat) {
95-
/* NAT module was loaded late. */
96-
if (nf_ct_is_confirmed(ct))
97-
return NF_ACCEPT;
98-
nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
99-
if (nat == NULL) {
100-
pr_debug("failed to add NAT extension\n");
101-
return NF_ACCEPT;
102-
}
103-
}
93+
nat = nf_ct_nat_ext_add(ct);
94+
if (nat == NULL)
95+
return NF_ACCEPT;
10496

10597
switch (ctinfo) {
10698
case IP_CT_RELATED:

‎net/ipv6/netfilter/nft_chain_nat_ipv6.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,9 @@ static unsigned int nf_nat_ipv6_fn(const struct nf_hook_ops *ops,
4747
if (ct == NULL || nf_ct_is_untracked(ct))
4848
return NF_ACCEPT;
4949

50-
nat = nfct_nat(ct);
51-
if (nat == NULL) {
52-
/* Conntrack module was loaded late, can't add extension. */
53-
if (nf_ct_is_confirmed(ct))
54-
return NF_ACCEPT;
55-
nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
56-
if (nat == NULL)
57-
return NF_ACCEPT;
58-
}
50+
nat = nf_ct_nat_ext_add(ct);
51+
if (nat == NULL)
52+
return NF_ACCEPT;
5953

6054
switch (ctinfo) {
6155
case IP_CT_RELATED:

‎net/netfilter/ipvs/ip_vs_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const char *ip_vs_proto_name(unsigned int proto)
9797
return "ICMPv6";
9898
#endif
9999
default:
100-
sprintf(buf, "IP_%d", proto);
100+
sprintf(buf, "IP_%u", proto);
101101
return buf;
102102
}
103103
}

‎net/netfilter/nf_nat_core.c‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,19 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
358358
rcu_read_unlock();
359359
}
360360

361+
struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct)
362+
{
363+
struct nf_conn_nat *nat = nfct_nat(ct);
364+
if (nat)
365+
return nat;
366+
367+
if (!nf_ct_is_confirmed(ct))
368+
nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
369+
370+
return nat;
371+
}
372+
EXPORT_SYMBOL_GPL(nf_ct_nat_ext_add);
373+
361374
unsigned int
362375
nf_nat_setup_info(struct nf_conn *ct,
363376
const struct nf_nat_range *range,
@@ -368,14 +381,9 @@ nf_nat_setup_info(struct nf_conn *ct,
368381
struct nf_conn_nat *nat;
369382

370383
/* nat helper or nfctnetlink also setup binding */
371-
nat = nfct_nat(ct);
372-
if (!nat) {
373-
nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
374-
if (nat == NULL) {
375-
pr_debug("failed to add NAT extension\n");
376-
return NF_ACCEPT;
377-
}
378-
}
384+
nat = nf_ct_nat_ext_add(ct);
385+
if (nat == NULL)
386+
return NF_ACCEPT;
379387

380388
NF_CT_ASSERT(maniptype == NF_NAT_MANIP_SRC ||
381389
maniptype == NF_NAT_MANIP_DST);

0 commit comments

Comments
 (0)