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