Antonio Quartulli | 0b87393 | 2013-01-04 03:05:31 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2010-2013 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 |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 | * 02110-1301, USA |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "main.h" |
Sven Eckelmann | b706b13 | 2012-06-10 23:58:51 +0200 | [diff] [blame] | 21 | #include "sysfs.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 22 | #include "translation-table.h" |
Antonio Quartulli | 33af49a | 2012-08-08 18:50:57 +0200 | [diff] [blame] | 23 | #include "distributed-arp-table.h" |
Marek Lindner | 3f4841f | 2013-04-23 21:40:00 +0800 | [diff] [blame] | 24 | #include "network-coding.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 25 | #include "originator.h" |
| 26 | #include "hard-interface.h" |
Antonio Quartulli | 90f4435 | 2013-07-02 11:04:35 +0200 | [diff] [blame^] | 27 | #include "soft-interface.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 28 | #include "gateway_common.h" |
| 29 | #include "gateway_client.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 30 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 31 | static struct net_device *batadv_kobj_to_netdev(struct kobject *obj) |
Sven Eckelmann | 3d222bb | 2011-06-05 10:20:19 +0200 | [diff] [blame] | 32 | { |
| 33 | struct device *dev = container_of(obj->parent, struct device, kobj); |
| 34 | return to_net_dev(dev); |
| 35 | } |
| 36 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 37 | static struct batadv_priv *batadv_kobj_to_batpriv(struct kobject *obj) |
Sven Eckelmann | 3d222bb | 2011-06-05 10:20:19 +0200 | [diff] [blame] | 38 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 39 | struct net_device *net_dev = batadv_kobj_to_netdev(obj); |
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, \ |
| 111 | }; |
| 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, \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 120 | }; |
| 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); \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 129 | return __batadv_store_bool_attr(buff, count, _post_func, attr, \ |
| 130 | &bat_priv->_name, net_dev); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 133 | #define BATADV_ATTR_SIF_SHOW_BOOL(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 134 | ssize_t batadv_show_##_name(struct kobject *kobj, \ |
| 135 | struct attribute *attr, char *buff) \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 136 | { \ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 137 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 138 | return sprintf(buff, "%s\n", \ |
| 139 | atomic_read(&bat_priv->_name) == 0 ? \ |
| 140 | "disabled" : "enabled"); \ |
| 141 | } \ |
| 142 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 143 | /* 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] | 144 | * (bat_priv) on or off |
| 145 | */ |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 146 | #define BATADV_ATTR_SIF_BOOL(_name, _mode, _post_func) \ |
| 147 | static BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \ |
| 148 | static BATADV_ATTR_SIF_SHOW_BOOL(_name) \ |
| 149 | static BATADV_ATTR(_name, _mode, batadv_show_##_name, \ |
| 150 | batadv_store_##_name) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 151 | |
| 152 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 153 | #define BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 154 | ssize_t batadv_store_##_name(struct kobject *kobj, \ |
| 155 | struct attribute *attr, char *buff, \ |
| 156 | size_t count) \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 157 | { \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 158 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 159 | struct batadv_priv *bat_priv = netdev_priv(net_dev); \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 160 | return __batadv_store_uint_attr(buff, count, _min, _max, \ |
| 161 | _post_func, attr, \ |
| 162 | &bat_priv->_name, net_dev); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 165 | #define BATADV_ATTR_SIF_SHOW_UINT(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 166 | ssize_t batadv_show_##_name(struct kobject *kobj, \ |
| 167 | struct attribute *attr, char *buff) \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 168 | { \ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 169 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 170 | return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \ |
| 171 | } \ |
| 172 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 173 | /* 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] | 174 | * (bat_priv) to an unsigned integer value |
| 175 | */ |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 176 | #define BATADV_ATTR_SIF_UINT(_name, _mode, _min, _max, _post_func) \ |
| 177 | static BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func)\ |
| 178 | static BATADV_ATTR_SIF_SHOW_UINT(_name) \ |
| 179 | static BATADV_ATTR(_name, _mode, batadv_show_##_name, \ |
| 180 | batadv_store_##_name) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 181 | |
Antonio Quartulli | 90f4435 | 2013-07-02 11:04:35 +0200 | [diff] [blame^] | 182 | #define BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \ |
| 183 | ssize_t batadv_store_vlan_##_name(struct kobject *kobj, \ |
| 184 | struct attribute *attr, char *buff, \ |
| 185 | size_t count) \ |
| 186 | { \ |
| 187 | struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\ |
| 188 | struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \ |
| 189 | kobj); \ |
| 190 | size_t res = __batadv_store_bool_attr(buff, count, _post_func, \ |
| 191 | attr, &vlan->_name, \ |
| 192 | bat_priv->soft_iface); \ |
| 193 | batadv_softif_vlan_free_ref(vlan); \ |
| 194 | return res; \ |
| 195 | } |
| 196 | |
| 197 | #define BATADV_ATTR_VLAN_SHOW_BOOL(_name) \ |
| 198 | ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \ |
| 199 | struct attribute *attr, char *buff) \ |
| 200 | { \ |
| 201 | struct batadv_priv *bat_priv = batadv_vlan_kobj_to_batpriv(kobj);\ |
| 202 | struct batadv_softif_vlan *vlan = batadv_kobj_to_vlan(bat_priv, \ |
| 203 | kobj); \ |
| 204 | size_t res = sprintf(buff, "%s\n", \ |
| 205 | atomic_read(&vlan->_name) == 0 ? \ |
| 206 | "disabled" : "enabled"); \ |
| 207 | batadv_softif_vlan_free_ref(vlan); \ |
| 208 | return res; \ |
| 209 | } |
| 210 | |
| 211 | /* Use this, if you are going to turn a [name] in the vlan struct on or off */ |
| 212 | #define BATADV_ATTR_VLAN_BOOL(_name, _mode, _post_func) \ |
| 213 | static BATADV_ATTR_VLAN_STORE_BOOL(_name, _post_func) \ |
| 214 | static BATADV_ATTR_VLAN_SHOW_BOOL(_name) \ |
| 215 | static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \ |
| 216 | batadv_store_vlan_##_name) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 217 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 218 | static int batadv_store_bool_attr(char *buff, size_t count, |
| 219 | struct net_device *net_dev, |
| 220 | const char *attr_name, atomic_t *attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 221 | { |
| 222 | int enabled = -1; |
| 223 | |
| 224 | if (buff[count - 1] == '\n') |
| 225 | buff[count - 1] = '\0'; |
| 226 | |
| 227 | if ((strncmp(buff, "1", 2) == 0) || |
| 228 | (strncmp(buff, "enable", 7) == 0) || |
| 229 | (strncmp(buff, "enabled", 8) == 0)) |
| 230 | enabled = 1; |
| 231 | |
| 232 | if ((strncmp(buff, "0", 2) == 0) || |
| 233 | (strncmp(buff, "disable", 8) == 0) || |
| 234 | (strncmp(buff, "disabled", 9) == 0)) |
| 235 | enabled = 0; |
| 236 | |
| 237 | if (enabled < 0) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 238 | batadv_info(net_dev, "%s: Invalid parameter received: %s\n", |
| 239 | attr_name, buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 240 | return -EINVAL; |
| 241 | } |
| 242 | |
| 243 | if (atomic_read(attr) == enabled) |
| 244 | return count; |
| 245 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 246 | batadv_info(net_dev, "%s: Changing from: %s to: %s\n", attr_name, |
| 247 | atomic_read(attr) == 1 ? "enabled" : "disabled", |
| 248 | enabled == 1 ? "enabled" : "disabled"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 249 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 250 | atomic_set(attr, (unsigned int)enabled); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 251 | return count; |
| 252 | } |
| 253 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 254 | static inline ssize_t |
| 255 | __batadv_store_bool_attr(char *buff, size_t count, |
| 256 | void (*post_func)(struct net_device *), |
| 257 | struct attribute *attr, |
| 258 | atomic_t *attr_store, struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 259 | { |
| 260 | int ret; |
| 261 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 262 | ret = batadv_store_bool_attr(buff, count, net_dev, attr->name, |
| 263 | attr_store); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 264 | if (post_func && ret) |
| 265 | post_func(net_dev); |
| 266 | |
| 267 | return ret; |
| 268 | } |
| 269 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 270 | static int batadv_store_uint_attr(const char *buff, size_t count, |
| 271 | struct net_device *net_dev, |
| 272 | const char *attr_name, |
| 273 | unsigned int min, unsigned int max, |
| 274 | atomic_t *attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 275 | { |
| 276 | unsigned long uint_val; |
| 277 | int ret; |
| 278 | |
Sven Eckelmann | 25a92b1 | 2011-09-30 13:32:01 +0200 | [diff] [blame] | 279 | ret = kstrtoul(buff, 10, &uint_val); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 280 | if (ret) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 281 | batadv_info(net_dev, "%s: Invalid parameter received: %s\n", |
| 282 | attr_name, buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 283 | return -EINVAL; |
| 284 | } |
| 285 | |
| 286 | if (uint_val < min) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 287 | batadv_info(net_dev, "%s: Value is too small: %lu min: %u\n", |
| 288 | attr_name, uint_val, min); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 289 | return -EINVAL; |
| 290 | } |
| 291 | |
| 292 | if (uint_val > max) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 293 | batadv_info(net_dev, "%s: Value is too big: %lu max: %u\n", |
| 294 | attr_name, uint_val, max); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | if (atomic_read(attr) == uint_val) |
| 299 | return count; |
| 300 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 301 | batadv_info(net_dev, "%s: Changing from: %i to: %lu\n", |
| 302 | attr_name, atomic_read(attr), uint_val); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 303 | |
| 304 | atomic_set(attr, uint_val); |
| 305 | return count; |
| 306 | } |
| 307 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 308 | static inline ssize_t |
| 309 | __batadv_store_uint_attr(const char *buff, size_t count, |
| 310 | int min, int max, |
| 311 | void (*post_func)(struct net_device *), |
| 312 | const struct attribute *attr, |
| 313 | atomic_t *attr_store, struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 314 | { |
| 315 | int ret; |
| 316 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 317 | ret = batadv_store_uint_attr(buff, count, net_dev, attr->name, min, max, |
| 318 | attr_store); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 319 | if (post_func && ret) |
| 320 | post_func(net_dev); |
| 321 | |
| 322 | return ret; |
| 323 | } |
| 324 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 325 | static ssize_t batadv_show_bat_algo(struct kobject *kobj, |
| 326 | struct attribute *attr, char *buff) |
Marek Lindner | ea3d2fd | 2011-11-29 00:15:37 +0800 | [diff] [blame] | 327 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 328 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
Marek Lindner | ea3d2fd | 2011-11-29 00:15:37 +0800 | [diff] [blame] | 329 | return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name); |
| 330 | } |
| 331 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 332 | static void batadv_post_gw_deselect(struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 333 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 334 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 335 | batadv_gw_deselect(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 338 | static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr, |
| 339 | char *buff) |
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 = batadv_kobj_to_batpriv(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 342 | int bytes_written; |
| 343 | |
| 344 | switch (atomic_read(&bat_priv->gw_mode)) { |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 345 | case BATADV_GW_MODE_CLIENT: |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 346 | bytes_written = sprintf(buff, "%s\n", |
| 347 | BATADV_GW_MODE_CLIENT_NAME); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 348 | break; |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 349 | case BATADV_GW_MODE_SERVER: |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 350 | bytes_written = sprintf(buff, "%s\n", |
| 351 | BATADV_GW_MODE_SERVER_NAME); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 352 | break; |
| 353 | default: |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 354 | bytes_written = sprintf(buff, "%s\n", |
| 355 | BATADV_GW_MODE_OFF_NAME); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 356 | break; |
| 357 | } |
| 358 | |
| 359 | return bytes_written; |
| 360 | } |
| 361 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 362 | static ssize_t batadv_store_gw_mode(struct kobject *kobj, |
| 363 | struct attribute *attr, char *buff, |
| 364 | size_t count) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 365 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 366 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 367 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 368 | char *curr_gw_mode_str; |
| 369 | int gw_mode_tmp = -1; |
| 370 | |
| 371 | if (buff[count - 1] == '\n') |
| 372 | buff[count - 1] = '\0'; |
| 373 | |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 374 | if (strncmp(buff, BATADV_GW_MODE_OFF_NAME, |
| 375 | strlen(BATADV_GW_MODE_OFF_NAME)) == 0) |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 376 | gw_mode_tmp = BATADV_GW_MODE_OFF; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 377 | |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 378 | if (strncmp(buff, BATADV_GW_MODE_CLIENT_NAME, |
| 379 | strlen(BATADV_GW_MODE_CLIENT_NAME)) == 0) |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 380 | gw_mode_tmp = BATADV_GW_MODE_CLIENT; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 381 | |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 382 | if (strncmp(buff, BATADV_GW_MODE_SERVER_NAME, |
| 383 | strlen(BATADV_GW_MODE_SERVER_NAME)) == 0) |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 384 | gw_mode_tmp = BATADV_GW_MODE_SERVER; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 385 | |
| 386 | if (gw_mode_tmp < 0) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 387 | batadv_info(net_dev, |
| 388 | "Invalid parameter for 'gw mode' setting received: %s\n", |
| 389 | buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 390 | return -EINVAL; |
| 391 | } |
| 392 | |
| 393 | if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp) |
| 394 | return count; |
| 395 | |
| 396 | switch (atomic_read(&bat_priv->gw_mode)) { |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 397 | case BATADV_GW_MODE_CLIENT: |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 398 | curr_gw_mode_str = BATADV_GW_MODE_CLIENT_NAME; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 399 | break; |
Sven Eckelmann | cd646ab | 2012-06-03 22:19:18 +0200 | [diff] [blame] | 400 | case BATADV_GW_MODE_SERVER: |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 401 | curr_gw_mode_str = BATADV_GW_MODE_SERVER_NAME; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 402 | break; |
| 403 | default: |
Sven Eckelmann | 97ea4ba | 2012-06-03 22:19:11 +0200 | [diff] [blame] | 404 | curr_gw_mode_str = BATADV_GW_MODE_OFF_NAME; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 405 | break; |
| 406 | } |
| 407 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 408 | batadv_info(net_dev, "Changing gw mode from: %s to: %s\n", |
| 409 | curr_gw_mode_str, buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 410 | |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 411 | batadv_gw_deselect(bat_priv); |
Antonio Quartulli | c6eaa3f | 2013-07-13 00:06:00 +0200 | [diff] [blame] | 412 | /* always call batadv_gw_check_client_stop() before changing the gateway |
| 413 | * state |
| 414 | */ |
| 415 | batadv_gw_check_client_stop(bat_priv); |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 416 | atomic_set(&bat_priv->gw_mode, (unsigned int)gw_mode_tmp); |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 417 | batadv_gw_tvlv_container_update(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 418 | return count; |
| 419 | } |
| 420 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 421 | static ssize_t batadv_show_gw_bwidth(struct kobject *kobj, |
| 422 | struct attribute *attr, char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 423 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 424 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 425 | uint32_t down, up; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 426 | |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 427 | down = atomic_read(&bat_priv->gw.bandwidth_down); |
| 428 | up = atomic_read(&bat_priv->gw.bandwidth_up); |
| 429 | |
| 430 | return sprintf(buff, "%u.%u/%u.%u MBit\n", down / 10, |
| 431 | down % 10, up / 10, up % 10); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 434 | static ssize_t batadv_store_gw_bwidth(struct kobject *kobj, |
| 435 | struct attribute *attr, char *buff, |
| 436 | size_t count) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 437 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 438 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 439 | |
| 440 | if (buff[count - 1] == '\n') |
| 441 | buff[count - 1] = '\0'; |
| 442 | |
Sven Eckelmann | 84d5e5e | 2012-05-12 02:09:30 +0200 | [diff] [blame] | 443 | return batadv_gw_bandwidth_set(net_dev, buff, count); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 446 | BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL); |
| 447 | BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 448 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 449 | BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR, NULL); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 450 | #endif |
Antonio Quartulli | 33af49a | 2012-08-08 18:50:57 +0200 | [diff] [blame] | 451 | #ifdef CONFIG_BATMAN_ADV_DAT |
Marek Lindner | 17cf0ea | 2013-04-23 21:39:59 +0800 | [diff] [blame] | 452 | BATADV_ATTR_SIF_BOOL(distributed_arp_table, S_IRUGO | S_IWUSR, |
| 453 | batadv_dat_status_update); |
Antonio Quartulli | 33af49a | 2012-08-08 18:50:57 +0200 | [diff] [blame] | 454 | #endif |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 455 | BATADV_ATTR_SIF_BOOL(fragmentation, S_IRUGO | S_IWUSR, batadv_update_min_mtu); |
| 456 | BATADV_ATTR_SIF_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL); |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 457 | static BATADV_ATTR(routing_algo, S_IRUGO, batadv_show_bat_algo, NULL); |
| 458 | static BATADV_ATTR(gw_mode, S_IRUGO | S_IWUSR, batadv_show_gw_mode, |
| 459 | batadv_store_gw_mode); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 460 | BATADV_ATTR_SIF_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * BATADV_JITTER, |
| 461 | INT_MAX, NULL); |
| 462 | 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] | 463 | NULL); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 464 | BATADV_ATTR_SIF_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, BATADV_TQ_MAX_VALUE, |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 465 | batadv_post_gw_deselect); |
| 466 | static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth, |
| 467 | batadv_store_gw_bwidth); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 468 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 469 | 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] | 470 | #endif |
Martin Hundebøll | d353d8d | 2013-01-25 11:12:38 +0100 | [diff] [blame] | 471 | #ifdef CONFIG_BATMAN_ADV_NC |
Marek Lindner | 3f4841f | 2013-04-23 21:40:00 +0800 | [diff] [blame] | 472 | BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR, |
| 473 | batadv_nc_status_update); |
Martin Hundebøll | d353d8d | 2013-01-25 11:12:38 +0100 | [diff] [blame] | 474 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 475 | |
Sven Eckelmann | b4d66b8 | 2012-06-05 22:31:29 +0200 | [diff] [blame] | 476 | static struct batadv_attribute *batadv_mesh_attrs[] = { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 477 | &batadv_attr_aggregated_ogms, |
| 478 | &batadv_attr_bonding, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 479 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 480 | &batadv_attr_bridge_loop_avoidance, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 481 | #endif |
Antonio Quartulli | 33af49a | 2012-08-08 18:50:57 +0200 | [diff] [blame] | 482 | #ifdef CONFIG_BATMAN_ADV_DAT |
| 483 | &batadv_attr_distributed_arp_table, |
| 484 | #endif |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 485 | &batadv_attr_fragmentation, |
| 486 | &batadv_attr_ap_isolation, |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 487 | &batadv_attr_routing_algo, |
| 488 | &batadv_attr_gw_mode, |
| 489 | &batadv_attr_orig_interval, |
| 490 | &batadv_attr_hop_penalty, |
| 491 | &batadv_attr_gw_sel_class, |
| 492 | &batadv_attr_gw_bandwidth, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 493 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 494 | &batadv_attr_log_level, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 495 | #endif |
Martin Hundebøll | d353d8d | 2013-01-25 11:12:38 +0100 | [diff] [blame] | 496 | #ifdef CONFIG_BATMAN_ADV_NC |
| 497 | &batadv_attr_network_coding, |
| 498 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 499 | NULL, |
| 500 | }; |
| 501 | |
Antonio Quartulli | 90f4435 | 2013-07-02 11:04:35 +0200 | [diff] [blame^] | 502 | /** |
| 503 | * batadv_vlan_attrs - array of vlan specific sysfs attributes |
| 504 | */ |
| 505 | static struct batadv_attribute *batadv_vlan_attrs[] = { |
| 506 | NULL, |
| 507 | }; |
| 508 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 509 | int batadv_sysfs_add_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 510 | { |
| 511 | struct kobject *batif_kobject = &dev->dev.kobj; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 512 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | b4d66b8 | 2012-06-05 22:31:29 +0200 | [diff] [blame] | 513 | struct batadv_attribute **bat_attr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 514 | int err; |
| 515 | |
Sven Eckelmann | 036cbfe | 2012-06-03 22:19:09 +0200 | [diff] [blame] | 516 | 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] | 517 | batif_kobject); |
| 518 | if (!bat_priv->mesh_obj) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 519 | 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] | 520 | BATADV_SYSFS_IF_MESH_SUBDIR); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 521 | goto out; |
| 522 | } |
| 523 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 524 | for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 525 | err = sysfs_create_file(bat_priv->mesh_obj, |
| 526 | &((*bat_attr)->attr)); |
| 527 | if (err) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 528 | batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n", |
Sven Eckelmann | 036cbfe | 2012-06-03 22:19:09 +0200 | [diff] [blame] | 529 | dev->name, BATADV_SYSFS_IF_MESH_SUBDIR, |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 530 | ((*bat_attr)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 531 | goto rem_attr; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | return 0; |
| 536 | |
| 537 | rem_attr: |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 538 | for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 539 | sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); |
| 540 | |
| 541 | kobject_put(bat_priv->mesh_obj); |
| 542 | bat_priv->mesh_obj = NULL; |
| 543 | out: |
| 544 | return -ENOMEM; |
| 545 | } |
| 546 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 547 | void batadv_sysfs_del_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 548 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 549 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | b4d66b8 | 2012-06-05 22:31:29 +0200 | [diff] [blame] | 550 | struct batadv_attribute **bat_attr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 551 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 552 | for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 553 | sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); |
| 554 | |
| 555 | kobject_put(bat_priv->mesh_obj); |
| 556 | bat_priv->mesh_obj = NULL; |
| 557 | } |
| 558 | |
Antonio Quartulli | 90f4435 | 2013-07-02 11:04:35 +0200 | [diff] [blame^] | 559 | /** |
| 560 | * batadv_sysfs_add_vlan - add all the needed sysfs objects for the new vlan |
| 561 | * @dev: netdev of the mesh interface |
| 562 | * @vlan: private data of the newly added VLAN interface |
| 563 | * |
| 564 | * Returns 0 on success and -ENOMEM if any of the structure allocations fails. |
| 565 | */ |
| 566 | int batadv_sysfs_add_vlan(struct net_device *dev, |
| 567 | struct batadv_softif_vlan *vlan) |
| 568 | { |
| 569 | char vlan_subdir[sizeof(BATADV_SYSFS_VLAN_SUBDIR_PREFIX) + 5]; |
| 570 | struct batadv_priv *bat_priv = netdev_priv(dev); |
| 571 | struct batadv_attribute **bat_attr; |
| 572 | int err; |
| 573 | |
| 574 | if (vlan->vid & BATADV_VLAN_HAS_TAG) { |
| 575 | sprintf(vlan_subdir, BATADV_SYSFS_VLAN_SUBDIR_PREFIX "%hu", |
| 576 | vlan->vid & VLAN_VID_MASK); |
| 577 | |
| 578 | vlan->kobj = kobject_create_and_add(vlan_subdir, |
| 579 | bat_priv->mesh_obj); |
| 580 | if (!vlan->kobj) { |
| 581 | batadv_err(dev, "Can't add sysfs directory: %s/%s\n", |
| 582 | dev->name, vlan_subdir); |
| 583 | goto out; |
| 584 | } |
| 585 | } else { |
| 586 | /* the untagged LAN uses the root folder to store its "VLAN |
| 587 | * specific attributes" |
| 588 | */ |
| 589 | vlan->kobj = bat_priv->mesh_obj; |
| 590 | kobject_get(bat_priv->mesh_obj); |
| 591 | } |
| 592 | |
| 593 | for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) { |
| 594 | err = sysfs_create_file(vlan->kobj, |
| 595 | &((*bat_attr)->attr)); |
| 596 | if (err) { |
| 597 | batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n", |
| 598 | dev->name, vlan_subdir, |
| 599 | ((*bat_attr)->attr).name); |
| 600 | goto rem_attr; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | return 0; |
| 605 | |
| 606 | rem_attr: |
| 607 | for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) |
| 608 | sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr)); |
| 609 | |
| 610 | kobject_put(vlan->kobj); |
| 611 | vlan->kobj = NULL; |
| 612 | out: |
| 613 | return -ENOMEM; |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * batadv_sysfs_del_vlan - remove all the sysfs objects for a given VLAN |
| 618 | * @bat_priv: the bat priv with all the soft interface information |
| 619 | * @vlan: the private data of the VLAN to destroy |
| 620 | */ |
| 621 | void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv, |
| 622 | struct batadv_softif_vlan *vlan) |
| 623 | { |
| 624 | struct batadv_attribute **bat_attr; |
| 625 | |
| 626 | for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr) |
| 627 | sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr)); |
| 628 | |
| 629 | kobject_put(vlan->kobj); |
| 630 | vlan->kobj = NULL; |
| 631 | } |
| 632 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 633 | static ssize_t batadv_show_mesh_iface(struct kobject *kobj, |
| 634 | struct attribute *attr, char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 635 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 636 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 637 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 638 | ssize_t length; |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 639 | const char *ifname; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 640 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 641 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 642 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 643 | return 0; |
| 644 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 645 | if (hard_iface->if_status == BATADV_IF_NOT_IN_USE) |
| 646 | ifname = "none"; |
| 647 | else |
| 648 | ifname = hard_iface->soft_iface->name; |
| 649 | |
| 650 | length = sprintf(buff, "%s\n", ifname); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 651 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 652 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 653 | |
| 654 | return length; |
| 655 | } |
| 656 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 657 | static ssize_t batadv_store_mesh_iface(struct kobject *kobj, |
| 658 | struct attribute *attr, char *buff, |
| 659 | size_t count) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 660 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 661 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 662 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 663 | int status_tmp = -1; |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 664 | int ret = count; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 665 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 666 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 667 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 668 | return count; |
| 669 | |
| 670 | if (buff[count - 1] == '\n') |
| 671 | buff[count - 1] = '\0'; |
| 672 | |
| 673 | if (strlen(buff) >= IFNAMSIZ) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 674 | pr_err("Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n", |
| 675 | buff); |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 676 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 677 | return -EINVAL; |
| 678 | } |
| 679 | |
| 680 | if (strncmp(buff, "none", 4) == 0) |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 681 | status_tmp = BATADV_IF_NOT_IN_USE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 682 | else |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 683 | status_tmp = BATADV_IF_I_WANT_YOU; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 684 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 685 | if (hard_iface->if_status == status_tmp) |
| 686 | goto out; |
| 687 | |
| 688 | if ((hard_iface->soft_iface) && |
| 689 | (strncmp(hard_iface->soft_iface->name, buff, IFNAMSIZ) == 0)) |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 690 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 691 | |
Matthias Schiffer | ac16d14 | 2013-05-28 17:32:32 +0200 | [diff] [blame] | 692 | rtnl_lock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 693 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 694 | if (status_tmp == BATADV_IF_NOT_IN_USE) { |
Sven Eckelmann | a15fd36 | 2013-02-11 17:10:24 +0800 | [diff] [blame] | 695 | batadv_hardif_disable_interface(hard_iface, |
| 696 | BATADV_IF_CLEANUP_AUTO); |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 697 | goto unlock; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 700 | /* if the interface already is in use */ |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 701 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) |
Sven Eckelmann | a15fd36 | 2013-02-11 17:10:24 +0800 | [diff] [blame] | 702 | batadv_hardif_disable_interface(hard_iface, |
| 703 | BATADV_IF_CLEANUP_AUTO); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 704 | |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 705 | ret = batadv_hardif_enable_interface(hard_iface, buff); |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 706 | |
| 707 | unlock: |
| 708 | rtnl_unlock(); |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 709 | out: |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 710 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 711 | return ret; |
| 712 | } |
| 713 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 714 | static ssize_t batadv_show_iface_status(struct kobject *kobj, |
| 715 | struct attribute *attr, char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 716 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 717 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 718 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 719 | ssize_t length; |
| 720 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 721 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 722 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 723 | return 0; |
| 724 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 725 | switch (hard_iface->if_status) { |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 726 | case BATADV_IF_TO_BE_REMOVED: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 727 | length = sprintf(buff, "disabling\n"); |
| 728 | break; |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 729 | case BATADV_IF_INACTIVE: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 730 | length = sprintf(buff, "inactive\n"); |
| 731 | break; |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 732 | case BATADV_IF_ACTIVE: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 733 | length = sprintf(buff, "active\n"); |
| 734 | break; |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 735 | case BATADV_IF_TO_BE_ACTIVATED: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 736 | length = sprintf(buff, "enabling\n"); |
| 737 | break; |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 738 | case BATADV_IF_NOT_IN_USE: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 739 | default: |
| 740 | length = sprintf(buff, "not in use\n"); |
| 741 | break; |
| 742 | } |
| 743 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 744 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 745 | |
| 746 | return length; |
| 747 | } |
| 748 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 749 | static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface, |
| 750 | batadv_store_mesh_iface); |
| 751 | static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 752 | |
Sven Eckelmann | b4d66b8 | 2012-06-05 22:31:29 +0200 | [diff] [blame] | 753 | static struct batadv_attribute *batadv_batman_attrs[] = { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 754 | &batadv_attr_mesh_iface, |
| 755 | &batadv_attr_iface_status, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 756 | NULL, |
| 757 | }; |
| 758 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 759 | 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] | 760 | { |
| 761 | struct kobject *hardif_kobject = &dev->dev.kobj; |
Sven Eckelmann | b4d66b8 | 2012-06-05 22:31:29 +0200 | [diff] [blame] | 762 | struct batadv_attribute **bat_attr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 763 | int err; |
| 764 | |
Sven Eckelmann | 036cbfe | 2012-06-03 22:19:09 +0200 | [diff] [blame] | 765 | *hardif_obj = kobject_create_and_add(BATADV_SYSFS_IF_BAT_SUBDIR, |
| 766 | hardif_kobject); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 767 | |
| 768 | if (!*hardif_obj) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 769 | 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] | 770 | BATADV_SYSFS_IF_BAT_SUBDIR); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 771 | goto out; |
| 772 | } |
| 773 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 774 | for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 775 | err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr)); |
| 776 | if (err) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 777 | batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n", |
Sven Eckelmann | 036cbfe | 2012-06-03 22:19:09 +0200 | [diff] [blame] | 778 | dev->name, BATADV_SYSFS_IF_BAT_SUBDIR, |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 779 | ((*bat_attr)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 780 | goto rem_attr; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | return 0; |
| 785 | |
| 786 | rem_attr: |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 787 | for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 788 | sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr)); |
| 789 | out: |
| 790 | return -ENOMEM; |
| 791 | } |
| 792 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 793 | void batadv_sysfs_del_hardif(struct kobject **hardif_obj) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 794 | { |
| 795 | kobject_put(*hardif_obj); |
| 796 | *hardif_obj = NULL; |
| 797 | } |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 798 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 799 | 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] | 800 | enum batadv_uev_action action, const char *data) |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 801 | { |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 802 | int ret = -ENOMEM; |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 803 | struct kobject *bat_kobj; |
| 804 | char *uevent_env[4] = { NULL, NULL, NULL, NULL }; |
| 805 | |
Marek Lindner | 736292c | 2013-01-12 19:19:06 +0800 | [diff] [blame] | 806 | bat_kobj = &bat_priv->soft_iface->dev.kobj; |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 807 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 808 | uevent_env[0] = kmalloc(strlen(BATADV_UEV_TYPE_VAR) + |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 809 | strlen(batadv_uev_type_str[type]) + 1, |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 810 | GFP_ATOMIC); |
| 811 | if (!uevent_env[0]) |
| 812 | goto out; |
| 813 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 814 | sprintf(uevent_env[0], "%s%s", BATADV_UEV_TYPE_VAR, |
| 815 | batadv_uev_type_str[type]); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 816 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 817 | uevent_env[1] = kmalloc(strlen(BATADV_UEV_ACTION_VAR) + |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 818 | strlen(batadv_uev_action_str[action]) + 1, |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 819 | GFP_ATOMIC); |
| 820 | if (!uevent_env[1]) |
| 821 | goto out; |
| 822 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 823 | sprintf(uevent_env[1], "%s%s", BATADV_UEV_ACTION_VAR, |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 824 | batadv_uev_action_str[action]); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 825 | |
| 826 | /* If the event is DEL, ignore the data field */ |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 827 | if (action != BATADV_UEV_DEL) { |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 828 | uevent_env[2] = kmalloc(strlen(BATADV_UEV_DATA_VAR) + |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 829 | strlen(data) + 1, GFP_ATOMIC); |
| 830 | if (!uevent_env[2]) |
| 831 | goto out; |
| 832 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 833 | sprintf(uevent_env[2], "%s%s", BATADV_UEV_DATA_VAR, data); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env); |
| 837 | out: |
| 838 | kfree(uevent_env[0]); |
| 839 | kfree(uevent_env[1]); |
| 840 | kfree(uevent_env[2]); |
| 841 | |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 842 | if (ret) |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 843 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 844 | "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n", |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 845 | batadv_uev_type_str[type], |
| 846 | batadv_uev_action_str[action], |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 847 | (action == BATADV_UEV_DEL ? "NULL" : data), ret); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 848 | return ret; |
| 849 | } |