| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * L2TP subsystem debugfs |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 2 | +/* L2TP subsystem debugfs |
|---|
| 3 | 3 | * |
|---|
| 4 | 4 | * 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. |
|---|
| 10 | 5 | */ |
|---|
| 11 | 6 | |
|---|
| 12 | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| .. | .. |
|---|
| 35 | 30 | #include "l2tp_core.h" |
|---|
| 36 | 31 | |
|---|
| 37 | 32 | static struct dentry *rootdir; |
|---|
| 38 | | -static struct dentry *tunnels; |
|---|
| 39 | 33 | |
|---|
| 40 | 34 | struct l2tp_dfs_seq_data { |
|---|
| 41 | 35 | struct net *net; |
|---|
| .. | .. |
|---|
| 64 | 58 | pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx); |
|---|
| 65 | 59 | pd->session_idx++; |
|---|
| 66 | 60 | |
|---|
| 67 | | - if (pd->session == NULL) { |
|---|
| 61 | + if (!pd->session) { |
|---|
| 68 | 62 | pd->session_idx = 0; |
|---|
| 69 | 63 | l2tp_dfs_next_tunnel(pd); |
|---|
| 70 | 64 | } |
|---|
| 71 | | - |
|---|
| 72 | 65 | } |
|---|
| 73 | 66 | |
|---|
| 74 | 67 | static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs) |
|---|
| .. | .. |
|---|
| 79 | 72 | if (!pos) |
|---|
| 80 | 73 | goto out; |
|---|
| 81 | 74 | |
|---|
| 82 | | - BUG_ON(m->private == NULL); |
|---|
| 75 | + if (WARN_ON(!m->private)) { |
|---|
| 76 | + pd = NULL; |
|---|
| 77 | + goto out; |
|---|
| 78 | + } |
|---|
| 83 | 79 | pd = m->private; |
|---|
| 84 | 80 | |
|---|
| 85 | | - if (pd->tunnel == NULL) |
|---|
| 81 | + if (!pd->tunnel) |
|---|
| 86 | 82 | l2tp_dfs_next_tunnel(pd); |
|---|
| 87 | 83 | else |
|---|
| 88 | 84 | l2tp_dfs_next_session(pd); |
|---|
| 89 | 85 | |
|---|
| 90 | 86 | /* NULL tunnel and session indicates end of list */ |
|---|
| 91 | | - if ((pd->tunnel == NULL) && (pd->session == NULL)) |
|---|
| 87 | + if (!pd->tunnel && !pd->session) |
|---|
| 92 | 88 | pd = NULL; |
|---|
| 93 | 89 | |
|---|
| 94 | 90 | out: |
|---|
| 95 | 91 | return pd; |
|---|
| 96 | 92 | } |
|---|
| 97 | | - |
|---|
| 98 | 93 | |
|---|
| 99 | 94 | static void *l2tp_dfs_seq_next(struct seq_file *m, void *v, loff_t *pos) |
|---|
| 100 | 95 | { |
|---|
| .. | .. |
|---|
| 153 | 148 | const struct ipv6_pinfo *np = inet6_sk(tunnel->sock); |
|---|
| 154 | 149 | |
|---|
| 155 | 150 | 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 | + } |
|---|
| 158 | 153 | #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 | + |
|---|
| 161 | 158 | if (tunnel->encap == L2TP_ENCAPTYPE_UDP) |
|---|
| 162 | 159 | seq_printf(m, " source port %hu, dest port %hu\n", |
|---|
| 163 | 160 | ntohs(inet->inet_sport), ntohs(inet->inet_dport)); |
|---|
| .. | .. |
|---|
| 170 | 167 | tunnel->sock ? refcount_read(&tunnel->sock->sk_refcnt) : 0, |
|---|
| 171 | 168 | refcount_read(&tunnel->ref_count)); |
|---|
| 172 | 169 | seq_printf(m, " %08x rx %ld/%ld/%ld rx %ld/%ld/%ld\n", |
|---|
| 173 | | - tunnel->debug, |
|---|
| 170 | + 0, |
|---|
| 174 | 171 | atomic_long_read(&tunnel->stats.tx_packets), |
|---|
| 175 | 172 | atomic_long_read(&tunnel->stats.tx_bytes), |
|---|
| 176 | 173 | atomic_long_read(&tunnel->stats.tx_errors), |
|---|
| .. | .. |
|---|
| 195 | 192 | session->recv_seq ? 'R' : '-', |
|---|
| 196 | 193 | session->send_seq ? 'S' : '-', |
|---|
| 197 | 194 | session->lns_mode ? "LNS" : "LAC", |
|---|
| 198 | | - session->debug, |
|---|
| 195 | + 0, |
|---|
| 199 | 196 | jiffies_to_msecs(session->reorder_timeout)); |
|---|
| 200 | 197 | seq_printf(m, " offset 0 l2specific %hu/%hu\n", |
|---|
| 201 | 198 | session->l2specific_type, l2tp_get_l2specific_len(session)); |
|---|
| .. | .. |
|---|
| 207 | 204 | seq_printf(m, "%02x%02x%02x%02x", |
|---|
| 208 | 205 | session->cookie[4], session->cookie[5], |
|---|
| 209 | 206 | session->cookie[6], session->cookie[7]); |
|---|
| 210 | | - seq_printf(m, "\n"); |
|---|
| 207 | + seq_puts(m, "\n"); |
|---|
| 211 | 208 | } |
|---|
| 212 | 209 | if (session->peer_cookie_len) { |
|---|
| 213 | 210 | seq_printf(m, " peer cookie %02x%02x%02x%02x", |
|---|
| .. | .. |
|---|
| 217 | 214 | seq_printf(m, "%02x%02x%02x%02x", |
|---|
| 218 | 215 | session->peer_cookie[4], session->peer_cookie[5], |
|---|
| 219 | 216 | session->peer_cookie[6], session->peer_cookie[7]); |
|---|
| 220 | | - seq_printf(m, "\n"); |
|---|
| 217 | + seq_puts(m, "\n"); |
|---|
| 221 | 218 | } |
|---|
| 222 | 219 | |
|---|
| 223 | 220 | seq_printf(m, " %hu/%hu tx %ld/%ld/%ld rx %ld/%ld/%ld\n", |
|---|
| .. | .. |
|---|
| 229 | 226 | atomic_long_read(&session->stats.rx_bytes), |
|---|
| 230 | 227 | atomic_long_read(&session->stats.rx_errors)); |
|---|
| 231 | 228 | |
|---|
| 232 | | - if (session->show != NULL) |
|---|
| 229 | + if (session->show) |
|---|
| 233 | 230 | session->show(m, session); |
|---|
| 234 | 231 | } |
|---|
| 235 | 232 | |
|---|
| .. | .. |
|---|
| 276 | 273 | int rc = -ENOMEM; |
|---|
| 277 | 274 | |
|---|
| 278 | 275 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); |
|---|
| 279 | | - if (pd == NULL) |
|---|
| 276 | + if (!pd) |
|---|
| 280 | 277 | goto out; |
|---|
| 281 | 278 | |
|---|
| 282 | 279 | /* Derive the network namespace from the pid opening the |
|---|
| .. | .. |
|---|
| 330 | 327 | |
|---|
| 331 | 328 | static int __init l2tp_debugfs_init(void) |
|---|
| 332 | 329 | { |
|---|
| 333 | | - int rc = 0; |
|---|
| 334 | | - |
|---|
| 335 | 330 | rootdir = debugfs_create_dir("l2tp", NULL); |
|---|
| 336 | | - if (IS_ERR(rootdir)) { |
|---|
| 337 | | - rc = PTR_ERR(rootdir); |
|---|
| 338 | | - rootdir = NULL; |
|---|
| 339 | | - goto out; |
|---|
| 340 | | - } |
|---|
| 341 | 331 | |
|---|
| 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); |
|---|
| 345 | 333 | |
|---|
| 346 | 334 | pr_info("L2TP debugfs support\n"); |
|---|
| 347 | 335 | |
|---|
| 348 | | -out: |
|---|
| 349 | | - if (rc) |
|---|
| 350 | | - pr_warn("unable to init\n"); |
|---|
| 351 | | - |
|---|
| 352 | | - return rc; |
|---|
| 336 | + return 0; |
|---|
| 353 | 337 | } |
|---|
| 354 | 338 | |
|---|
| 355 | 339 | static void __exit l2tp_debugfs_exit(void) |
|---|
| 356 | 340 | { |
|---|
| 357 | | - debugfs_remove(tunnels); |
|---|
| 358 | | - debugfs_remove(rootdir); |
|---|
| 341 | + debugfs_remove_recursive(rootdir); |
|---|
| 359 | 342 | } |
|---|
| 360 | 343 | |
|---|
| 361 | 344 | module_init(l2tp_debugfs_init); |
|---|