batman-adv: add patches from 2018.1-maint 2018-06-03
[feed/routing.git] / batman-adv / patches / 0008-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: [PATCH] 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: upstream, https://git.open-mesh.org/batman-adv.git/commit/127086f503f6495518b95455efebee33d328f335
30 ---
31 net/batman-adv/debugfs.c | 20 ++++++++++++++++++++
32 net/batman-adv/debugfs.h | 6 ++++++
33 net/batman-adv/hard-interface.c | 3 +++
34 3 files changed, 29 insertions(+)
35
36 diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c
37 index 4229b01ac7b54008e023df0ed6546a6d541498ba..7e5de7b9f6d53b846cebfa95bf694a20c640b2d6 100644
38 --- a/net/batman-adv/debugfs.c
39 +++ b/net/batman-adv/debugfs.c
40 @@ -19,6 +19,7 @@
41 #include "debugfs.h"
42 #include "main.h"
43
44 +#include <linux/dcache.h>
45 #include <linux/debugfs.h>
46 #include <linux/err.h>
47 #include <linux/errno.h>
48 @@ -343,6 +344,25 @@ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
49 return -ENOMEM;
50 }
51
52 +/**
53 + * batadv_debugfs_rename_hardif() - Fix debugfs path for renamed hardif
54 + * @hard_iface: hard interface which was renamed
55 + */
56 +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface)
57 +{
58 + const char *name = hard_iface->net_dev->name;
59 + struct dentry *dir;
60 + struct dentry *d;
61 +
62 + dir = hard_iface->debug_dir;
63 + if (!dir)
64 + return;
65 +
66 + d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
67 + if (!d)
68 + pr_err("Can't rename debugfs dir to %s\n", name);
69 +}
70 +
71 /**
72 * batadv_debugfs_del_hardif() - delete the base directory for a hard interface
73 * in debugfs.
74 diff --git a/net/batman-adv/debugfs.h b/net/batman-adv/debugfs.h
75 index 37b069698b04b369e68e4e8a31c3ac01575b0178..8538a7a75e937f50f8efdbf2fe879b4ac8dafadb 100644
76 --- a/net/batman-adv/debugfs.h
77 +++ b/net/batman-adv/debugfs.h
78 @@ -32,6 +32,7 @@ void batadv_debugfs_destroy(void);
79 int batadv_debugfs_add_meshif(struct net_device *dev);
80 void batadv_debugfs_del_meshif(struct net_device *dev);
81 int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface);
82 +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface);
83 void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface);
84
85 #else
86 @@ -59,6 +60,11 @@ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
87 return 0;
88 }
89
90 +static inline
91 +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface)
92 +{
93 +}
94 +
95 static inline
96 void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface)
97 {
98 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
99 index c405d15befd60bdabf9f50813c3bee446238d539..dc2763b1110727cc5dee62d555dd7c7b50f3b463 100644
100 --- a/net/batman-adv/hard-interface.c
101 +++ b/net/batman-adv/hard-interface.c
102 @@ -1051,6 +1051,9 @@ static int batadv_hard_if_event(struct notifier_block *this,
103 if (batadv_is_wifi_hardif(hard_iface))
104 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
105 break;
106 + case NETDEV_CHANGENAME:
107 + batadv_debugfs_rename_hardif(hard_iface);
108 + break;
109 default:
110 break;
111 }