blob: 0400c964e125617b9415b8164b982716492df066 [file] [log] [blame]
Thomas Gleixner47505b82019-05-23 11:14:41 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Vlad Yasevich60c778b2008-01-11 09:57:09 -05002/* SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * (C) Copyright IBM Corp. 2001, 2004
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09004 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -05005 * This file is part of the SCTP kernel implementation
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Support for memory object debugging. This allows one to monitor the
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +09008 * object allocations/deallocations for types instrumented for this
9 * via the proc fs.
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * Please send any bug reports or fixes you make to the
12 * email address(es):
Daniel Borkmann91705c62013-07-23 14:51:47 +020013 * lksctp developers <linux-sctp@vger.kernel.org>
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +090014 *
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +090015 * Written or modified by:
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * Jon Grimm <jgrimm@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
Joe Perches145ce502010-08-24 13:21:08 +000019#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/kernel.h>
22#include <net/sctp/sctp.h>
23
24/*
25 * Global counters to count raw object allocation counts.
26 * To add new counters, choose a unique suffix for the variable
27 * name as the helper macros key off this suffix to make
28 * life easier for the programmer.
29 */
30
31SCTP_DBG_OBJCNT(sock);
32SCTP_DBG_OBJCNT(ep);
33SCTP_DBG_OBJCNT(transport);
34SCTP_DBG_OBJCNT(assoc);
35SCTP_DBG_OBJCNT(bind_addr);
36SCTP_DBG_OBJCNT(bind_bucket);
37SCTP_DBG_OBJCNT(chunk);
38SCTP_DBG_OBJCNT(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039SCTP_DBG_OBJCNT(datamsg);
Vlad Yasevich1f485642007-10-09 01:15:59 -070040SCTP_DBG_OBJCNT(keys);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/* An array to make it easy to pretty print the debug information
43 * to the proc fs.
44 */
Xin Longd38ef5a2017-08-11 10:23:49 +080045static struct sctp_dbg_objcnt_entry sctp_dbg_objcnt[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 SCTP_DBG_OBJCNT_ENTRY(sock),
47 SCTP_DBG_OBJCNT_ENTRY(ep),
48 SCTP_DBG_OBJCNT_ENTRY(assoc),
49 SCTP_DBG_OBJCNT_ENTRY(transport),
50 SCTP_DBG_OBJCNT_ENTRY(chunk),
51 SCTP_DBG_OBJCNT_ENTRY(bind_addr),
52 SCTP_DBG_OBJCNT_ENTRY(bind_bucket),
53 SCTP_DBG_OBJCNT_ENTRY(addr),
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 SCTP_DBG_OBJCNT_ENTRY(datamsg),
Vlad Yasevich1f485642007-10-09 01:15:59 -070055 SCTP_DBG_OBJCNT_ENTRY(keys),
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
58/* Callback from procfs to read out objcount information.
59 * Walk through the entries in the sctp_dbg_objcnt array, dumping
60 * the raw object counts for each monitored type.
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
Pavel Emelyanov8ff65b42008-02-09 23:24:58 -080062static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Tetsuo Handa652586d2013-11-14 14:31:57 -080064 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Pavel Emelyanov8ff65b42008-02-09 23:24:58 -080066 i = (int)*(loff_t *)v;
Tetsuo Handa652586d2013-11-14 14:31:57 -080067 seq_setwidth(seq, 127);
68 seq_printf(seq, "%s: %d", sctp_dbg_objcnt[i].label,
69 atomic_read(sctp_dbg_objcnt[i].counter));
70 seq_pad(seq, '\n');
Pavel Emelyanov8ff65b42008-02-09 23:24:58 -080071 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Pavel Emelyanov8ff65b42008-02-09 23:24:58 -080074static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos)
75{
76 return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
77}
78
79static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)
80{
81}
82
wangweidong26ac8e52013-12-23 12:16:51 +080083static void *sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
Pavel Emelyanov8ff65b42008-02-09 23:24:58 -080084{
85 ++*pos;
86 return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
87}
88
89static const struct seq_operations sctp_objcnt_seq_ops = {
90 .start = sctp_objcnt_seq_start,
91 .next = sctp_objcnt_seq_next,
92 .stop = sctp_objcnt_seq_stop,
93 .show = sctp_objcnt_seq_show,
94};
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* Initialize the objcount in the proc filesystem. */
Eric W. Biederman13d782f2012-08-06 08:45:15 +000097void sctp_dbg_objcnt_init(struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Christophe Lucasee71a292005-07-18 13:38:07 -070099 struct proc_dir_entry *ent;
Pavel Emelyanov8ff65b42008-02-09 23:24:58 -0800100
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200101 ent = proc_create_seq("sctp_dbg_objcnt", 0,
102 net->sctp.proc_net_sctp, &sctp_objcnt_seq_ops);
Christophe Lucasee71a292005-07-18 13:38:07 -0700103 if (!ent)
Joe Perches145ce502010-08-24 13:21:08 +0000104 pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}