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

Commit a4ca44fa authored by Joe Perches's avatar Joe Perches Committed by David S. Miller
Browse files

net: l2tp: Standardize logging styles



Use more current logging styles.

Add pr_fmt to prefix output appropriately.
Convert printks to pr_<level>.
Convert PRINTK macros to new l2tp_<level> macros.
Neaten some <foo>_refcount debugging macros.
Use print_hex_dump_bytes instead of hand-coded loops.
Coalesce formats and align arguments.

Some KERN_DEBUG output is not now emitted unless
dynamic_debugging is enabled.

Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarJames Chapman <jchapman@katalix.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 02894034
Loading
Loading
Loading
Loading
+101 −115
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@
 * published by the Free Software Foundation.
 * published by the Free Software Foundation.
 */
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/list.h>
@@ -86,12 +88,6 @@
/* Default trace flags */
/* Default trace flags */
#define L2TP_DEFAULT_DEBUG_FLAGS	0
#define L2TP_DEFAULT_DEBUG_FLAGS	0


#define PRINTK(_mask, _type, _lvl, _fmt, args...)			\
	do {								\
		if ((_mask) & (_type))					\
			printk(_lvl "L2TP: " _fmt, ##args);		\
	} while (0)

/* Private data stored for received packets in the skb.
/* Private data stored for received packets in the skb.
 */
 */
struct l2tp_skb_cb {
struct l2tp_skb_cb {
@@ -141,12 +137,18 @@ static inline void l2tp_tunnel_dec_refcount_1(struct l2tp_tunnel *tunnel)
		l2tp_tunnel_free(tunnel);
		l2tp_tunnel_free(tunnel);
}
}
#ifdef L2TP_REFCNT_DEBUG
#ifdef L2TP_REFCNT_DEBUG
#define l2tp_tunnel_inc_refcount(_t) do { \
#define l2tp_tunnel_inc_refcount(_t)					\
		printk(KERN_DEBUG "l2tp_tunnel_inc_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \
do {									\
	pr_debug("l2tp_tunnel_inc_refcount: %s:%d %s: cnt=%d\n",	\
		 __func__, __LINE__, (_t)->name,			\
		 atomic_read(&_t->ref_count));				\
	l2tp_tunnel_inc_refcount_1(_t);					\
	l2tp_tunnel_inc_refcount_1(_t);					\
} while (0)
} while (0)
#define l2tp_tunnel_dec_refcount(_t) do { \
#define l2tp_tunnel_dec_refcount(_t)
		printk(KERN_DEBUG "l2tp_tunnel_dec_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \
do {									\
	pr_debug("l2tp_tunnel_dec_refcount: %s:%d %s: cnt=%d\n",	\
		 __func__, __LINE__, (_t)->name,			\
		 atomic_read(&_t->ref_count));				\
	l2tp_tunnel_dec_refcount_1(_t);					\
	l2tp_tunnel_dec_refcount_1(_t);					\
} while (0)
} while (0)
#else
#else
@@ -337,7 +339,7 @@ static void l2tp_recv_queue_skb(struct l2tp_session *session, struct sk_buff *sk
	skb_queue_walk_safe(&session->reorder_q, skbp, tmp) {
	skb_queue_walk_safe(&session->reorder_q, skbp, tmp) {
		if (L2TP_SKB_CB(skbp)->ns > ns) {
		if (L2TP_SKB_CB(skbp)->ns > ns) {
			__skb_queue_before(&session->reorder_q, skbp, skb);
			__skb_queue_before(&session->reorder_q, skbp, skb);
			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
			l2tp_dbg(session, L2TP_MSG_SEQ,
				 "%s: pkt %hu, inserted before %hu, reorder_q len=%d\n",
				 "%s: pkt %hu, inserted before %hu, reorder_q len=%d\n",
				 session->name, ns, L2TP_SKB_CB(skbp)->ns,
				 session->name, ns, L2TP_SKB_CB(skbp)->ns,
				 skb_queue_len(&session->reorder_q));
				 skb_queue_len(&session->reorder_q));
@@ -386,8 +388,8 @@ static void l2tp_recv_dequeue_skb(struct l2tp_session *session, struct sk_buff *
		else
		else
			session->nr &= 0xffffff;
			session->nr &= 0xffffff;


		PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
		l2tp_dbg(session, L2TP_MSG_SEQ, "%s: updated nr to %hu\n",
		       "%s: updated nr to %hu\n", session->name, session->nr);
			 session->name, session->nr);
	}
	}


	/* call private receive handler */
	/* call private receive handler */
@@ -422,9 +424,8 @@ start:
			sstats->rx_seq_discards++;
			sstats->rx_seq_discards++;
			sstats->rx_errors++;
			sstats->rx_errors++;
			u64_stats_update_end(&sstats->syncp);
			u64_stats_update_end(&sstats->syncp);
			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
			l2tp_dbg(session, L2TP_MSG_SEQ,
			       "%s: oos pkt %u len %d discarded (too old), "
				 "%s: oos pkt %u len %d discarded (too old), waiting for %u, reorder_q_len=%d\n",
			       "waiting for %u, reorder_q_len=%d\n",
				 session->name, L2TP_SKB_CB(skb)->ns,
				 session->name, L2TP_SKB_CB(skb)->ns,
				 L2TP_SKB_CB(skb)->length, session->nr,
				 L2TP_SKB_CB(skb)->length, session->nr,
				 skb_queue_len(&session->reorder_q));
				 skb_queue_len(&session->reorder_q));
@@ -438,7 +439,7 @@ start:


		if (L2TP_SKB_CB(skb)->has_seq) {
		if (L2TP_SKB_CB(skb)->has_seq) {
			if (session->reorder_skip) {
			if (session->reorder_skip) {
				PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
				l2tp_dbg(session, L2TP_MSG_SEQ,
					 "%s: advancing nr to next pkt: %u -> %u",
					 "%s: advancing nr to next pkt: %u -> %u",
					 session->name, session->nr,
					 session->name, session->nr,
					 L2TP_SKB_CB(skb)->ns);
					 L2TP_SKB_CB(skb)->ns);
@@ -446,9 +447,8 @@ start:
				session->nr = L2TP_SKB_CB(skb)->ns;
				session->nr = L2TP_SKB_CB(skb)->ns;
			}
			}
			if (L2TP_SKB_CB(skb)->ns != session->nr) {
			if (L2TP_SKB_CB(skb)->ns != session->nr) {
				PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
				l2tp_dbg(session, L2TP_MSG_SEQ,
				       "%s: holding oos pkt %u len %d, "
					 "%s: holding oos pkt %u len %d, waiting for %u, reorder_q_len=%d\n",
				       "waiting for %u, reorder_q_len=%d\n",
					 session->name, L2TP_SKB_CB(skb)->ns,
					 session->name, L2TP_SKB_CB(skb)->ns,
					 L2TP_SKB_CB(skb)->length, session->nr,
					 L2TP_SKB_CB(skb)->length, session->nr,
					 skb_queue_len(&session->reorder_q));
					 skb_queue_len(&session->reorder_q));
@@ -595,9 +595,10 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
	/* Parse and check optional cookie */
	/* Parse and check optional cookie */
	if (session->peer_cookie_len > 0) {
	if (session->peer_cookie_len > 0) {
		if (memcmp(ptr, &session->peer_cookie[0], session->peer_cookie_len)) {
		if (memcmp(ptr, &session->peer_cookie[0], session->peer_cookie_len)) {
			PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO,
			l2tp_info(tunnel, L2TP_MSG_DATA,
				  "%s: cookie mismatch (%u/%u). Discarding.\n",
				  "%s: cookie mismatch (%u/%u). Discarding.\n",
			       tunnel->name, tunnel->tunnel_id, session->session_id);
				  tunnel->name, tunnel->tunnel_id,
				  session->session_id);
			u64_stats_update_begin(&sstats->syncp);
			u64_stats_update_begin(&sstats->syncp);
			sstats->rx_cookie_discards++;
			sstats->rx_cookie_discards++;
			u64_stats_update_end(&sstats->syncp);
			u64_stats_update_end(&sstats->syncp);
@@ -626,7 +627,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
			L2TP_SKB_CB(skb)->ns = ns;
			L2TP_SKB_CB(skb)->ns = ns;
			L2TP_SKB_CB(skb)->has_seq = 1;
			L2TP_SKB_CB(skb)->has_seq = 1;


			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
			l2tp_dbg(session, L2TP_MSG_SEQ,
				 "%s: recv data ns=%u, nr=%u, session nr=%u\n",
				 "%s: recv data ns=%u, nr=%u, session nr=%u\n",
				 session->name, ns, nr, session->nr);
				 session->name, ns, nr, session->nr);
		}
		}
@@ -640,7 +641,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
			L2TP_SKB_CB(skb)->ns = ns;
			L2TP_SKB_CB(skb)->ns = ns;
			L2TP_SKB_CB(skb)->has_seq = 1;
			L2TP_SKB_CB(skb)->has_seq = 1;


			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
			l2tp_dbg(session, L2TP_MSG_SEQ,
				 "%s: recv data ns=%u, session nr=%u\n",
				 "%s: recv data ns=%u, session nr=%u\n",
				 session->name, ns, session->nr);
				 session->name, ns, session->nr);
		}
		}
@@ -655,7 +656,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
		 * configure it so.
		 * configure it so.
		 */
		 */
		if ((!session->lns_mode) && (!session->send_seq)) {
		if ((!session->lns_mode) && (!session->send_seq)) {
			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_INFO,
			l2tp_info(session, L2TP_MSG_SEQ,
				  "%s: requested to enable seq numbers by LNS\n",
				  "%s: requested to enable seq numbers by LNS\n",
				  session->name);
				  session->name);
			session->send_seq = -1;
			session->send_seq = -1;
@@ -666,9 +667,9 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
		 * If user has configured mandatory sequence numbers, discard.
		 * If user has configured mandatory sequence numbers, discard.
		 */
		 */
		if (session->recv_seq) {
		if (session->recv_seq) {
			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_WARNING,
			l2tp_warn(session, L2TP_MSG_SEQ,
			       "%s: recv data has no seq numbers when required. "
				  "%s: recv data has no seq numbers when required. Discarding.\n",
			       "Discarding\n", session->name);
				  session->name);
			u64_stats_update_begin(&sstats->syncp);
			u64_stats_update_begin(&sstats->syncp);
			sstats->rx_seq_discards++;
			sstats->rx_seq_discards++;
			u64_stats_update_end(&sstats->syncp);
			u64_stats_update_end(&sstats->syncp);
@@ -681,15 +682,15 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
		 * LAC is broken. Discard the frame.
		 * LAC is broken. Discard the frame.
		 */
		 */
		if ((!session->lns_mode) && (session->send_seq)) {
		if ((!session->lns_mode) && (session->send_seq)) {
			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_INFO,
			l2tp_info(session, L2TP_MSG_SEQ,
				  "%s: requested to disable seq numbers by LNS\n",
				  "%s: requested to disable seq numbers by LNS\n",
				  session->name);
				  session->name);
			session->send_seq = 0;
			session->send_seq = 0;
			l2tp_session_set_header_len(session, tunnel->version);
			l2tp_session_set_header_len(session, tunnel->version);
		} else if (session->send_seq) {
		} else if (session->send_seq) {
			PRINTK(session->debug, L2TP_MSG_SEQ, KERN_WARNING,
			l2tp_warn(session, L2TP_MSG_SEQ,
			       "%s: recv data has no seq numbers when required. "
				  "%s: recv data has no seq numbers when required. Discarding.\n",
			       "Discarding\n", session->name);
				  session->name);
			u64_stats_update_begin(&sstats->syncp);
			u64_stats_update_begin(&sstats->syncp);
			sstats->rx_seq_discards++;
			sstats->rx_seq_discards++;
			u64_stats_update_end(&sstats->syncp);
			u64_stats_update_end(&sstats->syncp);
@@ -749,9 +750,8 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
				u64_stats_update_begin(&sstats->syncp);
				u64_stats_update_begin(&sstats->syncp);
				sstats->rx_seq_discards++;
				sstats->rx_seq_discards++;
				u64_stats_update_end(&sstats->syncp);
				u64_stats_update_end(&sstats->syncp);
				PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
				l2tp_dbg(session, L2TP_MSG_SEQ,
				       "%s: oos pkt %u len %d discarded, "
					 "%s: oos pkt %u len %d discarded, waiting for %u, reorder_q_len=%d\n",
				       "waiting for %u, reorder_q_len=%d\n",
					 session->name, L2TP_SKB_CB(skb)->ns,
					 session->name, L2TP_SKB_CB(skb)->ns,
					 L2TP_SKB_CB(skb)->length, session->nr,
					 L2TP_SKB_CB(skb)->length, session->nr,
					 skb_queue_len(&session->reorder_q));
					 skb_queue_len(&session->reorder_q));
@@ -800,7 +800,6 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,
	unsigned char *ptr, *optr;
	unsigned char *ptr, *optr;
	u16 hdrflags;
	u16 hdrflags;
	u32 tunnel_id, session_id;
	u32 tunnel_id, session_id;
	int offset;
	u16 version;
	u16 version;
	int length;
	int length;
	struct l2tp_stats *tstats;
	struct l2tp_stats *tstats;
@@ -813,8 +812,9 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,


	/* Short packet? */
	/* Short packet? */
	if (!pskb_may_pull(skb, L2TP_HDR_SIZE_SEQ)) {
	if (!pskb_may_pull(skb, L2TP_HDR_SIZE_SEQ)) {
		PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO,
		l2tp_info(tunnel, L2TP_MSG_DATA,
		       "%s: recv short packet (len=%d)\n", tunnel->name, skb->len);
			  "%s: recv short packet (len=%d)\n",
			  tunnel->name, skb->len);
		goto error;
		goto error;
	}
	}


@@ -824,14 +824,8 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,
		if (!pskb_may_pull(skb, length))
		if (!pskb_may_pull(skb, length))
			goto error;
			goto error;


		printk(KERN_DEBUG "%s: recv: ", tunnel->name);
		pr_debug("%s: recv\n", tunnel->name);

		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, skb->data, length);
		offset = 0;
		do {
			printk(" %02X", skb->data[offset]);
		} while (++offset < length);

		printk("\n");
	}
	}


	/* Point to L2TP header */
	/* Point to L2TP header */
@@ -843,7 +837,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,
	/* Check protocol version */
	/* Check protocol version */
	version = hdrflags & L2TP_HDR_VER_MASK;
	version = hdrflags & L2TP_HDR_VER_MASK;
	if (version != tunnel->version) {
	if (version != tunnel->version) {
		PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO,
		l2tp_info(tunnel, L2TP_MSG_DATA,
			  "%s: recv protocol version mismatch: got %d expected %d\n",
			  "%s: recv protocol version mismatch: got %d expected %d\n",
			  tunnel->name, version, tunnel->version);
			  tunnel->name, version, tunnel->version);
		goto error;
		goto error;
@@ -854,8 +848,9 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,


	/* If type is control packet, it is handled by userspace. */
	/* If type is control packet, it is handled by userspace. */
	if (hdrflags & L2TP_HDRFLAG_T) {
	if (hdrflags & L2TP_HDRFLAG_T) {
		PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_DEBUG,
		l2tp_dbg(tunnel, L2TP_MSG_DATA,
		       "%s: recv control packet, len=%d\n", tunnel->name, length);
			 "%s: recv control packet, len=%d\n",
			 tunnel->name, length);
		goto error;
		goto error;
	}
	}


@@ -883,7 +878,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,
	session = l2tp_session_find(tunnel->l2tp_net, tunnel, session_id);
	session = l2tp_session_find(tunnel->l2tp_net, tunnel, session_id);
	if (!session || !session->recv_skb) {
	if (!session || !session->recv_skb) {
		/* Not found? Pass to userspace to deal with */
		/* Not found? Pass to userspace to deal with */
		PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO,
		l2tp_info(tunnel, L2TP_MSG_DATA,
			  "%s: no session found (%u/%u). Passing up.\n",
			  "%s: no session found (%u/%u). Passing up.\n",
			  tunnel->name, tunnel_id, session_id);
			  tunnel->name, tunnel_id, session_id);
		goto error;
		goto error;
@@ -925,8 +920,8 @@ int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
	if (tunnel == NULL)
	if (tunnel == NULL)
		goto pass_up;
		goto pass_up;


	PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_DEBUG,
	l2tp_dbg(tunnel, L2TP_MSG_DATA, "%s: received %d bytes\n",
	       "%s: received %d bytes\n", tunnel->name, skb->len);
		 tunnel->name, skb->len);


	if (l2tp_udp_recv_core(tunnel, skb, tunnel->recv_payload_hook))
	if (l2tp_udp_recv_core(tunnel, skb, tunnel->recv_payload_hook))
		goto pass_up_put;
		goto pass_up_put;
@@ -968,8 +963,8 @@ static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf)
		*bufp++ = 0;
		*bufp++ = 0;
		session->ns++;
		session->ns++;
		session->ns &= 0xffff;
		session->ns &= 0xffff;
		PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
		l2tp_dbg(session, L2TP_MSG_SEQ, "%s: updated ns to %u\n",
		       "%s: updated ns to %u\n", session->name, session->ns);
			 session->name, session->ns);
	}
	}


	return bufp - optr;
	return bufp - optr;
@@ -1005,8 +1000,9 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf)
				l2h = 0x40000000 | session->ns;
				l2h = 0x40000000 | session->ns;
				session->ns++;
				session->ns++;
				session->ns &= 0xffffff;
				session->ns &= 0xffffff;
				PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG,
				l2tp_dbg(session, L2TP_MSG_SEQ,
				       "%s: updated ns to %u\n", session->name, session->ns);
					 "%s: updated ns to %u\n",
					 session->name, session->ns);
			}
			}


			*((__be32 *) bufp) = htonl(l2h);
			*((__be32 *) bufp) = htonl(l2h);
@@ -1029,27 +1025,19 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,


	/* Debug */
	/* Debug */
	if (session->send_seq)
	if (session->send_seq)
		PRINTK(session->debug, L2TP_MSG_DATA, KERN_DEBUG,
		l2tp_dbg(session, L2TP_MSG_DATA, "%s: send %Zd bytes, ns=%u\n",
		       "%s: send %Zd bytes, ns=%u\n", session->name,
			 session->name, data_len, session->ns - 1);
		       data_len, session->ns - 1);
	else
	else
		PRINTK(session->debug, L2TP_MSG_DATA, KERN_DEBUG,
		l2tp_dbg(session, L2TP_MSG_DATA, "%s: send %Zd bytes\n",
		       "%s: send %Zd bytes\n", session->name, data_len);
			 session->name, data_len);


	if (session->debug & L2TP_MSG_DATA) {
	if (session->debug & L2TP_MSG_DATA) {
		int i;
		int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
		int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
		unsigned char *datap = skb->data + uhlen;
		unsigned char *datap = skb->data + uhlen;


		printk(KERN_DEBUG "%s: xmit:", session->name);
		pr_debug("%s: xmit\n", session->name);
		for (i = 0; i < (len - uhlen); i++) {
		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
			printk(" %02X", *datap++);
				     datap, min_t(size_t, 32, len - uhlen));
			if (i == 31) {
				printk(" ...");
				break;
			}
		}
		printk("\n");
	}
	}


	/* Queue the packet to IP for output */
	/* Queue the packet to IP for output */
@@ -1248,8 +1236,7 @@ static void l2tp_tunnel_destruct(struct sock *sk)
	if (tunnel == NULL)
	if (tunnel == NULL)
		goto end;
		goto end;


	PRINTK(tunnel->debug, L2TP_MSG_CONTROL, KERN_INFO,
	l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name);
	       "%s: closing...\n", tunnel->name);


	/* Close all sessions */
	/* Close all sessions */
	l2tp_tunnel_closeall(tunnel);
	l2tp_tunnel_closeall(tunnel);
@@ -1291,8 +1278,8 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)


	BUG_ON(tunnel == NULL);
	BUG_ON(tunnel == NULL);


	PRINTK(tunnel->debug, L2TP_MSG_CONTROL, KERN_INFO,
	l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing all sessions...\n",
	       "%s: closing all sessions...\n", tunnel->name);
		  tunnel->name);


	write_lock_bh(&tunnel->hlist_lock);
	write_lock_bh(&tunnel->hlist_lock);
	for (hash = 0; hash < L2TP_HASH_SIZE; hash++) {
	for (hash = 0; hash < L2TP_HASH_SIZE; hash++) {
@@ -1300,7 +1287,7 @@ again:
		hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) {
		hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) {
			session = hlist_entry(walk, struct l2tp_session, hlist);
			session = hlist_entry(walk, struct l2tp_session, hlist);


			PRINTK(session->debug, L2TP_MSG_CONTROL, KERN_INFO,
			l2tp_info(session, L2TP_MSG_CONTROL,
				  "%s: closing session\n", session->name);
				  "%s: closing session\n", session->name);


			hlist_del_init(&session->hlist);
			hlist_del_init(&session->hlist);
@@ -1354,8 +1341,7 @@ static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel)
	BUG_ON(atomic_read(&tunnel->ref_count) != 0);
	BUG_ON(atomic_read(&tunnel->ref_count) != 0);
	BUG_ON(tunnel->sock != NULL);
	BUG_ON(tunnel->sock != NULL);


	PRINTK(tunnel->debug, L2TP_MSG_CONTROL, KERN_INFO,
	l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: free...\n", tunnel->name);
	       "%s: free...\n", tunnel->name);


	/* Remove from tunnel list */
	/* Remove from tunnel list */
	spin_lock_bh(&pn->l2tp_tunnel_list_lock);
	spin_lock_bh(&pn->l2tp_tunnel_list_lock);
@@ -1536,7 +1522,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
		err = -EBADF;
		err = -EBADF;
		sock = sockfd_lookup(fd, &err);
		sock = sockfd_lookup(fd, &err);
		if (!sock) {
		if (!sock) {
			printk(KERN_ERR "tunl %hu: sockfd_lookup(fd=%d) returned %d\n",
			pr_err("tunl %hu: sockfd_lookup(fd=%d) returned %d\n",
			       tunnel_id, fd, err);
			       tunnel_id, fd, err);
			goto err;
			goto err;
		}
		}
@@ -1552,7 +1538,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
	case L2TP_ENCAPTYPE_UDP:
	case L2TP_ENCAPTYPE_UDP:
		err = -EPROTONOSUPPORT;
		err = -EPROTONOSUPPORT;
		if (sk->sk_protocol != IPPROTO_UDP) {
		if (sk->sk_protocol != IPPROTO_UDP) {
			printk(KERN_ERR "tunl %hu: fd %d wrong protocol, got %d, expected %d\n",
			pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n",
			       tunnel_id, fd, sk->sk_protocol, IPPROTO_UDP);
			       tunnel_id, fd, sk->sk_protocol, IPPROTO_UDP);
			goto err;
			goto err;
		}
		}
@@ -1560,7 +1546,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
	case L2TP_ENCAPTYPE_IP:
	case L2TP_ENCAPTYPE_IP:
		err = -EPROTONOSUPPORT;
		err = -EPROTONOSUPPORT;
		if (sk->sk_protocol != IPPROTO_L2TP) {
		if (sk->sk_protocol != IPPROTO_L2TP) {
			printk(KERN_ERR "tunl %hu: fd %d wrong protocol, got %d, expected %d\n",
			pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n",
			       tunnel_id, fd, sk->sk_protocol, IPPROTO_L2TP);
			       tunnel_id, fd, sk->sk_protocol, IPPROTO_L2TP);
			goto err;
			goto err;
		}
		}
@@ -1868,7 +1854,7 @@ static int __init l2tp_init(void)
	if (rc)
	if (rc)
		goto out;
		goto out;


	printk(KERN_INFO "L2TP core driver, %s\n", L2TP_DRV_VERSION);
	pr_info("L2TP core driver, %s\n", L2TP_DRV_VERSION);


out:
out:
	return rc;
	return rc;
+27 −8
Original line number Original line Diff line number Diff line
@@ -261,12 +261,18 @@ static inline void l2tp_session_dec_refcount_1(struct l2tp_session *session)
}
}


#ifdef L2TP_REFCNT_DEBUG
#ifdef L2TP_REFCNT_DEBUG
#define l2tp_session_inc_refcount(_s) do { \
#define l2tp_session_inc_refcount(_s)					\
		printk(KERN_DEBUG "l2tp_session_inc_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_s)->name, atomic_read(&_s->ref_count)); \
do {									\
	pr_debug("l2tp_session_inc_refcount: %s:%d %s: cnt=%d\n",	\
		 __func__, __LINE__, (_s)->name,			\
		 atomic_read(&_s->ref_count));				\
	l2tp_session_inc_refcount_1(_s);				\
	l2tp_session_inc_refcount_1(_s);				\
} while (0)
} while (0)
#define l2tp_session_dec_refcount(_s) do { \
#define l2tp_session_dec_refcount(_s)					\
		printk(KERN_DEBUG "l2tp_session_dec_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_s)->name, atomic_read(&_s->ref_count)); \
do {									\
	pr_debug("l2tp_session_dec_refcount: %s:%d %s: cnt=%d\n",	\
		 __func__, __LINE__, (_s)->name,			\
		 atomic_read(&_s->ref_count));				\
	l2tp_session_dec_refcount_1(_s);				\
	l2tp_session_dec_refcount_1(_s);				\
} while (0)
} while (0)
#else
#else
@@ -274,4 +280,17 @@ static inline void l2tp_session_dec_refcount_1(struct l2tp_session *session)
#define l2tp_session_dec_refcount(s) l2tp_session_dec_refcount_1(s)
#define l2tp_session_dec_refcount(s) l2tp_session_dec_refcount_1(s)
#endif
#endif


#define l2tp_printk(ptr, type, func, fmt, ...)				\
do {									\
	if (((ptr)->debug) & (type))					\
		func(fmt, ##__VA_ARGS__);				\
} while (0)

#define l2tp_warn(ptr, type, fmt, ...)					\
	l2tp_printk(ptr, type, pr_warn, fmt, ##__VA_ARGS__)
#define l2tp_info(ptr, type, fmt, ...)					\
	l2tp_printk(ptr, type, pr_info, fmt, ##__VA_ARGS__)
#define l2tp_dbg(ptr, type, fmt, ...)					\
	l2tp_printk(ptr, type, pr_debug, fmt, ##__VA_ARGS__)

#endif /* _L2TP_CORE_H_ */
#endif /* _L2TP_CORE_H_ */
+4 −2
Original line number Original line Diff line number Diff line
@@ -9,6 +9,8 @@
 *	2 of the License, or (at your option) any later version.
 *	2 of the License, or (at your option) any later version.
 */
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
#include <linux/socket.h>
@@ -325,11 +327,11 @@ static int __init l2tp_debugfs_init(void)
	if (tunnels == NULL)
	if (tunnels == NULL)
		rc = -EIO;
		rc = -EIO;


	printk(KERN_INFO "L2TP debugfs support\n");
	pr_info("L2TP debugfs support\n");


out:
out:
	if (rc)
	if (rc)
		printk(KERN_WARNING "l2tp debugfs: unable to init\n");
		pr_warn("unable to init\n");


	return rc;
	return rc;
}
}
+5 −10
Original line number Original line Diff line number Diff line
@@ -9,6 +9,8 @@
 *	2 of the License, or (at your option) any later version.
 *	2 of the License, or (at your option) any later version.
 */
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
#include <linux/socket.h>
@@ -115,21 +117,14 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,


	if (session->debug & L2TP_MSG_DATA) {
	if (session->debug & L2TP_MSG_DATA) {
		unsigned int length;
		unsigned int length;
		int offset;
		u8 *ptr = skb->data;
		u8 *ptr = skb->data;


		length = min(32u, skb->len);
		length = min(32u, skb->len);
		if (!pskb_may_pull(skb, length))
		if (!pskb_may_pull(skb, length))
			goto error;
			goto error;


		printk(KERN_DEBUG "%s: eth recv: ", session->name);
		pr_debug("%s: eth recv\n", session->name);

		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
		offset = 0;
		do {
			printk(" %02X", ptr[offset]);
		} while (++offset < length);

		printk("\n");
	}
	}


	if (!pskb_may_pull(skb, sizeof(ETH_HLEN)))
	if (!pskb_may_pull(skb, sizeof(ETH_HLEN)))
@@ -308,7 +303,7 @@ static int __init l2tp_eth_init(void)
	if (err)
	if (err)
		goto out_unreg;
		goto out_unreg;


	printk(KERN_INFO "L2TP ethernet pseudowire support (L2TPv3)\n");
	pr_info("L2TP ethernet pseudowire support (L2TPv3)\n");


	return 0;
	return 0;


+5 −10
Original line number Original line Diff line number Diff line
@@ -9,6 +9,8 @@
 *	2 of the License, or (at your option) any later version.
 *	2 of the License, or (at your option) any later version.
 */
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/icmp.h>
#include <linux/icmp.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
@@ -120,7 +122,6 @@ static int l2tp_ip_recv(struct sk_buff *skb)
	struct l2tp_session *session;
	struct l2tp_session *session;
	struct l2tp_tunnel *tunnel = NULL;
	struct l2tp_tunnel *tunnel = NULL;
	int length;
	int length;
	int offset;


	/* Point to L2TP header */
	/* Point to L2TP header */
	optr = ptr = skb->data;
	optr = ptr = skb->data;
@@ -155,14 +156,8 @@ static int l2tp_ip_recv(struct sk_buff *skb)
		if (!pskb_may_pull(skb, length))
		if (!pskb_may_pull(skb, length))
			goto discard;
			goto discard;


		printk(KERN_DEBUG "%s: ip recv: ", tunnel->name);
		pr_debug("%s: ip recv\n", tunnel->name);

		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
		offset = 0;
		do {
			printk(" %02X", ptr[offset]);
		} while (++offset < length);

		printk("\n");
	}
	}


	l2tp_recv_common(session, skb, ptr, optr, 0, skb->len, tunnel->recv_payload_hook);
	l2tp_recv_common(session, skb, ptr, optr, 0, skb->len, tunnel->recv_payload_hook);
@@ -593,7 +588,7 @@ static int __init l2tp_ip_init(void)
{
{
	int err;
	int err;


	printk(KERN_INFO "L2TP IP encapsulation support (L2TPv3)\n");
	pr_info("L2TP IP encapsulation support (L2TPv3)\n");


	err = proto_register(&l2tp_ip_prot, 1);
	err = proto_register(&l2tp_ip_prot, 1);
	if (err != 0)
	if (err != 0)
Loading