1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * (C) 2008 Krzysztof Piotr Oledzki <ole@ans.pl>
6 #ifndef _NF_CONNTRACK_ACCT_H
7 #define _NF_CONNTRACK_ACCT_H
8 #include <net/net_namespace.h>
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>
14 struct nf_conn_counter {
20 struct nf_conn_counter counter[IP_CT_DIR_MAX];
24 struct nf_conn_acct *nf_conn_acct_find(const struct nf_conn *ct)
26 return nf_ct_ext_find(ct, NF_CT_EXT_ACCT);
30 struct nf_conn_acct *nf_ct_acct_ext_add(struct nf_conn *ct, gfp_t gfp)
32 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
33 struct net *net = nf_ct_net(ct);
34 struct nf_conn_acct *acct;
36 if (!net->ct.sysctl_acct)
39 acct = nf_ct_ext_add(ct, NF_CT_EXT_ACCT, gfp);
41 pr_debug("failed to add accounting extension area");
50 /* Check if connection tracking accounting is enabled */
51 static inline bool nf_ct_acct_enabled(struct net *net)
53 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
54 return net->ct.sysctl_acct != 0;
60 /* Enable/disable connection tracking accounting */
61 static inline void nf_ct_set_acct(struct net *net, bool enable)
63 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
64 net->ct.sysctl_acct = enable;
68 void nf_ct_acct_add(struct nf_conn *ct, u32 dir, unsigned int packets,
71 static inline void nf_ct_acct_update(struct nf_conn *ct, u32 dir,
74 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
75 nf_ct_acct_add(ct, dir, 1, bytes);
79 void nf_conntrack_acct_pernet_init(struct net *net);
81 int nf_conntrack_acct_init(void);
82 void nf_conntrack_acct_fini(void);
84 #endif /* _NF_CONNTRACK_ACCT_H */