2019-05-23 12:14:41 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-01-11 17:57:09 +03:00
|
|
|
/* SCTP kernel implementation
|
2005-04-17 02:20:36 +04:00
|
|
|
* (C) Copyright IBM Corp. 2001, 2004
|
2007-02-09 17:25:18 +03:00
|
|
|
*
|
2008-01-11 17:57:09 +03:00
|
|
|
* This file is part of the SCTP kernel implementation
|
2007-02-09 17:25:18 +03:00
|
|
|
*
|
2005-04-17 02:20:36 +04:00
|
|
|
* Support for memory object debugging. This allows one to monitor the
|
2007-02-09 17:25:18 +03:00
|
|
|
* object allocations/deallocations for types instrumented for this
|
|
|
|
* via the proc fs.
|
|
|
|
*
|
2005-04-17 02:20:36 +04:00
|
|
|
* Please send any bug reports or fixes you make to the
|
|
|
|
* email address(es):
|
2013-07-23 16:51:47 +04:00
|
|
|
* lksctp developers <linux-sctp@vger.kernel.org>
|
2007-02-09 17:25:18 +03:00
|
|
|
*
|
|
|
|
* Written or modified by:
|
2005-04-17 02:20:36 +04:00
|
|
|
* Jon Grimm <jgrimm@us.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2010-08-24 17:21:08 +04:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <net/sctp/sctp.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global counters to count raw object allocation counts.
|
|
|
|
* To add new counters, choose a unique suffix for the variable
|
|
|
|
* name as the helper macros key off this suffix to make
|
|
|
|
* life easier for the programmer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
SCTP_DBG_OBJCNT(sock);
|
|
|
|
SCTP_DBG_OBJCNT(ep);
|
|
|
|
SCTP_DBG_OBJCNT(transport);
|
|
|
|
SCTP_DBG_OBJCNT(assoc);
|
|
|
|
SCTP_DBG_OBJCNT(bind_addr);
|
|
|
|
SCTP_DBG_OBJCNT(bind_bucket);
|
|
|
|
SCTP_DBG_OBJCNT(chunk);
|
|
|
|
SCTP_DBG_OBJCNT(addr);
|
|
|
|
SCTP_DBG_OBJCNT(datamsg);
|
2007-10-09 12:15:59 +04:00
|
|
|
SCTP_DBG_OBJCNT(keys);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* An array to make it easy to pretty print the debug information
|
|
|
|
* to the proc fs.
|
|
|
|
*/
|
2017-08-11 05:23:49 +03:00
|
|
|
static struct sctp_dbg_objcnt_entry sctp_dbg_objcnt[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
SCTP_DBG_OBJCNT_ENTRY(sock),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(ep),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(assoc),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(transport),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(chunk),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(bind_addr),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(bind_bucket),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(addr),
|
|
|
|
SCTP_DBG_OBJCNT_ENTRY(datamsg),
|
2007-10-09 12:15:59 +04:00
|
|
|
SCTP_DBG_OBJCNT_ENTRY(keys),
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Callback from procfs to read out objcount information.
|
|
|
|
* Walk through the entries in the sctp_dbg_objcnt array, dumping
|
|
|
|
* the raw object counts for each monitored type.
|
|
|
|
*/
|
2008-02-10 10:24:58 +03:00
|
|
|
static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2013-11-15 02:31:57 +04:00
|
|
|
int i;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-02-10 10:24:58 +03:00
|
|
|
i = (int)*(loff_t *)v;
|
2013-11-15 02:31:57 +04:00
|
|
|
seq_setwidth(seq, 127);
|
|
|
|
seq_printf(seq, "%s: %d", sctp_dbg_objcnt[i].label,
|
|
|
|
atomic_read(sctp_dbg_objcnt[i].counter));
|
|
|
|
seq_pad(seq, '\n');
|
2008-02-10 10:24:58 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos)
|
|
|
|
{
|
|
|
|
return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-23 08:16:51 +04:00
|
|
|
static void *sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
2008-02-10 10:24:58 +03:00
|
|
|
{
|
|
|
|
++*pos;
|
|
|
|
return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-02-10 10:24:58 +03:00
|
|
|
static const struct seq_operations sctp_objcnt_seq_ops = {
|
|
|
|
.start = sctp_objcnt_seq_start,
|
|
|
|
.next = sctp_objcnt_seq_next,
|
|
|
|
.stop = sctp_objcnt_seq_stop,
|
|
|
|
.show = sctp_objcnt_seq_show,
|
|
|
|
};
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Initialize the objcount in the proc filesystem. */
|
2012-08-06 12:45:15 +04:00
|
|
|
void sctp_dbg_objcnt_init(struct net *net)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2005-07-19 00:38:07 +04:00
|
|
|
struct proc_dir_entry *ent;
|
2008-02-10 10:24:58 +03:00
|
|
|
|
2018-04-13 20:44:18 +03:00
|
|
|
ent = proc_create_seq("sctp_dbg_objcnt", 0,
|
|
|
|
net->sctp.proc_net_sctp, &sctp_objcnt_seq_ops);
|
2005-07-19 00:38:07 +04:00
|
|
|
if (!ent)
|
2010-08-24 17:21:08 +04:00
|
|
|
pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|