blob: e78bd7f2f276b67716cd58df403a35e68578df90 [file] [log] [blame]
Sven Eckelmann0046b042016-01-01 00:01:03 +01001/* Copyright (C) 2010-2016 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00002 *
3 * Marek Lindner
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
Antonio Quartulliebf38fb2013-11-03 20:40:48 +010015 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000016 */
17
Sven Eckelmannb706b132012-06-10 23:58:51 +020018#include "sysfs.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020019#include "main.h"
20
21#include <linux/atomic.h>
22#include <linux/compiler.h>
23#include <linux/device.h>
24#include <linux/errno.h>
25#include <linux/fs.h>
26#include <linux/if.h>
27#include <linux/if_vlan.h>
28#include <linux/kernel.h>
Sven Eckelmannfcafa5e2016-05-15 11:07:42 +020029#include <linux/kref.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020030#include <linux/netdevice.h>
31#include <linux/printk.h>
32#include <linux/rculist.h>
33#include <linux/rcupdate.h>
34#include <linux/rtnetlink.h>
35#include <linux/slab.h>
36#include <linux/stat.h>
37#include <linux/stddef.h>
38#include <linux/string.h>
39#include <linux/stringify.h>
Sven Eckelmann77d69d82016-06-13 07:41:30 +020040#include <linux/workqueue.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020041
Sven Eckelmannfcafa5e2016-05-15 11:07:42 +020042#include "bridge_loop_avoidance.h"
Antonio Quartulli33af49a2012-08-08 18:50:57 +020043#include "distributed-arp-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000044#include "gateway_client.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020045#include "gateway_common.h"
46#include "hard-interface.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020047#include "log.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020048#include "network-coding.h"
49#include "packet.h"
50#include "soft-interface.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000051
Sven Eckelmann0ff9b862012-05-12 18:33:52 +020052static struct net_device *batadv_kobj_to_netdev(struct kobject *obj)
Sven Eckelmann3d222bb2011-06-05 10:20:19 +020053{
54 struct device *dev = container_of(obj->parent, struct device, kobj);
Antonio Quartullif1386942014-05-10 18:56:37 +020055
Sven Eckelmann3d222bb2011-06-05 10:20:19 +020056 return to_net_dev(dev);
57}
58
Sven Eckelmann56303d32012-06-05 22:31:31 +020059static struct batadv_priv *batadv_kobj_to_batpriv(struct kobject *obj)
Sven Eckelmann3d222bb2011-06-05 10:20:19 +020060{
Sven Eckelmann0ff9b862012-05-12 18:33:52 +020061 struct net_device *net_dev = batadv_kobj_to_netdev(obj);
Antonio Quartullif1386942014-05-10 18:56:37 +020062
Sven Eckelmann3d222bb2011-06-05 10:20:19 +020063 return netdev_priv(net_dev);
64}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000065
Antonio Quartulli90f44352013-07-02 11:04:35 +020066/**
67 * batadv_vlan_kobj_to_batpriv - convert a vlan kobj in the associated batpriv
68 * @obj: kobject to covert
69 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +020070 * Return: the associated batadv_priv struct.
Antonio Quartulli90f44352013-07-02 11:04:35 +020071 */
72static struct batadv_priv *batadv_vlan_kobj_to_batpriv(struct kobject *obj)
73{
74 /* VLAN specific attributes are located in the root sysfs folder if they
75 * refer to the untagged VLAN..
76 */
77 if (!strcmp(BATADV_SYSFS_IF_MESH_SUBDIR, obj->name))
78 return batadv_kobj_to_batpriv(obj);
79
80 /* ..while the attributes for the tagged vlans are located in
81 * the in the corresponding "vlan%VID" subfolder
82 */
83 return batadv_kobj_to_batpriv(obj->parent);
84}
85
86/**
87 * batadv_kobj_to_vlan - convert a kobj in the associated softif_vlan struct
Sven Eckelmann7afcbbe2015-10-31 12:29:29 +010088 * @bat_priv: the bat priv with all the soft interface information
Antonio Quartulli90f44352013-07-02 11:04:35 +020089 * @obj: kobject to covert
90 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +020091 * Return: the associated softif_vlan struct if found, NULL otherwise.
Antonio Quartulli90f44352013-07-02 11:04:35 +020092 */
93static struct batadv_softif_vlan *
94batadv_kobj_to_vlan(struct batadv_priv *bat_priv, struct kobject *obj)
95{
96 struct batadv_softif_vlan *vlan_tmp, *vlan = NULL;
97
98 rcu_read_lock();
99 hlist_for_each_entry_rcu(vlan_tmp, &bat_priv->softif_vlan_list, list) {
100 if (vlan_tmp->kobj != obj)
101 continue;
102
Sven Eckelmann6be4d302016-01-16 10:29:42 +0100103 if (!kref_get_unless_zero(&vlan_tmp->refcount))
Antonio Quartulli90f44352013-07-02 11:04:35 +0200104 continue;
105
106 vlan = vlan_tmp;
107 break;
108 }
109 rcu_read_unlock();
110
111 return vlan;
112}
113
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200114#define BATADV_UEV_TYPE_VAR "BATTYPE="
115#define BATADV_UEV_ACTION_VAR "BATACTION="
116#define BATADV_UEV_DATA_VAR "BATDATA="
Antonio Quartullic6bda682011-04-26 18:26:01 +0200117
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200118static char *batadv_uev_action_str[] = {
Antonio Quartullic6bda682011-04-26 18:26:01 +0200119 "add",
120 "del",
Simon Wunderlichcd9c7bf2016-03-12 10:49:33 +0100121 "change",
122 "loopdetect",
Antonio Quartullic6bda682011-04-26 18:26:01 +0200123};
124
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200125static char *batadv_uev_type_str[] = {
Simon Wunderlichcd9c7bf2016-03-12 10:49:33 +0100126 "gw",
127 "bla",
Antonio Quartullic6bda682011-04-26 18:26:01 +0200128};
129
Antonio Quartulli90f44352013-07-02 11:04:35 +0200130/* Use this, if you have customized show and store functions for vlan attrs */
131#define BATADV_ATTR_VLAN(_name, _mode, _show, _store) \
132struct batadv_attribute batadv_attr_vlan_##_name = { \
133 .attr = {.name = __stringify(_name), \
134 .mode = _mode }, \
135 .show = _show, \
136 .store = _store, \
Antonio Quartulli2b64df22014-05-15 11:24:26 +0200137}
Antonio Quartulli90f44352013-07-02 11:04:35 +0200138
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000139/* Use this, if you have customized show and store functions */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200140#define BATADV_ATTR(_name, _mode, _show, _store) \
Sven Eckelmannb4d66b82012-06-05 22:31:29 +0200141struct batadv_attribute batadv_attr_##_name = { \
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200142 .attr = {.name = __stringify(_name), \
143 .mode = _mode }, \
144 .show = _show, \
145 .store = _store, \
Antonio Quartulli2b64df22014-05-15 11:24:26 +0200146}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000147
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200148#define BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200149ssize_t batadv_store_##_name(struct kobject *kobj, \
150 struct attribute *attr, char *buff, \
151 size_t count) \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000152{ \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200153 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
Sven Eckelmann56303d32012-06-05 22:31:31 +0200154 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
Antonio Quartullif1386942014-05-10 18:56:37 +0200155 \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200156 return __batadv_store_bool_attr(buff, count, _post_func, attr, \
157 &bat_priv->_name, net_dev); \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000158}
159
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200160#define BATADV_ATTR_SIF_SHOW_BOOL(_name) \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200161ssize_t batadv_show_##_name(struct kobject *kobj, \
162 struct attribute *attr, char *buff) \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000163{ \
Sven Eckelmann56303d32012-06-05 22:31:31 +0200164 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
Antonio Quartullif1386942014-05-10 18:56:37 +0200165 \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000166 return sprintf(buff, "%s\n", \
167 atomic_read(&bat_priv->_name) == 0 ? \
168 "disabled" : "enabled"); \
169} \
170
Marek Lindnerf245c382012-03-11 06:17:51 +0800171/* Use this, if you are going to turn a [name] in the soft-interface
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200172 * (bat_priv) on or off
173 */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200174#define BATADV_ATTR_SIF_BOOL(_name, _mode, _post_func) \
175 static BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
176 static BATADV_ATTR_SIF_SHOW_BOOL(_name) \
177 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
178 batadv_store_##_name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000179
Antonio Quartulli6f70eb72015-03-01 00:50:16 +0800180#define BATADV_ATTR_SIF_STORE_UINT(_name, _var, _min, _max, _post_func) \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200181ssize_t batadv_store_##_name(struct kobject *kobj, \
182 struct attribute *attr, char *buff, \
183 size_t count) \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000184{ \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200185 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
Sven Eckelmann56303d32012-06-05 22:31:31 +0200186 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
Antonio Quartullif1386942014-05-10 18:56:37 +0200187 \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200188 return __batadv_store_uint_attr(buff, count, _min, _max, \
189 _post_func, attr, \
Antonio Quartulli6f70eb72015-03-01 00:50:16 +0800190 &bat_priv->_var, net_dev); \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000191}
192
Antonio Quartulli6f70eb72015-03-01 00:50:16 +0800193#define BATADV_ATTR_SIF_SHOW_UINT(_name, _var) \
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200194ssize_t batadv_show_##_name(struct kobject *kobj, \
195 struct attribute *attr, char *buff) \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000196{ \
Sven Eckelmann56303d32012-06-05 22:31:31 +0200197 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
Antonio Quartullif1386942014-05-10 18:56:37 +0200198 \
Antonio Quartulli6f70eb72015-03-01 00:50:16 +0800199 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_var)); \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000200} \
201
Marek Lindnerf245c382012-03-11 06:17:51 +0800202/* Use this, if you are going to set [name] in the soft-interface
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200203 * (bat_priv) to an unsigned integer value
204 */
Antonio Quartulli6f70eb72015-03-01 00:50:16 +0800205#define BATADV_ATTR_SIF_UINT(_name, _var, _mode, _min, _max, _post_func)\
206 static BATADV_ATTR_SIF_STORE_UINT(_name, _var, _min, _max, _post_func)\
207 static BATADV_ATTR_SIF_SHOW_UINT(_name, _var) \
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200208 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
209 batadv_store_##_name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000210
Antonio Quartulli90f44352013-07-02 11:04:35 +0200211#define BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \
212ssize_t batadv_store_vlan_##_name(struct kobject *kobj, \
213 struct attribute *attr, char *buff, \
214 size_t count) \
215{ \
216 struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
217 struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
218 kobj); \
219 size_t res = __batadv_store_bool_attr(buff, count, _post_func, \
220 attr, &vlan->_name, \
221 bat_priv->soft_iface); \
Antonio Quartullif1386942014-05-10 18:56:37 +0200222 \
Sven Eckelmann9c3bf082016-01-17 11:01:21 +0100223 batadv_softif_vlan_put(vlan); \
Antonio Quartulli90f44352013-07-02 11:04:35 +0200224 return res; \
225}
226
227#define BATADV_ATTR_VLAN_SHOW_BOOL(_name) \
228ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \
229 struct attribute *attr, char *buff) \
230{ \
231 struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
232 struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
233 kobj); \
234 size_t res = sprintf(buff, "%s\n", \
235 atomic_read(&vlan->_name) == 0 ? \
236 "disabled" : "enabled"); \
Antonio Quartullif1386942014-05-10 18:56:37 +0200237 \
Sven Eckelmann9c3bf082016-01-17 11:01:21 +0100238 batadv_softif_vlan_put(vlan); \
Antonio Quartulli90f44352013-07-02 11:04:35 +0200239 return res; \
240}
241
242/* Use this, if you are going to turn a [name] in the vlan struct on or off */
243#define BATADV_ATTR_VLAN_BOOL(_name, _mode, _post_func) \
244 static BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \
245 static BATADV_ATTR_VLAN_SHOW_BOOL(_name) \
246 static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \
247 batadv_store_vlan_##_name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000248
Linus Luessing0744ff82016-01-16 16:40:08 +0800249#define BATADV_ATTR_HIF_STORE_UINT(_name, _var, _min, _max, _post_func) \
250ssize_t batadv_store_##_name(struct kobject *kobj, \
251 struct attribute *attr, char *buff, \
252 size_t count) \
253{ \
254 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
255 struct batadv_hard_iface *hard_iface; \
256 ssize_t length; \
257 \
258 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
259 if (!hard_iface) \
260 return 0; \
261 \
262 length = __batadv_store_uint_attr(buff, count, _min, _max, \
263 _post_func, attr, \
264 &hard_iface->_var, net_dev); \
265 \
266 batadv_hardif_put(hard_iface); \
267 return length; \
268}
269
270#define BATADV_ATTR_HIF_SHOW_UINT(_name, _var) \
271ssize_t batadv_show_##_name(struct kobject *kobj, \
272 struct attribute *attr, char *buff) \
273{ \
274 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
275 struct batadv_hard_iface *hard_iface; \
276 ssize_t length; \
277 \
278 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
279 if (!hard_iface) \
280 return 0; \
281 \
282 length = sprintf(buff, "%i\n", atomic_read(&hard_iface->_var)); \
283 \
284 batadv_hardif_put(hard_iface); \
285 return length; \
286}
287
288/* Use this, if you are going to set [name] in hard_iface to an
289 * unsigned integer value
290 */
291#define BATADV_ATTR_HIF_UINT(_name, _var, _mode, _min, _max, _post_func)\
292 static BATADV_ATTR_HIF_STORE_UINT(_name, _var, _min, \
293 _max, _post_func) \
294 static BATADV_ATTR_HIF_SHOW_UINT(_name, _var) \
295 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
296 batadv_store_##_name)
297
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200298static int batadv_store_bool_attr(char *buff, size_t count,
299 struct net_device *net_dev,
Simon Wunderlich9e728e82015-11-17 14:11:26 +0100300 const char *attr_name, atomic_t *attr,
301 bool *changed)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000302{
303 int enabled = -1;
304
Simon Wunderlich9e728e82015-11-17 14:11:26 +0100305 *changed = false;
306
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000307 if (buff[count - 1] == '\n')
308 buff[count - 1] = '\0';
309
310 if ((strncmp(buff, "1", 2) == 0) ||
311 (strncmp(buff, "enable", 7) == 0) ||
312 (strncmp(buff, "enabled", 8) == 0))
313 enabled = 1;
314
315 if ((strncmp(buff, "0", 2) == 0) ||
316 (strncmp(buff, "disable", 8) == 0) ||
317 (strncmp(buff, "disabled", 9) == 0))
318 enabled = 0;
319
320 if (enabled < 0) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200321 batadv_info(net_dev, "%s: Invalid parameter received: %s\n",
322 attr_name, buff);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000323 return -EINVAL;
324 }
325
326 if (atomic_read(attr) == enabled)
327 return count;
328
Sven Eckelmann3e348192012-05-16 20:23:22 +0200329 batadv_info(net_dev, "%s: Changing from: %s to: %s\n", attr_name,
330 atomic_read(attr) == 1 ? "enabled" : "disabled",
331 enabled == 1 ? "enabled" : "disabled");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000332
Simon Wunderlich9e728e82015-11-17 14:11:26 +0100333 *changed = true;
334
Eric Dumazet95c96172012-04-15 05:58:06 +0000335 atomic_set(attr, (unsigned int)enabled);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000336 return count;
337}
338
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200339static inline ssize_t
340__batadv_store_bool_attr(char *buff, size_t count,
341 void (*post_func)(struct net_device *),
342 struct attribute *attr,
343 atomic_t *attr_store, struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000344{
Simon Wunderlich9e728e82015-11-17 14:11:26 +0100345 bool changed;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000346 int ret;
347
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200348 ret = batadv_store_bool_attr(buff, count, net_dev, attr->name,
Simon Wunderlich9e728e82015-11-17 14:11:26 +0100349 attr_store, &changed);
350 if (post_func && changed)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000351 post_func(net_dev);
352
353 return ret;
354}
355
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200356static int batadv_store_uint_attr(const char *buff, size_t count,
357 struct net_device *net_dev,
358 const char *attr_name,
359 unsigned int min, unsigned int max,
360 atomic_t *attr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000361{
362 unsigned long uint_val;
363 int ret;
364
Sven Eckelmann25a92b12011-09-30 13:32:01 +0200365 ret = kstrtoul(buff, 10, &uint_val);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000366 if (ret) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200367 batadv_info(net_dev, "%s: Invalid parameter received: %s\n",
368 attr_name, buff);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000369 return -EINVAL;
370 }
371
372 if (uint_val < min) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200373 batadv_info(net_dev, "%s: Value is too small: %lu min: %u\n",
374 attr_name, uint_val, min);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000375 return -EINVAL;
376 }
377
378 if (uint_val > max) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200379 batadv_info(net_dev, "%s: Value is too big: %lu max: %u\n",
380 attr_name, uint_val, max);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000381 return -EINVAL;
382 }
383
384 if (atomic_read(attr) == uint_val)
385 return count;
386
Sven Eckelmann3e348192012-05-16 20:23:22 +0200387 batadv_info(net_dev, "%s: Changing from: %i to: %lu\n",
388 attr_name, atomic_read(attr), uint_val);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000389
390 atomic_set(attr, uint_val);
391 return count;
392}
393
Antonio Quartullic149ca72016-05-06 02:46:37 +0800394static ssize_t __batadv_store_uint_attr(const char *buff, size_t count,
395 int min, int max,
396 void (*post_func)(struct net_device *),
397 const struct attribute *attr,
398 atomic_t *attr_store,
399 struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000400{
401 int ret;
402
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200403 ret = batadv_store_uint_attr(buff, count, net_dev, attr->name, min, max,
404 attr_store);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000405 if (post_func && ret)
406 post_func(net_dev);
407
408 return ret;
409}
410
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200411static ssize_t batadv_show_bat_algo(struct kobject *kobj,
412 struct attribute *attr, char *buff)
Marek Lindnerea3d2fd2011-11-29 00:15:37 +0800413{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200414 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
Antonio Quartullif1386942014-05-10 18:56:37 +0200415
Antonio Quartulli29824a52016-05-25 23:27:31 +0800416 return sprintf(buff, "%s\n", bat_priv->algo_ops->name);
Marek Lindnerea3d2fd2011-11-29 00:15:37 +0800417}
418
Antonio Quartulli4e820e72013-11-04 20:59:41 +0100419static void batadv_post_gw_reselect(struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000420{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200421 struct batadv_priv *bat_priv = netdev_priv(net_dev);
Antonio Quartullif1386942014-05-10 18:56:37 +0200422
Antonio Quartulli4e820e72013-11-04 20:59:41 +0100423 batadv_gw_reselect(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000424}
425
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200426static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr,
427 char *buff)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000428{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200429 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000430 int bytes_written;
431
Antonio Quartulli3a24a632016-05-06 02:46:38 +0800432 switch (atomic_read(&bat_priv->gw.mode)) {
Sven Eckelmanncd646ab2012-06-03 22:19:18 +0200433 case BATADV_GW_MODE_CLIENT:
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200434 bytes_written = sprintf(buff, "%s\n",
435 BATADV_GW_MODE_CLIENT_NAME);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000436 break;
Sven Eckelmanncd646ab2012-06-03 22:19:18 +0200437 case BATADV_GW_MODE_SERVER:
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200438 bytes_written = sprintf(buff, "%s\n",
439 BATADV_GW_MODE_SERVER_NAME);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000440 break;
441 default:
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200442 bytes_written = sprintf(buff, "%s\n",
443 BATADV_GW_MODE_OFF_NAME);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000444 break;
445 }
446
447 return bytes_written;
448}
449
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200450static ssize_t batadv_store_gw_mode(struct kobject *kobj,
451 struct attribute *attr, char *buff,
452 size_t count)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000453{
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200454 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200455 struct batadv_priv *bat_priv = netdev_priv(net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000456 char *curr_gw_mode_str;
457 int gw_mode_tmp = -1;
458
459 if (buff[count - 1] == '\n')
460 buff[count - 1] = '\0';
461
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200462 if (strncmp(buff, BATADV_GW_MODE_OFF_NAME,
463 strlen(BATADV_GW_MODE_OFF_NAME)) == 0)
Sven Eckelmanncd646ab2012-06-03 22:19:18 +0200464 gw_mode_tmp = BATADV_GW_MODE_OFF;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000465
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200466 if (strncmp(buff, BATADV_GW_MODE_CLIENT_NAME,
467 strlen(BATADV_GW_MODE_CLIENT_NAME)) == 0)
Sven Eckelmanncd646ab2012-06-03 22:19:18 +0200468 gw_mode_tmp = BATADV_GW_MODE_CLIENT;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000469
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200470 if (strncmp(buff, BATADV_GW_MODE_SERVER_NAME,
471 strlen(BATADV_GW_MODE_SERVER_NAME)) == 0)
Sven Eckelmanncd646ab2012-06-03 22:19:18 +0200472 gw_mode_tmp = BATADV_GW_MODE_SERVER;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000473
474 if (gw_mode_tmp < 0) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200475 batadv_info(net_dev,
476 "Invalid parameter for 'gw mode' setting received: %s\n",
477 buff);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000478 return -EINVAL;
479 }
480
Antonio Quartulli3a24a632016-05-06 02:46:38 +0800481 if (atomic_read(&bat_priv->gw.mode) == gw_mode_tmp)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000482 return count;
483
Antonio Quartulli3a24a632016-05-06 02:46:38 +0800484 switch (atomic_read(&bat_priv->gw.mode)) {
Sven Eckelmanncd646ab2012-06-03 22:19:18 +0200485 case BATADV_GW_MODE_CLIENT:
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200486 curr_gw_mode_str = BATADV_GW_MODE_CLIENT_NAME;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000487 break;
Sven Eckelmanncd646ab2012-06-03 22:19:18 +0200488 case BATADV_GW_MODE_SERVER:
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200489 curr_gw_mode_str = BATADV_GW_MODE_SERVER_NAME;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000490 break;
491 default:
Sven Eckelmann97ea4ba2012-06-03 22:19:11 +0200492 curr_gw_mode_str = BATADV_GW_MODE_OFF_NAME;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000493 break;
494 }
495
Sven Eckelmann3e348192012-05-16 20:23:22 +0200496 batadv_info(net_dev, "Changing gw mode from: %s to: %s\n",
497 curr_gw_mode_str, buff);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000498
Antonio Quartullif3163182013-11-04 20:59:40 +0100499 /* Invoking batadv_gw_reselect() is not enough to really de-select the
500 * current GW. It will only instruct the gateway client code to perform
501 * a re-election the next time that this is needed.
502 *
503 * When gw client mode is being switched off the current GW must be
504 * de-selected explicitly otherwise no GW_ADD uevent is thrown on
505 * client mode re-activation. This is operation is performed in
506 * batadv_gw_check_client_stop().
507 */
Antonio Quartulli4e820e72013-11-04 20:59:41 +0100508 batadv_gw_reselect(bat_priv);
Antonio Quartullic6eaa3f2013-07-13 00:06:00 +0200509 /* always call batadv_gw_check_client_stop() before changing the gateway
510 * state
511 */
512 batadv_gw_check_client_stop(bat_priv);
Antonio Quartulli3a24a632016-05-06 02:46:38 +0800513 atomic_set(&bat_priv->gw.mode, (unsigned int)gw_mode_tmp);
Marek Lindner414254e2013-04-23 21:39:58 +0800514 batadv_gw_tvlv_container_update(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000515 return count;
516}
517
Antonio Quartulli08686942016-07-03 12:46:32 +0200518static ssize_t batadv_show_gw_sel_class(struct kobject *kobj,
519 struct attribute *attr, char *buff)
520{
521 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
522
523 if (bat_priv->algo_ops->gw.show_sel_class)
524 return bat_priv->algo_ops->gw.show_sel_class(bat_priv, buff);
525
526 return sprintf(buff, "%i\n", atomic_read(&bat_priv->gw.sel_class));
527}
528
529static ssize_t batadv_store_gw_sel_class(struct kobject *kobj,
530 struct attribute *attr, char *buff,
531 size_t count)
532{
533 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
534
535 if (buff[count - 1] == '\n')
536 buff[count - 1] = '\0';
537
538 if (bat_priv->algo_ops->gw.store_sel_class)
539 return bat_priv->algo_ops->gw.store_sel_class(bat_priv, buff,
540 count);
541
542 return __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE,
543 batadv_post_gw_reselect, attr,
544 &bat_priv->gw.sel_class,
545 bat_priv->soft_iface);
546}
547
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200548static ssize_t batadv_show_gw_bwidth(struct kobject *kobj,
549 struct attribute *attr, char *buff)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000550{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200551 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
Sven Eckelmann6b5e9712015-05-26 18:34:26 +0200552 u32 down, up;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000553
Marek Lindner414254e2013-04-23 21:39:58 +0800554 down = atomic_read(&bat_priv->gw.bandwidth_down);
555 up = atomic_read(&bat_priv->gw.bandwidth_up);
556
557 return sprintf(buff, "%u.%u/%u.%u MBit\n", down / 10,
558 down % 10, up / 10, up % 10);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000559}
560
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200561static ssize_t batadv_store_gw_bwidth(struct kobject *kobj,
562 struct attribute *attr, char *buff,
563 size_t count)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000564{
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200565 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000566
567 if (buff[count - 1] == '\n')
568 buff[count - 1] = '\0';
569
Sven Eckelmann84d5e5e2012-05-12 02:09:30 +0200570 return batadv_gw_bandwidth_set(net_dev, buff, count);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000571}
572
Antonio Quartullic42edfe2013-11-16 12:03:47 +0100573/**
574 * batadv_show_isolation_mark - print the current isolation mark/mask
575 * @kobj: kobject representing the private mesh sysfs directory
576 * @attr: the batman-adv attribute the user is interacting with
577 * @buff: the buffer that will contain the data to send back to the user
578 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200579 * Return: the number of bytes written into 'buff' on success or a negative
Antonio Quartullic42edfe2013-11-16 12:03:47 +0100580 * error code in case of failure
581 */
582static ssize_t batadv_show_isolation_mark(struct kobject *kobj,
583 struct attribute *attr, char *buff)
584{
585 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
586
587 return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark,
588 bat_priv->isolation_mark_mask);
589}
590
591/**
592 * batadv_store_isolation_mark - parse and store the isolation mark/mask entered
593 * by the user
594 * @kobj: kobject representing the private mesh sysfs directory
595 * @attr: the batman-adv attribute the user is interacting with
596 * @buff: the buffer containing the user data
597 * @count: number of bytes in the buffer
598 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200599 * Return: 'count' on success or a negative error code in case of failure
Antonio Quartullic42edfe2013-11-16 12:03:47 +0100600 */
601static ssize_t batadv_store_isolation_mark(struct kobject *kobj,
602 struct attribute *attr, char *buff,
603 size_t count)
604{
605 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
606 struct batadv_priv *bat_priv = netdev_priv(net_dev);
Sven Eckelmann6b5e9712015-05-26 18:34:26 +0200607 u32 mark, mask;
Antonio Quartullic42edfe2013-11-16 12:03:47 +0100608 char *mask_ptr;
609
610 /* parse the mask if it has been specified, otherwise assume the mask is
611 * the biggest possible
612 */
613 mask = 0xFFFFFFFF;
614 mask_ptr = strchr(buff, '/');
615 if (mask_ptr) {
616 *mask_ptr = '\0';
617 mask_ptr++;
618
619 /* the mask must be entered in hex base as it is going to be a
620 * bitmask and not a prefix length
621 */
622 if (kstrtou32(mask_ptr, 16, &mask) < 0)
623 return -EINVAL;
624 }
625
626 /* the mark can be entered in any base */
627 if (kstrtou32(buff, 0, &mark) < 0)
628 return -EINVAL;
629
630 bat_priv->isolation_mark_mask = mask;
631 /* erase bits not covered by the mask */
632 bat_priv->isolation_mark = mark & bat_priv->isolation_mark_mask;
633
634 batadv_info(net_dev,
635 "New skb mark for extended isolation: %#.8x/%#.8x\n",
636 bat_priv->isolation_mark, bat_priv->isolation_mark_mask);
637
638 return count;
639}
640
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200641BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL);
642BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100643#ifdef CONFIG_BATMAN_ADV_BLA
Simon Wunderlichd68081a2015-11-09 16:20:52 +0100644BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR,
645 batadv_bla_status_update);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100646#endif
Antonio Quartulli33af49a2012-08-08 18:50:57 +0200647#ifdef CONFIG_BATMAN_ADV_DAT
Marek Lindner17cf0ea2013-04-23 21:39:59 +0800648BATADV_ATTR_SIF_BOOL(distributed_arp_table, S_IRUGO | S_IWUSR,
649 batadv_dat_status_update);
Antonio Quartulli33af49a2012-08-08 18:50:57 +0200650#endif
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200651BATADV_ATTR_SIF_BOOL(fragmentation, S_IRUGO | S_IWUSR, batadv_update_min_mtu);
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200652static BATADV_ATTR(routing_algo, S_IRUGO, batadv_show_bat_algo, NULL);
653static BATADV_ATTR(gw_mode, S_IRUGO | S_IWUSR, batadv_show_gw_mode,
654 batadv_store_gw_mode);
Antonio Quartulli6f70eb72015-03-01 00:50:16 +0800655BATADV_ATTR_SIF_UINT(orig_interval, orig_interval, S_IRUGO | S_IWUSR,
656 2 * BATADV_JITTER, INT_MAX, NULL);
657BATADV_ATTR_SIF_UINT(hop_penalty, hop_penalty, S_IRUGO | S_IWUSR, 0,
658 BATADV_TQ_MAX_VALUE, NULL);
Antonio Quartulli08686942016-07-03 12:46:32 +0200659static BATADV_ATTR(gw_sel_class, S_IRUGO | S_IWUSR, batadv_show_gw_sel_class,
660 batadv_store_gw_sel_class);
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200661static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth,
662 batadv_store_gw_bwidth);
Linus Lüssing1d8ab8d2014-02-15 17:47:52 +0100663#ifdef CONFIG_BATMAN_ADV_MCAST
664BATADV_ATTR_SIF_BOOL(multicast_mode, S_IRUGO | S_IWUSR, NULL);
665#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000666#ifdef CONFIG_BATMAN_ADV_DEBUG
Antonio Quartulli6f70eb72015-03-01 00:50:16 +0800667BATADV_ATTR_SIF_UINT(log_level, log_level, S_IRUGO | S_IWUSR, 0,
668 BATADV_DBG_ALL, NULL);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000669#endif
Martin Hundebølld353d8d2013-01-25 11:12:38 +0100670#ifdef CONFIG_BATMAN_ADV_NC
Marek Lindner3f4841f2013-04-23 21:40:00 +0800671BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR,
672 batadv_nc_status_update);
Martin Hundebølld353d8d2013-01-25 11:12:38 +0100673#endif
Antonio Quartullic42edfe2013-11-16 12:03:47 +0100674static BATADV_ATTR(isolation_mark, S_IRUGO | S_IWUSR,
675 batadv_show_isolation_mark, batadv_store_isolation_mark);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000676
Sven Eckelmannb4d66b82012-06-05 22:31:29 +0200677static struct batadv_attribute *batadv_mesh_attrs[] = {
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200678 &batadv_attr_aggregated_ogms,
679 &batadv_attr_bonding,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100680#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200681 &batadv_attr_bridge_loop_avoidance,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100682#endif
Antonio Quartulli33af49a2012-08-08 18:50:57 +0200683#ifdef CONFIG_BATMAN_ADV_DAT
684 &batadv_attr_distributed_arp_table,
685#endif
Linus Lüssing1d8ab8d2014-02-15 17:47:52 +0100686#ifdef CONFIG_BATMAN_ADV_MCAST
687 &batadv_attr_multicast_mode,
688#endif
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200689 &batadv_attr_fragmentation,
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200690 &batadv_attr_routing_algo,
691 &batadv_attr_gw_mode,
692 &batadv_attr_orig_interval,
693 &batadv_attr_hop_penalty,
694 &batadv_attr_gw_sel_class,
695 &batadv_attr_gw_bandwidth,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000696#ifdef CONFIG_BATMAN_ADV_DEBUG
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200697 &batadv_attr_log_level,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000698#endif
Martin Hundebølld353d8d2013-01-25 11:12:38 +0100699#ifdef CONFIG_BATMAN_ADV_NC
700 &batadv_attr_network_coding,
701#endif
Antonio Quartullic42edfe2013-11-16 12:03:47 +0100702 &batadv_attr_isolation_mark,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000703 NULL,
704};
705
Antonio Quartullib8cbd812013-07-02 11:04:36 +0200706BATADV_ATTR_VLAN_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL);
707
Sven Eckelmannf34ac9d2015-09-06 21:38:53 +0200708/* array of vlan specific sysfs attributes */
Antonio Quartulli90f44352013-07-02 11:04:35 +0200709static struct batadv_attribute *batadv_vlan_attrs[] = {
Antonio Quartullib8cbd812013-07-02 11:04:36 +0200710 &batadv_attr_vlan_ap_isolation,
Antonio Quartulli90f44352013-07-02 11:04:35 +0200711 NULL,
712};
713
Sven Eckelmann5853e222012-05-12 02:09:24 +0200714int batadv_sysfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000715{
716 struct kobject *batif_kobject = &dev->dev.kobj;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200717 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmannb4d66b82012-06-05 22:31:29 +0200718 struct batadv_attribute **bat_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000719 int err;
720
Sven Eckelmann036cbfe2012-06-03 22:19:09 +0200721 bat_priv->mesh_obj = kobject_create_and_add(BATADV_SYSFS_IF_MESH_SUBDIR,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000722 batif_kobject);
723 if (!bat_priv->mesh_obj) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200724 batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
Sven Eckelmann036cbfe2012-06-03 22:19:09 +0200725 BATADV_SYSFS_IF_MESH_SUBDIR);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000726 goto out;
727 }
728
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200729 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000730 err = sysfs_create_file(bat_priv->mesh_obj,
731 &((*bat_attr)->attr));
732 if (err) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200733 batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
Sven Eckelmann036cbfe2012-06-03 22:19:09 +0200734 dev->name, BATADV_SYSFS_IF_MESH_SUBDIR,
Sven Eckelmann3e348192012-05-16 20:23:22 +0200735 ((*bat_attr)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000736 goto rem_attr;
737 }
738 }
739
740 return 0;
741
742rem_attr:
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200743 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000744 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
745
Sven Eckelmannf4acb102016-06-13 07:41:32 +0200746 kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE);
747 kobject_del(bat_priv->mesh_obj);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000748 kobject_put(bat_priv->mesh_obj);
749 bat_priv->mesh_obj = NULL;
750out:
751 return -ENOMEM;
752}
753
Sven Eckelmann5853e222012-05-12 02:09:24 +0200754void batadv_sysfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000755{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200756 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmannb4d66b82012-06-05 22:31:29 +0200757 struct batadv_attribute **bat_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000758
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200759 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000760 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
761
Sven Eckelmannf4acb102016-06-13 07:41:32 +0200762 kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE);
763 kobject_del(bat_priv->mesh_obj);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000764 kobject_put(bat_priv->mesh_obj);
765 bat_priv->mesh_obj = NULL;
766}
767
Antonio Quartulli90f44352013-07-02 11:04:35 +0200768/**
769 * batadv_sysfs_add_vlan - add all the needed sysfs objects for the new vlan
770 * @dev: netdev of the mesh interface
771 * @vlan: private data of the newly added VLAN interface
772 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200773 * Return: 0 on success and -ENOMEM if any of the structure allocations fails.
Antonio Quartulli90f44352013-07-02 11:04:35 +0200774 */
775int batadv_sysfs_add_vlan(struct net_device *dev,
776 struct batadv_softif_vlan *vlan)
777{
778 char vlan_subdir[sizeof(BATADV_SYSFS_VLAN_SUBDIR_PREFIX) + 5];
779 struct batadv_priv *bat_priv = netdev_priv(dev);
780 struct batadv_attribute **bat_attr;
781 int err;
782
783 if (vlan->vid & BATADV_VLAN_HAS_TAG) {
784 sprintf(vlan_subdir, BATADV_SYSFS_VLAN_SUBDIR_PREFIX "%hu",
785 vlan->vid & VLAN_VID_MASK);
786
787 vlan->kobj = kobject_create_and_add(vlan_subdir,
788 bat_priv->mesh_obj);
789 if (!vlan->kobj) {
790 batadv_err(dev, "Can't add sysfs directory: %s/%s\n",
791 dev->name, vlan_subdir);
792 goto out;
793 }
794 } else {
795 /* the untagged LAN uses the root folder to store its "VLAN
796 * specific attributes"
797 */
798 vlan->kobj = bat_priv->mesh_obj;
799 kobject_get(bat_priv->mesh_obj);
800 }
801
802 for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) {
803 err = sysfs_create_file(vlan->kobj,
804 &((*bat_attr)->attr));
805 if (err) {
806 batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
807 dev->name, vlan_subdir,
808 ((*bat_attr)->attr).name);
809 goto rem_attr;
810 }
811 }
812
813 return 0;
814
815rem_attr:
816 for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
817 sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
818
Sven Eckelmannf4acb102016-06-13 07:41:32 +0200819 if (vlan->kobj != bat_priv->mesh_obj) {
820 kobject_uevent(vlan->kobj, KOBJ_REMOVE);
821 kobject_del(vlan->kobj);
822 }
Antonio Quartulli90f44352013-07-02 11:04:35 +0200823 kobject_put(vlan->kobj);
824 vlan->kobj = NULL;
825out:
826 return -ENOMEM;
827}
828
829/**
830 * batadv_sysfs_del_vlan - remove all the sysfs objects for a given VLAN
831 * @bat_priv: the bat priv with all the soft interface information
832 * @vlan: the private data of the VLAN to destroy
833 */
834void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv,
835 struct batadv_softif_vlan *vlan)
836{
837 struct batadv_attribute **bat_attr;
838
839 for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
840 sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
841
Sven Eckelmannf4acb102016-06-13 07:41:32 +0200842 if (vlan->kobj != bat_priv->mesh_obj) {
843 kobject_uevent(vlan->kobj, KOBJ_REMOVE);
844 kobject_del(vlan->kobj);
845 }
Antonio Quartulli90f44352013-07-02 11:04:35 +0200846 kobject_put(vlan->kobj);
847 vlan->kobj = NULL;
848}
849
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200850static ssize_t batadv_show_mesh_iface(struct kobject *kobj,
851 struct attribute *attr, char *buff)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000852{
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200853 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200854 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000855 ssize_t length;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200856 const char *ifname;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000857
Sven Eckelmann56303d32012-06-05 22:31:31 +0200858 hard_iface = batadv_hardif_get_by_netdev(net_dev);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000859 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000860 return 0;
861
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200862 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
863 ifname = "none";
864 else
865 ifname = hard_iface->soft_iface->name;
866
867 length = sprintf(buff, "%s\n", ifname);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000868
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100869 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000870
871 return length;
872}
873
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200874/**
875 * batadv_store_mesh_iface_finish - store new hardif mesh_iface state
876 * @net_dev: netdevice to add/remove to/from batman-adv soft-interface
877 * @ifname: name of soft-interface to modify
878 *
879 * Changes the parts of the hard+soft interface which can not be modified under
880 * sysfs lock (to prevent deadlock situations).
881 *
882 * Return: 0 on success, 0 < on failure
883 */
884static int batadv_store_mesh_iface_finish(struct net_device *net_dev,
885 char ifname[IFNAMSIZ])
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000886{
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200887 struct net *net = dev_net(net_dev);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200888 struct batadv_hard_iface *hard_iface;
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200889 int status_tmp;
890 int ret = 0;
891
892 ASSERT_RTNL();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000893
Sven Eckelmann56303d32012-06-05 22:31:31 +0200894 hard_iface = batadv_hardif_get_by_netdev(net_dev);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000895 if (!hard_iface)
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200896 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000897
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200898 if (strncmp(ifname, "none", 4) == 0)
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200899 status_tmp = BATADV_IF_NOT_IN_USE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000900 else
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200901 status_tmp = BATADV_IF_I_WANT_YOU;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000902
Marek Lindnere6c10f42011-02-18 12:33:20 +0000903 if (hard_iface->if_status == status_tmp)
904 goto out;
905
906 if ((hard_iface->soft_iface) &&
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200907 (strncmp(hard_iface->soft_iface->name, ifname, IFNAMSIZ) == 0))
Marek Lindnered75ccb2011-02-10 14:33:51 +0000908 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000909
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200910 if (status_tmp == BATADV_IF_NOT_IN_USE) {
Sven Eckelmanna15fd362013-02-11 17:10:24 +0800911 batadv_hardif_disable_interface(hard_iface,
912 BATADV_IF_CLEANUP_AUTO);
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200913 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000914 }
915
Sven Eckelmann3a4375a2011-05-03 13:10:06 +0200916 /* if the interface already is in use */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200917 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmanna15fd362013-02-11 17:10:24 +0800918 batadv_hardif_disable_interface(hard_iface,
919 BATADV_IF_CLEANUP_AUTO);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000920
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200921 ret = batadv_hardif_enable_interface(hard_iface, net, ifname);
Marek Lindnered75ccb2011-02-10 14:33:51 +0000922out:
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100923 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000924 return ret;
925}
926
Sven Eckelmann77d69d82016-06-13 07:41:30 +0200927/**
928 * batadv_store_mesh_iface_work - store new hardif mesh_iface state
929 * @work: work queue item
930 *
931 * Changes the parts of the hard+soft interface which can not be modified under
932 * sysfs lock (to prevent deadlock situations).
933 */
934static void batadv_store_mesh_iface_work(struct work_struct *work)
935{
936 struct batadv_store_mesh_work *store_work;
937 int ret;
938
939 store_work = container_of(work, struct batadv_store_mesh_work, work);
940
941 rtnl_lock();
942 ret = batadv_store_mesh_iface_finish(store_work->net_dev,
943 store_work->soft_iface_name);
944 rtnl_unlock();
945
946 if (ret < 0)
947 pr_err("Failed to store new mesh_iface state %s for %s: %d\n",
948 store_work->soft_iface_name, store_work->net_dev->name,
949 ret);
950
951 dev_put(store_work->net_dev);
952 kfree(store_work);
953}
954
955static ssize_t batadv_store_mesh_iface(struct kobject *kobj,
956 struct attribute *attr, char *buff,
957 size_t count)
958{
959 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
960 struct batadv_store_mesh_work *store_work;
961
962 if (buff[count - 1] == '\n')
963 buff[count - 1] = '\0';
964
965 if (strlen(buff) >= IFNAMSIZ) {
966 pr_err("Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n",
967 buff);
968 return -EINVAL;
969 }
970
971 store_work = kmalloc(sizeof(*store_work), GFP_KERNEL);
972 if (!store_work)
973 return -ENOMEM;
974
975 dev_hold(net_dev);
976 INIT_WORK(&store_work->work, batadv_store_mesh_iface_work);
977 store_work->net_dev = net_dev;
978 strlcpy(store_work->soft_iface_name, buff,
979 sizeof(store_work->soft_iface_name));
980
981 queue_work(batadv_event_workqueue, &store_work->work);
982
983 return count;
984}
985
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200986static ssize_t batadv_show_iface_status(struct kobject *kobj,
987 struct attribute *attr, char *buff)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000988{
Sven Eckelmann0ff9b862012-05-12 18:33:52 +0200989 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200990 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000991 ssize_t length;
992
Sven Eckelmann56303d32012-06-05 22:31:31 +0200993 hard_iface = batadv_hardif_get_by_netdev(net_dev);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000994 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000995 return 0;
996
Marek Lindnere6c10f42011-02-18 12:33:20 +0000997 switch (hard_iface->if_status) {
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200998 case BATADV_IF_TO_BE_REMOVED:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000999 length = sprintf(buff, "disabling\n");
1000 break;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +02001001 case BATADV_IF_INACTIVE:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001002 length = sprintf(buff, "inactive\n");
1003 break;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +02001004 case BATADV_IF_ACTIVE:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001005 length = sprintf(buff, "active\n");
1006 break;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +02001007 case BATADV_IF_TO_BE_ACTIVATED:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001008 length = sprintf(buff, "enabling\n");
1009 break;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +02001010 case BATADV_IF_NOT_IN_USE:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001011 default:
1012 length = sprintf(buff, "not in use\n");
1013 break;
1014 }
1015
Sven Eckelmann82047ad2016-01-17 11:01:10 +01001016 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001017
1018 return length;
1019}
1020
Antonio Quartulli0b5ecc62016-01-16 16:40:14 +08001021#ifdef CONFIG_BATMAN_ADV_BATMAN_V
1022
1023/**
1024 * batadv_store_throughput_override - parse and store throughput override
1025 * entered by the user
1026 * @kobj: kobject representing the private mesh sysfs directory
1027 * @attr: the batman-adv attribute the user is interacting with
1028 * @buff: the buffer containing the user data
1029 * @count: number of bytes in the buffer
1030 *
1031 * Return: 'count' on success or a negative error code in case of failure
1032 */
1033static ssize_t batadv_store_throughput_override(struct kobject *kobj,
1034 struct attribute *attr,
1035 char *buff, size_t count)
1036{
1037 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
1038 struct batadv_hard_iface *hard_iface;
1039 u32 tp_override;
1040 u32 old_tp_override;
1041 bool ret;
1042
1043 hard_iface = batadv_hardif_get_by_netdev(net_dev);
1044 if (!hard_iface)
1045 return -EINVAL;
1046
1047 if (buff[count - 1] == '\n')
1048 buff[count - 1] = '\0';
1049
1050 ret = batadv_parse_throughput(net_dev, buff, "throughput_override",
1051 &tp_override);
1052 if (!ret)
1053 return count;
1054
1055 old_tp_override = atomic_read(&hard_iface->bat_v.throughput_override);
1056 if (old_tp_override == tp_override)
1057 goto out;
1058
1059 batadv_info(net_dev, "%s: Changing from: %u.%u MBit to: %u.%u MBit\n",
1060 "throughput_override",
1061 old_tp_override / 10, old_tp_override % 10,
1062 tp_override / 10, tp_override % 10);
1063
1064 atomic_set(&hard_iface->bat_v.throughput_override, tp_override);
1065
1066out:
1067 batadv_hardif_put(hard_iface);
1068 return count;
1069}
1070
1071static ssize_t batadv_show_throughput_override(struct kobject *kobj,
1072 struct attribute *attr,
1073 char *buff)
1074{
1075 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
1076 struct batadv_hard_iface *hard_iface;
1077 u32 tp_override;
1078
1079 hard_iface = batadv_hardif_get_by_netdev(net_dev);
1080 if (!hard_iface)
1081 return -EINVAL;
1082
1083 tp_override = atomic_read(&hard_iface->bat_v.throughput_override);
1084
1085 return sprintf(buff, "%u.%u MBit\n", tp_override / 10,
1086 tp_override % 10);
1087}
1088
1089#endif
1090
Sven Eckelmann347c80f2012-06-03 22:19:07 +02001091static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface,
1092 batadv_store_mesh_iface);
1093static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL);
Linus Luessing7f136cd2016-01-16 16:40:11 +08001094#ifdef CONFIG_BATMAN_ADV_BATMAN_V
1095BATADV_ATTR_HIF_UINT(elp_interval, bat_v.elp_interval, S_IRUGO | S_IWUSR,
1096 2 * BATADV_JITTER, INT_MAX, NULL);
Antonio Quartulli0b5ecc62016-01-16 16:40:14 +08001097static BATADV_ATTR(throughput_override, S_IRUGO | S_IWUSR,
1098 batadv_show_throughput_override,
1099 batadv_store_throughput_override);
Linus Luessing7f136cd2016-01-16 16:40:11 +08001100#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001101
Sven Eckelmannb4d66b82012-06-05 22:31:29 +02001102static struct batadv_attribute *batadv_batman_attrs[] = {
Sven Eckelmann0ff9b862012-05-12 18:33:52 +02001103 &batadv_attr_mesh_iface,
1104 &batadv_attr_iface_status,
Linus Luessing7f136cd2016-01-16 16:40:11 +08001105#ifdef CONFIG_BATMAN_ADV_BATMAN_V
1106 &batadv_attr_elp_interval,
Antonio Quartulli0b5ecc62016-01-16 16:40:14 +08001107 &batadv_attr_throughput_override,
Linus Luessing7f136cd2016-01-16 16:40:11 +08001108#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001109 NULL,
1110};
1111
Sven Eckelmann5853e222012-05-12 02:09:24 +02001112int batadv_sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001113{
1114 struct kobject *hardif_kobject = &dev->dev.kobj;
Sven Eckelmannb4d66b82012-06-05 22:31:29 +02001115 struct batadv_attribute **bat_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001116 int err;
1117
Sven Eckelmann036cbfe2012-06-03 22:19:09 +02001118 *hardif_obj = kobject_create_and_add(BATADV_SYSFS_IF_BAT_SUBDIR,
1119 hardif_kobject);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001120
1121 if (!*hardif_obj) {
Sven Eckelmann3e348192012-05-16 20:23:22 +02001122 batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
Sven Eckelmann036cbfe2012-06-03 22:19:09 +02001123 BATADV_SYSFS_IF_BAT_SUBDIR);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001124 goto out;
1125 }
1126
Sven Eckelmann0ff9b862012-05-12 18:33:52 +02001127 for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001128 err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr));
1129 if (err) {
Sven Eckelmann3e348192012-05-16 20:23:22 +02001130 batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
Sven Eckelmann036cbfe2012-06-03 22:19:09 +02001131 dev->name, BATADV_SYSFS_IF_BAT_SUBDIR,
Sven Eckelmann3e348192012-05-16 20:23:22 +02001132 ((*bat_attr)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001133 goto rem_attr;
1134 }
1135 }
1136
1137 return 0;
1138
1139rem_attr:
Sven Eckelmann0ff9b862012-05-12 18:33:52 +02001140 for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001141 sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr));
1142out:
1143 return -ENOMEM;
1144}
1145
Sven Eckelmann5853e222012-05-12 02:09:24 +02001146void batadv_sysfs_del_hardif(struct kobject **hardif_obj)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001147{
Sven Eckelmannf4acb102016-06-13 07:41:32 +02001148 kobject_uevent(*hardif_obj, KOBJ_REMOVE);
1149 kobject_del(*hardif_obj);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001150 kobject_put(*hardif_obj);
1151 *hardif_obj = NULL;
1152}
Antonio Quartullic6bda682011-04-26 18:26:01 +02001153
Sven Eckelmann56303d32012-06-05 22:31:31 +02001154int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001155 enum batadv_uev_action action, const char *data)
Antonio Quartullic6bda682011-04-26 18:26:01 +02001156{
Sven Eckelmann5346c352012-05-05 13:27:28 +02001157 int ret = -ENOMEM;
Antonio Quartullic6bda682011-04-26 18:26:01 +02001158 struct kobject *bat_kobj;
1159 char *uevent_env[4] = { NULL, NULL, NULL, NULL };
1160
Marek Lindner736292c2013-01-12 19:19:06 +08001161 bat_kobj = &bat_priv->soft_iface->dev.kobj;
Antonio Quartullic6bda682011-04-26 18:26:01 +02001162
Himangi Saraogib98fe242014-06-29 00:06:29 +05301163 uevent_env[0] = kasprintf(GFP_ATOMIC,
1164 "%s%s", BATADV_UEV_TYPE_VAR,
1165 batadv_uev_type_str[type]);
Antonio Quartullic6bda682011-04-26 18:26:01 +02001166 if (!uevent_env[0])
1167 goto out;
1168
Himangi Saraogib98fe242014-06-29 00:06:29 +05301169 uevent_env[1] = kasprintf(GFP_ATOMIC,
1170 "%s%s", BATADV_UEV_ACTION_VAR,
1171 batadv_uev_action_str[action]);
Antonio Quartullic6bda682011-04-26 18:26:01 +02001172 if (!uevent_env[1])
1173 goto out;
1174
Antonio Quartullic6bda682011-04-26 18:26:01 +02001175 /* If the event is DEL, ignore the data field */
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001176 if (action != BATADV_UEV_DEL) {
Himangi Saraogib98fe242014-06-29 00:06:29 +05301177 uevent_env[2] = kasprintf(GFP_ATOMIC,
1178 "%s%s", BATADV_UEV_DATA_VAR, data);
Antonio Quartullic6bda682011-04-26 18:26:01 +02001179 if (!uevent_env[2])
1180 goto out;
Antonio Quartullic6bda682011-04-26 18:26:01 +02001181 }
1182
1183 ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
1184out:
1185 kfree(uevent_env[0]);
1186 kfree(uevent_env[1]);
1187 kfree(uevent_env[2]);
1188
Antonio Quartullic6bda682011-04-26 18:26:01 +02001189 if (ret)
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001190 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02001191 "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
Sven Eckelmann0ff9b862012-05-12 18:33:52 +02001192 batadv_uev_type_str[type],
1193 batadv_uev_action_str[action],
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001194 (action == BATADV_UEV_DEL ? "NULL" : data), ret);
Antonio Quartullic6bda682011-04-26 18:26:01 +02001195 return ret;
1196}