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