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