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