]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/net/netfilter/nf_conntrack_acct.h
netfilter: flowtable: add vlan support
[mirror_ubuntu-jammy-kernel.git] / include / net / netfilter / nf_conntrack_acct.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
58401572
KPO
2/*
3 * (C) 2008 Krzysztof Piotr Oledzki <ole@ans.pl>
58401572
KPO
4 */
5
6#ifndef _NF_CONNTRACK_ACCT_H
7#define _NF_CONNTRACK_ACCT_H
d716a4df 8#include <net/net_namespace.h>
58401572
KPO
9#include <linux/netfilter/nf_conntrack_common.h>
10#include <linux/netfilter/nf_conntrack_tuple_common.h>
11#include <net/netfilter/nf_conntrack.h>
12#include <net/netfilter/nf_conntrack_extend.h>
13
14struct nf_conn_counter {
b3e0bfa7
ED
15 atomic64_t packets;
16 atomic64_t bytes;
58401572
KPO
17};
18
f7b13e43
HE
19struct nf_conn_acct {
20 struct nf_conn_counter counter[IP_CT_DIR_MAX];
21};
22
58401572 23static inline
f7b13e43 24struct nf_conn_acct *nf_conn_acct_find(const struct nf_conn *ct)
58401572
KPO
25{
26 return nf_ct_ext_find(ct, NF_CT_EXT_ACCT);
27}
28
29static inline
f7b13e43 30struct nf_conn_acct *nf_ct_acct_ext_add(struct nf_conn *ct, gfp_t gfp)
58401572 31{
0abc8bf4 32#if IS_ENABLED(CONFIG_NF_CONNTRACK)
d716a4df 33 struct net *net = nf_ct_net(ct);
f7b13e43 34 struct nf_conn_acct *acct;
58401572 35
d716a4df 36 if (!net->ct.sysctl_acct)
58401572
KPO
37 return NULL;
38
39 acct = nf_ct_ext_add(ct, NF_CT_EXT_ACCT, gfp);
40 if (!acct)
41 pr_debug("failed to add accounting extension area");
42
43
44 return acct;
0abc8bf4
JS
45#else
46 return NULL;
47#endif
b0edba2a 48}
58401572 49
a8756201
TG
50/* Check if connection tracking accounting is enabled */
51static inline bool nf_ct_acct_enabled(struct net *net)
52{
0abc8bf4 53#if IS_ENABLED(CONFIG_NF_CONNTRACK)
a8756201 54 return net->ct.sysctl_acct != 0;
0abc8bf4
JS
55#else
56 return false;
57#endif
a8756201
TG
58}
59
60/* Enable/disable connection tracking accounting */
61static inline void nf_ct_set_acct(struct net *net, bool enable)
62{
0abc8bf4 63#if IS_ENABLED(CONFIG_NF_CONNTRACK)
a8756201 64 net->ct.sysctl_acct = enable;
0abc8bf4 65#endif
a8756201
TG
66}
67
9312eaba 68void nf_ct_acct_add(struct nf_conn *ct, u32 dir, unsigned int packets,
69 unsigned int bytes);
70
71static inline void nf_ct_acct_update(struct nf_conn *ct, u32 dir,
72 unsigned int bytes)
73{
74#if IS_ENABLED(CONFIG_NF_CONNTRACK)
75 nf_ct_acct_add(ct, dir, 1, bytes);
76#endif
77}
8ac2bd35 78
fc3893fd 79void nf_conntrack_acct_pernet_init(struct net *net);
58401572 80
4e77be46
JP
81int nf_conntrack_acct_init(void);
82void nf_conntrack_acct_fini(void);
0abc8bf4 83
58401572 84#endif /* _NF_CONNTRACK_ACCT_H */