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