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