Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb33381d authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller
Browse files

net: sctp: rework debugging framework to use pr_debug and friends

We should get rid of all own SCTP debug printk macros and use the ones
that the kernel offers anyway instead. This makes the code more readable
and conform to the kernel code, and offers all the features of dynamic
debbuging that pr_debug() et al has, such as only turning on/off portions
of debug messages at runtime through debugfs. The runtime cost of having
CONFIG_DYNAMIC_DEBUG enabled, but none of the debug statements printing,
is negligible [1]. If kernel debugging is completly turned off, then these
statements will also compile into "empty" functions.

While we're at it, we also need to change the Kconfig option as it /now/
only refers to the ifdef'ed code portions in outqueue.c that enable further
debugging/tracing of SCTP transaction fields. Also, since SCTP_ASSERT code
was enabled with this Kconfig option and has now been removed, we
transform those code parts into WARNs resp. where appropriate BUG_ONs so
that those bugs can be more easily detected as probably not many people
have SCTP debugging permanently turned on.

To turn on all SCTP debugging, the following steps are needed:

 # mount -t debugfs none /sys/kernel/debug
 # echo -n 'module sctp +p' > /sys/kernel/debug/dynamic_debug/control

This can be done more fine-grained on a per file, per line basis and others
as described in [2].

 [1] https://www.kernel.org/doc/ols/2009/ols2009-pages-39-46.pdf


 [2] Documentation/dynamic-debug-howto.txt

Signed-off-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 10679643
Loading
Loading
Loading
Loading
+0 −75
Original line number Original line Diff line number Diff line
@@ -83,16 +83,6 @@
#include <net/sctp/structs.h>
#include <net/sctp/structs.h>
#include <net/sctp/constants.h>
#include <net/sctp/constants.h>



/* Set SCTP_DEBUG flag via config if not already set. */
#ifndef SCTP_DEBUG
#ifdef CONFIG_SCTP_DBG_MSG
#define SCTP_DEBUG	1
#else
#define SCTP_DEBUG      0
#endif /* CONFIG_SCTP_DBG */
#endif /* SCTP_DEBUG */

#ifdef CONFIG_IP_SCTP_MODULE
#ifdef CONFIG_IP_SCTP_MODULE
#define SCTP_PROTOSW_FLAG 0
#define SCTP_PROTOSW_FLAG 0
#else /* static! */
#else /* static! */
@@ -270,61 +260,6 @@ static inline void sctp_max_rto(struct sctp_association *asoc,
	}
	}
}
}


/* Print debugging messages.  */
#if SCTP_DEBUG
extern int sctp_debug_flag;
#define SCTP_DEBUG_PRINTK(fmt, args...)			\
do {							\
	if (sctp_debug_flag)				\
		printk(KERN_DEBUG pr_fmt(fmt), ##args);	\
} while (0)
#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)		\
do {							\
	if (sctp_debug_flag)				\
		pr_cont(fmt, ##args);			\
} while (0)
#define SCTP_DEBUG_PRINTK_IPADDR(fmt_lead, fmt_trail,			\
				 args_lead, addr, args_trail...)	\
do {									\
	const union sctp_addr *_addr = (addr);				\
	if (sctp_debug_flag) {						\
		if (_addr->sa.sa_family == AF_INET6) {			\
			printk(KERN_DEBUG				\
			       pr_fmt(fmt_lead "%pI6" fmt_trail),	\
			       args_lead,				\
			       &_addr->v6.sin6_addr,			\
			       args_trail);				\
		} else {						\
			printk(KERN_DEBUG				\
			       pr_fmt(fmt_lead "%pI4" fmt_trail),	\
			       args_lead,				\
			       &_addr->v4.sin_addr.s_addr,		\
			       args_trail);				\
		}							\
	}								\
} while (0)
#define SCTP_ENABLE_DEBUG { sctp_debug_flag = 1; }
#define SCTP_DISABLE_DEBUG { sctp_debug_flag = 0; }

#define SCTP_ASSERT(expr, str, func) \
	if (!(expr)) { \
		SCTP_DEBUG_PRINTK("Assertion Failed: %s(%s) at %s:%s:%d\n", \
			str, (#expr), __FILE__, __func__, __LINE__); \
		func; \
	}

#else	/* SCTP_DEBUG */

#define SCTP_DEBUG_PRINTK(whatever...)
#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
#define SCTP_ENABLE_DEBUG
#define SCTP_DISABLE_DEBUG
#define SCTP_ASSERT(expr, str, func)

#endif /* SCTP_DEBUG */


/*
/*
 * Macros for keeping a global reference of object allocations.
 * Macros for keeping a global reference of object allocations.
 */
 */
@@ -597,16 +532,6 @@ static inline int param_type2af(__be16 type)
	}
	}
}
}


/* Perform some sanity checks. */
static inline int sctp_sanity_check(void)
{
	SCTP_ASSERT(sizeof(struct sctp_ulpevent) <=
		    sizeof(((struct sk_buff *)0)->cb),
		    "SCTP: ulpevent does not fit in skb!\n", return 0);

	return 1;
}

/* Warning: The following hash functions assume a power of two 'size'. */
/* Warning: The following hash functions assume a power of two 'size'. */
/* This is the hash function for the SCTP port hash table. */
/* This is the hash function for the SCTP port hash table. */
static inline int sctp_phashfn(struct net *net, __u16 lport)
static inline int sctp_phashfn(struct net *net, __u16 lport)
+7 −5
Original line number Original line Diff line number Diff line
@@ -30,7 +30,8 @@ menuconfig IP_SCTP
	  homing at either or both ends of an association."
	  homing at either or both ends of an association."


	  To compile this protocol support as a module, choose M here: the
	  To compile this protocol support as a module, choose M here: the
	  module will be called sctp.
	  module will be called sctp. Debug messages are handeled by the
	  kernel's dynamic debugging framework.


	  If in doubt, say N.
	  If in doubt, say N.


@@ -48,13 +49,14 @@ config NET_SCTPPROBE
        To compile this code as a module, choose M here: the
        To compile this code as a module, choose M here: the
        module will be called sctp_probe.
        module will be called sctp_probe.


config SCTP_DBG_MSG
config SCTP_DBG_TSNS
	bool "SCTP: Debug messages"
	bool "SCTP: Debug transactions"
	help
	help
	  If you say Y, this will enable verbose debugging messages. 
	  If you say Y, this will enable transaction debugging, visible
	  from the kernel's dynamic debugging framework.


	  If unsure, say N.  However, if you are running into problems, use 
	  If unsure, say N.  However, if you are running into problems, use 
	  this option to gather detailed trace information
	  this option to gather outqueue trace information.


config SCTP_DBG_OBJCNT
config SCTP_DBG_OBJCNT
	bool "SCTP: Debug object counts"
	bool "SCTP: Debug object counts"
+33 −34
Original line number Original line Diff line number Diff line
@@ -357,7 +357,8 @@ struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep,
		goto fail_init;
		goto fail_init;


	SCTP_DBG_OBJCNT_INC(assoc);
	SCTP_DBG_OBJCNT_INC(assoc);
	SCTP_DEBUG_PRINTK("Created asoc %p\n", asoc);

	pr_debug("Created asoc %p\n", asoc);


	return asoc;
	return asoc;


@@ -455,7 +456,10 @@ void sctp_association_free(struct sctp_association *asoc)
/* Cleanup and free up an association. */
/* Cleanup and free up an association. */
static void sctp_association_destroy(struct sctp_association *asoc)
static void sctp_association_destroy(struct sctp_association *asoc)
{
{
	SCTP_ASSERT(asoc->base.dead, "Assoc is not dead", return);
	if (unlikely(!asoc->base.dead)) {
		WARN(1, "Attempt to destroy undead association %p!\n", asoc);
		return;
	}


	sctp_endpoint_put(asoc->ep);
	sctp_endpoint_put(asoc->ep);
	sock_put(asoc->base.sk);
	sock_put(asoc->base.sk);
@@ -536,11 +540,8 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
	struct list_head	*pos;
	struct list_head	*pos;
	struct sctp_transport	*transport;
	struct sctp_transport	*transport;


	SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_rm_peer:association %p addr: ",
	pr_debug("%s: association:%p addr:%pISpc\n",
				 " port: %d\n",
		 __func__, asoc, &peer->ipaddr.sa);
				 asoc,
				 (&peer->ipaddr),
				 ntohs(peer->ipaddr.v4.sin_port));


	/* If we are to remove the current retran_path, update it
	/* If we are to remove the current retran_path, update it
	 * to the next peer before removing this peer from the list.
	 * to the next peer before removing this peer from the list.
@@ -636,12 +637,8 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
	/* AF_INET and AF_INET6 share common port field. */
	/* AF_INET and AF_INET6 share common port field. */
	port = ntohs(addr->v4.sin_port);
	port = ntohs(addr->v4.sin_port);


	SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_add_peer:association %p addr: ",
	pr_debug("%s: association:%p addr:%pISpc state:%d\n", __func__,
				 " port: %d state:%d\n",
		 asoc, &addr->sa, peer_state);
				 asoc,
				 addr,
				 port,
				 peer_state);


	/* Set the port if it has not been set yet.  */
	/* Set the port if it has not been set yet.  */
	if (0 == asoc->peer.port)
	if (0 == asoc->peer.port)
@@ -708,8 +705,9 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
	else
	else
		asoc->pathmtu = peer->pathmtu;
		asoc->pathmtu = peer->pathmtu;


	SCTP_DEBUG_PRINTK("sctp_assoc_add_peer:association %p PMTU set to "
	pr_debug("%s: association:%p PMTU set to %d\n", __func__, asoc,
			  "%d\n", asoc, asoc->pathmtu);
		 asoc->pathmtu);

	peer->pmtu_pending = 0;
	peer->pmtu_pending = 0;


	asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu);
	asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu);
@@ -1349,12 +1347,8 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
	else
	else
		t = asoc->peer.retran_path;
		t = asoc->peer.retran_path;


	SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association"
	pr_debug("%s: association:%p addr:%pISpc\n", __func__, asoc,
				 " %p addr: ",
		 &t->ipaddr.sa);
				 " port: %d\n",
				 asoc,
				 (&t->ipaddr),
				 ntohs(t->ipaddr.v4.sin_port));
}
}


/* Choose the transport for sending retransmit packet.  */
/* Choose the transport for sending retransmit packet.  */
@@ -1401,8 +1395,8 @@ void sctp_assoc_sync_pmtu(struct sock *sk, struct sctp_association *asoc)
		asoc->frag_point = sctp_frag_point(asoc, pmtu);
		asoc->frag_point = sctp_frag_point(asoc, pmtu);
	}
	}


	SCTP_DEBUG_PRINTK("%s: asoc:%p, pmtu:%d, frag_point:%d\n",
	pr_debug("%s: asoc:%p, pmtu:%d, frag_point:%d\n", __func__, asoc,
			  __func__, asoc, asoc->pathmtu, asoc->frag_point);
		 asoc->pathmtu, asoc->frag_point);
}
}


/* Should we send a SACK to update our peer? */
/* Should we send a SACK to update our peer? */
@@ -1454,9 +1448,9 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned int len)
		asoc->rwnd_press -= change;
		asoc->rwnd_press -= change;
	}
	}


	SCTP_DEBUG_PRINTK("%s: asoc %p rwnd increased by %d to (%u, %u) "
	pr_debug("%s: asoc:%p rwnd increased by %d to (%u, %u) - %u\n",
			  "- %u\n", __func__, asoc, len, asoc->rwnd,
		 __func__, asoc, len, asoc->rwnd, asoc->rwnd_over,
			  asoc->rwnd_over, asoc->a_rwnd);
		 asoc->a_rwnd);


	/* Send a window update SACK if the rwnd has increased by at least the
	/* Send a window update SACK if the rwnd has increased by at least the
	 * minimum of the association's PMTU and half of the receive buffer.
	 * minimum of the association's PMTU and half of the receive buffer.
@@ -1465,9 +1459,11 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned int len)
	 */
	 */
	if (sctp_peer_needs_update(asoc)) {
	if (sctp_peer_needs_update(asoc)) {
		asoc->a_rwnd = asoc->rwnd;
		asoc->a_rwnd = asoc->rwnd;
		SCTP_DEBUG_PRINTK("%s: Sending window update SACK- asoc: %p "

				  "rwnd: %u a_rwnd: %u\n", __func__,
		pr_debug("%s: sending window update SACK- asoc:%p rwnd:%u "
				  asoc, asoc->rwnd, asoc->a_rwnd);
			 "a_rwnd:%u\n", __func__, asoc, asoc->rwnd,
			 asoc->a_rwnd);

		sack = sctp_make_sack(asoc);
		sack = sctp_make_sack(asoc);
		if (!sack)
		if (!sack)
			return;
			return;
@@ -1489,8 +1485,10 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned int len)
	int rx_count;
	int rx_count;
	int over = 0;
	int over = 0;


	SCTP_ASSERT(asoc->rwnd, "rwnd zero", return);
	if (unlikely(!asoc->rwnd || asoc->rwnd_over))
	SCTP_ASSERT(!asoc->rwnd_over, "rwnd_over not zero", return);
		pr_debug("%s: association:%p has asoc->rwnd:%u, "
			 "asoc->rwnd_over:%u!\n", __func__, asoc,
			 asoc->rwnd, asoc->rwnd_over);


	if (asoc->ep->rcvbuf_policy)
	if (asoc->ep->rcvbuf_policy)
		rx_count = atomic_read(&asoc->rmem_alloc);
		rx_count = atomic_read(&asoc->rmem_alloc);
@@ -1515,9 +1513,10 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned int len)
		asoc->rwnd_over = len - asoc->rwnd;
		asoc->rwnd_over = len - asoc->rwnd;
		asoc->rwnd = 0;
		asoc->rwnd = 0;
	}
	}
	SCTP_DEBUG_PRINTK("%s: asoc %p rwnd decreased by %d to (%u, %u, %u)\n",

			  __func__, asoc, len, asoc->rwnd,
	pr_debug("%s: asoc:%p rwnd decreased by %d to (%u, %u, %u)\n",
			  asoc->rwnd_over, asoc->rwnd_press);
		 __func__, asoc, len, asoc->rwnd, asoc->rwnd_over,
		 asoc->rwnd_press);
}
}


/* Build the bind address list for the association based on info from the
/* Build the bind address list for the association based on info from the
+3 −2
Original line number Original line Diff line number Diff line
@@ -193,8 +193,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
		msg->expires_at = jiffies +
		msg->expires_at = jiffies +
				    msecs_to_jiffies(sinfo->sinfo_timetolive);
				    msecs_to_jiffies(sinfo->sinfo_timetolive);
		msg->can_abandon = 1;
		msg->can_abandon = 1;
		SCTP_DEBUG_PRINTK("%s: msg:%p expires_at: %ld jiffies:%ld\n",

				  __func__, msg, msg->expires_at, jiffies);
		pr_debug("%s: msg:%p expires_at:%ld jiffies:%ld\n", __func__,
			 msg, msg->expires_at, jiffies);
	}
	}


	/* This is the biggest possible DATA chunk that can fit into
	/* This is the biggest possible DATA chunk that can fit into
+0 −4
Original line number Original line Diff line number Diff line
@@ -47,10 +47,6 @@


#include <net/sctp/sctp.h>
#include <net/sctp/sctp.h>


#if SCTP_DEBUG
int sctp_debug_flag = 1;	/* Initially enable DEBUG */
#endif	/* SCTP_DEBUG */

/* These are printable forms of Chunk ID's from section 3.1.  */
/* These are printable forms of Chunk ID's from section 3.1.  */
static const char *const sctp_cid_tbl[SCTP_NUM_BASE_CHUNK_TYPES] = {
static const char *const sctp_cid_tbl[SCTP_NUM_BASE_CHUNK_TYPES] = {
	"DATA",
	"DATA",
Loading