Skip to content

Commit bb33381

Browse files
Daniel Borkmanndavem330
authored andcommitted
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: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1067964 commit bb33381

17 files changed

Lines changed: 383 additions & 484 deletions

‎include/net/sctp/sctp.h‎

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@
8383
#include <net/sctp/structs.h>
8484
#include <net/sctp/constants.h>
8585

86-
87-
/* Set SCTP_DEBUG flag via config if not already set. */
88-
#ifndef SCTP_DEBUG
89-
#ifdef CONFIG_SCTP_DBG_MSG
90-
#define SCTP_DEBUG 1
91-
#else
92-
#define SCTP_DEBUG 0
93-
#endif /* CONFIG_SCTP_DBG */
94-
#endif /* SCTP_DEBUG */
95-
9686
#ifdef CONFIG_IP_SCTP_MODULE
9787
#define SCTP_PROTOSW_FLAG 0
9888
#else /* static! */
@@ -270,61 +260,6 @@ static inline void sctp_max_rto(struct sctp_association *asoc,
270260
}
271261
}
272262

273-
/* Print debugging messages. */
274-
#if SCTP_DEBUG
275-
extern int sctp_debug_flag;
276-
#define SCTP_DEBUG_PRINTK(fmt, args...) \
277-
do { \
278-
if (sctp_debug_flag) \
279-
printk(KERN_DEBUG pr_fmt(fmt), ##args); \
280-
} while (0)
281-
#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) \
282-
do { \
283-
if (sctp_debug_flag) \
284-
pr_cont(fmt, ##args); \
285-
} while (0)
286-
#define SCTP_DEBUG_PRINTK_IPADDR(fmt_lead, fmt_trail, \
287-
args_lead, addr, args_trail...) \
288-
do { \
289-
const union sctp_addr *_addr = (addr); \
290-
if (sctp_debug_flag) { \
291-
if (_addr->sa.sa_family == AF_INET6) { \
292-
printk(KERN_DEBUG \
293-
pr_fmt(fmt_lead "%pI6" fmt_trail), \
294-
args_lead, \
295-
&_addr->v6.sin6_addr, \
296-
args_trail); \
297-
} else { \
298-
printk(KERN_DEBUG \
299-
pr_fmt(fmt_lead "%pI4" fmt_trail), \
300-
args_lead, \
301-
&_addr->v4.sin_addr.s_addr, \
302-
args_trail); \
303-
} \
304-
} \
305-
} while (0)
306-
#define SCTP_ENABLE_DEBUG { sctp_debug_flag = 1; }
307-
#define SCTP_DISABLE_DEBUG { sctp_debug_flag = 0; }
308-
309-
#define SCTP_ASSERT(expr, str, func) \
310-
if (!(expr)) { \
311-
SCTP_DEBUG_PRINTK("Assertion Failed: %s(%s) at %s:%s:%d\n", \
312-
str, (#expr), __FILE__, __func__, __LINE__); \
313-
func; \
314-
}
315-
316-
#else /* SCTP_DEBUG */
317-
318-
#define SCTP_DEBUG_PRINTK(whatever...)
319-
#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
320-
#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
321-
#define SCTP_ENABLE_DEBUG
322-
#define SCTP_DISABLE_DEBUG
323-
#define SCTP_ASSERT(expr, str, func)
324-
325-
#endif /* SCTP_DEBUG */
326-
327-
328263
/*
329264
* Macros for keeping a global reference of object allocations.
330265
*/
@@ -597,16 +532,6 @@ static inline int param_type2af(__be16 type)
597532
}
598533
}
599534

600-
/* Perform some sanity checks. */
601-
static inline int sctp_sanity_check(void)
602-
{
603-
SCTP_ASSERT(sizeof(struct sctp_ulpevent) <=
604-
sizeof(((struct sk_buff *)0)->cb),
605-
"SCTP: ulpevent does not fit in skb!\n", return 0);
606-
607-
return 1;
608-
}
609-
610535
/* Warning: The following hash functions assume a power of two 'size'. */
611536
/* This is the hash function for the SCTP port hash table. */
612537
static inline int sctp_phashfn(struct net *net, __u16 lport)

‎net/sctp/Kconfig‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ menuconfig IP_SCTP
3030
homing at either or both ends of an association."
3131

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

3536
If in doubt, say N.
3637

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

51-
config SCTP_DBG_MSG
52-
bool "SCTP: Debug messages"
52+
config SCTP_DBG_TSNS
53+
bool "SCTP: Debug transactions"
5354
help
54-
If you say Y, this will enable verbose debugging messages.
55+
If you say Y, this will enable transaction debugging, visible
56+
from the kernel's dynamic debugging framework.
5557

5658
If unsure, say N. However, if you are running into problems, use
57-
this option to gather detailed trace information
59+
this option to gather outqueue trace information.
5860

5961
config SCTP_DBG_OBJCNT
6062
bool "SCTP: Debug object counts"

‎net/sctp/associola.c‎

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ struct sctp_association *sctp_association_new(const struct sctp_endpoint *ep,
357357
goto fail_init;
358358

359359
SCTP_DBG_OBJCNT_INC(assoc);
360-
SCTP_DEBUG_PRINTK("Created asoc %p\n", asoc);
360+
361+
pr_debug("Created asoc %p\n", asoc);
361362

362363
return asoc;
363364

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

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

539-
SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_rm_peer:association %p addr: ",
540-
" port: %d\n",
541-
asoc,
542-
(&peer->ipaddr),
543-
ntohs(peer->ipaddr.v4.sin_port));
543+
pr_debug("%s: association:%p addr:%pISpc\n",
544+
__func__, asoc, &peer->ipaddr.sa);
544545

545546
/* If we are to remove the current retran_path, update it
546547
* 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,
636637
/* AF_INET and AF_INET6 share common port field. */
637638
port = ntohs(addr->v4.sin_port);
638639

639-
SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_add_peer:association %p addr: ",
640-
" port: %d state:%d\n",
641-
asoc,
642-
addr,
643-
port,
644-
peer_state);
640+
pr_debug("%s: association:%p addr:%pISpc state:%d\n", __func__,
641+
asoc, &addr->sa, peer_state);
645642

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

711-
SCTP_DEBUG_PRINTK("sctp_assoc_add_peer:association %p PMTU set to "
712-
"%d\n", asoc, asoc->pathmtu);
708+
pr_debug("%s: association:%p PMTU set to %d\n", __func__, asoc,
709+
asoc->pathmtu);
710+
713711
peer->pmtu_pending = 0;
714712

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

1352-
SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association"
1353-
" %p addr: ",
1354-
" port: %d\n",
1355-
asoc,
1356-
(&t->ipaddr),
1357-
ntohs(t->ipaddr.v4.sin_port));
1350+
pr_debug("%s: association:%p addr:%pISpc\n", __func__, asoc,
1351+
&t->ipaddr.sa);
13581352
}
13591353

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

1404-
SCTP_DEBUG_PRINTK("%s: asoc:%p, pmtu:%d, frag_point:%d\n",
1405-
__func__, asoc, asoc->pathmtu, asoc->frag_point);
1398+
pr_debug("%s: asoc:%p, pmtu:%d, frag_point:%d\n", __func__, asoc,
1399+
asoc->pathmtu, asoc->frag_point);
14061400
}
14071401

14081402
/* 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)
14541448
asoc->rwnd_press -= change;
14551449
}
14561450

1457-
SCTP_DEBUG_PRINTK("%s: asoc %p rwnd increased by %d to (%u, %u) "
1458-
"- %u\n", __func__, asoc, len, asoc->rwnd,
1459-
asoc->rwnd_over, asoc->a_rwnd);
1451+
pr_debug("%s: asoc:%p rwnd increased by %d to (%u, %u) - %u\n",
1452+
__func__, asoc, len, asoc->rwnd, asoc->rwnd_over,
1453+
asoc->a_rwnd);
14601454

14611455
/* Send a window update SACK if the rwnd has increased by at least the
14621456
* 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)
14651459
*/
14661460
if (sctp_peer_needs_update(asoc)) {
14671461
asoc->a_rwnd = asoc->rwnd;
1468-
SCTP_DEBUG_PRINTK("%s: Sending window update SACK- asoc: %p "
1469-
"rwnd: %u a_rwnd: %u\n", __func__,
1470-
asoc, asoc->rwnd, asoc->a_rwnd);
1462+
1463+
pr_debug("%s: sending window update SACK- asoc:%p rwnd:%u "
1464+
"a_rwnd:%u\n", __func__, asoc, asoc->rwnd,
1465+
asoc->a_rwnd);
1466+
14711467
sack = sctp_make_sack(asoc);
14721468
if (!sack)
14731469
return;
@@ -1489,8 +1485,10 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned int len)
14891485
int rx_count;
14901486
int over = 0;
14911487

1492-
SCTP_ASSERT(asoc->rwnd, "rwnd zero", return);
1493-
SCTP_ASSERT(!asoc->rwnd_over, "rwnd_over not zero", return);
1488+
if (unlikely(!asoc->rwnd || asoc->rwnd_over))
1489+
pr_debug("%s: association:%p has asoc->rwnd:%u, "
1490+
"asoc->rwnd_over:%u!\n", __func__, asoc,
1491+
asoc->rwnd, asoc->rwnd_over);
14941492

14951493
if (asoc->ep->rcvbuf_policy)
14961494
rx_count = atomic_read(&asoc->rmem_alloc);
@@ -1515,9 +1513,10 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned int len)
15151513
asoc->rwnd_over = len - asoc->rwnd;
15161514
asoc->rwnd = 0;
15171515
}
1518-
SCTP_DEBUG_PRINTK("%s: asoc %p rwnd decreased by %d to (%u, %u, %u)\n",
1519-
__func__, asoc, len, asoc->rwnd,
1520-
asoc->rwnd_over, asoc->rwnd_press);
1516+
1517+
pr_debug("%s: asoc:%p rwnd decreased by %d to (%u, %u, %u)\n",
1518+
__func__, asoc, len, asoc->rwnd, asoc->rwnd_over,
1519+
asoc->rwnd_press);
15211520
}
15221521

15231522
/* Build the bind address list for the association based on info from the

‎net/sctp/chunk.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
193193
msg->expires_at = jiffies +
194194
msecs_to_jiffies(sinfo->sinfo_timetolive);
195195
msg->can_abandon = 1;
196-
SCTP_DEBUG_PRINTK("%s: msg:%p expires_at: %ld jiffies:%ld\n",
197-
__func__, msg, msg->expires_at, jiffies);
196+
197+
pr_debug("%s: msg:%p expires_at:%ld jiffies:%ld\n", __func__,
198+
msg, msg->expires_at, jiffies);
198199
}
199200

200201
/* This is the biggest possible DATA chunk that can fit into

‎net/sctp/debug.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@
4747

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

50-
#if SCTP_DEBUG
51-
int sctp_debug_flag = 1; /* Initially enable DEBUG */
52-
#endif /* SCTP_DEBUG */
53-
5450
/* These are printable forms of Chunk ID's from section 3.1. */
5551
static const char *const sctp_cid_tbl[SCTP_NUM_BASE_CHUNK_TYPES] = {
5652
"DATA",

‎net/sctp/endpointola.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
249249
{
250250
struct sock *sk;
251251

252-
SCTP_ASSERT(ep->base.dead, "Endpoint is not dead", return);
252+
if (unlikely(!ep->base.dead)) {
253+
WARN(1, "Attempt to destroy undead endpoint %p!\n", ep);
254+
return;
255+
}
253256

254257
/* Free the digest buffer */
255258
kfree(ep->digest);

‎net/sctp/input.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,6 @@ void sctp_icmp_proto_unreachable(struct sock *sk,
454454
struct sctp_association *asoc,
455455
struct sctp_transport *t)
456456
{
457-
SCTP_DEBUG_PRINTK("%s\n", __func__);
458-
459457
if (sock_owned_by_user(sk)) {
460458
if (timer_pending(&t->proto_unreach_timer))
461459
return;
@@ -464,10 +462,12 @@ void sctp_icmp_proto_unreachable(struct sock *sk,
464462
jiffies + (HZ/20)))
465463
sctp_association_hold(asoc);
466464
}
467-
468465
} else {
469466
struct net *net = sock_net(sk);
470467

468+
pr_debug("%s: unrecognized next header type "
469+
"encountered!\n", __func__);
470+
471471
if (del_timer(&t->proto_unreach_timer))
472472
sctp_association_put(asoc);
473473

‎net/sctp/inqueue.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
219219
chunk->end_of_packet = 1;
220220
}
221221

222-
SCTP_DEBUG_PRINTK("+++sctp_inq_pop+++ chunk %p[%s],"
223-
" length %d, skb->len %d\n",chunk,
224-
sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)),
225-
ntohs(chunk->chunk_hdr->length), chunk->skb->len);
222+
pr_debug("+++sctp_inq_pop+++ chunk:%p[%s], length:%d, skb->len:%d\n",
223+
chunk, sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)),
224+
ntohs(chunk->chunk_hdr->length), chunk->skb->len);
225+
226226
return chunk;
227227
}
228228

@@ -238,4 +238,3 @@ void sctp_inq_set_th_handler(struct sctp_inq *q, work_func_t callback)
238238
{
239239
INIT_WORK(&q->immediate, callback);
240240
}
241-

0 commit comments

Comments
 (0)