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