blob: fee9b5cf37a7c22be761c61ba133d03281c116e7 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -08002/*
3 * xfrm_proc.c
4 *
5 * Copyright (C)2006-2007 USAGI/WIDE Project
6 *
7 * Authors: Masahide NAKAMURA <nakam@linux-ipv6.org>
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -08008 */
9#include <linux/proc_fs.h>
10#include <linux/seq_file.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040011#include <linux/export.h>
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080012#include <net/snmp.h>
13#include <net/xfrm.h>
14
Alexey Dobriyan58339292010-01-22 10:17:26 +000015static const struct snmp_mib xfrm_mib_list[] = {
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080016 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),
Masahide NAKAMURA9472c9e2008-01-31 17:14:58 -080022 SNMP_MIB_ITEM("XfrmInStateSeqError", LINUX_MIB_XFRMINSTATESEQERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080023 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),
Masahide NAKAMURA9472c9e2008-01-31 17:14:58 -080036 SNMP_MIB_ITEM("XfrmOutStateSeqError", LINUX_MIB_XFRMOUTSTATESEQERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080037 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),
jamal72032fd2010-02-18 03:35:07 +000041 SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
Li RongQingbb65a9c2012-12-28 16:06:28 +080042 SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
Fan Du4c4d41f2013-06-06 10:15:54 +080043 SNMP_MIB_ITEM("XfrmAcquireError", LINUX_MIB_XFRMACQUIREERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080044 SNMP_MIB_SENTINEL
45};
46
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080047static int xfrm_statistics_seq_show(struct seq_file *seq, void *v)
48{
Jia He076138732016-09-30 11:29:02 +080049 unsigned long buff[LINUX_MIB_XFRMMAX];
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080050 struct net *net = seq->private;
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080051 int i;
Jia He076138732016-09-30 11:29:02 +080052
53 memset(buff, 0, sizeof(unsigned long) * LINUX_MIB_XFRMMAX);
54
55 snmp_get_cpu_field_batch(buff, xfrm_mib_list,
56 net->mib.xfrm_statistics);
Weilong Chen9b7a7872013-12-24 09:43:46 +080057 for (i = 0; xfrm_mib_list[i].name; i++)
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080058 seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name,
Jia He076138732016-09-30 11:29:02 +080059 buff[i]);
60
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080061 return 0;
62}
63
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080064int __net_init xfrm_proc_init(struct net *net)
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080065{
Christoph Hellwig3617d942018-04-13 20:38:35 +020066 if (!proc_create_net_single("xfrm_stat", 0444, net->proc_net,
67 xfrm_statistics_seq_show, NULL))
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080068 return -ENOMEM;
69 return 0;
70}
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080071
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080072void xfrm_proc_fini(struct net *net)
73{
Gao fengece31ff2013-02-18 01:34:56 +000074 remove_proc_entry("xfrm_stat", net->proc_net);
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080075}