1 /* Copyright (C) 2010-2012 B.A.T.M.A.N. contributors:
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.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "bat_sysfs.h"
22 #include "translation-table.h"
23 #include "originator.h"
24 #include "hard-interface.h"
25 #include "gateway_common.h"
26 #include "gateway_client.h"
29 static struct net_device
*batadv_kobj_to_netdev(struct kobject
*obj
)
31 struct device
*dev
= container_of(obj
->parent
, struct device
, kobj
);
32 return to_net_dev(dev
);
35 static struct bat_priv
*batadv_kobj_to_batpriv(struct kobject
*obj
)
37 struct net_device
*net_dev
= batadv_kobj_to_netdev(obj
);
38 return netdev_priv(net_dev
);
41 #define BATADV_UEV_TYPE_VAR "BATTYPE="
42 #define BATADV_UEV_ACTION_VAR "BATACTION="
43 #define BATADV_UEV_DATA_VAR "BATDATA="
45 static char *batadv_uev_action_str
[] = {
51 static char *batadv_uev_type_str
[] = {
55 /* Use this, if you have customized show and store functions */
56 #define BATADV_ATTR(_name, _mode, _show, _store) \
57 struct bat_attribute batadv_attr_##_name = { \
58 .attr = {.name = __stringify(_name), \
64 #define BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
65 ssize_t batadv_store_##_name(struct kobject *kobj, \
66 struct attribute *attr, char *buff, \
69 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
70 struct bat_priv *bat_priv = netdev_priv(net_dev); \
71 return __batadv_store_bool_attr(buff, count, _post_func, attr, \
72 &bat_priv->_name, net_dev); \
75 #define BATADV_ATTR_SIF_SHOW_BOOL(_name) \
76 ssize_t batadv_show_##_name(struct kobject *kobj, \
77 struct attribute *attr, char *buff) \
79 struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
80 return sprintf(buff, "%s\n", \
81 atomic_read(&bat_priv->_name) == 0 ? \
82 "disabled" : "enabled"); \
85 /* Use this, if you are going to turn a [name] in the soft-interface
86 * (bat_priv) on or off
88 #define BATADV_ATTR_SIF_BOOL(_name, _mode, _post_func) \
89 static BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
90 static BATADV_ATTR_SIF_SHOW_BOOL(_name) \
91 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
95 #define BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func) \
96 ssize_t batadv_store_##_name(struct kobject *kobj, \
97 struct attribute *attr, char *buff, \
100 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
101 struct bat_priv *bat_priv = netdev_priv(net_dev); \
102 return __batadv_store_uint_attr(buff, count, _min, _max, \
104 &bat_priv->_name, net_dev); \
107 #define BATADV_ATTR_SIF_SHOW_UINT(_name) \
108 ssize_t batadv_show_##_name(struct kobject *kobj, \
109 struct attribute *attr, char *buff) \
111 struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
112 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \
115 /* Use this, if you are going to set [name] in the soft-interface
116 * (bat_priv) to an unsigned integer value
118 #define BATADV_ATTR_SIF_UINT(_name, _mode, _min, _max, _post_func) \
119 static BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func)\
120 static BATADV_ATTR_SIF_SHOW_UINT(_name) \
121 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
122 batadv_store_##_name)
125 #define BATADV_ATTR_HIF_STORE_UINT(_name, _min, _max, _post_func) \
126 ssize_t batadv_store_##_name(struct kobject *kobj, \
127 struct attribute *attr, char *buff, \
130 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
131 struct hard_iface *hard_iface; \
134 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
138 length = __batadv_store_uint_attr(buff, count, _min, _max, \
140 &hard_iface->_name, net_dev); \
142 batadv_hardif_free_ref(hard_iface); \
146 #define BATADV_ATTR_HIF_SHOW_UINT(_name) \
147 ssize_t batadv_show_##_name(struct kobject *kobj, \
148 struct attribute *attr, char *buff) \
150 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
151 struct hard_iface *hard_iface; \
154 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
158 length = sprintf(buff, "%i\n", atomic_read(&hard_iface->_name));\
160 batadv_hardif_free_ref(hard_iface); \
164 /* Use this, if you are going to set [name] in hard_iface to an
165 * unsigned integer value
167 #define BATADV_ATTR_HIF_UINT(_name, _mode, _min, _max, _post_func) \
168 static BATADV_ATTR_HIF_STORE_UINT(_name, _min, _max, _post_func)\
169 static BATADV_ATTR_HIF_SHOW_UINT(_name) \
170 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
171 batadv_store_##_name)
174 static int batadv_store_bool_attr(char *buff
, size_t count
,
175 struct net_device
*net_dev
,
176 const char *attr_name
, atomic_t
*attr
)
180 if (buff
[count
- 1] == '\n')
181 buff
[count
- 1] = '\0';
183 if ((strncmp(buff
, "1", 2) == 0) ||
184 (strncmp(buff
, "enable", 7) == 0) ||
185 (strncmp(buff
, "enabled", 8) == 0))
188 if ((strncmp(buff
, "0", 2) == 0) ||
189 (strncmp(buff
, "disable", 8) == 0) ||
190 (strncmp(buff
, "disabled", 9) == 0))
194 batadv_info(net_dev
, "%s: Invalid parameter received: %s\n",
199 if (atomic_read(attr
) == enabled
)
202 batadv_info(net_dev
, "%s: Changing from: %s to: %s\n", attr_name
,
203 atomic_read(attr
) == 1 ? "enabled" : "disabled",
204 enabled
== 1 ? "enabled" : "disabled");
206 atomic_set(attr
, (unsigned int)enabled
);
210 static inline ssize_t
211 __batadv_store_bool_attr(char *buff
, size_t count
,
212 void (*post_func
)(struct net_device
*),
213 struct attribute
*attr
,
214 atomic_t
*attr_store
, struct net_device
*net_dev
)
218 ret
= batadv_store_bool_attr(buff
, count
, net_dev
, attr
->name
,
220 if (post_func
&& ret
)
226 static int batadv_store_uint_attr(const char *buff
, size_t count
,
227 struct net_device
*net_dev
,
228 const char *attr_name
,
229 unsigned int min
, unsigned int max
,
232 unsigned long uint_val
;
235 ret
= kstrtoul(buff
, 10, &uint_val
);
237 batadv_info(net_dev
, "%s: Invalid parameter received: %s\n",
242 if (uint_val
< min
) {
243 batadv_info(net_dev
, "%s: Value is too small: %lu min: %u\n",
244 attr_name
, uint_val
, min
);
248 if (uint_val
> max
) {
249 batadv_info(net_dev
, "%s: Value is too big: %lu max: %u\n",
250 attr_name
, uint_val
, max
);
254 if (atomic_read(attr
) == uint_val
)
257 batadv_info(net_dev
, "%s: Changing from: %i to: %lu\n",
258 attr_name
, atomic_read(attr
), uint_val
);
260 atomic_set(attr
, uint_val
);
264 static inline ssize_t
265 __batadv_store_uint_attr(const char *buff
, size_t count
,
267 void (*post_func
)(struct net_device
*),
268 const struct attribute
*attr
,
269 atomic_t
*attr_store
, struct net_device
*net_dev
)
273 ret
= batadv_store_uint_attr(buff
, count
, net_dev
, attr
->name
, min
, max
,
275 if (post_func
&& ret
)
281 static ssize_t
batadv_show_vis_mode(struct kobject
*kobj
,
282 struct attribute
*attr
, char *buff
)
284 struct bat_priv
*bat_priv
= batadv_kobj_to_batpriv(kobj
);
285 int vis_mode
= atomic_read(&bat_priv
->vis_mode
);
287 return sprintf(buff
, "%s\n",
288 vis_mode
== VIS_TYPE_CLIENT_UPDATE
?
289 "client" : "server");
292 static ssize_t
batadv_store_vis_mode(struct kobject
*kobj
,
293 struct attribute
*attr
, char *buff
,
296 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
297 struct bat_priv
*bat_priv
= netdev_priv(net_dev
);
299 int ret
, vis_mode_tmp
= -1;
300 const char *old_mode
, *new_mode
;
302 ret
= kstrtoul(buff
, 10, &val
);
304 if (((count
== 2) && (!ret
) && (val
== VIS_TYPE_CLIENT_UPDATE
)) ||
305 (strncmp(buff
, "client", 6) == 0) ||
306 (strncmp(buff
, "off", 3) == 0))
307 vis_mode_tmp
= VIS_TYPE_CLIENT_UPDATE
;
309 if (((count
== 2) && (!ret
) && (val
== VIS_TYPE_SERVER_SYNC
)) ||
310 (strncmp(buff
, "server", 6) == 0))
311 vis_mode_tmp
= VIS_TYPE_SERVER_SYNC
;
313 if (vis_mode_tmp
< 0) {
314 if (buff
[count
- 1] == '\n')
315 buff
[count
- 1] = '\0';
318 "Invalid parameter for 'vis mode' setting received: %s\n",
323 if (atomic_read(&bat_priv
->vis_mode
) == vis_mode_tmp
)
326 if (atomic_read(&bat_priv
->vis_mode
) == VIS_TYPE_CLIENT_UPDATE
)
331 if (vis_mode_tmp
== VIS_TYPE_CLIENT_UPDATE
)
336 batadv_info(net_dev
, "Changing vis mode from: %s to: %s\n", old_mode
,
339 atomic_set(&bat_priv
->vis_mode
, (unsigned int)vis_mode_tmp
);
343 static ssize_t
batadv_show_bat_algo(struct kobject
*kobj
,
344 struct attribute
*attr
, char *buff
)
346 struct bat_priv
*bat_priv
= batadv_kobj_to_batpriv(kobj
);
347 return sprintf(buff
, "%s\n", bat_priv
->bat_algo_ops
->name
);
350 static void batadv_post_gw_deselect(struct net_device
*net_dev
)
352 struct bat_priv
*bat_priv
= netdev_priv(net_dev
);
353 batadv_gw_deselect(bat_priv
);
356 static ssize_t
batadv_show_gw_mode(struct kobject
*kobj
, struct attribute
*attr
,
359 struct bat_priv
*bat_priv
= batadv_kobj_to_batpriv(kobj
);
362 switch (atomic_read(&bat_priv
->gw_mode
)) {
364 bytes_written
= sprintf(buff
, "%s\n", GW_MODE_CLIENT_NAME
);
367 bytes_written
= sprintf(buff
, "%s\n", GW_MODE_SERVER_NAME
);
370 bytes_written
= sprintf(buff
, "%s\n", GW_MODE_OFF_NAME
);
374 return bytes_written
;
377 static ssize_t
batadv_store_gw_mode(struct kobject
*kobj
,
378 struct attribute
*attr
, char *buff
,
381 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
382 struct bat_priv
*bat_priv
= netdev_priv(net_dev
);
383 char *curr_gw_mode_str
;
384 int gw_mode_tmp
= -1;
386 if (buff
[count
- 1] == '\n')
387 buff
[count
- 1] = '\0';
389 if (strncmp(buff
, GW_MODE_OFF_NAME
, strlen(GW_MODE_OFF_NAME
)) == 0)
390 gw_mode_tmp
= GW_MODE_OFF
;
392 if (strncmp(buff
, GW_MODE_CLIENT_NAME
,
393 strlen(GW_MODE_CLIENT_NAME
)) == 0)
394 gw_mode_tmp
= GW_MODE_CLIENT
;
396 if (strncmp(buff
, GW_MODE_SERVER_NAME
,
397 strlen(GW_MODE_SERVER_NAME
)) == 0)
398 gw_mode_tmp
= GW_MODE_SERVER
;
400 if (gw_mode_tmp
< 0) {
402 "Invalid parameter for 'gw mode' setting received: %s\n",
407 if (atomic_read(&bat_priv
->gw_mode
) == gw_mode_tmp
)
410 switch (atomic_read(&bat_priv
->gw_mode
)) {
412 curr_gw_mode_str
= GW_MODE_CLIENT_NAME
;
415 curr_gw_mode_str
= GW_MODE_SERVER_NAME
;
418 curr_gw_mode_str
= GW_MODE_OFF_NAME
;
422 batadv_info(net_dev
, "Changing gw mode from: %s to: %s\n",
423 curr_gw_mode_str
, buff
);
425 batadv_gw_deselect(bat_priv
);
426 atomic_set(&bat_priv
->gw_mode
, (unsigned int)gw_mode_tmp
);
430 static ssize_t
batadv_show_gw_bwidth(struct kobject
*kobj
,
431 struct attribute
*attr
, char *buff
)
433 struct bat_priv
*bat_priv
= batadv_kobj_to_batpriv(kobj
);
435 int gw_bandwidth
= atomic_read(&bat_priv
->gw_bandwidth
);
437 batadv_gw_bandwidth_to_kbit(gw_bandwidth
, &down
, &up
);
438 return sprintf(buff
, "%i%s/%i%s\n",
439 (down
> 2048 ? down
/ 1024 : down
),
440 (down
> 2048 ? "MBit" : "KBit"),
441 (up
> 2048 ? up
/ 1024 : up
),
442 (up
> 2048 ? "MBit" : "KBit"));
445 static ssize_t
batadv_store_gw_bwidth(struct kobject
*kobj
,
446 struct attribute
*attr
, char *buff
,
449 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
451 if (buff
[count
- 1] == '\n')
452 buff
[count
- 1] = '\0';
454 return batadv_gw_bandwidth_set(net_dev
, buff
, count
);
457 BATADV_ATTR_SIF_BOOL(aggregated_ogms
, S_IRUGO
| S_IWUSR
, NULL
);
458 BATADV_ATTR_SIF_BOOL(bonding
, S_IRUGO
| S_IWUSR
, NULL
);
459 #ifdef CONFIG_BATMAN_ADV_BLA
460 BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance
, S_IRUGO
| S_IWUSR
, NULL
);
462 BATADV_ATTR_SIF_BOOL(fragmentation
, S_IRUGO
| S_IWUSR
, batadv_update_min_mtu
);
463 BATADV_ATTR_SIF_BOOL(ap_isolation
, S_IRUGO
| S_IWUSR
, NULL
);
464 static BATADV_ATTR(vis_mode
, S_IRUGO
| S_IWUSR
, batadv_show_vis_mode
,
465 batadv_store_vis_mode
);
466 static BATADV_ATTR(routing_algo
, S_IRUGO
, batadv_show_bat_algo
, NULL
);
467 static BATADV_ATTR(gw_mode
, S_IRUGO
| S_IWUSR
, batadv_show_gw_mode
,
468 batadv_store_gw_mode
);
469 BATADV_ATTR_SIF_UINT(orig_interval
, S_IRUGO
| S_IWUSR
, 2 * JITTER
, INT_MAX
,
471 BATADV_ATTR_SIF_UINT(hop_penalty
, S_IRUGO
| S_IWUSR
, 0, TQ_MAX_VALUE
, NULL
);
472 BATADV_ATTR_SIF_UINT(gw_sel_class
, S_IRUGO
| S_IWUSR
, 1, TQ_MAX_VALUE
,
473 batadv_post_gw_deselect
);
474 static BATADV_ATTR(gw_bandwidth
, S_IRUGO
| S_IWUSR
, batadv_show_gw_bwidth
,
475 batadv_store_gw_bwidth
);
476 #ifdef CONFIG_BATMAN_ADV_DEBUG
477 BATADV_ATTR_SIF_UINT(log_level
, S_IRUGO
| S_IWUSR
, 0, DBG_ALL
, NULL
);
480 static struct bat_attribute
*batadv_mesh_attrs
[] = {
481 &batadv_attr_aggregated_ogms
,
482 &batadv_attr_bonding
,
483 #ifdef CONFIG_BATMAN_ADV_BLA
484 &batadv_attr_bridge_loop_avoidance
,
486 &batadv_attr_fragmentation
,
487 &batadv_attr_ap_isolation
,
488 &batadv_attr_vis_mode
,
489 &batadv_attr_routing_algo
,
490 &batadv_attr_gw_mode
,
491 &batadv_attr_orig_interval
,
492 &batadv_attr_hop_penalty
,
493 &batadv_attr_gw_sel_class
,
494 &batadv_attr_gw_bandwidth
,
495 #ifdef CONFIG_BATMAN_ADV_DEBUG
496 &batadv_attr_log_level
,
501 int batadv_sysfs_add_meshif(struct net_device
*dev
)
503 struct kobject
*batif_kobject
= &dev
->dev
.kobj
;
504 struct bat_priv
*bat_priv
= netdev_priv(dev
);
505 struct bat_attribute
**bat_attr
;
508 bat_priv
->mesh_obj
= kobject_create_and_add(BATADV_SYSFS_IF_MESH_SUBDIR
,
510 if (!bat_priv
->mesh_obj
) {
511 batadv_err(dev
, "Can't add sysfs directory: %s/%s\n", dev
->name
,
512 BATADV_SYSFS_IF_MESH_SUBDIR
);
516 for (bat_attr
= batadv_mesh_attrs
; *bat_attr
; ++bat_attr
) {
517 err
= sysfs_create_file(bat_priv
->mesh_obj
,
518 &((*bat_attr
)->attr
));
520 batadv_err(dev
, "Can't add sysfs file: %s/%s/%s\n",
521 dev
->name
, BATADV_SYSFS_IF_MESH_SUBDIR
,
522 ((*bat_attr
)->attr
).name
);
530 for (bat_attr
= batadv_mesh_attrs
; *bat_attr
; ++bat_attr
)
531 sysfs_remove_file(bat_priv
->mesh_obj
, &((*bat_attr
)->attr
));
533 kobject_put(bat_priv
->mesh_obj
);
534 bat_priv
->mesh_obj
= NULL
;
539 void batadv_sysfs_del_meshif(struct net_device
*dev
)
541 struct bat_priv
*bat_priv
= netdev_priv(dev
);
542 struct bat_attribute
**bat_attr
;
544 for (bat_attr
= batadv_mesh_attrs
; *bat_attr
; ++bat_attr
)
545 sysfs_remove_file(bat_priv
->mesh_obj
, &((*bat_attr
)->attr
));
547 kobject_put(bat_priv
->mesh_obj
);
548 bat_priv
->mesh_obj
= NULL
;
551 static ssize_t
batadv_show_mesh_iface(struct kobject
*kobj
,
552 struct attribute
*attr
, char *buff
)
554 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
555 struct hard_iface
*hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
561 length
= sprintf(buff
, "%s\n", hard_iface
->if_status
== IF_NOT_IN_USE
?
562 "none" : hard_iface
->soft_iface
->name
);
564 batadv_hardif_free_ref(hard_iface
);
569 static ssize_t
batadv_store_mesh_iface(struct kobject
*kobj
,
570 struct attribute
*attr
, char *buff
,
573 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
574 struct hard_iface
*hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
581 if (buff
[count
- 1] == '\n')
582 buff
[count
- 1] = '\0';
584 if (strlen(buff
) >= IFNAMSIZ
) {
585 pr_err("Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n",
587 batadv_hardif_free_ref(hard_iface
);
591 if (strncmp(buff
, "none", 4) == 0)
592 status_tmp
= IF_NOT_IN_USE
;
594 status_tmp
= IF_I_WANT_YOU
;
596 if (hard_iface
->if_status
== status_tmp
)
599 if ((hard_iface
->soft_iface
) &&
600 (strncmp(hard_iface
->soft_iface
->name
, buff
, IFNAMSIZ
) == 0))
603 if (!rtnl_trylock()) {
608 if (status_tmp
== IF_NOT_IN_USE
) {
609 batadv_hardif_disable_interface(hard_iface
);
613 /* if the interface already is in use */
614 if (hard_iface
->if_status
!= IF_NOT_IN_USE
)
615 batadv_hardif_disable_interface(hard_iface
);
617 ret
= batadv_hardif_enable_interface(hard_iface
, buff
);
622 batadv_hardif_free_ref(hard_iface
);
626 static ssize_t
batadv_show_iface_status(struct kobject
*kobj
,
627 struct attribute
*attr
, char *buff
)
629 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
630 struct hard_iface
*hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
636 switch (hard_iface
->if_status
) {
637 case IF_TO_BE_REMOVED
:
638 length
= sprintf(buff
, "disabling\n");
641 length
= sprintf(buff
, "inactive\n");
644 length
= sprintf(buff
, "active\n");
646 case IF_TO_BE_ACTIVATED
:
647 length
= sprintf(buff
, "enabling\n");
651 length
= sprintf(buff
, "not in use\n");
655 batadv_hardif_free_ref(hard_iface
);
660 static BATADV_ATTR(mesh_iface
, S_IRUGO
| S_IWUSR
, batadv_show_mesh_iface
,
661 batadv_store_mesh_iface
);
662 static BATADV_ATTR(iface_status
, S_IRUGO
, batadv_show_iface_status
, NULL
);
664 static struct bat_attribute
*batadv_batman_attrs
[] = {
665 &batadv_attr_mesh_iface
,
666 &batadv_attr_iface_status
,
670 int batadv_sysfs_add_hardif(struct kobject
**hardif_obj
, struct net_device
*dev
)
672 struct kobject
*hardif_kobject
= &dev
->dev
.kobj
;
673 struct bat_attribute
**bat_attr
;
676 *hardif_obj
= kobject_create_and_add(BATADV_SYSFS_IF_BAT_SUBDIR
,
680 batadv_err(dev
, "Can't add sysfs directory: %s/%s\n", dev
->name
,
681 BATADV_SYSFS_IF_BAT_SUBDIR
);
685 for (bat_attr
= batadv_batman_attrs
; *bat_attr
; ++bat_attr
) {
686 err
= sysfs_create_file(*hardif_obj
, &((*bat_attr
)->attr
));
688 batadv_err(dev
, "Can't add sysfs file: %s/%s/%s\n",
689 dev
->name
, BATADV_SYSFS_IF_BAT_SUBDIR
,
690 ((*bat_attr
)->attr
).name
);
698 for (bat_attr
= batadv_batman_attrs
; *bat_attr
; ++bat_attr
)
699 sysfs_remove_file(*hardif_obj
, &((*bat_attr
)->attr
));
704 void batadv_sysfs_del_hardif(struct kobject
**hardif_obj
)
706 kobject_put(*hardif_obj
);
710 int batadv_throw_uevent(struct bat_priv
*bat_priv
, enum uev_type type
,
711 enum uev_action action
, const char *data
)
714 struct hard_iface
*primary_if
= NULL
;
715 struct kobject
*bat_kobj
;
716 char *uevent_env
[4] = { NULL
, NULL
, NULL
, NULL
};
718 primary_if
= batadv_primary_if_get_selected(bat_priv
);
722 bat_kobj
= &primary_if
->soft_iface
->dev
.kobj
;
724 uevent_env
[0] = kmalloc(strlen(BATADV_UEV_TYPE_VAR
) +
725 strlen(batadv_uev_type_str
[type
]) + 1,
730 sprintf(uevent_env
[0], "%s%s", BATADV_UEV_TYPE_VAR
,
731 batadv_uev_type_str
[type
]);
733 uevent_env
[1] = kmalloc(strlen(BATADV_UEV_ACTION_VAR
) +
734 strlen(batadv_uev_action_str
[action
]) + 1,
739 sprintf(uevent_env
[1], "%s%s", BATADV_UEV_ACTION_VAR
,
740 batadv_uev_action_str
[action
]);
742 /* If the event is DEL, ignore the data field */
743 if (action
!= UEV_DEL
) {
744 uevent_env
[2] = kmalloc(strlen(BATADV_UEV_DATA_VAR
) +
745 strlen(data
) + 1, GFP_ATOMIC
);
749 sprintf(uevent_env
[2], "%s%s", BATADV_UEV_DATA_VAR
, data
);
752 ret
= kobject_uevent_env(bat_kobj
, KOBJ_CHANGE
, uevent_env
);
754 kfree(uevent_env
[0]);
755 kfree(uevent_env
[1]);
756 kfree(uevent_env
[2]);
759 batadv_hardif_free_ref(primary_if
);
762 batadv_dbg(DBG_BATMAN
, bat_priv
,
763 "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
764 batadv_uev_type_str
[type
],
765 batadv_uev_action_str
[action
],
766 (action
== UEV_DEL
? "NULL" : data
), ret
);