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