batman-adv: Refresh patches
[feed/routing.git] / batman-adv / patches / 0042-batman-adv-Fix-debugfs-path-for-renamed-hardif.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Fri, 1 Jun 2018 19:24:23 +0200
3 Subject: batman-adv: Fix debugfs path for renamed hardif
4
5 batman-adv is creating special debugfs directories in the init
6 net_namespace for each valid hard-interface (net_device). But it is
7 possible to rename a net_device to a completely different name then the
8 original one.
9
10 It can therefore happen that a user registers a new net_device which gets
11 the name "wlan0" assigned by default. batman-adv is also adding a new
12 directory under $debugfs/batman-adv/ with the name "wlan0".
13
14 The user then decides to rename this device to "wl_pri" and registers a
15 different device. The kernel may now decide to use the name "wlan0" again
16 for this new device. batman-adv will detect it as a valid net_device and
17 tries to create a directory with the name "wlan0" under
18 $debugfs/batman-adv/. But there already exists one with this name under
19 this path and thus this fails. batman-adv will detect a problem and
20 rollback the registering of this device.
21
22 batman-adv must therefore take care of renaming the debugfs directories
23 for hard-interfaces whenever it detects such a net_device rename.
24
25 Fixes: 3c926a01c8e8 ("batman-adv: add debugfs structure for information per interface")
26 Reported-by: John Soros <sorosj@gmail.com>
27 Signed-off-by: Sven Eckelmann <sven@narfation.org>
28
29 Origin: backport, https://git.open-mesh.org/batman-adv.git/commit/127086f503f6495518b95455efebee33d328f335
30
31 diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c
32 index 77925504379dac7d64777393ddae326b5d6d9505..a229d2d9acfd1f3d6fea071aa0df3bf06a0e2ecf 100644
33 --- a/net/batman-adv/debugfs.c
34 +++ b/net/batman-adv/debugfs.c
35 @@ -18,6 +18,7 @@
36 #include "debugfs.h"
37 #include "main.h"
38
39 +#include <linux/dcache.h>
40 #include <linux/debugfs.h>
41 #include <linux/device.h>
42 #include <linux/errno.h>
43 @@ -337,6 +338,25 @@ out:
44 return -ENOMEM;
45 }
46
47 +/**
48 + * batadv_debugfs_rename_hardif() - Fix debugfs path for renamed hardif
49 + * @hard_iface: hard interface which was renamed
50 + */
51 +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface)
52 +{
53 + const char *name = hard_iface->net_dev->name;
54 + struct dentry *dir;
55 + struct dentry *d;
56 +
57 + dir = hard_iface->debug_dir;
58 + if (!dir)
59 + return;
60 +
61 + d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
62 + if (!d)
63 + pr_err("Can't rename debugfs dir to %s\n", name);
64 +}
65 +
66 /**
67 * batadv_debugfs_del_hardif - delete the base directory for a hard interface
68 * in debugfs.
69 diff --git a/net/batman-adv/debugfs.h b/net/batman-adv/debugfs.h
70 index e49121ee55f696547ddc9774ba6c425af2d49b57..3d9b684b862d0aa9d2380fbcb15fd4ef68a4511c 100644
71 --- a/net/batman-adv/debugfs.h
72 +++ b/net/batman-adv/debugfs.h
73 @@ -31,6 +31,7 @@ void batadv_debugfs_destroy(void);
74 int batadv_debugfs_add_meshif(struct net_device *dev);
75 void batadv_debugfs_del_meshif(struct net_device *dev);
76 int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface);
77 +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface);
78 void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface);
79
80 #else
81 @@ -58,6 +59,11 @@ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
82 return 0;
83 }
84
85 +static inline
86 +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface)
87 +{
88 +}
89 +
90 static inline
91 void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface)
92 {
93 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
94 index ebeea5816a06b33c4944b01e40cee157c88bdff7..507eaff8582a8c58adc6d23abc42bb6c31d2816f 100644
95 --- a/net/batman-adv/hard-interface.c
96 +++ b/net/batman-adv/hard-interface.c
97 @@ -1020,6 +1020,9 @@ static int batadv_hard_if_event(struct notifier_block *this,
98 if (batadv_is_wifi_hardif(hard_iface))
99 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
100 break;
101 + case NETDEV_CHANGENAME:
102 + batadv_debugfs_rename_hardif(hard_iface);
103 + break;
104 default:
105 break;
106 }