GNU Linux-libre 4.9.318-gnu1
[releases.git] / net / batman-adv / sysfs.c
1 /* Copyright (C) 2010-2016  B.A.T.M.A.N. contributors:
2  *
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
15  * along with this program; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "sysfs.h"
19 #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>
29 #include <linux/kref.h>
30 #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>
40 #include <linux/workqueue.h>
41
42 #include "bridge_loop_avoidance.h"
43 #include "distributed-arp-table.h"
44 #include "gateway_client.h"
45 #include "gateway_common.h"
46 #include "hard-interface.h"
47 #include "log.h"
48 #include "network-coding.h"
49 #include "packet.h"
50 #include "soft-interface.h"
51
52 static struct net_device *batadv_kobj_to_netdev(struct kobject *obj)
53 {
54         struct device *dev = container_of(obj->parent, struct device, kobj);
55
56         return to_net_dev(dev);
57 }
58
59 static struct batadv_priv *batadv_kobj_to_batpriv(struct kobject *obj)
60 {
61         struct net_device *net_dev = batadv_kobj_to_netdev(obj);
62
63         return netdev_priv(net_dev);
64 }
65
66 /**
67  * batadv_vlan_kobj_to_batpriv - convert a vlan kobj in the associated batpriv
68  * @obj: kobject to covert
69  *
70  * Return: the associated batadv_priv struct.
71  */
72 static 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
88  * @bat_priv: the bat priv with all the soft interface information
89  * @obj: kobject to covert
90  *
91  * Return: the associated softif_vlan struct if found, NULL otherwise.
92  */
93 static struct batadv_softif_vlan *
94 batadv_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
103                 if (!kref_get_unless_zero(&vlan_tmp->refcount))
104                         continue;
105
106                 vlan = vlan_tmp;
107                 break;
108         }
109         rcu_read_unlock();
110
111         return vlan;
112 }
113
114 #define BATADV_UEV_TYPE_VAR     "BATTYPE="
115 #define BATADV_UEV_ACTION_VAR   "BATACTION="
116 #define BATADV_UEV_DATA_VAR     "BATDATA="
117
118 static char *batadv_uev_action_str[] = {
119         "add",
120         "del",
121         "change",
122         "loopdetect",
123 };
124
125 static char *batadv_uev_type_str[] = {
126         "gw",
127         "bla",
128 };
129
130 /* Use this, if you have customized show and store functions for vlan attrs */
131 #define BATADV_ATTR_VLAN(_name, _mode, _show, _store)   \
132 struct batadv_attribute batadv_attr_vlan_##_name = {    \
133         .attr = {.name = __stringify(_name),            \
134                  .mode = _mode },                       \
135         .show   = _show,                                \
136         .store  = _store,                               \
137 }
138
139 /* Use this, if you have customized show and store functions */
140 #define BATADV_ATTR(_name, _mode, _show, _store)        \
141 struct batadv_attribute batadv_attr_##_name = {         \
142         .attr = {.name = __stringify(_name),            \
143                  .mode = _mode },                       \
144         .show   = _show,                                \
145         .store  = _store,                               \
146 }
147
148 #define BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func)                   \
149 ssize_t batadv_store_##_name(struct kobject *kobj,                      \
150                              struct attribute *attr, char *buff,        \
151                              size_t count)                              \
152 {                                                                       \
153         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);       \
154         struct batadv_priv *bat_priv = netdev_priv(net_dev);            \
155                                                                         \
156         return __batadv_store_bool_attr(buff, count, _post_func, attr,  \
157                                         &bat_priv->_name, net_dev);     \
158 }
159
160 #define BATADV_ATTR_SIF_SHOW_BOOL(_name)                                \
161 ssize_t batadv_show_##_name(struct kobject *kobj,                       \
162                             struct attribute *attr, char *buff)         \
163 {                                                                       \
164         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);    \
165                                                                         \
166         return sprintf(buff, "%s\n",                                    \
167                        atomic_read(&bat_priv->_name) == 0 ?             \
168                        "disabled" : "enabled");                         \
169 }                                                                       \
170
171 /* Use this, if you are going to turn a [name] in the soft-interface
172  * (bat_priv) on or off
173  */
174 #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)
179
180 #define BATADV_ATTR_SIF_STORE_UINT(_name, _var, _min, _max, _post_func) \
181 ssize_t batadv_store_##_name(struct kobject *kobj,                      \
182                              struct attribute *attr, char *buff,        \
183                              size_t count)                              \
184 {                                                                       \
185         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);       \
186         struct batadv_priv *bat_priv = netdev_priv(net_dev);            \
187                                                                         \
188         return __batadv_store_uint_attr(buff, count, _min, _max,        \
189                                         _post_func, attr,               \
190                                         &bat_priv->_var, net_dev,       \
191                                         NULL);  \
192 }
193
194 #define BATADV_ATTR_SIF_SHOW_UINT(_name, _var)                          \
195 ssize_t batadv_show_##_name(struct kobject *kobj,                       \
196                             struct attribute *attr, char *buff)         \
197 {                                                                       \
198         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);    \
199                                                                         \
200         return sprintf(buff, "%i\n", atomic_read(&bat_priv->_var));     \
201 }                                                                       \
202
203 /* Use this, if you are going to set [name] in the soft-interface
204  * (bat_priv) to an unsigned integer value
205  */
206 #define BATADV_ATTR_SIF_UINT(_name, _var, _mode, _min, _max, _post_func)\
207         static BATADV_ATTR_SIF_STORE_UINT(_name, _var, _min, _max, _post_func)\
208         static BATADV_ATTR_SIF_SHOW_UINT(_name, _var)                   \
209         static BATADV_ATTR(_name, _mode, batadv_show_##_name,           \
210                            batadv_store_##_name)
211
212 #define BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func)                  \
213 ssize_t batadv_store_vlan_##_name(struct kobject *kobj,                 \
214                                   struct attribute *attr, char *buff,   \
215                                   size_t count)                         \
216 {                                                                       \
217         struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
218         struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
219                                                               kobj);    \
220         size_t res = __batadv_store_bool_attr(buff, count, _post_func,  \
221                                               attr, &vlan->_name,       \
222                                               bat_priv->soft_iface);    \
223                                                                         \
224         batadv_softif_vlan_put(vlan);                                   \
225         return res;                                                     \
226 }
227
228 #define BATADV_ATTR_VLAN_SHOW_BOOL(_name)                               \
229 ssize_t batadv_show_vlan_##_name(struct kobject *kobj,                  \
230                                  struct attribute *attr, char *buff)    \
231 {                                                                       \
232         struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
233         struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
234                                                               kobj);    \
235         size_t res = sprintf(buff, "%s\n",                              \
236                              atomic_read(&vlan->_name) == 0 ?           \
237                              "disabled" : "enabled");                   \
238                                                                         \
239         batadv_softif_vlan_put(vlan);                                   \
240         return res;                                                     \
241 }
242
243 /* Use this, if you are going to turn a [name] in the vlan struct on or off */
244 #define BATADV_ATTR_VLAN_BOOL(_name, _mode, _post_func)                 \
245         static BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func)           \
246         static BATADV_ATTR_VLAN_SHOW_BOOL(_name)                        \
247         static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \
248                                 batadv_store_vlan_##_name)
249
250 #define BATADV_ATTR_HIF_STORE_UINT(_name, _var, _min, _max, _post_func) \
251 ssize_t batadv_store_##_name(struct kobject *kobj,                      \
252                              struct attribute *attr, char *buff,        \
253                              size_t count)                              \
254 {                                                                       \
255         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);       \
256         struct batadv_hard_iface *hard_iface;                           \
257         ssize_t length;                                                 \
258                                                                         \
259         hard_iface = batadv_hardif_get_by_netdev(net_dev);              \
260         if (!hard_iface)                                                \
261                 return 0;                                               \
262                                                                         \
263         length = __batadv_store_uint_attr(buff, count, _min, _max,      \
264                                           _post_func, attr,             \
265                                           &hard_iface->_var,            \
266                                           hard_iface->soft_iface,       \
267                                           net_dev);                     \
268                                                                         \
269         batadv_hardif_put(hard_iface);                          \
270         return length;                                                  \
271 }
272
273 #define BATADV_ATTR_HIF_SHOW_UINT(_name, _var)                          \
274 ssize_t batadv_show_##_name(struct kobject *kobj,                       \
275                             struct attribute *attr, char *buff)         \
276 {                                                                       \
277         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);       \
278         struct batadv_hard_iface *hard_iface;                           \
279         ssize_t length;                                                 \
280                                                                         \
281         hard_iface = batadv_hardif_get_by_netdev(net_dev);              \
282         if (!hard_iface)                                                \
283                 return 0;                                               \
284                                                                         \
285         length = sprintf(buff, "%i\n", atomic_read(&hard_iface->_var)); \
286                                                                         \
287         batadv_hardif_put(hard_iface);                          \
288         return length;                                                  \
289 }
290
291 /* Use this, if you are going to set [name] in hard_iface to an
292  * unsigned integer value
293  */
294 #define BATADV_ATTR_HIF_UINT(_name, _var, _mode, _min, _max, _post_func)\
295         static BATADV_ATTR_HIF_STORE_UINT(_name, _var, _min,            \
296                                           _max, _post_func)             \
297         static BATADV_ATTR_HIF_SHOW_UINT(_name, _var)                   \
298         static BATADV_ATTR(_name, _mode, batadv_show_##_name,           \
299                            batadv_store_##_name)
300
301 static int batadv_store_bool_attr(char *buff, size_t count,
302                                   struct net_device *net_dev,
303                                   const char *attr_name, atomic_t *attr,
304                                   bool *changed)
305 {
306         int enabled = -1;
307
308         *changed = false;
309
310         if (buff[count - 1] == '\n')
311                 buff[count - 1] = '\0';
312
313         if ((strncmp(buff, "1", 2) == 0) ||
314             (strncmp(buff, "enable", 7) == 0) ||
315             (strncmp(buff, "enabled", 8) == 0))
316                 enabled = 1;
317
318         if ((strncmp(buff, "0", 2) == 0) ||
319             (strncmp(buff, "disable", 8) == 0) ||
320             (strncmp(buff, "disabled", 9) == 0))
321                 enabled = 0;
322
323         if (enabled < 0) {
324                 batadv_info(net_dev, "%s: Invalid parameter received: %s\n",
325                             attr_name, buff);
326                 return -EINVAL;
327         }
328
329         if (atomic_read(attr) == enabled)
330                 return count;
331
332         batadv_info(net_dev, "%s: Changing from: %s to: %s\n", attr_name,
333                     atomic_read(attr) == 1 ? "enabled" : "disabled",
334                     enabled == 1 ? "enabled" : "disabled");
335
336         *changed = true;
337
338         atomic_set(attr, (unsigned int)enabled);
339         return count;
340 }
341
342 static inline ssize_t
343 __batadv_store_bool_attr(char *buff, size_t count,
344                          void (*post_func)(struct net_device *),
345                          struct attribute *attr,
346                          atomic_t *attr_store, struct net_device *net_dev)
347 {
348         bool changed;
349         int ret;
350
351         ret = batadv_store_bool_attr(buff, count, net_dev, attr->name,
352                                      attr_store, &changed);
353         if (post_func && changed)
354                 post_func(net_dev);
355
356         return ret;
357 }
358
359 static int batadv_store_uint_attr(const char *buff, size_t count,
360                                   struct net_device *net_dev,
361                                   struct net_device *slave_dev,
362                                   const char *attr_name,
363                                   unsigned int min, unsigned int max,
364                                   atomic_t *attr)
365 {
366         char ifname[IFNAMSIZ + 3] = "";
367         unsigned long uint_val;
368         int ret;
369
370         ret = kstrtoul(buff, 10, &uint_val);
371         if (ret) {
372                 batadv_info(net_dev, "%s: Invalid parameter received: %s\n",
373                             attr_name, buff);
374                 return -EINVAL;
375         }
376
377         if (uint_val < min) {
378                 batadv_info(net_dev, "%s: Value is too small: %lu min: %u\n",
379                             attr_name, uint_val, min);
380                 return -EINVAL;
381         }
382
383         if (uint_val > max) {
384                 batadv_info(net_dev, "%s: Value is too big: %lu max: %u\n",
385                             attr_name, uint_val, max);
386                 return -EINVAL;
387         }
388
389         if (atomic_read(attr) == uint_val)
390                 return count;
391
392         if (slave_dev)
393                 snprintf(ifname, sizeof(ifname), "%s: ", slave_dev->name);
394
395         batadv_info(net_dev, "%s: %sChanging from: %i to: %lu\n",
396                     attr_name, ifname, atomic_read(attr), uint_val);
397
398         atomic_set(attr, uint_val);
399         return count;
400 }
401
402 static ssize_t __batadv_store_uint_attr(const char *buff, size_t count,
403                                         int min, int max,
404                                         void (*post_func)(struct net_device *),
405                                         const struct attribute *attr,
406                                         atomic_t *attr_store,
407                                         struct net_device *net_dev,
408                                         struct net_device *slave_dev)
409 {
410         int ret;
411
412         ret = batadv_store_uint_attr(buff, count, net_dev, slave_dev,
413                                      attr->name, min, max, attr_store);
414         if (post_func && ret)
415                 post_func(net_dev);
416
417         return ret;
418 }
419
420 static ssize_t batadv_show_bat_algo(struct kobject *kobj,
421                                     struct attribute *attr, char *buff)
422 {
423         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
424
425         return sprintf(buff, "%s\n", bat_priv->algo_ops->name);
426 }
427
428 static void batadv_post_gw_reselect(struct net_device *net_dev)
429 {
430         struct batadv_priv *bat_priv = netdev_priv(net_dev);
431
432         batadv_gw_reselect(bat_priv);
433 }
434
435 static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr,
436                                    char *buff)
437 {
438         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
439         int bytes_written;
440
441         /* GW mode is not available if the routing algorithm in use does not
442          * implement the GW API
443          */
444         if (!bat_priv->algo_ops->gw.get_best_gw_node ||
445             !bat_priv->algo_ops->gw.is_eligible)
446                 return -ENOENT;
447
448         switch (atomic_read(&bat_priv->gw.mode)) {
449         case BATADV_GW_MODE_CLIENT:
450                 bytes_written = sprintf(buff, "%s\n",
451                                         BATADV_GW_MODE_CLIENT_NAME);
452                 break;
453         case BATADV_GW_MODE_SERVER:
454                 bytes_written = sprintf(buff, "%s\n",
455                                         BATADV_GW_MODE_SERVER_NAME);
456                 break;
457         default:
458                 bytes_written = sprintf(buff, "%s\n",
459                                         BATADV_GW_MODE_OFF_NAME);
460                 break;
461         }
462
463         return bytes_written;
464 }
465
466 static ssize_t batadv_store_gw_mode(struct kobject *kobj,
467                                     struct attribute *attr, char *buff,
468                                     size_t count)
469 {
470         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
471         struct batadv_priv *bat_priv = netdev_priv(net_dev);
472         char *curr_gw_mode_str;
473         int gw_mode_tmp = -1;
474
475         /* toggling GW mode is allowed only if the routing algorithm in use
476          * provides the GW API
477          */
478         if (!bat_priv->algo_ops->gw.get_best_gw_node ||
479             !bat_priv->algo_ops->gw.is_eligible)
480                 return -EINVAL;
481
482         if (buff[count - 1] == '\n')
483                 buff[count - 1] = '\0';
484
485         if (strncmp(buff, BATADV_GW_MODE_OFF_NAME,
486                     strlen(BATADV_GW_MODE_OFF_NAME)) == 0)
487                 gw_mode_tmp = BATADV_GW_MODE_OFF;
488
489         if (strncmp(buff, BATADV_GW_MODE_CLIENT_NAME,
490                     strlen(BATADV_GW_MODE_CLIENT_NAME)) == 0)
491                 gw_mode_tmp = BATADV_GW_MODE_CLIENT;
492
493         if (strncmp(buff, BATADV_GW_MODE_SERVER_NAME,
494                     strlen(BATADV_GW_MODE_SERVER_NAME)) == 0)
495                 gw_mode_tmp = BATADV_GW_MODE_SERVER;
496
497         if (gw_mode_tmp < 0) {
498                 batadv_info(net_dev,
499                             "Invalid parameter for 'gw mode' setting received: %s\n",
500                             buff);
501                 return -EINVAL;
502         }
503
504         if (atomic_read(&bat_priv->gw.mode) == gw_mode_tmp)
505                 return count;
506
507         switch (atomic_read(&bat_priv->gw.mode)) {
508         case BATADV_GW_MODE_CLIENT:
509                 curr_gw_mode_str = BATADV_GW_MODE_CLIENT_NAME;
510                 break;
511         case BATADV_GW_MODE_SERVER:
512                 curr_gw_mode_str = BATADV_GW_MODE_SERVER_NAME;
513                 break;
514         default:
515                 curr_gw_mode_str = BATADV_GW_MODE_OFF_NAME;
516                 break;
517         }
518
519         batadv_info(net_dev, "Changing gw mode from: %s to: %s\n",
520                     curr_gw_mode_str, buff);
521
522         /* Invoking batadv_gw_reselect() is not enough to really de-select the
523          * current GW. It will only instruct the gateway client code to perform
524          * a re-election the next time that this is needed.
525          *
526          * When gw client mode is being switched off the current GW must be
527          * de-selected explicitly otherwise no GW_ADD uevent is thrown on
528          * client mode re-activation. This is operation is performed in
529          * batadv_gw_check_client_stop().
530          */
531         batadv_gw_reselect(bat_priv);
532         /* always call batadv_gw_check_client_stop() before changing the gateway
533          * state
534          */
535         batadv_gw_check_client_stop(bat_priv);
536         atomic_set(&bat_priv->gw.mode, (unsigned int)gw_mode_tmp);
537         batadv_gw_tvlv_container_update(bat_priv);
538         return count;
539 }
540
541 static ssize_t batadv_show_gw_sel_class(struct kobject *kobj,
542                                         struct attribute *attr, char *buff)
543 {
544         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
545
546         /* GW selection class is not available if the routing algorithm in use
547          * does not implement the GW API
548          */
549         if (!bat_priv->algo_ops->gw.get_best_gw_node ||
550             !bat_priv->algo_ops->gw.is_eligible)
551                 return -ENOENT;
552
553         if (bat_priv->algo_ops->gw.show_sel_class)
554                 return bat_priv->algo_ops->gw.show_sel_class(bat_priv, buff);
555
556         return sprintf(buff, "%i\n", atomic_read(&bat_priv->gw.sel_class));
557 }
558
559 static ssize_t batadv_store_gw_sel_class(struct kobject *kobj,
560                                          struct attribute *attr, char *buff,
561                                          size_t count)
562 {
563         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
564
565         /* setting the GW selection class is allowed only if the routing
566          * algorithm in use implements the GW API
567          */
568         if (!bat_priv->algo_ops->gw.get_best_gw_node ||
569             !bat_priv->algo_ops->gw.is_eligible)
570                 return -EINVAL;
571
572         if (buff[count - 1] == '\n')
573                 buff[count - 1] = '\0';
574
575         if (bat_priv->algo_ops->gw.store_sel_class)
576                 return bat_priv->algo_ops->gw.store_sel_class(bat_priv, buff,
577                                                               count);
578
579         return __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE,
580                                         batadv_post_gw_reselect, attr,
581                                         &bat_priv->gw.sel_class,
582                                         bat_priv->soft_iface, NULL);
583 }
584
585 static ssize_t batadv_show_gw_bwidth(struct kobject *kobj,
586                                      struct attribute *attr, char *buff)
587 {
588         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
589         u32 down, up;
590
591         down = atomic_read(&bat_priv->gw.bandwidth_down);
592         up = atomic_read(&bat_priv->gw.bandwidth_up);
593
594         return sprintf(buff, "%u.%u/%u.%u MBit\n", down / 10,
595                        down % 10, up / 10, up % 10);
596 }
597
598 static ssize_t batadv_store_gw_bwidth(struct kobject *kobj,
599                                       struct attribute *attr, char *buff,
600                                       size_t count)
601 {
602         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
603
604         if (buff[count - 1] == '\n')
605                 buff[count - 1] = '\0';
606
607         return batadv_gw_bandwidth_set(net_dev, buff, count);
608 }
609
610 /**
611  * batadv_show_isolation_mark - print the current isolation mark/mask
612  * @kobj: kobject representing the private mesh sysfs directory
613  * @attr: the batman-adv attribute the user is interacting with
614  * @buff: the buffer that will contain the data to send back to the user
615  *
616  * Return: the number of bytes written into 'buff' on success or a negative
617  * error code in case of failure
618  */
619 static ssize_t batadv_show_isolation_mark(struct kobject *kobj,
620                                           struct attribute *attr, char *buff)
621 {
622         struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
623
624         return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark,
625                        bat_priv->isolation_mark_mask);
626 }
627
628 /**
629  * batadv_store_isolation_mark - parse and store the isolation mark/mask entered
630  *  by the user
631  * @kobj: kobject representing the private mesh sysfs directory
632  * @attr: the batman-adv attribute the user is interacting with
633  * @buff: the buffer containing the user data
634  * @count: number of bytes in the buffer
635  *
636  * Return: 'count' on success or a negative error code in case of failure
637  */
638 static ssize_t batadv_store_isolation_mark(struct kobject *kobj,
639                                            struct attribute *attr, char *buff,
640                                            size_t count)
641 {
642         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
643         struct batadv_priv *bat_priv = netdev_priv(net_dev);
644         u32 mark, mask;
645         char *mask_ptr;
646
647         /* parse the mask if it has been specified, otherwise assume the mask is
648          * the biggest possible
649          */
650         mask = 0xFFFFFFFF;
651         mask_ptr = strchr(buff, '/');
652         if (mask_ptr) {
653                 *mask_ptr = '\0';
654                 mask_ptr++;
655
656                 /* the mask must be entered in hex base as it is going to be a
657                  * bitmask and not a prefix length
658                  */
659                 if (kstrtou32(mask_ptr, 16, &mask) < 0)
660                         return -EINVAL;
661         }
662
663         /* the mark can be entered in any base */
664         if (kstrtou32(buff, 0, &mark) < 0)
665                 return -EINVAL;
666
667         bat_priv->isolation_mark_mask = mask;
668         /* erase bits not covered by the mask */
669         bat_priv->isolation_mark = mark & bat_priv->isolation_mark_mask;
670
671         batadv_info(net_dev,
672                     "New skb mark for extended isolation: %#.8x/%#.8x\n",
673                     bat_priv->isolation_mark, bat_priv->isolation_mark_mask);
674
675         return count;
676 }
677
678 BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL);
679 BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
680 #ifdef CONFIG_BATMAN_ADV_BLA
681 BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR,
682                      batadv_bla_status_update);
683 #endif
684 #ifdef CONFIG_BATMAN_ADV_DAT
685 BATADV_ATTR_SIF_BOOL(distributed_arp_table, S_IRUGO | S_IWUSR,
686                      batadv_dat_status_update);
687 #endif
688 BATADV_ATTR_SIF_BOOL(fragmentation, S_IRUGO | S_IWUSR, batadv_update_min_mtu);
689 static BATADV_ATTR(routing_algo, S_IRUGO, batadv_show_bat_algo, NULL);
690 static BATADV_ATTR(gw_mode, S_IRUGO | S_IWUSR, batadv_show_gw_mode,
691                    batadv_store_gw_mode);
692 BATADV_ATTR_SIF_UINT(orig_interval, orig_interval, S_IRUGO | S_IWUSR,
693                      2 * BATADV_JITTER, INT_MAX, NULL);
694 BATADV_ATTR_SIF_UINT(hop_penalty, hop_penalty, S_IRUGO | S_IWUSR, 0,
695                      BATADV_TQ_MAX_VALUE, NULL);
696 static BATADV_ATTR(gw_sel_class, S_IRUGO | S_IWUSR, batadv_show_gw_sel_class,
697                    batadv_store_gw_sel_class);
698 static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth,
699                    batadv_store_gw_bwidth);
700 #ifdef CONFIG_BATMAN_ADV_MCAST
701 BATADV_ATTR_SIF_BOOL(multicast_mode, S_IRUGO | S_IWUSR, NULL);
702 #endif
703 #ifdef CONFIG_BATMAN_ADV_DEBUG
704 BATADV_ATTR_SIF_UINT(log_level, log_level, S_IRUGO | S_IWUSR, 0,
705                      BATADV_DBG_ALL, NULL);
706 #endif
707 #ifdef CONFIG_BATMAN_ADV_NC
708 BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR,
709                      batadv_nc_status_update);
710 #endif
711 static BATADV_ATTR(isolation_mark, S_IRUGO | S_IWUSR,
712                    batadv_show_isolation_mark, batadv_store_isolation_mark);
713
714 static struct batadv_attribute *batadv_mesh_attrs[] = {
715         &batadv_attr_aggregated_ogms,
716         &batadv_attr_bonding,
717 #ifdef CONFIG_BATMAN_ADV_BLA
718         &batadv_attr_bridge_loop_avoidance,
719 #endif
720 #ifdef CONFIG_BATMAN_ADV_DAT
721         &batadv_attr_distributed_arp_table,
722 #endif
723 #ifdef CONFIG_BATMAN_ADV_MCAST
724         &batadv_attr_multicast_mode,
725 #endif
726         &batadv_attr_fragmentation,
727         &batadv_attr_routing_algo,
728         &batadv_attr_gw_mode,
729         &batadv_attr_orig_interval,
730         &batadv_attr_hop_penalty,
731         &batadv_attr_gw_sel_class,
732         &batadv_attr_gw_bandwidth,
733 #ifdef CONFIG_BATMAN_ADV_DEBUG
734         &batadv_attr_log_level,
735 #endif
736 #ifdef CONFIG_BATMAN_ADV_NC
737         &batadv_attr_network_coding,
738 #endif
739         &batadv_attr_isolation_mark,
740         NULL,
741 };
742
743 BATADV_ATTR_VLAN_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL);
744
745 /* array of vlan specific sysfs attributes */
746 static struct batadv_attribute *batadv_vlan_attrs[] = {
747         &batadv_attr_vlan_ap_isolation,
748         NULL,
749 };
750
751 int batadv_sysfs_add_meshif(struct net_device *dev)
752 {
753         struct kobject *batif_kobject = &dev->dev.kobj;
754         struct batadv_priv *bat_priv = netdev_priv(dev);
755         struct batadv_attribute **bat_attr;
756         int err;
757
758         bat_priv->mesh_obj = kobject_create_and_add(BATADV_SYSFS_IF_MESH_SUBDIR,
759                                                     batif_kobject);
760         if (!bat_priv->mesh_obj) {
761                 batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
762                            BATADV_SYSFS_IF_MESH_SUBDIR);
763                 goto out;
764         }
765
766         for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) {
767                 err = sysfs_create_file(bat_priv->mesh_obj,
768                                         &((*bat_attr)->attr));
769                 if (err) {
770                         batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
771                                    dev->name, BATADV_SYSFS_IF_MESH_SUBDIR,
772                                    ((*bat_attr)->attr).name);
773                         goto rem_attr;
774                 }
775         }
776
777         return 0;
778
779 rem_attr:
780         for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
781                 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
782
783         kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE);
784         kobject_del(bat_priv->mesh_obj);
785         kobject_put(bat_priv->mesh_obj);
786         bat_priv->mesh_obj = NULL;
787 out:
788         return -ENOMEM;
789 }
790
791 void batadv_sysfs_del_meshif(struct net_device *dev)
792 {
793         struct batadv_priv *bat_priv = netdev_priv(dev);
794         struct batadv_attribute **bat_attr;
795
796         for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
797                 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
798
799         kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE);
800         kobject_del(bat_priv->mesh_obj);
801         kobject_put(bat_priv->mesh_obj);
802         bat_priv->mesh_obj = NULL;
803 }
804
805 /**
806  * batadv_sysfs_add_vlan - add all the needed sysfs objects for the new vlan
807  * @dev: netdev of the mesh interface
808  * @vlan: private data of the newly added VLAN interface
809  *
810  * Return: 0 on success and -ENOMEM if any of the structure allocations fails.
811  */
812 int batadv_sysfs_add_vlan(struct net_device *dev,
813                           struct batadv_softif_vlan *vlan)
814 {
815         char vlan_subdir[sizeof(BATADV_SYSFS_VLAN_SUBDIR_PREFIX) + 5];
816         struct batadv_priv *bat_priv = netdev_priv(dev);
817         struct batadv_attribute **bat_attr;
818         int err;
819
820         if (vlan->vid & BATADV_VLAN_HAS_TAG) {
821                 sprintf(vlan_subdir, BATADV_SYSFS_VLAN_SUBDIR_PREFIX "%hu",
822                         vlan->vid & VLAN_VID_MASK);
823
824                 vlan->kobj = kobject_create_and_add(vlan_subdir,
825                                                     bat_priv->mesh_obj);
826                 if (!vlan->kobj) {
827                         batadv_err(dev, "Can't add sysfs directory: %s/%s\n",
828                                    dev->name, vlan_subdir);
829                         goto out;
830                 }
831         } else {
832                 /* the untagged LAN uses the root folder to store its "VLAN
833                  * specific attributes"
834                  */
835                 vlan->kobj = bat_priv->mesh_obj;
836                 kobject_get(bat_priv->mesh_obj);
837         }
838
839         for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) {
840                 err = sysfs_create_file(vlan->kobj,
841                                         &((*bat_attr)->attr));
842                 if (err) {
843                         batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
844                                    dev->name, vlan_subdir,
845                                    ((*bat_attr)->attr).name);
846                         goto rem_attr;
847                 }
848         }
849
850         return 0;
851
852 rem_attr:
853         for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
854                 sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
855
856         if (vlan->kobj != bat_priv->mesh_obj) {
857                 kobject_uevent(vlan->kobj, KOBJ_REMOVE);
858                 kobject_del(vlan->kobj);
859         }
860         kobject_put(vlan->kobj);
861         vlan->kobj = NULL;
862 out:
863         return -ENOMEM;
864 }
865
866 /**
867  * batadv_sysfs_del_vlan - remove all the sysfs objects for a given VLAN
868  * @bat_priv: the bat priv with all the soft interface information
869  * @vlan: the private data of the VLAN to destroy
870  */
871 void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv,
872                            struct batadv_softif_vlan *vlan)
873 {
874         struct batadv_attribute **bat_attr;
875
876         for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
877                 sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
878
879         if (vlan->kobj != bat_priv->mesh_obj) {
880                 kobject_uevent(vlan->kobj, KOBJ_REMOVE);
881                 kobject_del(vlan->kobj);
882         }
883         kobject_put(vlan->kobj);
884         vlan->kobj = NULL;
885 }
886
887 static ssize_t batadv_show_mesh_iface(struct kobject *kobj,
888                                       struct attribute *attr, char *buff)
889 {
890         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
891         struct batadv_hard_iface *hard_iface;
892         ssize_t length;
893         const char *ifname;
894
895         hard_iface = batadv_hardif_get_by_netdev(net_dev);
896         if (!hard_iface)
897                 return 0;
898
899         if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
900                 ifname =  "none";
901         else
902                 ifname = hard_iface->soft_iface->name;
903
904         length = sprintf(buff, "%s\n", ifname);
905
906         batadv_hardif_put(hard_iface);
907
908         return length;
909 }
910
911 /**
912  * batadv_store_mesh_iface_finish - store new hardif mesh_iface state
913  * @net_dev: netdevice to add/remove to/from batman-adv soft-interface
914  * @ifname: name of soft-interface to modify
915  *
916  * Changes the parts of the hard+soft interface which can not be modified under
917  * sysfs lock (to prevent deadlock situations).
918  *
919  * Return: 0 on success, 0 < on failure
920  */
921 static int batadv_store_mesh_iface_finish(struct net_device *net_dev,
922                                           char ifname[IFNAMSIZ])
923 {
924         struct net *net = dev_net(net_dev);
925         struct batadv_hard_iface *hard_iface;
926         int status_tmp;
927         int ret = 0;
928
929         ASSERT_RTNL();
930
931         hard_iface = batadv_hardif_get_by_netdev(net_dev);
932         if (!hard_iface)
933                 return 0;
934
935         if (strncmp(ifname, "none", 4) == 0)
936                 status_tmp = BATADV_IF_NOT_IN_USE;
937         else
938                 status_tmp = BATADV_IF_I_WANT_YOU;
939
940         if (hard_iface->if_status == status_tmp)
941                 goto out;
942
943         if ((hard_iface->soft_iface) &&
944             (strncmp(hard_iface->soft_iface->name, ifname, IFNAMSIZ) == 0))
945                 goto out;
946
947         if (status_tmp == BATADV_IF_NOT_IN_USE) {
948                 batadv_hardif_disable_interface(hard_iface,
949                                                 BATADV_IF_CLEANUP_AUTO);
950                 goto out;
951         }
952
953         /* if the interface already is in use */
954         if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
955                 batadv_hardif_disable_interface(hard_iface,
956                                                 BATADV_IF_CLEANUP_AUTO);
957
958         ret = batadv_hardif_enable_interface(hard_iface, net, ifname);
959 out:
960         batadv_hardif_put(hard_iface);
961         return ret;
962 }
963
964 /**
965  * batadv_store_mesh_iface_work - store new hardif mesh_iface state
966  * @work: work queue item
967  *
968  * Changes the parts of the hard+soft interface which can not be modified under
969  * sysfs lock (to prevent deadlock situations).
970  */
971 static void batadv_store_mesh_iface_work(struct work_struct *work)
972 {
973         struct batadv_store_mesh_work *store_work;
974         int ret;
975
976         store_work = container_of(work, struct batadv_store_mesh_work, work);
977
978         rtnl_lock();
979         ret = batadv_store_mesh_iface_finish(store_work->net_dev,
980                                              store_work->soft_iface_name);
981         rtnl_unlock();
982
983         if (ret < 0)
984                 pr_err("Failed to store new mesh_iface state %s for %s: %d\n",
985                        store_work->soft_iface_name, store_work->net_dev->name,
986                        ret);
987
988         dev_put(store_work->net_dev);
989         kfree(store_work);
990 }
991
992 static ssize_t batadv_store_mesh_iface(struct kobject *kobj,
993                                        struct attribute *attr, char *buff,
994                                        size_t count)
995 {
996         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
997         struct batadv_store_mesh_work *store_work;
998
999         if (buff[count - 1] == '\n')
1000                 buff[count - 1] = '\0';
1001
1002         if (strlen(buff) >= IFNAMSIZ) {
1003                 pr_err("Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n",
1004                        buff);
1005                 return -EINVAL;
1006         }
1007
1008         store_work = kmalloc(sizeof(*store_work), GFP_KERNEL);
1009         if (!store_work)
1010                 return -ENOMEM;
1011
1012         dev_hold(net_dev);
1013         INIT_WORK(&store_work->work, batadv_store_mesh_iface_work);
1014         store_work->net_dev = net_dev;
1015         strlcpy(store_work->soft_iface_name, buff,
1016                 sizeof(store_work->soft_iface_name));
1017
1018         queue_work(batadv_event_workqueue, &store_work->work);
1019
1020         return count;
1021 }
1022
1023 static ssize_t batadv_show_iface_status(struct kobject *kobj,
1024                                         struct attribute *attr, char *buff)
1025 {
1026         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
1027         struct batadv_hard_iface *hard_iface;
1028         ssize_t length;
1029
1030         hard_iface = batadv_hardif_get_by_netdev(net_dev);
1031         if (!hard_iface)
1032                 return 0;
1033
1034         switch (hard_iface->if_status) {
1035         case BATADV_IF_TO_BE_REMOVED:
1036                 length = sprintf(buff, "disabling\n");
1037                 break;
1038         case BATADV_IF_INACTIVE:
1039                 length = sprintf(buff, "inactive\n");
1040                 break;
1041         case BATADV_IF_ACTIVE:
1042                 length = sprintf(buff, "active\n");
1043                 break;
1044         case BATADV_IF_TO_BE_ACTIVATED:
1045                 length = sprintf(buff, "enabling\n");
1046                 break;
1047         case BATADV_IF_NOT_IN_USE:
1048         default:
1049                 length = sprintf(buff, "not in use\n");
1050                 break;
1051         }
1052
1053         batadv_hardif_put(hard_iface);
1054
1055         return length;
1056 }
1057
1058 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
1059
1060 /**
1061  * batadv_store_throughput_override - parse and store throughput override
1062  *  entered by the user
1063  * @kobj: kobject representing the private mesh sysfs directory
1064  * @attr: the batman-adv attribute the user is interacting with
1065  * @buff: the buffer containing the user data
1066  * @count: number of bytes in the buffer
1067  *
1068  * Return: 'count' on success or a negative error code in case of failure
1069  */
1070 static ssize_t batadv_store_throughput_override(struct kobject *kobj,
1071                                                 struct attribute *attr,
1072                                                 char *buff, size_t count)
1073 {
1074         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
1075         struct batadv_hard_iface *hard_iface;
1076         u32 tp_override;
1077         u32 old_tp_override;
1078         bool ret;
1079
1080         hard_iface = batadv_hardif_get_by_netdev(net_dev);
1081         if (!hard_iface)
1082                 return -EINVAL;
1083
1084         if (buff[count - 1] == '\n')
1085                 buff[count - 1] = '\0';
1086
1087         ret = batadv_parse_throughput(net_dev, buff, "throughput_override",
1088                                       &tp_override);
1089         if (!ret)
1090                 goto out;
1091
1092         old_tp_override = atomic_read(&hard_iface->bat_v.throughput_override);
1093         if (old_tp_override == tp_override)
1094                 goto out;
1095
1096         batadv_info(hard_iface->soft_iface,
1097                     "%s: %s: Changing from: %u.%u MBit to: %u.%u MBit\n",
1098                     "throughput_override", net_dev->name,
1099                     old_tp_override / 10, old_tp_override % 10,
1100                     tp_override / 10, tp_override % 10);
1101
1102         atomic_set(&hard_iface->bat_v.throughput_override, tp_override);
1103
1104 out:
1105         batadv_hardif_put(hard_iface);
1106         return count;
1107 }
1108
1109 static ssize_t batadv_show_throughput_override(struct kobject *kobj,
1110                                                struct attribute *attr,
1111                                                char *buff)
1112 {
1113         struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
1114         struct batadv_hard_iface *hard_iface;
1115         u32 tp_override;
1116
1117         hard_iface = batadv_hardif_get_by_netdev(net_dev);
1118         if (!hard_iface)
1119                 return -EINVAL;
1120
1121         tp_override = atomic_read(&hard_iface->bat_v.throughput_override);
1122
1123         batadv_hardif_put(hard_iface);
1124         return sprintf(buff, "%u.%u MBit\n", tp_override / 10,
1125                        tp_override % 10);
1126 }
1127
1128 #endif
1129
1130 static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface,
1131                    batadv_store_mesh_iface);
1132 static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL);
1133 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
1134 BATADV_ATTR_HIF_UINT(elp_interval, bat_v.elp_interval, S_IRUGO | S_IWUSR,
1135                      2 * BATADV_JITTER, INT_MAX, NULL);
1136 static BATADV_ATTR(throughput_override, S_IRUGO | S_IWUSR,
1137                    batadv_show_throughput_override,
1138                    batadv_store_throughput_override);
1139 #endif
1140
1141 static struct batadv_attribute *batadv_batman_attrs[] = {
1142         &batadv_attr_mesh_iface,
1143         &batadv_attr_iface_status,
1144 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
1145         &batadv_attr_elp_interval,
1146         &batadv_attr_throughput_override,
1147 #endif
1148         NULL,
1149 };
1150
1151 int batadv_sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev)
1152 {
1153         struct kobject *hardif_kobject = &dev->dev.kobj;
1154         struct batadv_attribute **bat_attr;
1155         int err;
1156
1157         *hardif_obj = kobject_create_and_add(BATADV_SYSFS_IF_BAT_SUBDIR,
1158                                              hardif_kobject);
1159
1160         if (!*hardif_obj) {
1161                 batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
1162                            BATADV_SYSFS_IF_BAT_SUBDIR);
1163                 goto out;
1164         }
1165
1166         for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) {
1167                 err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr));
1168                 if (err) {
1169                         batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
1170                                    dev->name, BATADV_SYSFS_IF_BAT_SUBDIR,
1171                                    ((*bat_attr)->attr).name);
1172                         goto rem_attr;
1173                 }
1174         }
1175
1176         return 0;
1177
1178 rem_attr:
1179         for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr)
1180                 sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr));
1181 out:
1182         return -ENOMEM;
1183 }
1184
1185 void batadv_sysfs_del_hardif(struct kobject **hardif_obj)
1186 {
1187         kobject_uevent(*hardif_obj, KOBJ_REMOVE);
1188         kobject_del(*hardif_obj);
1189         kobject_put(*hardif_obj);
1190         *hardif_obj = NULL;
1191 }
1192
1193 int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
1194                         enum batadv_uev_action action, const char *data)
1195 {
1196         int ret = -ENOMEM;
1197         struct kobject *bat_kobj;
1198         char *uevent_env[4] = { NULL, NULL, NULL, NULL };
1199
1200         bat_kobj = &bat_priv->soft_iface->dev.kobj;
1201
1202         uevent_env[0] = kasprintf(GFP_ATOMIC,
1203                                   "%s%s", BATADV_UEV_TYPE_VAR,
1204                                   batadv_uev_type_str[type]);
1205         if (!uevent_env[0])
1206                 goto out;
1207
1208         uevent_env[1] = kasprintf(GFP_ATOMIC,
1209                                   "%s%s", BATADV_UEV_ACTION_VAR,
1210                                   batadv_uev_action_str[action]);
1211         if (!uevent_env[1])
1212                 goto out;
1213
1214         /* If the event is DEL, ignore the data field */
1215         if (action != BATADV_UEV_DEL) {
1216                 uevent_env[2] = kasprintf(GFP_ATOMIC,
1217                                           "%s%s", BATADV_UEV_DATA_VAR, data);
1218                 if (!uevent_env[2])
1219                         goto out;
1220         }
1221
1222         ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
1223 out:
1224         kfree(uevent_env[0]);
1225         kfree(uevent_env[1]);
1226         kfree(uevent_env[2]);
1227
1228         if (ret)
1229                 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1230                            "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
1231                            batadv_uev_type_str[type],
1232                            batadv_uev_action_str[action],
1233                            (action == BATADV_UEV_DEL ? "NULL" : data), ret);
1234         return ret;
1235 }