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