]>
Commit | Line | Data |
---|---|---|
7db7d9f3 | 1 | // SPDX-License-Identifier: GPL-2.0 |
6b1aea8c | 2 | /* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors: |
c6c8fea2 SE |
3 | * |
4 | * Marek Lindner | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of version 2 of the GNU General Public | |
8 | * License as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
ebf38fb7 | 16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
c6c8fea2 SE |
17 | */ |
18 | ||
1e2c2a4f | 19 | #include "debugfs.h" |
c6c8fea2 SE |
20 | #include "main.h" |
21 | ||
a5dac4da | 22 | #include <asm/current.h> |
36dc621c | 23 | #include <linux/dcache.h> |
c6c8fea2 | 24 | #include <linux/debugfs.h> |
3e7514af | 25 | #include <linux/err.h> |
1e2c2a4f SE |
26 | #include <linux/errno.h> |
27 | #include <linux/export.h> | |
1e2c2a4f | 28 | #include <linux/fs.h> |
1e2c2a4f | 29 | #include <linux/netdevice.h> |
1e2c2a4f | 30 | #include <linux/printk.h> |
a5dac4da | 31 | #include <linux/sched.h> |
1e2c2a4f | 32 | #include <linux/seq_file.h> |
1e2c2a4f SE |
33 | #include <linux/stat.h> |
34 | #include <linux/stddef.h> | |
35 | #include <linux/stringify.h> | |
36 | #include <linux/sysfs.h> | |
94969208 | 37 | #include <net/net_namespace.h> |
c6c8fea2 | 38 | |
01d350d1 | 39 | #include "bat_algo.h" |
9bf8e4d4 | 40 | #include "bridge_loop_avoidance.h" |
2f1dfbe1 | 41 | #include "distributed-arp-table.h" |
1e2c2a4f SE |
42 | #include "gateway_client.h" |
43 | #include "icmp_socket.h" | |
ba412080 | 44 | #include "log.h" |
4e3e823b | 45 | #include "multicast.h" |
d56b1705 | 46 | #include "network-coding.h" |
1e2c2a4f SE |
47 | #include "originator.h" |
48 | #include "translation-table.h" | |
c6c8fea2 | 49 | |
9e466250 | 50 | static struct dentry *batadv_debugfs; |
c6c8fea2 | 51 | |
00caf6a2 SE |
52 | /** |
53 | * batadv_debugfs_deprecated() - Log use of deprecated batadv debugfs access | |
54 | * @file: file which was accessed | |
55 | * @alt: explanation what can be used as alternative | |
56 | */ | |
57 | void batadv_debugfs_deprecated(struct file *file, const char *alt) | |
58 | { | |
59 | struct dentry *dentry = file_dentry(file); | |
60 | const char *name = dentry->d_name.name; | |
61 | ||
62 | pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of debugfs file \"%s\".\n%s", | |
63 | current->comm, task_pid_nr(current), name, alt); | |
64 | } | |
65 | ||
9e466250 | 66 | static int batadv_algorithms_open(struct inode *inode, struct file *file) |
1c280471 | 67 | { |
00caf6a2 SE |
68 | batadv_debugfs_deprecated(file, |
69 | "Use genl command BATADV_CMD_GET_ROUTING_ALGOS instead\n"); | |
3193e8fd | 70 | return single_open(file, batadv_algo_seq_print_text, NULL); |
1c280471 ML |
71 | } |
72 | ||
7587405a ML |
73 | static int neighbors_open(struct inode *inode, struct file *file) |
74 | { | |
75 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
76 | ||
00caf6a2 SE |
77 | batadv_debugfs_deprecated(file, |
78 | "Use genl command BATADV_CMD_GET_NEIGHBORS instead\n"); | |
7587405a ML |
79 | return single_open(file, batadv_hardif_neigh_seq_print_text, net_dev); |
80 | } | |
81 | ||
9e466250 | 82 | static int batadv_originators_open(struct inode *inode, struct file *file) |
c6c8fea2 SE |
83 | { |
84 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 85 | |
00caf6a2 SE |
86 | batadv_debugfs_deprecated(file, |
87 | "Use genl command BATADV_CMD_GET_ORIGINATORS instead\n"); | |
7d211efc | 88 | return single_open(file, batadv_orig_seq_print_text, net_dev); |
c6c8fea2 SE |
89 | } |
90 | ||
cb1c92ec | 91 | /** |
7e9a8c2c SE |
92 | * batadv_originators_hardif_open() - handles debugfs output for the originator |
93 | * table of an hard interface | |
cb1c92ec SW |
94 | * @inode: inode pointer to debugfs file |
95 | * @file: pointer to the seq_file | |
7afcbbef SE |
96 | * |
97 | * Return: 0 on success or negative error number in case of failure | |
cb1c92ec SW |
98 | */ |
99 | static int batadv_originators_hardif_open(struct inode *inode, | |
100 | struct file *file) | |
101 | { | |
102 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 103 | |
00caf6a2 SE |
104 | batadv_debugfs_deprecated(file, |
105 | "Use genl command BATADV_CMD_GET_HARDIFS instead\n"); | |
cb1c92ec SW |
106 | return single_open(file, batadv_orig_hardif_seq_print_text, net_dev); |
107 | } | |
108 | ||
9e466250 | 109 | static int batadv_gateways_open(struct inode *inode, struct file *file) |
c6c8fea2 SE |
110 | { |
111 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 112 | |
00caf6a2 SE |
113 | batadv_debugfs_deprecated(file, |
114 | "Use genl command BATADV_CMD_GET_GATEWAYS instead\n"); | |
7cf06bc6 | 115 | return single_open(file, batadv_gw_client_seq_print_text, net_dev); |
c6c8fea2 SE |
116 | } |
117 | ||
9e466250 | 118 | static int batadv_transtable_global_open(struct inode *inode, struct file *file) |
c6c8fea2 SE |
119 | { |
120 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 121 | |
00caf6a2 SE |
122 | batadv_debugfs_deprecated(file, |
123 | "Use genl command BATADV_CMD_GET_TRANSTABLE_GLOBAL instead\n"); | |
08c36d3e | 124 | return single_open(file, batadv_tt_global_seq_print_text, net_dev); |
c6c8fea2 SE |
125 | } |
126 | ||
7a5cc242 | 127 | #ifdef CONFIG_BATMAN_ADV_BLA |
9e466250 | 128 | static int batadv_bla_claim_table_open(struct inode *inode, struct file *file) |
9bf8e4d4 SW |
129 | { |
130 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 131 | |
00caf6a2 SE |
132 | batadv_debugfs_deprecated(file, |
133 | "Use genl command BATADV_CMD_GET_BLA_CLAIM instead\n"); | |
08adf151 SE |
134 | return single_open(file, batadv_bla_claim_table_seq_print_text, |
135 | net_dev); | |
9bf8e4d4 | 136 | } |
536a23f1 SW |
137 | |
138 | static int batadv_bla_backbone_table_open(struct inode *inode, | |
139 | struct file *file) | |
140 | { | |
141 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 142 | |
00caf6a2 SE |
143 | batadv_debugfs_deprecated(file, |
144 | "Use genl command BATADV_CMD_GET_BLA_BACKBONE instead\n"); | |
536a23f1 SW |
145 | return single_open(file, batadv_bla_backbone_table_seq_print_text, |
146 | net_dev); | |
147 | } | |
148 | ||
7a5cc242 | 149 | #endif |
9bf8e4d4 | 150 | |
17224474 | 151 | #ifdef CONFIG_BATMAN_ADV_DAT |
2f1dfbe1 | 152 | /** |
be01dc33 | 153 | * batadv_dat_cache_open() - Prepare file handler for reads from dat_cache |
2f1dfbe1 AQ |
154 | * @inode: inode which was opened |
155 | * @file: file handle to be initialized | |
7afcbbef SE |
156 | * |
157 | * Return: 0 on success or negative error number in case of failure | |
2f1dfbe1 AQ |
158 | */ |
159 | static int batadv_dat_cache_open(struct inode *inode, struct file *file) | |
160 | { | |
161 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 162 | |
00caf6a2 SE |
163 | batadv_debugfs_deprecated(file, |
164 | "Use genl command BATADV_CMD_GET_DAT_CACHE instead\n"); | |
2f1dfbe1 AQ |
165 | return single_open(file, batadv_dat_cache_seq_print_text, net_dev); |
166 | } | |
17224474 | 167 | #endif |
2f1dfbe1 | 168 | |
9e466250 | 169 | static int batadv_transtable_local_open(struct inode *inode, struct file *file) |
c6c8fea2 SE |
170 | { |
171 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 172 | |
00caf6a2 SE |
173 | batadv_debugfs_deprecated(file, |
174 | "Use genl command BATADV_CMD_GET_TRANSTABLE_LOCAL instead\n"); | |
08c36d3e | 175 | return single_open(file, batadv_tt_local_seq_print_text, net_dev); |
c6c8fea2 SE |
176 | } |
177 | ||
7f223c0c | 178 | struct batadv_debuginfo { |
c6c8fea2 SE |
179 | struct attribute attr; |
180 | const struct file_operations fops; | |
181 | }; | |
182 | ||
d56b1705 MH |
183 | #ifdef CONFIG_BATMAN_ADV_NC |
184 | static int batadv_nc_nodes_open(struct inode *inode, struct file *file) | |
185 | { | |
186 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
f138694b | 187 | |
00caf6a2 | 188 | batadv_debugfs_deprecated(file, ""); |
d56b1705 MH |
189 | return single_open(file, batadv_nc_nodes_seq_print_text, net_dev); |
190 | } | |
191 | #endif | |
192 | ||
4e3e823b LL |
193 | #ifdef CONFIG_BATMAN_ADV_MCAST |
194 | /** | |
7e9a8c2c | 195 | * batadv_mcast_flags_open() - prepare file handler for reads from mcast_flags |
4e3e823b LL |
196 | * @inode: inode which was opened |
197 | * @file: file handle to be initialized | |
198 | * | |
199 | * Return: 0 on success or negative error number in case of failure | |
200 | */ | |
201 | static int batadv_mcast_flags_open(struct inode *inode, struct file *file) | |
202 | { | |
203 | struct net_device *net_dev = (struct net_device *)inode->i_private; | |
204 | ||
00caf6a2 SE |
205 | batadv_debugfs_deprecated(file, |
206 | "Use genl command BATADV_CMD_GET_MCAST_FLAGS instead\n"); | |
4e3e823b LL |
207 | return single_open(file, batadv_mcast_flags_seq_print_text, net_dev); |
208 | } | |
209 | #endif | |
210 | ||
347c80f0 | 211 | #define BATADV_DEBUGINFO(_name, _mode, _open) \ |
7f223c0c | 212 | struct batadv_debuginfo batadv_debuginfo_##_name = { \ |
121bdca0 SW |
213 | .attr = { \ |
214 | .name = __stringify(_name), \ | |
215 | .mode = _mode, \ | |
216 | }, \ | |
217 | .fops = { \ | |
218 | .owner = THIS_MODULE, \ | |
219 | .open = _open, \ | |
220 | .read = seq_read, \ | |
221 | .llseek = seq_lseek, \ | |
222 | .release = single_release, \ | |
223 | }, \ | |
2b64df20 | 224 | } |
c6c8fea2 | 225 | |
637fbd12 AQ |
226 | /* the following attributes are general and therefore they will be directly |
227 | * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs | |
228 | */ | |
507b37cf | 229 | static BATADV_DEBUGINFO(routing_algos, 0444, batadv_algorithms_open); |
637fbd12 AQ |
230 | |
231 | static struct batadv_debuginfo *batadv_general_debuginfos[] = { | |
232 | &batadv_debuginfo_routing_algos, | |
233 | NULL, | |
234 | }; | |
235 | ||
236 | /* The following attributes are per soft interface */ | |
507b37cf SE |
237 | static BATADV_DEBUGINFO(neighbors, 0444, neighbors_open); |
238 | static BATADV_DEBUGINFO(originators, 0444, batadv_originators_open); | |
239 | static BATADV_DEBUGINFO(gateways, 0444, batadv_gateways_open); | |
240 | static BATADV_DEBUGINFO(transtable_global, 0444, batadv_transtable_global_open); | |
7a5cc242 | 241 | #ifdef CONFIG_BATMAN_ADV_BLA |
507b37cf SE |
242 | static BATADV_DEBUGINFO(bla_claim_table, 0444, batadv_bla_claim_table_open); |
243 | static BATADV_DEBUGINFO(bla_backbone_table, 0444, | |
536a23f1 | 244 | batadv_bla_backbone_table_open); |
7a5cc242 | 245 | #endif |
17224474 | 246 | #ifdef CONFIG_BATMAN_ADV_DAT |
507b37cf | 247 | static BATADV_DEBUGINFO(dat_cache, 0444, batadv_dat_cache_open); |
17224474 | 248 | #endif |
507b37cf | 249 | static BATADV_DEBUGINFO(transtable_local, 0444, batadv_transtable_local_open); |
d56b1705 | 250 | #ifdef CONFIG_BATMAN_ADV_NC |
507b37cf | 251 | static BATADV_DEBUGINFO(nc_nodes, 0444, batadv_nc_nodes_open); |
d56b1705 | 252 | #endif |
4e3e823b | 253 | #ifdef CONFIG_BATMAN_ADV_MCAST |
507b37cf | 254 | static BATADV_DEBUGINFO(mcast_flags, 0444, batadv_mcast_flags_open); |
4e3e823b | 255 | #endif |
c6c8fea2 | 256 | |
7f223c0c | 257 | static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { |
7587405a | 258 | &batadv_debuginfo_neighbors, |
9e466250 SE |
259 | &batadv_debuginfo_originators, |
260 | &batadv_debuginfo_gateways, | |
261 | &batadv_debuginfo_transtable_global, | |
7a5cc242 | 262 | #ifdef CONFIG_BATMAN_ADV_BLA |
9e466250 | 263 | &batadv_debuginfo_bla_claim_table, |
536a23f1 | 264 | &batadv_debuginfo_bla_backbone_table, |
7a5cc242 | 265 | #endif |
17224474 | 266 | #ifdef CONFIG_BATMAN_ADV_DAT |
2f1dfbe1 | 267 | &batadv_debuginfo_dat_cache, |
17224474 | 268 | #endif |
9e466250 | 269 | &batadv_debuginfo_transtable_local, |
d56b1705 MH |
270 | #ifdef CONFIG_BATMAN_ADV_NC |
271 | &batadv_debuginfo_nc_nodes, | |
4e3e823b LL |
272 | #endif |
273 | #ifdef CONFIG_BATMAN_ADV_MCAST | |
274 | &batadv_debuginfo_mcast_flags, | |
d56b1705 | 275 | #endif |
c6c8fea2 SE |
276 | NULL, |
277 | }; | |
278 | ||
5bc7c1eb SW |
279 | #define BATADV_HARDIF_DEBUGINFO(_name, _mode, _open) \ |
280 | struct batadv_debuginfo batadv_hardif_debuginfo_##_name = { \ | |
281 | .attr = { \ | |
282 | .name = __stringify(_name), \ | |
283 | .mode = _mode, \ | |
284 | }, \ | |
285 | .fops = { \ | |
286 | .owner = THIS_MODULE, \ | |
287 | .open = _open, \ | |
288 | .read = seq_read, \ | |
289 | .llseek = seq_lseek, \ | |
290 | .release = single_release, \ | |
291 | }, \ | |
2b64df20 | 292 | } |
aa143d28 | 293 | |
507b37cf | 294 | static BATADV_HARDIF_DEBUGINFO(originators, 0444, |
cb1c92ec | 295 | batadv_originators_hardif_open); |
5bc7c1eb SW |
296 | |
297 | static struct batadv_debuginfo *batadv_hardif_debuginfos[] = { | |
cb1c92ec | 298 | &batadv_hardif_debuginfo_originators, |
5bc7c1eb SW |
299 | NULL, |
300 | }; | |
301 | ||
ff15c27c SE |
302 | /** |
303 | * batadv_debugfs_init() - Initialize soft interface independent debugfs entries | |
304 | */ | |
40a072d7 | 305 | void batadv_debugfs_init(void) |
c6c8fea2 | 306 | { |
637fbd12 | 307 | struct batadv_debuginfo **bat_debug; |
1c280471 ML |
308 | struct dentry *file; |
309 | ||
54590e4d | 310 | batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL); |
9e466250 SE |
311 | if (batadv_debugfs == ERR_PTR(-ENODEV)) |
312 | batadv_debugfs = NULL; | |
1c280471 | 313 | |
9e466250 | 314 | if (!batadv_debugfs) |
637fbd12 | 315 | goto err; |
1c280471 | 316 | |
637fbd12 AQ |
317 | for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) { |
318 | file = debugfs_create_file(((*bat_debug)->attr).name, | |
319 | S_IFREG | ((*bat_debug)->attr).mode, | |
320 | batadv_debugfs, NULL, | |
321 | &(*bat_debug)->fops); | |
322 | if (!file) { | |
323 | pr_err("Can't add general debugfs file: %s\n", | |
324 | ((*bat_debug)->attr).name); | |
325 | goto err; | |
326 | } | |
327 | } | |
1c280471 | 328 | |
1c280471 | 329 | return; |
637fbd12 AQ |
330 | err: |
331 | debugfs_remove_recursive(batadv_debugfs); | |
5bc7c1eb | 332 | batadv_debugfs = NULL; |
c6c8fea2 SE |
333 | } |
334 | ||
ff15c27c SE |
335 | /** |
336 | * batadv_debugfs_destroy() - Remove all debugfs entries | |
337 | */ | |
40a072d7 | 338 | void batadv_debugfs_destroy(void) |
c6c8fea2 | 339 | { |
3f87c423 AQ |
340 | debugfs_remove_recursive(batadv_debugfs); |
341 | batadv_debugfs = NULL; | |
c6c8fea2 SE |
342 | } |
343 | ||
5bc7c1eb | 344 | /** |
7e9a8c2c | 345 | * batadv_debugfs_add_hardif() - creates the base directory for a hard interface |
5bc7c1eb SW |
346 | * in debugfs. |
347 | * @hard_iface: hard interface which should be added. | |
7afcbbef SE |
348 | * |
349 | * Return: 0 on success or negative error number in case of failure | |
5bc7c1eb SW |
350 | */ |
351 | int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) | |
352 | { | |
94969208 | 353 | struct net *net = dev_net(hard_iface->net_dev); |
5bc7c1eb SW |
354 | struct batadv_debuginfo **bat_debug; |
355 | struct dentry *file; | |
356 | ||
357 | if (!batadv_debugfs) | |
358 | goto out; | |
359 | ||
94969208 AL |
360 | if (net != &init_net) |
361 | return 0; | |
362 | ||
5bc7c1eb SW |
363 | hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, |
364 | batadv_debugfs); | |
365 | if (!hard_iface->debug_dir) | |
366 | goto out; | |
367 | ||
368 | for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug) { | |
369 | file = debugfs_create_file(((*bat_debug)->attr).name, | |
370 | S_IFREG | ((*bat_debug)->attr).mode, | |
371 | hard_iface->debug_dir, | |
372 | hard_iface->net_dev, | |
373 | &(*bat_debug)->fops); | |
374 | if (!file) | |
375 | goto rem_attr; | |
376 | } | |
377 | ||
378 | return 0; | |
379 | rem_attr: | |
380 | debugfs_remove_recursive(hard_iface->debug_dir); | |
381 | hard_iface->debug_dir = NULL; | |
382 | out: | |
5bc7c1eb | 383 | return -ENOMEM; |
5bc7c1eb SW |
384 | } |
385 | ||
36dc621c SE |
386 | /** |
387 | * batadv_debugfs_rename_hardif() - Fix debugfs path for renamed hardif | |
388 | * @hard_iface: hard interface which was renamed | |
389 | */ | |
390 | void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface) | |
391 | { | |
392 | const char *name = hard_iface->net_dev->name; | |
393 | struct dentry *dir; | |
394 | struct dentry *d; | |
395 | ||
396 | dir = hard_iface->debug_dir; | |
397 | if (!dir) | |
398 | return; | |
399 | ||
400 | d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name); | |
401 | if (!d) | |
402 | pr_err("Can't rename debugfs dir to %s\n", name); | |
403 | } | |
404 | ||
5bc7c1eb | 405 | /** |
7e9a8c2c | 406 | * batadv_debugfs_del_hardif() - delete the base directory for a hard interface |
5bc7c1eb SW |
407 | * in debugfs. |
408 | * @hard_iface: hard interface which is deleted. | |
409 | */ | |
410 | void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) | |
411 | { | |
94969208 AL |
412 | struct net *net = dev_net(hard_iface->net_dev); |
413 | ||
414 | if (net != &init_net) | |
415 | return; | |
416 | ||
5bc7c1eb SW |
417 | if (batadv_debugfs) { |
418 | debugfs_remove_recursive(hard_iface->debug_dir); | |
419 | hard_iface->debug_dir = NULL; | |
420 | } | |
421 | } | |
422 | ||
ff15c27c SE |
423 | /** |
424 | * batadv_debugfs_add_meshif() - Initialize interface dependent debugfs entries | |
425 | * @dev: netdev struct of the soft interface | |
426 | * | |
427 | * Return: 0 on success or negative error number in case of failure | |
428 | */ | |
40a072d7 | 429 | int batadv_debugfs_add_meshif(struct net_device *dev) |
c6c8fea2 | 430 | { |
56303d34 | 431 | struct batadv_priv *bat_priv = netdev_priv(dev); |
7f223c0c | 432 | struct batadv_debuginfo **bat_debug; |
94969208 | 433 | struct net *net = dev_net(dev); |
c6c8fea2 SE |
434 | struct dentry *file; |
435 | ||
9e466250 | 436 | if (!batadv_debugfs) |
c6c8fea2 SE |
437 | goto out; |
438 | ||
94969208 AL |
439 | if (net != &init_net) |
440 | return 0; | |
441 | ||
9e466250 | 442 | bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); |
c6c8fea2 SE |
443 | if (!bat_priv->debug_dir) |
444 | goto out; | |
445 | ||
9039dc7e | 446 | if (batadv_socket_setup(bat_priv) < 0) |
5346c35e SE |
447 | goto rem_attr; |
448 | ||
9e466250 | 449 | if (batadv_debug_log_setup(bat_priv) < 0) |
5346c35e | 450 | goto rem_attr; |
c6c8fea2 | 451 | |
9e466250 | 452 | for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) { |
c6c8fea2 | 453 | file = debugfs_create_file(((*bat_debug)->attr).name, |
0aca2369 SE |
454 | S_IFREG | ((*bat_debug)->attr).mode, |
455 | bat_priv->debug_dir, | |
456 | dev, &(*bat_debug)->fops); | |
c6c8fea2 | 457 | if (!file) { |
3e34819e SE |
458 | batadv_err(dev, "Can't add debugfs file: %s/%s\n", |
459 | dev->name, ((*bat_debug)->attr).name); | |
c6c8fea2 SE |
460 | goto rem_attr; |
461 | } | |
462 | } | |
463 | ||
d56b1705 MH |
464 | if (batadv_nc_init_debugfs(bat_priv) < 0) |
465 | goto rem_attr; | |
466 | ||
c6c8fea2 SE |
467 | return 0; |
468 | rem_attr: | |
469 | debugfs_remove_recursive(bat_priv->debug_dir); | |
470 | bat_priv->debug_dir = NULL; | |
471 | out: | |
c6c8fea2 | 472 | return -ENOMEM; |
c6c8fea2 SE |
473 | } |
474 | ||
6da7be7d SE |
475 | /** |
476 | * batadv_debugfs_rename_meshif() - Fix debugfs path for renamed softif | |
477 | * @dev: net_device which was renamed | |
478 | */ | |
479 | void batadv_debugfs_rename_meshif(struct net_device *dev) | |
480 | { | |
481 | struct batadv_priv *bat_priv = netdev_priv(dev); | |
482 | const char *name = dev->name; | |
483 | struct dentry *dir; | |
484 | struct dentry *d; | |
485 | ||
486 | dir = bat_priv->debug_dir; | |
487 | if (!dir) | |
488 | return; | |
489 | ||
490 | d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name); | |
491 | if (!d) | |
492 | pr_err("Can't rename debugfs dir to %s\n", name); | |
493 | } | |
494 | ||
ff15c27c SE |
495 | /** |
496 | * batadv_debugfs_del_meshif() - Remove interface dependent debugfs entries | |
497 | * @dev: netdev struct of the soft interface | |
498 | */ | |
40a072d7 | 499 | void batadv_debugfs_del_meshif(struct net_device *dev) |
c6c8fea2 | 500 | { |
56303d34 | 501 | struct batadv_priv *bat_priv = netdev_priv(dev); |
94969208 AL |
502 | struct net *net = dev_net(dev); |
503 | ||
504 | if (net != &init_net) | |
505 | return; | |
c6c8fea2 | 506 | |
9e466250 | 507 | batadv_debug_log_cleanup(bat_priv); |
c6c8fea2 | 508 | |
9e466250 | 509 | if (batadv_debugfs) { |
c6c8fea2 SE |
510 | debugfs_remove_recursive(bat_priv->debug_dir); |
511 | bat_priv->debug_dir = NULL; | |
512 | } | |
513 | } |