hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/net/l2tp/l2tp_debugfs.c
....@@ -1,12 +1,7 @@
1
-/*
2
- * L2TP subsystem debugfs
1
+// SPDX-License-Identifier: GPL-2.0-or-later
2
+/* L2TP subsystem debugfs
33 *
44 * Copyright (c) 2010 Katalix Systems Ltd
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version
9
- * 2 of the License, or (at your option) any later version.
105 */
116
127 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -35,7 +30,6 @@
3530 #include "l2tp_core.h"
3631
3732 static struct dentry *rootdir;
38
-static struct dentry *tunnels;
3933
4034 struct l2tp_dfs_seq_data {
4135 struct net *net;
....@@ -64,11 +58,10 @@
6458 pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx);
6559 pd->session_idx++;
6660
67
- if (pd->session == NULL) {
61
+ if (!pd->session) {
6862 pd->session_idx = 0;
6963 l2tp_dfs_next_tunnel(pd);
7064 }
71
-
7265 }
7366
7467 static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs)
....@@ -79,22 +72,24 @@
7972 if (!pos)
8073 goto out;
8174
82
- BUG_ON(m->private == NULL);
75
+ if (WARN_ON(!m->private)) {
76
+ pd = NULL;
77
+ goto out;
78
+ }
8379 pd = m->private;
8480
85
- if (pd->tunnel == NULL)
81
+ if (!pd->tunnel)
8682 l2tp_dfs_next_tunnel(pd);
8783 else
8884 l2tp_dfs_next_session(pd);
8985
9086 /* NULL tunnel and session indicates end of list */
91
- if ((pd->tunnel == NULL) && (pd->session == NULL))
87
+ if (!pd->tunnel && !pd->session)
9288 pd = NULL;
9389
9490 out:
9591 return pd;
9692 }
97
-
9893
9994 static void *l2tp_dfs_seq_next(struct seq_file *m, void *v, loff_t *pos)
10095 {
....@@ -153,11 +148,13 @@
153148 const struct ipv6_pinfo *np = inet6_sk(tunnel->sock);
154149
155150 seq_printf(m, " from %pI6c to %pI6c\n",
156
- &np->saddr, &tunnel->sock->sk_v6_daddr);
157
- } else
151
+ &np->saddr, &tunnel->sock->sk_v6_daddr);
152
+ }
158153 #endif
159
- seq_printf(m, " from %pI4 to %pI4\n",
160
- &inet->inet_saddr, &inet->inet_daddr);
154
+ if (tunnel->sock->sk_family == AF_INET)
155
+ seq_printf(m, " from %pI4 to %pI4\n",
156
+ &inet->inet_saddr, &inet->inet_daddr);
157
+
161158 if (tunnel->encap == L2TP_ENCAPTYPE_UDP)
162159 seq_printf(m, " source port %hu, dest port %hu\n",
163160 ntohs(inet->inet_sport), ntohs(inet->inet_dport));
....@@ -170,7 +167,7 @@
170167 tunnel->sock ? refcount_read(&tunnel->sock->sk_refcnt) : 0,
171168 refcount_read(&tunnel->ref_count));
172169 seq_printf(m, " %08x rx %ld/%ld/%ld rx %ld/%ld/%ld\n",
173
- tunnel->debug,
170
+ 0,
174171 atomic_long_read(&tunnel->stats.tx_packets),
175172 atomic_long_read(&tunnel->stats.tx_bytes),
176173 atomic_long_read(&tunnel->stats.tx_errors),
....@@ -195,7 +192,7 @@
195192 session->recv_seq ? 'R' : '-',
196193 session->send_seq ? 'S' : '-',
197194 session->lns_mode ? "LNS" : "LAC",
198
- session->debug,
195
+ 0,
199196 jiffies_to_msecs(session->reorder_timeout));
200197 seq_printf(m, " offset 0 l2specific %hu/%hu\n",
201198 session->l2specific_type, l2tp_get_l2specific_len(session));
....@@ -207,7 +204,7 @@
207204 seq_printf(m, "%02x%02x%02x%02x",
208205 session->cookie[4], session->cookie[5],
209206 session->cookie[6], session->cookie[7]);
210
- seq_printf(m, "\n");
207
+ seq_puts(m, "\n");
211208 }
212209 if (session->peer_cookie_len) {
213210 seq_printf(m, " peer cookie %02x%02x%02x%02x",
....@@ -217,7 +214,7 @@
217214 seq_printf(m, "%02x%02x%02x%02x",
218215 session->peer_cookie[4], session->peer_cookie[5],
219216 session->peer_cookie[6], session->peer_cookie[7]);
220
- seq_printf(m, "\n");
217
+ seq_puts(m, "\n");
221218 }
222219
223220 seq_printf(m, " %hu/%hu tx %ld/%ld/%ld rx %ld/%ld/%ld\n",
....@@ -229,7 +226,7 @@
229226 atomic_long_read(&session->stats.rx_bytes),
230227 atomic_long_read(&session->stats.rx_errors));
231228
232
- if (session->show != NULL)
229
+ if (session->show)
233230 session->show(m, session);
234231 }
235232
....@@ -276,7 +273,7 @@
276273 int rc = -ENOMEM;
277274
278275 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
279
- if (pd == NULL)
276
+ if (!pd)
280277 goto out;
281278
282279 /* Derive the network namespace from the pid opening the
....@@ -330,32 +327,18 @@
330327
331328 static int __init l2tp_debugfs_init(void)
332329 {
333
- int rc = 0;
334
-
335330 rootdir = debugfs_create_dir("l2tp", NULL);
336
- if (IS_ERR(rootdir)) {
337
- rc = PTR_ERR(rootdir);
338
- rootdir = NULL;
339
- goto out;
340
- }
341331
342
- tunnels = debugfs_create_file("tunnels", 0600, rootdir, NULL, &l2tp_dfs_fops);
343
- if (tunnels == NULL)
344
- rc = -EIO;
332
+ debugfs_create_file("tunnels", 0600, rootdir, NULL, &l2tp_dfs_fops);
345333
346334 pr_info("L2TP debugfs support\n");
347335
348
-out:
349
- if (rc)
350
- pr_warn("unable to init\n");
351
-
352
- return rc;
336
+ return 0;
353337 }
354338
355339 static void __exit l2tp_debugfs_exit(void)
356340 {
357
- debugfs_remove(tunnels);
358
- debugfs_remove(rootdir);
341
+ debugfs_remove_recursive(rootdir);
359342 }
360343
361344 module_init(l2tp_debugfs_init);