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