xref: /linux/net/xfrm/xfrm_proc.c (revision daa2be74b1b2302004945b2a5e32424e177cc7da)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * xfrm_proc.c
4  *
5  * Copyright (C)2006-2007 USAGI/WIDE Project
6  *
7  * Authors:	Masahide NAKAMURA <nakam@linux-ipv6.org>
8  */
9 #include <linux/proc_fs.h>
10 #include <linux/seq_file.h>
11 #include <linux/export.h>
12 #include <net/snmp.h>
13 #include <net/xfrm.h>
14 
15 static const struct snmp_mib xfrm_mib_list[] = {
16 	SNMP_MIB_ITEM("XfrmInError", LINUX_MIB_XFRMINERROR),
17 	SNMP_MIB_ITEM("XfrmInBufferError", LINUX_MIB_XFRMINBUFFERERROR),
18 	SNMP_MIB_ITEM("XfrmInHdrError", LINUX_MIB_XFRMINHDRERROR),
19 	SNMP_MIB_ITEM("XfrmInNoStates", LINUX_MIB_XFRMINNOSTATES),
20 	SNMP_MIB_ITEM("XfrmInStateProtoError", LINUX_MIB_XFRMINSTATEPROTOERROR),
21 	SNMP_MIB_ITEM("XfrmInStateModeError", LINUX_MIB_XFRMINSTATEMODEERROR),
22 	SNMP_MIB_ITEM("XfrmInStateSeqError", LINUX_MIB_XFRMINSTATESEQERROR),
23 	SNMP_MIB_ITEM("XfrmInStateExpired", LINUX_MIB_XFRMINSTATEEXPIRED),
24 	SNMP_MIB_ITEM("XfrmInStateMismatch", LINUX_MIB_XFRMINSTATEMISMATCH),
25 	SNMP_MIB_ITEM("XfrmInStateInvalid", LINUX_MIB_XFRMINSTATEINVALID),
26 	SNMP_MIB_ITEM("XfrmInTmplMismatch", LINUX_MIB_XFRMINTMPLMISMATCH),
27 	SNMP_MIB_ITEM("XfrmInNoPols", LINUX_MIB_XFRMINNOPOLS),
28 	SNMP_MIB_ITEM("XfrmInPolBlock", LINUX_MIB_XFRMINPOLBLOCK),
29 	SNMP_MIB_ITEM("XfrmInPolError", LINUX_MIB_XFRMINPOLERROR),
30 	SNMP_MIB_ITEM("XfrmOutError", LINUX_MIB_XFRMOUTERROR),
31 	SNMP_MIB_ITEM("XfrmOutBundleGenError", LINUX_MIB_XFRMOUTBUNDLEGENERROR),
32 	SNMP_MIB_ITEM("XfrmOutBundleCheckError", LINUX_MIB_XFRMOUTBUNDLECHECKERROR),
33 	SNMP_MIB_ITEM("XfrmOutNoStates", LINUX_MIB_XFRMOUTNOSTATES),
34 	SNMP_MIB_ITEM("XfrmOutStateProtoError", LINUX_MIB_XFRMOUTSTATEPROTOERROR),
35 	SNMP_MIB_ITEM("XfrmOutStateModeError", LINUX_MIB_XFRMOUTSTATEMODEERROR),
36 	SNMP_MIB_ITEM("XfrmOutStateSeqError", LINUX_MIB_XFRMOUTSTATESEQERROR),
37 	SNMP_MIB_ITEM("XfrmOutStateExpired", LINUX_MIB_XFRMOUTSTATEEXPIRED),
38 	SNMP_MIB_ITEM("XfrmOutPolBlock", LINUX_MIB_XFRMOUTPOLBLOCK),
39 	SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD),
40 	SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR),
41 	SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
42 	SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
43 	SNMP_MIB_ITEM("XfrmAcquireError", LINUX_MIB_XFRMACQUIREERROR),
44 	SNMP_MIB_ITEM("XfrmOutStateDirError", LINUX_MIB_XFRMOUTSTATEDIRERROR),
45 	SNMP_MIB_ITEM("XfrmInStateDirError", LINUX_MIB_XFRMINSTATEDIRERROR),
46 	SNMP_MIB_SENTINEL
47 };
48 
49 static int xfrm_statistics_seq_show(struct seq_file *seq, void *v)
50 {
51 	unsigned long buff[LINUX_MIB_XFRMMAX];
52 	struct net *net = seq->private;
53 	int i;
54 
55 	memset(buff, 0, sizeof(unsigned long) * LINUX_MIB_XFRMMAX);
56 
57 	xfrm_state_update_stats(net);
58 	snmp_get_cpu_field_batch(buff, xfrm_mib_list,
59 				 net->mib.xfrm_statistics);
60 	for (i = 0; xfrm_mib_list[i].name; i++)
61 		seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name,
62 						buff[i]);
63 
64 	return 0;
65 }
66 
67 int __net_init xfrm_proc_init(struct net *net)
68 {
69 	if (!proc_create_net_single("xfrm_stat", 0444, net->proc_net,
70 			 xfrm_statistics_seq_show, NULL))
71 		return -ENOMEM;
72 	return 0;
73 }
74 
75 void xfrm_proc_fini(struct net *net)
76 {
77 	remove_proc_entry("xfrm_stat", net->proc_net);
78 }
79