| 
									
										
										
										
											2008-01-11 09:57:09 -05:00
										 |  |  | /* SCTP kernel implementation
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * (C) Copyright IBM Corp. 2001, 2004 | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-01-11 09:57:09 -05:00
										 |  |  |  * This file is part of the SCTP kernel implementation | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * Support for memory object debugging.  This allows one to monitor the | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * object allocations/deallocations for types instrumented for this | 
					
						
							|  |  |  |  * via the proc fs. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-01-11 09:57:09 -05:00
										 |  |  |  * This SCTP implementation is free software; | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * you can redistribute it and/or modify it under the terms of | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation; either version 2, or (at your option) | 
					
						
							|  |  |  |  * any later version. | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-01-11 09:57:09 -05:00
										 |  |  |  * This SCTP implementation is distributed in the hope that it | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * will be useful, but WITHOUT ANY WARRANTY; without even the implied | 
					
						
							|  |  |  |  *                 ************************ | 
					
						
							|  |  |  |  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
					
						
							|  |  |  |  * See the GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with GNU CC; see the file COPYING.  If not, write to | 
					
						
							|  |  |  |  * the Free Software Foundation, 59 Temple Place - Suite 330, | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * Boston, MA 02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * Please send any bug reports or fixes you make to the | 
					
						
							|  |  |  |  * email address(es): | 
					
						
							|  |  |  |  *    lksctp developers <lksctp-developers@lists.sourceforge.net> | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * Or submit a bug report through the following website: | 
					
						
							|  |  |  |  *    http://www.sf.net/projects/lksctp
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * Written or modified by: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  *    Jon Grimm             <jgrimm@us.ibm.com> | 
					
						
							| 
									
										
										
										
											2007-02-09 23:25:18 +09:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * Any bugs reported given to us we will try to fix... any fixes shared will | 
					
						
							|  |  |  |  * be incorporated into the next SCTP release. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-24 13:21:08 +00:00
										 |  |  | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07: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(ssnmap); | 
					
						
							|  |  |  | SCTP_DBG_OBJCNT(datamsg); | 
					
						
							| 
									
										
										
										
											2007-10-09 01:15:59 -07:00
										 |  |  | SCTP_DBG_OBJCNT(keys); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* An array to make it easy to pretty print the debug information
 | 
					
						
							|  |  |  |  * to the proc fs. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = { | 
					
						
							|  |  |  | 	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(ssnmap), | 
					
						
							|  |  |  | 	SCTP_DBG_OBJCNT_ENTRY(datamsg), | 
					
						
							| 
									
										
										
										
											2007-10-09 01:15:59 -07:00
										 |  |  | 	SCTP_DBG_OBJCNT_ENTRY(keys), | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07: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-09 23:24:58 -08:00
										 |  |  | static int sctp_objcnt_seq_show(struct seq_file *seq, void *v) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-04-24 01:02:16 -07:00
										 |  |  | 	int i, len; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-09 23:24:58 -08:00
										 |  |  | 	i = (int)*(loff_t *)v; | 
					
						
							| 
									
										
										
										
											2008-04-24 01:02:16 -07:00
										 |  |  | 	seq_printf(seq, "%s: %d%n", sctp_dbg_objcnt[i].label, | 
					
						
							|  |  |  | 				atomic_read(sctp_dbg_objcnt[i].counter), &len); | 
					
						
							|  |  |  | 	seq_printf(seq, "%*s\n", 127 - len, ""); | 
					
						
							| 
									
										
										
										
											2008-02-09 23:24:58 -08: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) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void * sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	++*pos; | 
					
						
							|  |  |  | 	return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-09 23:24:58 -08: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, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sctp_objcnt_seq_open(struct inode *inode, struct file *file) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return seq_open(file, &sctp_objcnt_seq_ops); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct file_operations sctp_objcnt_ops = { | 
					
						
							|  |  |  | 	.open	 = sctp_objcnt_seq_open, | 
					
						
							|  |  |  | 	.read	 = seq_read, | 
					
						
							|  |  |  | 	.llseek	 = seq_lseek, | 
					
						
							|  |  |  | 	.release = seq_release, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* Initialize the objcount in the proc filesystem.  */ | 
					
						
							| 
									
										
										
										
											2012-08-06 08:45:15 +00:00
										 |  |  | void sctp_dbg_objcnt_init(struct net *net) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-07-18 13:38:07 -07:00
										 |  |  | 	struct proc_dir_entry *ent; | 
					
						
							| 
									
										
										
										
											2008-02-09 23:24:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-28 14:13:16 -08:00
										 |  |  | 	ent = proc_create("sctp_dbg_objcnt", 0, | 
					
						
							| 
									
										
										
										
											2012-08-06 08:45:15 +00:00
										 |  |  | 			  net->sctp.proc_net_sctp, &sctp_objcnt_ops); | 
					
						
							| 
									
										
										
										
											2005-07-18 13:38:07 -07:00
										 |  |  | 	if (!ent) | 
					
						
							| 
									
										
										
										
											2010-08-24 13:21:08 +00:00
										 |  |  | 		pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Cleanup the objcount entry in the proc filesystem.  */ | 
					
						
							| 
									
										
										
										
											2012-08-06 08:45:15 +00:00
										 |  |  | void sctp_dbg_objcnt_exit(struct net *net) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-06 08:45:15 +00:00
										 |  |  | 	remove_proc_entry("sctp_dbg_objcnt", net->sctp.proc_net_sctp); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |