Masahide NAKAMURA | 558f82e | 2007-12-20 20:42:57 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | static struct snmp_mib xfrm_mib_list[] = { |
| 19 | 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 NAKAMURA | 9472c9e | 2008-01-31 17:14:58 -0800 | [diff] [blame] | 25 | SNMP_MIB_ITEM("XfrmInStateSeqError", LINUX_MIB_XFRMINSTATESEQERROR), |
Masahide NAKAMURA | 558f82e | 2007-12-20 20:42:57 -0800 | [diff] [blame] | 26 | 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 NAKAMURA | 9472c9e | 2008-01-31 17:14:58 -0800 | [diff] [blame] | 39 | SNMP_MIB_ITEM("XfrmOutStateSeqError", LINUX_MIB_XFRMOUTSTATESEQERROR), |
Masahide NAKAMURA | 558f82e | 2007-12-20 20:42:57 -0800 | [diff] [blame] | 40 | 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), |
| 44 | SNMP_MIB_SENTINEL |
| 45 | }; |
| 46 | |
| 47 | static unsigned long |
| 48 | fold_field(void *mib[], int offt) |
| 49 | { |
| 50 | unsigned long res = 0; |
| 51 | int i; |
| 52 | |
| 53 | for_each_possible_cpu(i) { |
| 54 | res += *(((unsigned long *)per_cpu_ptr(mib[0], i)) + offt); |
| 55 | res += *(((unsigned long *)per_cpu_ptr(mib[1], i)) + offt); |
| 56 | } |
| 57 | return res; |
| 58 | } |
| 59 | |
| 60 | static int xfrm_statistics_seq_show(struct seq_file *seq, void *v) |
| 61 | { |
| 62 | int i; |
| 63 | for (i=0; xfrm_mib_list[i].name; i++) |
| 64 | seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name, |
| 65 | fold_field((void **)xfrm_statistics, |
| 66 | xfrm_mib_list[i].entry)); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int xfrm_statistics_seq_open(struct inode *inode, struct file *file) |
| 71 | { |
| 72 | return single_open(file, xfrm_statistics_seq_show, NULL); |
| 73 | } |
| 74 | |
| 75 | static struct file_operations xfrm_statistics_seq_fops = { |
| 76 | .owner = THIS_MODULE, |
| 77 | .open = xfrm_statistics_seq_open, |
| 78 | .read = seq_read, |
| 79 | .llseek = seq_lseek, |
| 80 | .release = single_release, |
| 81 | }; |
| 82 | |
| 83 | int __init xfrm_proc_init(void) |
| 84 | { |
| 85 | int rc = 0; |
| 86 | |
| 87 | if (!proc_net_fops_create(&init_net, "xfrm_stat", S_IRUGO, |
| 88 | &xfrm_statistics_seq_fops)) |
| 89 | goto stat_fail; |
| 90 | |
| 91 | out: |
| 92 | return rc; |
| 93 | |
| 94 | stat_fail: |
| 95 | rc = -ENOMEM; |
| 96 | goto out; |
| 97 | } |