1 /* Copyright (C) 2010-2013 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
22 #include "translation-table.h"
23 #include "distributed-arp-table.h"
24 #include "network-coding.h"
25 #include "originator.h"
26 #include "hard-interface.h"
27 #include "soft-interface.h"
28 #include "gateway_common.h"
29 #include "gateway_client.h"
31 static struct net_device
*batadv_kobj_to_netdev(struct kobject
*obj
)
33 struct device
*dev
= container_of(obj
->parent
, struct device
, kobj
);
34 return to_net_dev(dev
);
37 static struct batadv_priv
*batadv_kobj_to_batpriv(struct kobject
*obj
)
39 struct net_device
*net_dev
= batadv_kobj_to_netdev(obj
);
40 return netdev_priv(net_dev
);
44 * batadv_vlan_kobj_to_batpriv - convert a vlan kobj in the associated batpriv
45 * @obj: kobject to covert
47 * Returns the associated batadv_priv struct.
49 static struct batadv_priv
*batadv_vlan_kobj_to_batpriv(struct kobject
*obj
)
51 /* VLAN specific attributes are located in the root sysfs folder if they
52 * refer to the untagged VLAN..
54 if (!strcmp(BATADV_SYSFS_IF_MESH_SUBDIR
, obj
->name
))
55 return batadv_kobj_to_batpriv(obj
);
57 /* ..while the attributes for the tagged vlans are located in
58 * the in the corresponding "vlan%VID" subfolder
60 return batadv_kobj_to_batpriv(obj
->parent
);
64 * batadv_kobj_to_vlan - convert a kobj in the associated softif_vlan struct
65 * @obj: kobject to covert
67 * Returns the associated softif_vlan struct if found, NULL otherwise.
69 static struct batadv_softif_vlan
*
70 batadv_kobj_to_vlan(struct batadv_priv
*bat_priv
, struct kobject
*obj
)
72 struct batadv_softif_vlan
*vlan_tmp
, *vlan
= NULL
;
75 hlist_for_each_entry_rcu(vlan_tmp
, &bat_priv
->softif_vlan_list
, list
) {
76 if (vlan_tmp
->kobj
!= obj
)
79 if (!atomic_inc_not_zero(&vlan_tmp
->refcount
))
90 #define BATADV_UEV_TYPE_VAR "BATTYPE="
91 #define BATADV_UEV_ACTION_VAR "BATACTION="
92 #define BATADV_UEV_DATA_VAR "BATDATA="
94 static char *batadv_uev_action_str
[] = {
100 static char *batadv_uev_type_str
[] = {
104 /* Use this, if you have customized show and store functions for vlan attrs */
105 #define BATADV_ATTR_VLAN(_name, _mode, _show, _store) \
106 struct batadv_attribute batadv_attr_vlan_##_name = { \
107 .attr = {.name = __stringify(_name), \
113 /* Use this, if you have customized show and store functions */
114 #define BATADV_ATTR(_name, _mode, _show, _store) \
115 struct batadv_attribute batadv_attr_##_name = { \
116 .attr = {.name = __stringify(_name), \
122 #define BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
123 ssize_t batadv_store_##_name(struct kobject *kobj, \
124 struct attribute *attr, char *buff, \
127 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
128 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
129 return __batadv_store_bool_attr(buff, count, _post_func, attr, \
130 &bat_priv->_name, net_dev); \
133 #define BATADV_ATTR_SIF_SHOW_BOOL(_name) \
134 ssize_t batadv_show_##_name(struct kobject *kobj, \
135 struct attribute *attr, char *buff) \
137 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
138 return sprintf(buff, "%s\n", \
139 atomic_read(&bat_priv->_name) == 0 ? \
140 "disabled" : "enabled"); \
143 /* Use this, if you are going to turn a [name] in the soft-interface
144 * (bat_priv) on or off
146 #define BATADV_ATTR_SIF_BOOL(_name, _mode, _post_func) \
147 static BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
148 static BATADV_ATTR_SIF_SHOW_BOOL(_name) \
149 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
150 batadv_store_##_name)
153 #define BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func) \
154 ssize_t batadv_store_##_name(struct kobject *kobj, \
155 struct attribute *attr, char *buff, \
158 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
159 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
160 return __batadv_store_uint_attr(buff, count, _min, _max, \
162 &bat_priv->_name, net_dev); \
165 #define BATADV_ATTR_SIF_SHOW_UINT(_name) \
166 ssize_t batadv_show_##_name(struct kobject *kobj, \
167 struct attribute *attr, char *buff) \
169 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
170 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \
173 /* Use this, if you are going to set [name] in the soft-interface
174 * (bat_priv) to an unsigned integer value
176 #define BATADV_ATTR_SIF_UINT(_name, _mode, _min, _max, _post_func) \
177 static BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func)\
178 static BATADV_ATTR_SIF_SHOW_UINT(_name) \
179 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
180 batadv_store_##_name)
182 #define BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \
183 ssize_t batadv_store_vlan_##_name(struct kobject *kobj, \
184 struct attribute *attr, char *buff, \
187 struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
188 struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
190 size_t res = __batadv_store_bool_attr(buff, count, _post_func, \
191 attr, &vlan->_name, \
192 bat_priv->soft_iface); \
193 batadv_softif_vlan_free_ref(vlan); \
197 #define BATADV_ATTR_VLAN_SHOW_BOOL(_name) \
198 ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \
199 struct attribute *attr, char *buff) \
201 struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
202 struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
204 size_t res = sprintf(buff, "%s\n", \
205 atomic_read(&vlan->_name) == 0 ? \
206 "disabled" : "enabled"); \
207 batadv_softif_vlan_free_ref(vlan); \
211 /* Use this, if you are going to turn a [name] in the vlan struct on or off */
212 #define BATADV_ATTR_VLAN_BOOL(_name, _mode, _post_func) \
213 static BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \
214 static BATADV_ATTR_VLAN_SHOW_BOOL(_name) \
215 static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \
216 batadv_store_vlan_##_name)
218 static int batadv_store_bool_attr(char *buff
, size_t count
,
219 struct net_device
*net_dev
,
220 const char *attr_name
, atomic_t
*attr
)
224 if (buff
[count
- 1] == '\n')
225 buff
[count
- 1] = '\0';
227 if ((strncmp(buff
, "1", 2) == 0) ||
228 (strncmp(buff
, "enable", 7) == 0) ||
229 (strncmp(buff
, "enabled", 8) == 0))
232 if ((strncmp(buff
, "0", 2) == 0) ||
233 (strncmp(buff
, "disable", 8) == 0) ||
234 (strncmp(buff
, "disabled", 9) == 0))
238 batadv_info(net_dev
, "%s: Invalid parameter received: %s\n",
243 if (atomic_read(attr
) == enabled
)
246 batadv_info(net_dev
, "%s: Changing from: %s to: %s\n", attr_name
,
247 atomic_read(attr
) == 1 ? "enabled" : "disabled",
248 enabled
== 1 ? "enabled" : "disabled");
250 atomic_set(attr
, (unsigned int)enabled
);
254 static inline ssize_t
255 __batadv_store_bool_attr(char *buff
, size_t count
,
256 void (*post_func
)(struct net_device
*),
257 struct attribute
*attr
,
258 atomic_t
*attr_store
, struct net_device
*net_dev
)
262 ret
= batadv_store_bool_attr(buff
, count
, net_dev
, attr
->name
,
264 if (post_func
&& ret
)
270 static int batadv_store_uint_attr(const char *buff
, size_t count
,
271 struct net_device
*net_dev
,
272 const char *attr_name
,
273 unsigned int min
, unsigned int max
,
276 unsigned long uint_val
;
279 ret
= kstrtoul(buff
, 10, &uint_val
);
281 batadv_info(net_dev
, "%s: Invalid parameter received: %s\n",
286 if (uint_val
< min
) {
287 batadv_info(net_dev
, "%s: Value is too small: %lu min: %u\n",
288 attr_name
, uint_val
, min
);
292 if (uint_val
> max
) {
293 batadv_info(net_dev
, "%s: Value is too big: %lu max: %u\n",
294 attr_name
, uint_val
, max
);
298 if (atomic_read(attr
) == uint_val
)
301 batadv_info(net_dev
, "%s: Changing from: %i to: %lu\n",
302 attr_name
, atomic_read(attr
), uint_val
);
304 atomic_set(attr
, uint_val
);
308 static inline ssize_t
309 __batadv_store_uint_attr(const char *buff
, size_t count
,
311 void (*post_func
)(struct net_device
*),
312 const struct attribute
*attr
,
313 atomic_t
*attr_store
, struct net_device
*net_dev
)
317 ret
= batadv_store_uint_attr(buff
, count
, net_dev
, attr
->name
, min
, max
,
319 if (post_func
&& ret
)
325 static ssize_t
batadv_show_bat_algo(struct kobject
*kobj
,
326 struct attribute
*attr
, char *buff
)
328 struct batadv_priv
*bat_priv
= batadv_kobj_to_batpriv(kobj
);
329 return sprintf(buff
, "%s\n", bat_priv
->bat_algo_ops
->name
);
332 static void batadv_post_gw_deselect(struct net_device
*net_dev
)
334 struct batadv_priv
*bat_priv
= netdev_priv(net_dev
);
335 batadv_gw_deselect(bat_priv
);
338 static ssize_t
batadv_show_gw_mode(struct kobject
*kobj
, struct attribute
*attr
,
341 struct batadv_priv
*bat_priv
= batadv_kobj_to_batpriv(kobj
);
344 switch (atomic_read(&bat_priv
->gw_mode
)) {
345 case BATADV_GW_MODE_CLIENT
:
346 bytes_written
= sprintf(buff
, "%s\n",
347 BATADV_GW_MODE_CLIENT_NAME
);
349 case BATADV_GW_MODE_SERVER
:
350 bytes_written
= sprintf(buff
, "%s\n",
351 BATADV_GW_MODE_SERVER_NAME
);
354 bytes_written
= sprintf(buff
, "%s\n",
355 BATADV_GW_MODE_OFF_NAME
);
359 return bytes_written
;
362 static ssize_t
batadv_store_gw_mode(struct kobject
*kobj
,
363 struct attribute
*attr
, char *buff
,
366 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
367 struct batadv_priv
*bat_priv
= netdev_priv(net_dev
);
368 char *curr_gw_mode_str
;
369 int gw_mode_tmp
= -1;
371 if (buff
[count
- 1] == '\n')
372 buff
[count
- 1] = '\0';
374 if (strncmp(buff
, BATADV_GW_MODE_OFF_NAME
,
375 strlen(BATADV_GW_MODE_OFF_NAME
)) == 0)
376 gw_mode_tmp
= BATADV_GW_MODE_OFF
;
378 if (strncmp(buff
, BATADV_GW_MODE_CLIENT_NAME
,
379 strlen(BATADV_GW_MODE_CLIENT_NAME
)) == 0)
380 gw_mode_tmp
= BATADV_GW_MODE_CLIENT
;
382 if (strncmp(buff
, BATADV_GW_MODE_SERVER_NAME
,
383 strlen(BATADV_GW_MODE_SERVER_NAME
)) == 0)
384 gw_mode_tmp
= BATADV_GW_MODE_SERVER
;
386 if (gw_mode_tmp
< 0) {
388 "Invalid parameter for 'gw mode' setting received: %s\n",
393 if (atomic_read(&bat_priv
->gw_mode
) == gw_mode_tmp
)
396 switch (atomic_read(&bat_priv
->gw_mode
)) {
397 case BATADV_GW_MODE_CLIENT
:
398 curr_gw_mode_str
= BATADV_GW_MODE_CLIENT_NAME
;
400 case BATADV_GW_MODE_SERVER
:
401 curr_gw_mode_str
= BATADV_GW_MODE_SERVER_NAME
;
404 curr_gw_mode_str
= BATADV_GW_MODE_OFF_NAME
;
408 batadv_info(net_dev
, "Changing gw mode from: %s to: %s\n",
409 curr_gw_mode_str
, buff
);
411 batadv_gw_deselect(bat_priv
);
412 /* always call batadv_gw_check_client_stop() before changing the gateway
415 batadv_gw_check_client_stop(bat_priv
);
416 atomic_set(&bat_priv
->gw_mode
, (unsigned int)gw_mode_tmp
);
417 batadv_gw_tvlv_container_update(bat_priv
);
421 static ssize_t
batadv_show_gw_bwidth(struct kobject
*kobj
,
422 struct attribute
*attr
, char *buff
)
424 struct batadv_priv
*bat_priv
= batadv_kobj_to_batpriv(kobj
);
427 down
= atomic_read(&bat_priv
->gw
.bandwidth_down
);
428 up
= atomic_read(&bat_priv
->gw
.bandwidth_up
);
430 return sprintf(buff
, "%u.%u/%u.%u MBit\n", down
/ 10,
431 down
% 10, up
/ 10, up
% 10);
434 static ssize_t
batadv_store_gw_bwidth(struct kobject
*kobj
,
435 struct attribute
*attr
, char *buff
,
438 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
440 if (buff
[count
- 1] == '\n')
441 buff
[count
- 1] = '\0';
443 return batadv_gw_bandwidth_set(net_dev
, buff
, count
);
446 BATADV_ATTR_SIF_BOOL(aggregated_ogms
, S_IRUGO
| S_IWUSR
, NULL
);
447 BATADV_ATTR_SIF_BOOL(bonding
, S_IRUGO
| S_IWUSR
, NULL
);
448 #ifdef CONFIG_BATMAN_ADV_BLA
449 BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance
, S_IRUGO
| S_IWUSR
, NULL
);
451 #ifdef CONFIG_BATMAN_ADV_DAT
452 BATADV_ATTR_SIF_BOOL(distributed_arp_table
, S_IRUGO
| S_IWUSR
,
453 batadv_dat_status_update
);
455 BATADV_ATTR_SIF_BOOL(fragmentation
, S_IRUGO
| S_IWUSR
, batadv_update_min_mtu
);
456 static BATADV_ATTR(routing_algo
, S_IRUGO
, batadv_show_bat_algo
, NULL
);
457 static BATADV_ATTR(gw_mode
, S_IRUGO
| S_IWUSR
, batadv_show_gw_mode
,
458 batadv_store_gw_mode
);
459 BATADV_ATTR_SIF_UINT(orig_interval
, S_IRUGO
| S_IWUSR
, 2 * BATADV_JITTER
,
461 BATADV_ATTR_SIF_UINT(hop_penalty
, S_IRUGO
| S_IWUSR
, 0, BATADV_TQ_MAX_VALUE
,
463 BATADV_ATTR_SIF_UINT(gw_sel_class
, S_IRUGO
| S_IWUSR
, 1, BATADV_TQ_MAX_VALUE
,
464 batadv_post_gw_deselect
);
465 static BATADV_ATTR(gw_bandwidth
, S_IRUGO
| S_IWUSR
, batadv_show_gw_bwidth
,
466 batadv_store_gw_bwidth
);
467 #ifdef CONFIG_BATMAN_ADV_DEBUG
468 BATADV_ATTR_SIF_UINT(log_level
, S_IRUGO
| S_IWUSR
, 0, BATADV_DBG_ALL
, NULL
);
470 #ifdef CONFIG_BATMAN_ADV_NC
471 BATADV_ATTR_SIF_BOOL(network_coding
, S_IRUGO
| S_IWUSR
,
472 batadv_nc_status_update
);
475 static struct batadv_attribute
*batadv_mesh_attrs
[] = {
476 &batadv_attr_aggregated_ogms
,
477 &batadv_attr_bonding
,
478 #ifdef CONFIG_BATMAN_ADV_BLA
479 &batadv_attr_bridge_loop_avoidance
,
481 #ifdef CONFIG_BATMAN_ADV_DAT
482 &batadv_attr_distributed_arp_table
,
484 &batadv_attr_fragmentation
,
485 &batadv_attr_routing_algo
,
486 &batadv_attr_gw_mode
,
487 &batadv_attr_orig_interval
,
488 &batadv_attr_hop_penalty
,
489 &batadv_attr_gw_sel_class
,
490 &batadv_attr_gw_bandwidth
,
491 #ifdef CONFIG_BATMAN_ADV_DEBUG
492 &batadv_attr_log_level
,
494 #ifdef CONFIG_BATMAN_ADV_NC
495 &batadv_attr_network_coding
,
500 BATADV_ATTR_VLAN_BOOL(ap_isolation
, S_IRUGO
| S_IWUSR
, NULL
);
503 * batadv_vlan_attrs - array of vlan specific sysfs attributes
505 static struct batadv_attribute
*batadv_vlan_attrs
[] = {
506 &batadv_attr_vlan_ap_isolation
,
510 int batadv_sysfs_add_meshif(struct net_device
*dev
)
512 struct kobject
*batif_kobject
= &dev
->dev
.kobj
;
513 struct batadv_priv
*bat_priv
= netdev_priv(dev
);
514 struct batadv_attribute
**bat_attr
;
517 bat_priv
->mesh_obj
= kobject_create_and_add(BATADV_SYSFS_IF_MESH_SUBDIR
,
519 if (!bat_priv
->mesh_obj
) {
520 batadv_err(dev
, "Can't add sysfs directory: %s/%s\n", dev
->name
,
521 BATADV_SYSFS_IF_MESH_SUBDIR
);
525 for (bat_attr
= batadv_mesh_attrs
; *bat_attr
; ++bat_attr
) {
526 err
= sysfs_create_file(bat_priv
->mesh_obj
,
527 &((*bat_attr
)->attr
));
529 batadv_err(dev
, "Can't add sysfs file: %s/%s/%s\n",
530 dev
->name
, BATADV_SYSFS_IF_MESH_SUBDIR
,
531 ((*bat_attr
)->attr
).name
);
539 for (bat_attr
= batadv_mesh_attrs
; *bat_attr
; ++bat_attr
)
540 sysfs_remove_file(bat_priv
->mesh_obj
, &((*bat_attr
)->attr
));
542 kobject_put(bat_priv
->mesh_obj
);
543 bat_priv
->mesh_obj
= NULL
;
548 void batadv_sysfs_del_meshif(struct net_device
*dev
)
550 struct batadv_priv
*bat_priv
= netdev_priv(dev
);
551 struct batadv_attribute
**bat_attr
;
553 for (bat_attr
= batadv_mesh_attrs
; *bat_attr
; ++bat_attr
)
554 sysfs_remove_file(bat_priv
->mesh_obj
, &((*bat_attr
)->attr
));
556 kobject_put(bat_priv
->mesh_obj
);
557 bat_priv
->mesh_obj
= NULL
;
561 * batadv_sysfs_add_vlan - add all the needed sysfs objects for the new vlan
562 * @dev: netdev of the mesh interface
563 * @vlan: private data of the newly added VLAN interface
565 * Returns 0 on success and -ENOMEM if any of the structure allocations fails.
567 int batadv_sysfs_add_vlan(struct net_device
*dev
,
568 struct batadv_softif_vlan
*vlan
)
570 char vlan_subdir
[sizeof(BATADV_SYSFS_VLAN_SUBDIR_PREFIX
) + 5];
571 struct batadv_priv
*bat_priv
= netdev_priv(dev
);
572 struct batadv_attribute
**bat_attr
;
575 if (vlan
->vid
& BATADV_VLAN_HAS_TAG
) {
576 sprintf(vlan_subdir
, BATADV_SYSFS_VLAN_SUBDIR_PREFIX
"%hu",
577 vlan
->vid
& VLAN_VID_MASK
);
579 vlan
->kobj
= kobject_create_and_add(vlan_subdir
,
582 batadv_err(dev
, "Can't add sysfs directory: %s/%s\n",
583 dev
->name
, vlan_subdir
);
587 /* the untagged LAN uses the root folder to store its "VLAN
588 * specific attributes"
590 vlan
->kobj
= bat_priv
->mesh_obj
;
591 kobject_get(bat_priv
->mesh_obj
);
594 for (bat_attr
= batadv_vlan_attrs
; *bat_attr
; ++bat_attr
) {
595 err
= sysfs_create_file(vlan
->kobj
,
596 &((*bat_attr
)->attr
));
598 batadv_err(dev
, "Can't add sysfs file: %s/%s/%s\n",
599 dev
->name
, vlan_subdir
,
600 ((*bat_attr
)->attr
).name
);
608 for (bat_attr
= batadv_vlan_attrs
; *bat_attr
; ++bat_attr
)
609 sysfs_remove_file(vlan
->kobj
, &((*bat_attr
)->attr
));
611 kobject_put(vlan
->kobj
);
618 * batadv_sysfs_del_vlan - remove all the sysfs objects for a given VLAN
619 * @bat_priv: the bat priv with all the soft interface information
620 * @vlan: the private data of the VLAN to destroy
622 void batadv_sysfs_del_vlan(struct batadv_priv
*bat_priv
,
623 struct batadv_softif_vlan
*vlan
)
625 struct batadv_attribute
**bat_attr
;
627 for (bat_attr
= batadv_vlan_attrs
; *bat_attr
; ++bat_attr
)
628 sysfs_remove_file(vlan
->kobj
, &((*bat_attr
)->attr
));
630 kobject_put(vlan
->kobj
);
634 static ssize_t
batadv_show_mesh_iface(struct kobject
*kobj
,
635 struct attribute
*attr
, char *buff
)
637 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
638 struct batadv_hard_iface
*hard_iface
;
642 hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
646 if (hard_iface
->if_status
== BATADV_IF_NOT_IN_USE
)
649 ifname
= hard_iface
->soft_iface
->name
;
651 length
= sprintf(buff
, "%s\n", ifname
);
653 batadv_hardif_free_ref(hard_iface
);
658 static ssize_t
batadv_store_mesh_iface(struct kobject
*kobj
,
659 struct attribute
*attr
, char *buff
,
662 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
663 struct batadv_hard_iface
*hard_iface
;
667 hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
671 if (buff
[count
- 1] == '\n')
672 buff
[count
- 1] = '\0';
674 if (strlen(buff
) >= IFNAMSIZ
) {
675 pr_err("Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n",
677 batadv_hardif_free_ref(hard_iface
);
681 if (strncmp(buff
, "none", 4) == 0)
682 status_tmp
= BATADV_IF_NOT_IN_USE
;
684 status_tmp
= BATADV_IF_I_WANT_YOU
;
686 if (hard_iface
->if_status
== status_tmp
)
689 if ((hard_iface
->soft_iface
) &&
690 (strncmp(hard_iface
->soft_iface
->name
, buff
, IFNAMSIZ
) == 0))
695 if (status_tmp
== BATADV_IF_NOT_IN_USE
) {
696 batadv_hardif_disable_interface(hard_iface
,
697 BATADV_IF_CLEANUP_AUTO
);
701 /* if the interface already is in use */
702 if (hard_iface
->if_status
!= BATADV_IF_NOT_IN_USE
)
703 batadv_hardif_disable_interface(hard_iface
,
704 BATADV_IF_CLEANUP_AUTO
);
706 ret
= batadv_hardif_enable_interface(hard_iface
, buff
);
711 batadv_hardif_free_ref(hard_iface
);
715 static ssize_t
batadv_show_iface_status(struct kobject
*kobj
,
716 struct attribute
*attr
, char *buff
)
718 struct net_device
*net_dev
= batadv_kobj_to_netdev(kobj
);
719 struct batadv_hard_iface
*hard_iface
;
722 hard_iface
= batadv_hardif_get_by_netdev(net_dev
);
726 switch (hard_iface
->if_status
) {
727 case BATADV_IF_TO_BE_REMOVED
:
728 length
= sprintf(buff
, "disabling\n");
730 case BATADV_IF_INACTIVE
:
731 length
= sprintf(buff
, "inactive\n");
733 case BATADV_IF_ACTIVE
:
734 length
= sprintf(buff
, "active\n");
736 case BATADV_IF_TO_BE_ACTIVATED
:
737 length
= sprintf(buff
, "enabling\n");
739 case BATADV_IF_NOT_IN_USE
:
741 length
= sprintf(buff
, "not in use\n");
745 batadv_hardif_free_ref(hard_iface
);
750 static BATADV_ATTR(mesh_iface
, S_IRUGO
| S_IWUSR
, batadv_show_mesh_iface
,
751 batadv_store_mesh_iface
);
752 static BATADV_ATTR(iface_status
, S_IRUGO
, batadv_show_iface_status
, NULL
);
754 static struct batadv_attribute
*batadv_batman_attrs
[] = {
755 &batadv_attr_mesh_iface
,
756 &batadv_attr_iface_status
,
760 int batadv_sysfs_add_hardif(struct kobject
**hardif_obj
, struct net_device
*dev
)
762 struct kobject
*hardif_kobject
= &dev
->dev
.kobj
;
763 struct batadv_attribute
**bat_attr
;
766 *hardif_obj
= kobject_create_and_add(BATADV_SYSFS_IF_BAT_SUBDIR
,
770 batadv_err(dev
, "Can't add sysfs directory: %s/%s\n", dev
->name
,
771 BATADV_SYSFS_IF_BAT_SUBDIR
);
775 for (bat_attr
= batadv_batman_attrs
; *bat_attr
; ++bat_attr
) {
776 err
= sysfs_create_file(*hardif_obj
, &((*bat_attr
)->attr
));
778 batadv_err(dev
, "Can't add sysfs file: %s/%s/%s\n",
779 dev
->name
, BATADV_SYSFS_IF_BAT_SUBDIR
,
780 ((*bat_attr
)->attr
).name
);
788 for (bat_attr
= batadv_batman_attrs
; *bat_attr
; ++bat_attr
)
789 sysfs_remove_file(*hardif_obj
, &((*bat_attr
)->attr
));
794 void batadv_sysfs_del_hardif(struct kobject
**hardif_obj
)
796 kobject_put(*hardif_obj
);
800 int batadv_throw_uevent(struct batadv_priv
*bat_priv
, enum batadv_uev_type type
,
801 enum batadv_uev_action action
, const char *data
)
804 struct kobject
*bat_kobj
;
805 char *uevent_env
[4] = { NULL
, NULL
, NULL
, NULL
};
807 bat_kobj
= &bat_priv
->soft_iface
->dev
.kobj
;
809 uevent_env
[0] = kmalloc(strlen(BATADV_UEV_TYPE_VAR
) +
810 strlen(batadv_uev_type_str
[type
]) + 1,
815 sprintf(uevent_env
[0], "%s%s", BATADV_UEV_TYPE_VAR
,
816 batadv_uev_type_str
[type
]);
818 uevent_env
[1] = kmalloc(strlen(BATADV_UEV_ACTION_VAR
) +
819 strlen(batadv_uev_action_str
[action
]) + 1,
824 sprintf(uevent_env
[1], "%s%s", BATADV_UEV_ACTION_VAR
,
825 batadv_uev_action_str
[action
]);
827 /* If the event is DEL, ignore the data field */
828 if (action
!= BATADV_UEV_DEL
) {
829 uevent_env
[2] = kmalloc(strlen(BATADV_UEV_DATA_VAR
) +
830 strlen(data
) + 1, GFP_ATOMIC
);
834 sprintf(uevent_env
[2], "%s%s", BATADV_UEV_DATA_VAR
, data
);
837 ret
= kobject_uevent_env(bat_kobj
, KOBJ_CHANGE
, uevent_env
);
839 kfree(uevent_env
[0]);
840 kfree(uevent_env
[1]);
841 kfree(uevent_env
[2]);
844 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
845 "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
846 batadv_uev_type_str
[type
],
847 batadv_uev_action_str
[action
],
848 (action
== BATADV_UEV_DEL
? "NULL" : data
), ret
);