Thomas Gleixner | 47505b8 | 2019-05-23 11:14:41 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 2 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * (C) Copyright IBM Corp. 2001, 2004 |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 5 | * This file is part of the SCTP kernel implementation |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Support for memory object debugging. This allows one to monitor the |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 8 | * object allocations/deallocations for types instrumented for this |
| 9 | * via the proc fs. |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Please send any bug reports or fixes you make to the |
| 12 | * email address(es): |
Daniel Borkmann | 91705c6 | 2013-07-23 14:51:47 +0200 | [diff] [blame] | 13 | * lksctp developers <linux-sctp@vger.kernel.org> |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 14 | * |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 15 | * Written or modified by: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * Jon Grimm <jgrimm@us.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Joe Perches | 145ce50 | 2010-08-24 13:21:08 +0000 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #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 | |
| 31 | SCTP_DBG_OBJCNT(sock); |
| 32 | SCTP_DBG_OBJCNT(ep); |
| 33 | SCTP_DBG_OBJCNT(transport); |
| 34 | SCTP_DBG_OBJCNT(assoc); |
| 35 | SCTP_DBG_OBJCNT(bind_addr); |
| 36 | SCTP_DBG_OBJCNT(bind_bucket); |
| 37 | SCTP_DBG_OBJCNT(chunk); |
| 38 | SCTP_DBG_OBJCNT(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | SCTP_DBG_OBJCNT(datamsg); |
Vlad Yasevich | 1f48564 | 2007-10-09 01:15:59 -0700 | [diff] [blame] | 40 | SCTP_DBG_OBJCNT(keys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* An array to make it easy to pretty print the debug information |
| 43 | * to the proc fs. |
| 44 | */ |
Xin Long | d38ef5a | 2017-08-11 10:23:49 +0800 | [diff] [blame] | 45 | static struct sctp_dbg_objcnt_entry sctp_dbg_objcnt[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | SCTP_DBG_OBJCNT_ENTRY(datamsg), |
Vlad Yasevich | 1f48564 | 2007-10-09 01:15:59 -0700 | [diff] [blame] | 55 | SCTP_DBG_OBJCNT_ENTRY(keys), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }; |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | */ |
Pavel Emelyanov | 8ff65b4 | 2008-02-09 23:24:58 -0800 | [diff] [blame] | 62 | static int sctp_objcnt_seq_show(struct seq_file *seq, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
Tetsuo Handa | 652586d | 2013-11-14 14:31:57 -0800 | [diff] [blame] | 64 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Pavel Emelyanov | 8ff65b4 | 2008-02-09 23:24:58 -0800 | [diff] [blame] | 66 | i = (int)*(loff_t *)v; |
Tetsuo Handa | 652586d | 2013-11-14 14:31:57 -0800 | [diff] [blame] | 67 | 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 Emelyanov | 8ff65b4 | 2008-02-09 23:24:58 -0800 | [diff] [blame] | 71 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Pavel Emelyanov | 8ff65b4 | 2008-02-09 23:24:58 -0800 | [diff] [blame] | 74 | static 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 | |
| 79 | static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v) |
| 80 | { |
| 81 | } |
| 82 | |
wangweidong | 26ac8e5 | 2013-12-23 12:16:51 +0800 | [diff] [blame] | 83 | static void *sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
Pavel Emelyanov | 8ff65b4 | 2008-02-09 23:24:58 -0800 | [diff] [blame] | 84 | { |
| 85 | ++*pos; |
| 86 | return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos; |
| 87 | } |
| 88 | |
| 89 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* Initialize the objcount in the proc filesystem. */ |
Eric W. Biederman | 13d782f | 2012-08-06 08:45:15 +0000 | [diff] [blame] | 97 | void sctp_dbg_objcnt_init(struct net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Christophe Lucas | ee71a29 | 2005-07-18 13:38:07 -0700 | [diff] [blame] | 99 | struct proc_dir_entry *ent; |
Pavel Emelyanov | 8ff65b4 | 2008-02-09 23:24:58 -0800 | [diff] [blame] | 100 | |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 101 | ent = proc_create_seq("sctp_dbg_objcnt", 0, |
| 102 | net->sctp.proc_net_sctp, &sctp_objcnt_seq_ops); |
Christophe Lucas | ee71a29 | 2005-07-18 13:38:07 -0700 | [diff] [blame] | 103 | if (!ent) |
Joe Perches | 145ce50 | 2010-08-24 13:21:08 +0000 | [diff] [blame] | 104 | pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |