Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /* SCTP kernel implementation
0003  * (C) Copyright IBM Corp. 2001, 2004
0004  *
0005  * This file is part of the SCTP kernel implementation
0006  *
0007  * Support for memory object debugging.  This allows one to monitor the
0008  * object allocations/deallocations for types instrumented for this
0009  * via the proc fs.
0010  *
0011  * Please send any bug reports or fixes you make to the
0012  * email address(es):
0013  *    lksctp developers <linux-sctp@vger.kernel.org>
0014  *
0015  * Written or modified by:
0016  *    Jon Grimm             <jgrimm@us.ibm.com>
0017  */
0018 
0019 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0020 
0021 #include <linux/kernel.h>
0022 #include <net/sctp/sctp.h>
0023 
0024 /*
0025  * Global counters to count raw object allocation counts.
0026  * To add new counters, choose a unique suffix for the variable
0027  * name as the helper macros key off this suffix to make
0028  * life easier for the programmer.
0029  */
0030 
0031 SCTP_DBG_OBJCNT(sock);
0032 SCTP_DBG_OBJCNT(ep);
0033 SCTP_DBG_OBJCNT(transport);
0034 SCTP_DBG_OBJCNT(assoc);
0035 SCTP_DBG_OBJCNT(bind_addr);
0036 SCTP_DBG_OBJCNT(bind_bucket);
0037 SCTP_DBG_OBJCNT(chunk);
0038 SCTP_DBG_OBJCNT(addr);
0039 SCTP_DBG_OBJCNT(datamsg);
0040 SCTP_DBG_OBJCNT(keys);
0041 
0042 /* An array to make it easy to pretty print the debug information
0043  * to the proc fs.
0044  */
0045 static struct sctp_dbg_objcnt_entry sctp_dbg_objcnt[] = {
0046     SCTP_DBG_OBJCNT_ENTRY(sock),
0047     SCTP_DBG_OBJCNT_ENTRY(ep),
0048     SCTP_DBG_OBJCNT_ENTRY(assoc),
0049     SCTP_DBG_OBJCNT_ENTRY(transport),
0050     SCTP_DBG_OBJCNT_ENTRY(chunk),
0051     SCTP_DBG_OBJCNT_ENTRY(bind_addr),
0052     SCTP_DBG_OBJCNT_ENTRY(bind_bucket),
0053     SCTP_DBG_OBJCNT_ENTRY(addr),
0054     SCTP_DBG_OBJCNT_ENTRY(datamsg),
0055     SCTP_DBG_OBJCNT_ENTRY(keys),
0056 };
0057 
0058 /* Callback from procfs to read out objcount information.
0059  * Walk through the entries in the sctp_dbg_objcnt array, dumping
0060  * the raw object counts for each monitored type.
0061  */
0062 static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
0063 {
0064     int i;
0065 
0066     i = (int)*(loff_t *)v;
0067     seq_setwidth(seq, 127);
0068     seq_printf(seq, "%s: %d", sctp_dbg_objcnt[i].label,
0069                 atomic_read(sctp_dbg_objcnt[i].counter));
0070     seq_pad(seq, '\n');
0071     return 0;
0072 }
0073 
0074 static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos)
0075 {
0076     return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
0077 }
0078 
0079 static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)
0080 {
0081 }
0082 
0083 static void *sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
0084 {
0085     ++*pos;
0086     return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
0087 }
0088 
0089 static const struct seq_operations sctp_objcnt_seq_ops = {
0090     .start = sctp_objcnt_seq_start,
0091     .next  = sctp_objcnt_seq_next,
0092     .stop  = sctp_objcnt_seq_stop,
0093     .show  = sctp_objcnt_seq_show,
0094 };
0095 
0096 /* Initialize the objcount in the proc filesystem.  */
0097 void sctp_dbg_objcnt_init(struct net *net)
0098 {
0099     struct proc_dir_entry *ent;
0100 
0101     ent = proc_create_seq("sctp_dbg_objcnt", 0,
0102               net->sctp.proc_net_sctp, &sctp_objcnt_seq_ops);
0103     if (!ent)
0104         pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n");
0105 }