18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * xfrm_proc.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C)2006-2007 USAGI/WIDE Project 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Authors: Masahide NAKAMURA <nakam@linux-ipv6.org> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#include <linux/proc_fs.h> 108c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 118c2ecf20Sopenharmony_ci#include <linux/export.h> 128c2ecf20Sopenharmony_ci#include <net/snmp.h> 138c2ecf20Sopenharmony_ci#include <net/xfrm.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistatic const struct snmp_mib xfrm_mib_list[] = { 168c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInError", LINUX_MIB_XFRMINERROR), 178c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInBufferError", LINUX_MIB_XFRMINBUFFERERROR), 188c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInHdrError", LINUX_MIB_XFRMINHDRERROR), 198c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInNoStates", LINUX_MIB_XFRMINNOSTATES), 208c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInStateProtoError", LINUX_MIB_XFRMINSTATEPROTOERROR), 218c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInStateModeError", LINUX_MIB_XFRMINSTATEMODEERROR), 228c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInStateSeqError", LINUX_MIB_XFRMINSTATESEQERROR), 238c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInStateExpired", LINUX_MIB_XFRMINSTATEEXPIRED), 248c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInStateMismatch", LINUX_MIB_XFRMINSTATEMISMATCH), 258c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInStateInvalid", LINUX_MIB_XFRMINSTATEINVALID), 268c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInTmplMismatch", LINUX_MIB_XFRMINTMPLMISMATCH), 278c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInNoPols", LINUX_MIB_XFRMINNOPOLS), 288c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInPolBlock", LINUX_MIB_XFRMINPOLBLOCK), 298c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmInPolError", LINUX_MIB_XFRMINPOLERROR), 308c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutError", LINUX_MIB_XFRMOUTERROR), 318c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutBundleGenError", LINUX_MIB_XFRMOUTBUNDLEGENERROR), 328c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutBundleCheckError", LINUX_MIB_XFRMOUTBUNDLECHECKERROR), 338c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutNoStates", LINUX_MIB_XFRMOUTNOSTATES), 348c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutStateProtoError", LINUX_MIB_XFRMOUTSTATEPROTOERROR), 358c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutStateModeError", LINUX_MIB_XFRMOUTSTATEMODEERROR), 368c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutStateSeqError", LINUX_MIB_XFRMOUTSTATESEQERROR), 378c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutStateExpired", LINUX_MIB_XFRMOUTSTATEEXPIRED), 388c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutPolBlock", LINUX_MIB_XFRMOUTPOLBLOCK), 398c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutPolDead", LINUX_MIB_XFRMOUTPOLDEAD), 408c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutPolError", LINUX_MIB_XFRMOUTPOLERROR), 418c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmFwdHdrError", LINUX_MIB_XFRMFWDHDRERROR), 428c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmOutStateInvalid", LINUX_MIB_XFRMOUTSTATEINVALID), 438c2ecf20Sopenharmony_ci SNMP_MIB_ITEM("XfrmAcquireError", LINUX_MIB_XFRMACQUIREERROR), 448c2ecf20Sopenharmony_ci SNMP_MIB_SENTINEL 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic int xfrm_statistics_seq_show(struct seq_file *seq, void *v) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci unsigned long buff[LINUX_MIB_XFRMMAX]; 508c2ecf20Sopenharmony_ci struct net *net = seq->private; 518c2ecf20Sopenharmony_ci int i; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci memset(buff, 0, sizeof(unsigned long) * LINUX_MIB_XFRMMAX); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci snmp_get_cpu_field_batch(buff, xfrm_mib_list, 568c2ecf20Sopenharmony_ci net->mib.xfrm_statistics); 578c2ecf20Sopenharmony_ci for (i = 0; xfrm_mib_list[i].name; i++) 588c2ecf20Sopenharmony_ci seq_printf(seq, "%-24s\t%lu\n", xfrm_mib_list[i].name, 598c2ecf20Sopenharmony_ci buff[i]); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci return 0; 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciint __net_init xfrm_proc_init(struct net *net) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci if (!proc_create_net_single("xfrm_stat", 0444, net->proc_net, 678c2ecf20Sopenharmony_ci xfrm_statistics_seq_show, NULL)) 688c2ecf20Sopenharmony_ci return -ENOMEM; 698c2ecf20Sopenharmony_ci return 0; 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_civoid xfrm_proc_fini(struct net *net) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci remove_proc_entry("xfrm_stat", net->proc_net); 758c2ecf20Sopenharmony_ci} 76