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