blob: 9c4fbd8935f48e28c3c86d9da443904f55f93ec3 [file] [log] [blame]
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -08001/*
2 * xfrm_proc.c
3 *
4 * Copyright (C)2006-2007 USAGI/WIDE Project
5 *
6 * Authors: Masahide NAKAMURA <nakam@linux-ipv6.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13#include <linux/proc_fs.h>
14#include <linux/seq_file.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040015#include <linux/export.h>
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080016#include <net/snmp.h>
17#include <net/xfrm.h>
18
Alexey Dobriyan58339292010-01-22 10:17:26 +000019static const struct snmp_mib xfrm_mib_list[] = {
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080020 SNMP_MIB_ITEM("XfrmInError", LINUX_MIB_XFRMINERROR),
21 SNMP_MIB_ITEM("XfrmInBufferError", LINUX_MIB_XFRMINBUFFERERROR),
22 SNMP_MIB_ITEM("XfrmInHdrError", LINUX_MIB_XFRMINHDRERROR),
23 SNMP_MIB_ITEM("XfrmInNoStates", LINUX_MIB_XFRMINNOSTATES),
24 SNMP_MIB_ITEM("XfrmInStateProtoError", LINUX_MIB_XFRMINSTATEPROTOERROR),
25 SNMP_MIB_ITEM("XfrmInStateModeError", LINUX_MIB_XFRMINSTATEMODEERROR),
Masahide NAKAMURA9472c9e2008-01-31 17:14:58 -080026 SNMP_MIB_ITEM("XfrmInStateSeqError", LINUX_MIB_XFRMINSTATESEQERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080027 SNMP_MIB_ITEM("XfrmInStateExpired", LINUX_MIB_XFRMINSTATEEXPIRED),
28 SNMP_MIB_ITEM("XfrmInStateMismatch", LINUX_MIB_XFRMINSTATEMISMATCH),
29 SNMP_MIB_ITEM("XfrmInStateInvalid", LINUX_MIB_XFRMINSTATEINVALID),
30 SNMP_MIB_ITEM("XfrmInTmplMismatch", LINUX_MIB_XFRMINTMPLMISMATCH),
31 SNMP_MIB_ITEM("XfrmInNoPols", LINUX_MIB_XFRMINNOPOLS),
32 SNMP_MIB_ITEM("XfrmInPolBlock", LINUX_MIB_XFRMINPOLBLOCK),
33 SNMP_MIB_ITEM("XfrmInPolError", LINUX_MIB_XFRMINPOLERROR),
34 SNMP_MIB_ITEM("XfrmOutError", LINUX_MIB_XFRMOUTERROR),
35 SNMP_MIB_ITEM("XfrmOutBundleGenError", LINUX_MIB_XFRMOUTBUNDLEGENERROR),
36 SNMP_MIB_ITEM("XfrmOutBundleCheckError", LINUX_MIB_XFRMOUTBUNDLECHECKERROR),
37 SNMP_MIB_ITEM("XfrmOutNoStates", LINUX_MIB_XFRMOUTNOSTATES),
38 SNMP_MIB_ITEM("XfrmOutStateProtoError", LINUX_MIB_XFRMOUTSTATEPROTOERROR),
39 SNMP_MIB_ITEM("XfrmOutStateModeError", LINUX_MIB_XFRMOUTSTATEMODEERROR),
Masahide NAKAMURA9472c9e2008-01-31 17:14:58 -080040 SNMP_MIB_ITEM("XfrmOutStateSeqError", LINUX_MIB_XFRMOUTSTATESEQERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080041 SNMP_MIB_ITEM("XfrmOutStateExpired", LINUX_MIB_XFRMOUTSTATEEXPIRED),
42 SNMP_MIB_ITEM("XfrmOutPolBlock", LINUX_MIB_XFRMOUTPOLBLOCK),
43 SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD),
44 SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR),
jamal72032fd2010-02-18 03:35:07 +000045 SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
Li RongQingbb65a9c2012-12-28 16:06:28 +080046 SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID),
Fan Du4c4d41f2013-06-06 10:15:54 +080047 SNMP_MIB_ITEM("XfrmAcquireError", LINUX_MIB_XFRMACQUIREERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080048 SNMP_MIB_SENTINEL
49};
50
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080051static int xfrm_statistics_seq_show(struct seq_file *seq, void *v)
52{
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080053 struct net *net = seq->private;
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080054 int i;
Weilong Chen9b7a7872013-12-24 09:43:46 +080055 for (i = 0; xfrm_mib_list[i].name; i++)
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080056 seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name,
WANG Cong698365f2014-05-05 15:55:55 -070057 snmp_fold_field(net->mib.xfrm_statistics,
Rusty Russell91b208c2008-12-29 18:20:06 -080058 xfrm_mib_list[i].entry));
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080059 return 0;
60}
61
62static int xfrm_statistics_seq_open(struct inode *inode, struct file *file)
63{
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080064 return single_open_net(inode, file, xfrm_statistics_seq_show);
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080065}
66
Stephen Hemminger5ca1b992009-09-01 19:25:05 +000067static const struct file_operations xfrm_statistics_seq_fops = {
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080068 .owner = THIS_MODULE,
69 .open = xfrm_statistics_seq_open,
70 .read = seq_read,
71 .llseek = seq_lseek,
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080072 .release = single_release_net,
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080073};
74
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080075int __net_init xfrm_proc_init(struct net *net)
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080076{
Gao fengd4beaa62013-02-18 01:34:54 +000077 if (!proc_create("xfrm_stat", S_IRUGO, net->proc_net,
78 &xfrm_statistics_seq_fops))
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080079 return -ENOMEM;
80 return 0;
81}
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080082
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080083void xfrm_proc_fini(struct net *net)
84{
Gao fengece31ff2013-02-18 01:34:56 +000085 remove_proc_entry("xfrm_stat", net->proc_net);
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080086}