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