blob: 58d9ae005597a9b963b24ed620aa2e915c93e3bc [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>
15#include <net/snmp.h>
16#include <net/xfrm.h>
17
Alexey Dobriyan58339292010-01-22 10:17:26 +000018static const struct snmp_mib xfrm_mib_list[] = {
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080019 SNMP_MIB_ITEM("XfrmInError", LINUX_MIB_XFRMINERROR),
20 SNMP_MIB_ITEM("XfrmInBufferError", LINUX_MIB_XFRMINBUFFERERROR),
21 SNMP_MIB_ITEM("XfrmInHdrError", LINUX_MIB_XFRMINHDRERROR),
22 SNMP_MIB_ITEM("XfrmInNoStates", LINUX_MIB_XFRMINNOSTATES),
23 SNMP_MIB_ITEM("XfrmInStateProtoError", LINUX_MIB_XFRMINSTATEPROTOERROR),
24 SNMP_MIB_ITEM("XfrmInStateModeError", LINUX_MIB_XFRMINSTATEMODEERROR),
Masahide NAKAMURA9472c9e2008-01-31 17:14:58 -080025 SNMP_MIB_ITEM("XfrmInStateSeqError", LINUX_MIB_XFRMINSTATESEQERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080026 SNMP_MIB_ITEM("XfrmInStateExpired", LINUX_MIB_XFRMINSTATEEXPIRED),
27 SNMP_MIB_ITEM("XfrmInStateMismatch", LINUX_MIB_XFRMINSTATEMISMATCH),
28 SNMP_MIB_ITEM("XfrmInStateInvalid", LINUX_MIB_XFRMINSTATEINVALID),
29 SNMP_MIB_ITEM("XfrmInTmplMismatch", LINUX_MIB_XFRMINTMPLMISMATCH),
30 SNMP_MIB_ITEM("XfrmInNoPols", LINUX_MIB_XFRMINNOPOLS),
31 SNMP_MIB_ITEM("XfrmInPolBlock", LINUX_MIB_XFRMINPOLBLOCK),
32 SNMP_MIB_ITEM("XfrmInPolError", LINUX_MIB_XFRMINPOLERROR),
33 SNMP_MIB_ITEM("XfrmOutError", LINUX_MIB_XFRMOUTERROR),
34 SNMP_MIB_ITEM("XfrmOutBundleGenError", LINUX_MIB_XFRMOUTBUNDLEGENERROR),
35 SNMP_MIB_ITEM("XfrmOutBundleCheckError", LINUX_MIB_XFRMOUTBUNDLECHECKERROR),
36 SNMP_MIB_ITEM("XfrmOutNoStates", LINUX_MIB_XFRMOUTNOSTATES),
37 SNMP_MIB_ITEM("XfrmOutStateProtoError", LINUX_MIB_XFRMOUTSTATEPROTOERROR),
38 SNMP_MIB_ITEM("XfrmOutStateModeError", LINUX_MIB_XFRMOUTSTATEMODEERROR),
Masahide NAKAMURA9472c9e2008-01-31 17:14:58 -080039 SNMP_MIB_ITEM("XfrmOutStateSeqError", LINUX_MIB_XFRMOUTSTATESEQERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080040 SNMP_MIB_ITEM("XfrmOutStateExpired", LINUX_MIB_XFRMOUTSTATEEXPIRED),
41 SNMP_MIB_ITEM("XfrmOutPolBlock", LINUX_MIB_XFRMOUTPOLBLOCK),
42 SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD),
43 SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR),
jamal72032fd2010-02-18 03:35:07 +000044 SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR),
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080045 SNMP_MIB_SENTINEL
46};
47
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080048static int xfrm_statistics_seq_show(struct seq_file *seq, void *v)
49{
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080050 struct net *net = seq->private;
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080051 int i;
52 for (i=0; xfrm_mib_list[i].name; i++)
53 seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name,
Tejun Heo7d720c32010-02-16 15:20:26 +000054 snmp_fold_field((void __percpu **)
55 net->mib.xfrm_statistics,
Rusty Russell91b208c2008-12-29 18:20:06 -080056 xfrm_mib_list[i].entry));
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080057 return 0;
58}
59
60static int xfrm_statistics_seq_open(struct inode *inode, struct file *file)
61{
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080062 return single_open_net(inode, file, xfrm_statistics_seq_show);
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080063}
64
Stephen Hemminger5ca1b992009-09-01 19:25:05 +000065static const struct file_operations xfrm_statistics_seq_fops = {
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080066 .owner = THIS_MODULE,
67 .open = xfrm_statistics_seq_open,
68 .read = seq_read,
69 .llseek = seq_lseek,
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080070 .release = single_release_net,
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080071};
72
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080073int __net_init xfrm_proc_init(struct net *net)
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080074{
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080075 if (!proc_net_fops_create(net, "xfrm_stat", S_IRUGO,
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080076 &xfrm_statistics_seq_fops))
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080077 return -ENOMEM;
78 return 0;
79}
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080080
Alexey Dobriyanc68cd1a2008-11-25 18:00:14 -080081void xfrm_proc_fini(struct net *net)
82{
83 proc_net_remove(net, "xfrm_stat");
Masahide NAKAMURA558f82e2007-12-20 20:42:57 -080084}