1 /* Copyright (C) 2010-2014 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, see <http://www.gnu.org/licenses/>.
20 #include "translation-table.h"
21 #include "distributed-arp-table.h"
22 #include "network-coding.h"
23 #include "originator.h"
24 #include "hard-interface.h"
25 #include "soft-interface.h"
26 #include "gateway_common.h"
27 #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);
33 return to_net_dev(dev);
36 static struct batadv_priv *batadv_kobj_to_batpriv(struct kobject *obj)
38 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); \
130 return __batadv_store_bool_attr(buff, count, _post_func, attr, \
131 &bat_priv->_name, net_dev); \
134 #define BATADV_ATTR_SIF_SHOW_BOOL(_name) \
135 ssize_t batadv_show_##_name(struct kobject *kobj, \
136 struct attribute *attr, char *buff) \
138 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
140 return sprintf(buff, "%s\n", \
141 atomic_read(&bat_priv->_name) == 0 ? \
142 "disabled" : "enabled"); \
145 /* Use this, if you are going to turn a [name] in the soft-interface
146 * (bat_priv) on or off
148 #define BATADV_ATTR_SIF_BOOL(_name, _mode, _post_func) \
149 static BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
150 static BATADV_ATTR_SIF_SHOW_BOOL(_name) \
151 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
152 batadv_store_##_name)
155 #define BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func) \
156 ssize_t batadv_store_##_name(struct kobject *kobj, \
157 struct attribute *attr, char *buff, \
160 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
161 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
163 return __batadv_store_uint_attr(buff, count, _min, _max, \
165 &bat_priv->_name, net_dev); \
168 #define BATADV_ATTR_SIF_SHOW_UINT(_name) \
169 ssize_t batadv_show_##_name(struct kobject *kobj, \
170 struct attribute *attr, char *buff) \
172 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
174 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \
177 /* Use this, if you are going to set [name] in the soft-interface
178 * (bat_priv) to an unsigned integer value
180 #define BATADV_ATTR_SIF_UINT(_name, _mode, _min, _max, _post_func) \
181 static BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func)\
182 static BATADV_ATTR_SIF_SHOW_UINT(_name) \
183 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
184 batadv_store_##_name)
186 #define BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \
187 ssize_t batadv_store_vlan_##_name(struct kobject *kobj, \
188 struct attribute *attr, char *buff, \
191 struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
192 struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
194 size_t res = __batadv_store_bool_attr(buff, count, _post_func, \
195 attr, &vlan->_name, \
196 bat_priv->soft_iface); \
198 batadv_softif_vlan_free_ref(vlan); \
202 #define BATADV_ATTR_VLAN_SHOW_BOOL(_name) \
203 ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \
204 struct attribute *attr, char *buff) \
206 struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\
207 struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \
209 size_t res = sprintf(buff, "%s\n", \
210 atomic_read(&vlan->_name) == 0 ? \
211 "disabled" : "enabled"); \
213 batadv_softif_vlan_free_ref(vlan); \
217 /* Use this, if you are going to turn a [name] in the vlan struct on or off */
218 #define BATADV_ATTR_VLAN_BOOL(_name, _mode, _post_func) \
219 static BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \
220 static BATADV_ATTR_VLAN_SHOW_BOOL(_name) \
221 static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \
222 batadv_store_vlan_##_name)
224 static int batadv_store_bool_attr(char *buff, size_t count,
225 struct net_device *net_dev,
226 const char *attr_name, atomic_t *attr)
230 if (buff[count - 1] == '\n')
231 buff[count - 1] = '\0';
233 if ((strncmp(buff, "1", 2) == 0) ||
234 (strncmp(buff, "enable", 7) == 0) ||
235 (strncmp(buff, "enabled", 8) == 0))
238 if ((strncmp(buff, "0", 2) == 0) ||
239 (strncmp(buff, "disable", 8) == 0) ||
240 (strncmp(buff, "disabled", 9) == 0))
244 batadv_info(net_dev, "%s: Invalid parameter received: %s\n",
249 if (atomic_read(attr) == enabled)
252 batadv_info(net_dev, "%s: Changing from: %s to: %s\n", attr_name,
253 atomic_read(attr) == 1 ? "enabled" : "disabled",
254 enabled == 1 ? "enabled" : "disabled");
256 atomic_set(attr, (unsigned int)enabled);
260 static inline ssize_t
261 __batadv_store_bool_attr(char *buff, size_t count,
262 void (*post_func)(struct net_device *),
263 struct attribute *attr,
264 atomic_t *attr_store, struct net_device *net_dev)
268 ret = batadv_store_bool_attr(buff, count, net_dev, attr->name,
270 if (post_func && ret)
276 static int batadv_store_uint_attr(const char *buff, size_t count,
277 struct net_device *net_dev,
278 const char *attr_name,
279 unsigned int min, unsigned int max,
282 unsigned long uint_val;
285 ret = kstrtoul(buff, 10, &uint_val);
287 batadv_info(net_dev, "%s: Invalid parameter received: %s\n",
292 if (uint_val < min) {
293 batadv_info(net_dev, "%s: Value is too small: %lu min: %u\n",
294 attr_name, uint_val, min);
298 if (uint_val > max) {
299 batadv_info(net_dev, "%s: Value is too big: %lu max: %u\n",
300 attr_name, uint_val, max);
304 if (atomic_read(attr) == uint_val)
307 batadv_info(net_dev, "%s: Changing from: %i to: %lu\n",
308 attr_name, atomic_read(attr), uint_val);
310 atomic_set(attr, uint_val);
314 static inline ssize_t
315 __batadv_store_uint_attr(const char *buff, size_t count,
317 void (*post_func)(struct net_device *),
318 const struct attribute *attr,
319 atomic_t *attr_store, struct net_device *net_dev)
323 ret = batadv_store_uint_attr(buff, count, net_dev, attr->name, min, max,
325 if (post_func && ret)
331 static ssize_t batadv_show_bat_algo(struct kobject *kobj,
332 struct attribute *attr, char *buff)
334 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
336 return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name);
339 static void batadv_post_gw_reselect(struct net_device *net_dev)
341 struct batadv_priv *bat_priv = netdev_priv(net_dev);
343 batadv_gw_reselect(bat_priv);
346 static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr,
349 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
352 switch (atomic_read(&bat_priv->gw_mode)) {
353 case BATADV_GW_MODE_CLIENT:
354 bytes_written = sprintf(buff, "%s\n",
355 BATADV_GW_MODE_CLIENT_NAME);
357 case BATADV_GW_MODE_SERVER:
358 bytes_written = sprintf(buff, "%s\n",
359 BATADV_GW_MODE_SERVER_NAME);
362 bytes_written = sprintf(buff, "%s\n",
363 BATADV_GW_MODE_OFF_NAME);
367 return bytes_written;
370 static ssize_t batadv_store_gw_mode(struct kobject *kobj,
371 struct attribute *attr, char *buff,
374 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
375 struct batadv_priv *bat_priv = netdev_priv(net_dev);
376 char *curr_gw_mode_str;
377 int gw_mode_tmp = -1;
379 if (buff[count - 1] == '\n')
380 buff[count - 1] = '\0';
382 if (strncmp(buff, BATADV_GW_MODE_OFF_NAME,
383 strlen(BATADV_GW_MODE_OFF_NAME)) == 0)
384 gw_mode_tmp = BATADV_GW_MODE_OFF;
386 if (strncmp(buff, BATADV_GW_MODE_CLIENT_NAME,
387 strlen(BATADV_GW_MODE_CLIENT_NAME)) == 0)
388 gw_mode_tmp = BATADV_GW_MODE_CLIENT;
390 if (strncmp(buff, BATADV_GW_MODE_SERVER_NAME,
391 strlen(BATADV_GW_MODE_SERVER_NAME)) == 0)
392 gw_mode_tmp = BATADV_GW_MODE_SERVER;
394 if (gw_mode_tmp < 0) {
396 "Invalid parameter for 'gw mode' setting received: %s\n",
401 if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp)
404 switch (atomic_read(&bat_priv->gw_mode)) {
405 case BATADV_GW_MODE_CLIENT:
406 curr_gw_mode_str = BATADV_GW_MODE_CLIENT_NAME;
408 case BATADV_GW_MODE_SERVER:
409 curr_gw_mode_str = BATADV_GW_MODE_SERVER_NAME;
412 curr_gw_mode_str = BATADV_GW_MODE_OFF_NAME;
416 batadv_info(net_dev, "Changing gw mode from: %s to: %s\n",
417 curr_gw_mode_str, buff);
419 /* Invoking batadv_gw_reselect() is not enough to really de-select the
420 * current GW. It will only instruct the gateway client code to perform
421 * a re-election the next time that this is needed.
423 * When gw client mode is being switched off the current GW must be
424 * de-selected explicitly otherwise no GW_ADD uevent is thrown on
425 * client mode re-activation. This is operation is performed in
426 * batadv_gw_check_client_stop().
428 batadv_gw_reselect(bat_priv);
429 /* always call batadv_gw_check_client_stop() before changing the gateway
432 batadv_gw_check_client_stop(bat_priv);
433 atomic_set(&bat_priv->gw_mode, (unsigned int)gw_mode_tmp);
434 batadv_gw_tvlv_container_update(bat_priv);
438 static ssize_t batadv_show_gw_bwidth(struct kobject *kobj,
439 struct attribute *attr, char *buff)
441 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
444 down = atomic_read(&bat_priv->gw.bandwidth_down);
445 up = atomic_read(&bat_priv->gw.bandwidth_up);
447 return sprintf(buff, "%u.%u/%u.%u MBit\n", down / 10,
448 down % 10, up / 10, up % 10);
451 static ssize_t batadv_store_gw_bwidth(struct kobject *kobj,
452 struct attribute *attr, char *buff,
455 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
457 if (buff[count - 1] == '\n')
458 buff[count - 1] = '\0';
460 return batadv_gw_bandwidth_set(net_dev, buff, count);
464 * batadv_show_isolation_mark - print the current isolation mark/mask
465 * @kobj: kobject representing the private mesh sysfs directory
466 * @attr: the batman-adv attribute the user is interacting with
467 * @buff: the buffer that will contain the data to send back to the user
469 * Returns the number of bytes written into 'buff' on success or a negative
470 * error code in case of failure
472 static ssize_t batadv_show_isolation_mark(struct kobject *kobj,
473 struct attribute *attr, char *buff)
475 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
477 return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark,
478 bat_priv->isolation_mark_mask);
482 * batadv_store_isolation_mark - parse and store the isolation mark/mask entered
484 * @kobj: kobject representing the private mesh sysfs directory
485 * @attr: the batman-adv attribute the user is interacting with
486 * @buff: the buffer containing the user data
487 * @count: number of bytes in the buffer
489 * Returns 'count' on success or a negative error code in case of failure
491 static ssize_t batadv_store_isolation_mark(struct kobject *kobj,
492 struct attribute *attr, char *buff,
495 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
496 struct batadv_priv *bat_priv = netdev_priv(net_dev);
500 /* parse the mask if it has been specified, otherwise assume the mask is
501 * the biggest possible
504 mask_ptr = strchr(buff, '/');
509 /* the mask must be entered in hex base as it is going to be a
510 * bitmask and not a prefix length
512 if (kstrtou32(mask_ptr, 16, &mask) < 0)
516 /* the mark can be entered in any base */
517 if (kstrtou32(buff, 0, &mark) < 0)
520 bat_priv->isolation_mark_mask = mask;
521 /* erase bits not covered by the mask */
522 bat_priv->isolation_mark = mark & bat_priv->isolation_mark_mask;
525 "New skb mark for extended isolation: %#.8x/%#.8x\n",
526 bat_priv->isolation_mark, bat_priv->isolation_mark_mask);
531 BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL);
532 BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
533 #ifdef CONFIG_BATMAN_ADV_BLA
534 BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR, NULL);
536 #ifdef CONFIG_BATMAN_ADV_DAT
537 BATADV_ATTR_SIF_BOOL(distributed_arp_table, S_IRUGO | S_IWUSR,
538 batadv_dat_status_update);
540 BATADV_ATTR_SIF_BOOL(fragmentation, S_IRUGO | S_IWUSR, batadv_update_min_mtu);
541 static BATADV_ATTR(routing_algo, S_IRUGO, batadv_show_bat_algo, NULL);
542 static BATADV_ATTR(gw_mode, S_IRUGO | S_IWUSR, batadv_show_gw_mode,
543 batadv_store_gw_mode);
544 BATADV_ATTR_SIF_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * BATADV_JITTER,
546 BATADV_ATTR_SIF_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, BATADV_TQ_MAX_VALUE,
548 BATADV_ATTR_SIF_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, BATADV_TQ_MAX_VALUE,
549 batadv_post_gw_reselect);
550 static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth,
551 batadv_store_gw_bwidth);
552 #ifdef CONFIG_BATMAN_ADV_MCAST
553 BATADV_ATTR_SIF_BOOL(multicast_mode, S_IRUGO | S_IWUSR, NULL);
555 #ifdef CONFIG_BATMAN_ADV_DEBUG
556 BATADV_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, BATADV_DBG_ALL, NULL);
558 #ifdef CONFIG_BATMAN_ADV_NC
559 BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR,
560 batadv_nc_status_update);
562 static BATADV_ATTR(isolation_mark, S_IRUGO | S_IWUSR,
563 batadv_show_isolation_mark, batadv_store_isolation_mark);
565 static struct batadv_attribute *batadv_mesh_attrs[] = {
566 &batadv_attr_aggregated_ogms,
567 &batadv_attr_bonding,
568 #ifdef CONFIG_BATMAN_ADV_BLA
569 &batadv_attr_bridge_loop_avoidance,
571 #ifdef CONFIG_BATMAN_ADV_DAT
572 &batadv_attr_distributed_arp_table,
574 #ifdef CONFIG_BATMAN_ADV_MCAST
575 &batadv_attr_multicast_mode,
577 &batadv_attr_fragmentation,
578 &batadv_attr_routing_algo,
579 &batadv_attr_gw_mode,
580 &batadv_attr_orig_interval,
581 &batadv_attr_hop_penalty,
582 &batadv_attr_gw_sel_class,
583 &batadv_attr_gw_bandwidth,
584 #ifdef CONFIG_BATMAN_ADV_DEBUG
585 &batadv_attr_log_level,
587 #ifdef CONFIG_BATMAN_ADV_NC
588 &batadv_attr_network_coding,
590 &batadv_attr_isolation_mark,
594 BATADV_ATTR_VLAN_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL);
597 * batadv_vlan_attrs - array of vlan specific sysfs attributes
599 static struct batadv_attribute *batadv_vlan_attrs[] = {
600 &batadv_attr_vlan_ap_isolation,
604 int batadv_sysfs_add_meshif(struct net_device *dev)
606 struct kobject *batif_kobject = &dev->dev.kobj;
607 struct batadv_priv *bat_priv = netdev_priv(dev);
608 struct batadv_attribute **bat_attr;
611 bat_priv->mesh_obj = kobject_create_and_add(BATADV_SYSFS_IF_MESH_SUBDIR,
613 if (!bat_priv->mesh_obj) {
614 batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
615 BATADV_SYSFS_IF_MESH_SUBDIR);
619 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) {
620 err = sysfs_create_file(bat_priv->mesh_obj,
621 &((*bat_attr)->attr));
623 batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
624 dev->name, BATADV_SYSFS_IF_MESH_SUBDIR,
625 ((*bat_attr)->attr).name);
633 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
634 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
636 kobject_put(bat_priv->mesh_obj);
637 bat_priv->mesh_obj = NULL;
642 void batadv_sysfs_del_meshif(struct net_device *dev)
644 struct batadv_priv *bat_priv = netdev_priv(dev);
645 struct batadv_attribute **bat_attr;
647 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
648 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
650 kobject_put(bat_priv->mesh_obj);
651 bat_priv->mesh_obj = NULL;
655 * batadv_sysfs_add_vlan - add all the needed sysfs objects for the new vlan
656 * @dev: netdev of the mesh interface
657 * @vlan: private data of the newly added VLAN interface
659 * Returns 0 on success and -ENOMEM if any of the structure allocations fails.
661 int batadv_sysfs_add_vlan(struct net_device *dev,
662 struct batadv_softif_vlan *vlan)
664 char vlan_subdir[sizeof(BATADV_SYSFS_VLAN_SUBDIR_PREFIX) + 5];
665 struct batadv_priv *bat_priv = netdev_priv(dev);
666 struct batadv_attribute **bat_attr;
669 if (vlan->vid & BATADV_VLAN_HAS_TAG) {
670 sprintf(vlan_subdir, BATADV_SYSFS_VLAN_SUBDIR_PREFIX "%hu",
671 vlan->vid & VLAN_VID_MASK);
673 vlan->kobj = kobject_create_and_add(vlan_subdir,
676 batadv_err(dev, "Can't add sysfs directory: %s/%s\n",
677 dev->name, vlan_subdir);
681 /* the untagged LAN uses the root folder to store its "VLAN
682 * specific attributes"
684 vlan->kobj = bat_priv->mesh_obj;
685 kobject_get(bat_priv->mesh_obj);
688 for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) {
689 err = sysfs_create_file(vlan->kobj,
690 &((*bat_attr)->attr));
692 batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
693 dev->name, vlan_subdir,
694 ((*bat_attr)->attr).name);
702 for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
703 sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
705 kobject_put(vlan->kobj);
712 * batadv_sysfs_del_vlan - remove all the sysfs objects for a given VLAN
713 * @bat_priv: the bat priv with all the soft interface information
714 * @vlan: the private data of the VLAN to destroy
716 void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv,
717 struct batadv_softif_vlan *vlan)
719 struct batadv_attribute **bat_attr;
721 for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
722 sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
724 kobject_put(vlan->kobj);
728 static ssize_t batadv_show_mesh_iface(struct kobject *kobj,
729 struct attribute *attr, char *buff)
731 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
732 struct batadv_hard_iface *hard_iface;
736 hard_iface = batadv_hardif_get_by_netdev(net_dev);
740 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
743 ifname = hard_iface->soft_iface->name;
745 length = sprintf(buff, "%s\n", ifname);
747 batadv_hardif_free_ref(hard_iface);
752 static ssize_t batadv_store_mesh_iface(struct kobject *kobj,
753 struct attribute *attr, char *buff,
756 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
757 struct batadv_hard_iface *hard_iface;
761 hard_iface = batadv_hardif_get_by_netdev(net_dev);
765 if (buff[count - 1] == '\n')
766 buff[count - 1] = '\0';
768 if (strlen(buff) >= IFNAMSIZ) {
769 pr_err("Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n",
771 batadv_hardif_free_ref(hard_iface);
775 if (strncmp(buff, "none", 4) == 0)
776 status_tmp = BATADV_IF_NOT_IN_USE;
778 status_tmp = BATADV_IF_I_WANT_YOU;
780 if (hard_iface->if_status == status_tmp)
783 if ((hard_iface->soft_iface) &&
784 (strncmp(hard_iface->soft_iface->name, buff, IFNAMSIZ) == 0))
789 if (status_tmp == BATADV_IF_NOT_IN_USE) {
790 batadv_hardif_disable_interface(hard_iface,
791 BATADV_IF_CLEANUP_AUTO);
795 /* if the interface already is in use */
796 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
797 batadv_hardif_disable_interface(hard_iface,
798 BATADV_IF_CLEANUP_AUTO);
800 ret = batadv_hardif_enable_interface(hard_iface, buff);
805 batadv_hardif_free_ref(hard_iface);
809 static ssize_t batadv_show_iface_status(struct kobject *kobj,
810 struct attribute *attr, char *buff)
812 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
813 struct batadv_hard_iface *hard_iface;
816 hard_iface = batadv_hardif_get_by_netdev(net_dev);
820 switch (hard_iface->if_status) {
821 case BATADV_IF_TO_BE_REMOVED:
822 length = sprintf(buff, "disabling\n");
824 case BATADV_IF_INACTIVE:
825 length = sprintf(buff, "inactive\n");
827 case BATADV_IF_ACTIVE:
828 length = sprintf(buff, "active\n");
830 case BATADV_IF_TO_BE_ACTIVATED:
831 length = sprintf(buff, "enabling\n");
833 case BATADV_IF_NOT_IN_USE:
835 length = sprintf(buff, "not in use\n");
839 batadv_hardif_free_ref(hard_iface);
844 static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface,
845 batadv_store_mesh_iface);
846 static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL);
848 static struct batadv_attribute *batadv_batman_attrs[] = {
849 &batadv_attr_mesh_iface,
850 &batadv_attr_iface_status,
854 int batadv_sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev)
856 struct kobject *hardif_kobject = &dev->dev.kobj;
857 struct batadv_attribute **bat_attr;
860 *hardif_obj = kobject_create_and_add(BATADV_SYSFS_IF_BAT_SUBDIR,
864 batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
865 BATADV_SYSFS_IF_BAT_SUBDIR);
869 for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) {
870 err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr));
872 batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n",
873 dev->name, BATADV_SYSFS_IF_BAT_SUBDIR,
874 ((*bat_attr)->attr).name);
882 for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr)
883 sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr));
888 void batadv_sysfs_del_hardif(struct kobject **hardif_obj)
890 kobject_put(*hardif_obj);
894 int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
895 enum batadv_uev_action action, const char *data)
898 struct kobject *bat_kobj;
899 char *uevent_env[4] = { NULL, NULL, NULL, NULL };
901 bat_kobj = &bat_priv->soft_iface->dev.kobj;
903 uevent_env[0] = kasprintf(GFP_ATOMIC,
904 "%s%s", BATADV_UEV_TYPE_VAR,
905 batadv_uev_type_str[type]);
909 uevent_env[1] = kasprintf(GFP_ATOMIC,
910 "%s%s", BATADV_UEV_ACTION_VAR,
911 batadv_uev_action_str[action]);
915 /* If the event is DEL, ignore the data field */
916 if (action != BATADV_UEV_DEL) {
917 uevent_env[2] = kasprintf(GFP_ATOMIC,
918 "%s%s", BATADV_UEV_DATA_VAR, data);
923 ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
925 kfree(uevent_env[0]);
926 kfree(uevent_env[1]);
927 kfree(uevent_env[2]);
930 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
931 "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
932 batadv_uev_type_str[type],
933 batadv_uev_action_str[action],
934 (action == BATADV_UEV_DEL ? "NULL" : data), ret);