/* SCTP kernel implementation1* (C) Copyright IBM Corp. 2001, 20042*3* This file is part of the SCTP kernel implementation4*5* Support for memory object debugging. This allows one to monitor the6* object allocations/deallocations for types instrumented for this7* via the proc fs.8*9* This SCTP implementation is free software;10* you can redistribute it and/or modify it under the terms of11* the GNU General Public License as published by12* the Free Software Foundation; either version 2, or (at your option)13* any later version.14*15* This SCTP implementation is distributed in the hope that it16* will be useful, but WITHOUT ANY WARRANTY; without even the implied17* ************************18* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.19* See the GNU General Public License for more details.20*21* You should have received a copy of the GNU General Public License22* along with GNU CC; see the file COPYING. If not, write to23* the Free Software Foundation, 59 Temple Place - Suite 330,24* Boston, MA 02111-1307, USA.25*26* Please send any bug reports or fixes you make to the27* email address(es):28* lksctp developers <[email protected]>29*30* Or submit a bug report through the following website:31* http://www.sf.net/projects/lksctp32*33* Written or modified by:34* Jon Grimm <[email protected]>35*36* Any bugs reported given to us we will try to fix... any fixes shared will37* be incorporated into the next SCTP release.38*/3940#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt4142#include <linux/kernel.h>43#include <net/sctp/sctp.h>4445/*46* Global counters to count raw object allocation counts.47* To add new counters, choose a unique suffix for the variable48* name as the helper macros key off this suffix to make49* life easier for the programmer.50*/5152SCTP_DBG_OBJCNT(sock);53SCTP_DBG_OBJCNT(ep);54SCTP_DBG_OBJCNT(transport);55SCTP_DBG_OBJCNT(assoc);56SCTP_DBG_OBJCNT(bind_addr);57SCTP_DBG_OBJCNT(bind_bucket);58SCTP_DBG_OBJCNT(chunk);59SCTP_DBG_OBJCNT(addr);60SCTP_DBG_OBJCNT(ssnmap);61SCTP_DBG_OBJCNT(datamsg);62SCTP_DBG_OBJCNT(keys);6364/* An array to make it easy to pretty print the debug information65* to the proc fs.66*/67static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = {68SCTP_DBG_OBJCNT_ENTRY(sock),69SCTP_DBG_OBJCNT_ENTRY(ep),70SCTP_DBG_OBJCNT_ENTRY(assoc),71SCTP_DBG_OBJCNT_ENTRY(transport),72SCTP_DBG_OBJCNT_ENTRY(chunk),73SCTP_DBG_OBJCNT_ENTRY(bind_addr),74SCTP_DBG_OBJCNT_ENTRY(bind_bucket),75SCTP_DBG_OBJCNT_ENTRY(addr),76SCTP_DBG_OBJCNT_ENTRY(ssnmap),77SCTP_DBG_OBJCNT_ENTRY(datamsg),78SCTP_DBG_OBJCNT_ENTRY(keys),79};8081/* Callback from procfs to read out objcount information.82* Walk through the entries in the sctp_dbg_objcnt array, dumping83* the raw object counts for each monitored type.84*/85static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)86{87int i, len;8889i = (int)*(loff_t *)v;90seq_printf(seq, "%s: %d%n", sctp_dbg_objcnt[i].label,91atomic_read(sctp_dbg_objcnt[i].counter), &len);92seq_printf(seq, "%*s\n", 127 - len, "");93return 0;94}9596static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos)97{98return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;99}100101static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)102{103}104105static void * sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)106{107++*pos;108return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;109}110111static const struct seq_operations sctp_objcnt_seq_ops = {112.start = sctp_objcnt_seq_start,113.next = sctp_objcnt_seq_next,114.stop = sctp_objcnt_seq_stop,115.show = sctp_objcnt_seq_show,116};117118static int sctp_objcnt_seq_open(struct inode *inode, struct file *file)119{120return seq_open(file, &sctp_objcnt_seq_ops);121}122123static const struct file_operations sctp_objcnt_ops = {124.open = sctp_objcnt_seq_open,125.read = seq_read,126.llseek = seq_lseek,127.release = seq_release,128};129130/* Initialize the objcount in the proc filesystem. */131void sctp_dbg_objcnt_init(void)132{133struct proc_dir_entry *ent;134135ent = proc_create("sctp_dbg_objcnt", 0,136proc_net_sctp, &sctp_objcnt_ops);137if (!ent)138pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n");139}140141/* Cleanup the objcount entry in the proc filesystem. */142void sctp_dbg_objcnt_exit(void)143{144remove_proc_entry("sctp_dbg_objcnt", proc_net_sctp);145}146147148149150