hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/batman-adv/sysfs.c
....@@ -1,24 +1,13 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors:
2
+/* Copyright (C) 2010-2020 B.A.T.M.A.N. contributors:
33 *
44 * Marek Lindner
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of version 2 of the GNU General Public
8
- * License as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful, but
11
- * WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
175 */
186
197 #include "sysfs.h"
208 #include "main.h"
219
10
+#include <asm/current.h>
2211 #include <linux/atomic.h>
2312 #include <linux/compiler.h>
2413 #include <linux/device.h>
....@@ -29,17 +18,20 @@
2918 #include <linux/kernel.h>
3019 #include <linux/kobject.h>
3120 #include <linux/kref.h>
21
+#include <linux/limits.h>
3222 #include <linux/netdevice.h>
3323 #include <linux/printk.h>
3424 #include <linux/rculist.h>
3525 #include <linux/rcupdate.h>
3626 #include <linux/rtnetlink.h>
27
+#include <linux/sched.h>
3728 #include <linux/slab.h>
3829 #include <linux/stddef.h>
3930 #include <linux/string.h>
4031 #include <linux/stringify.h>
4132 #include <linux/workqueue.h>
4233 #include <uapi/linux/batadv_packet.h>
34
+#include <uapi/linux/batman_adv.h>
4335
4436 #include "bridge_loop_avoidance.h"
4537 #include "distributed-arp-table.h"
....@@ -47,8 +39,19 @@
4739 #include "gateway_common.h"
4840 #include "hard-interface.h"
4941 #include "log.h"
42
+#include "netlink.h"
5043 #include "network-coding.h"
5144 #include "soft-interface.h"
45
+
46
+/**
47
+ * batadv_sysfs_deprecated() - Log use of deprecated batadv sysfs access
48
+ * @attr: attribute which was accessed
49
+ */
50
+static void batadv_sysfs_deprecated(struct attribute *attr)
51
+{
52
+ pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of sysfs file \"%s\".\nUse batadv genl family instead",
53
+ current->comm, task_pid_nr(current), attr->name);
54
+}
5255
5356 static struct net_device *batadv_kobj_to_netdev(struct kobject *obj)
5457 {
....@@ -112,22 +115,6 @@
112115 return vlan;
113116 }
114117
115
-#define BATADV_UEV_TYPE_VAR "BATTYPE="
116
-#define BATADV_UEV_ACTION_VAR "BATACTION="
117
-#define BATADV_UEV_DATA_VAR "BATDATA="
118
-
119
-static char *batadv_uev_action_str[] = {
120
- "add",
121
- "del",
122
- "change",
123
- "loopdetect",
124
-};
125
-
126
-static char *batadv_uev_type_str[] = {
127
- "gw",
128
- "bla",
129
-};
130
-
131118 /* Use this, if you have customized show and store functions for vlan attrs */
132119 #define BATADV_ATTR_VLAN(_name, _mode, _show, _store) \
133120 struct batadv_attribute batadv_attr_vlan_##_name = { \
....@@ -153,9 +140,15 @@
153140 { \
154141 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
155142 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
143
+ ssize_t length; \
156144 \
157
- return __batadv_store_bool_attr(buff, count, _post_func, attr, \
158
- &bat_priv->_name, net_dev); \
145
+ batadv_sysfs_deprecated(attr); \
146
+ length = __batadv_store_bool_attr(buff, count, _post_func, attr,\
147
+ &bat_priv->_name, net_dev); \
148
+ \
149
+ batadv_netlink_notify_mesh(bat_priv); \
150
+ \
151
+ return length; \
159152 }
160153
161154 #define BATADV_ATTR_SIF_SHOW_BOOL(_name) \
....@@ -164,6 +157,7 @@
164157 { \
165158 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
166159 \
160
+ batadv_sysfs_deprecated(attr); \
167161 return sprintf(buff, "%s\n", \
168162 atomic_read(&bat_priv->_name) == 0 ? \
169163 "disabled" : "enabled"); \
....@@ -185,11 +179,17 @@
185179 { \
186180 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
187181 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
182
+ ssize_t length; \
188183 \
189
- return __batadv_store_uint_attr(buff, count, _min, _max, \
190
- _post_func, attr, \
191
- &bat_priv->_var, net_dev, \
192
- NULL); \
184
+ batadv_sysfs_deprecated(attr); \
185
+ length = __batadv_store_uint_attr(buff, count, _min, _max, \
186
+ _post_func, attr, \
187
+ &bat_priv->_var, net_dev, \
188
+ NULL); \
189
+ \
190
+ batadv_netlink_notify_mesh(bat_priv); \
191
+ \
192
+ return length; \
193193 }
194194
195195 #define BATADV_ATTR_SIF_SHOW_UINT(_name, _var) \
....@@ -198,6 +198,7 @@
198198 { \
199199 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
200200 \
201
+ batadv_sysfs_deprecated(attr); \
201202 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_var)); \
202203 } \
203204
....@@ -222,6 +223,12 @@
222223 attr, &vlan->_name, \
223224 bat_priv->soft_iface); \
224225 \
226
+ batadv_sysfs_deprecated(attr); \
227
+ if (vlan->vid) \
228
+ batadv_netlink_notify_vlan(bat_priv, vlan); \
229
+ else \
230
+ batadv_netlink_notify_mesh(bat_priv); \
231
+ \
225232 batadv_softif_vlan_put(vlan); \
226233 return res; \
227234 }
....@@ -237,6 +244,7 @@
237244 atomic_read(&vlan->_name) == 0 ? \
238245 "disabled" : "enabled"); \
239246 \
247
+ batadv_sysfs_deprecated(attr); \
240248 batadv_softif_vlan_put(vlan); \
241249 return res; \
242250 }
....@@ -255,8 +263,10 @@
255263 { \
256264 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
257265 struct batadv_hard_iface *hard_iface; \
266
+ struct batadv_priv *bat_priv; \
258267 ssize_t length; \
259268 \
269
+ batadv_sysfs_deprecated(attr); \
260270 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
261271 if (!hard_iface) \
262272 return 0; \
....@@ -266,6 +276,11 @@
266276 &hard_iface->_var, \
267277 hard_iface->soft_iface, \
268278 net_dev); \
279
+ \
280
+ if (hard_iface->soft_iface) { \
281
+ bat_priv = netdev_priv(hard_iface->soft_iface); \
282
+ batadv_netlink_notify_hardif(bat_priv, hard_iface); \
283
+ } \
269284 \
270285 batadv_hardif_put(hard_iface); \
271286 return length; \
....@@ -279,6 +294,7 @@
279294 struct batadv_hard_iface *hard_iface; \
280295 ssize_t length; \
281296 \
297
+ batadv_sysfs_deprecated(attr); \
282298 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
283299 if (!hard_iface) \
284300 return 0; \
....@@ -423,6 +439,7 @@
423439 {
424440 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
425441
442
+ batadv_sysfs_deprecated(attr);
426443 return sprintf(buff, "%s\n", bat_priv->algo_ops->name);
427444 }
428445
....@@ -438,6 +455,8 @@
438455 {
439456 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
440457 int bytes_written;
458
+
459
+ batadv_sysfs_deprecated(attr);
441460
442461 /* GW mode is not available if the routing algorithm in use does not
443462 * implement the GW API
....@@ -472,6 +491,8 @@
472491 struct batadv_priv *bat_priv = netdev_priv(net_dev);
473492 char *curr_gw_mode_str;
474493 int gw_mode_tmp = -1;
494
+
495
+ batadv_sysfs_deprecated(attr);
475496
476497 /* toggling GW mode is allowed only if the routing algorithm in use
477498 * provides the GW API
....@@ -536,6 +557,9 @@
536557 batadv_gw_check_client_stop(bat_priv);
537558 atomic_set(&bat_priv->gw.mode, (unsigned int)gw_mode_tmp);
538559 batadv_gw_tvlv_container_update(bat_priv);
560
+
561
+ batadv_netlink_notify_mesh(bat_priv);
562
+
539563 return count;
540564 }
541565
....@@ -543,6 +567,8 @@
543567 struct attribute *attr, char *buff)
544568 {
545569 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
570
+
571
+ batadv_sysfs_deprecated(attr);
546572
547573 /* GW selection class is not available if the routing algorithm in use
548574 * does not implement the GW API
....@@ -562,6 +588,9 @@
562588 size_t count)
563589 {
564590 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
591
+ ssize_t length;
592
+
593
+ batadv_sysfs_deprecated(attr);
565594
566595 /* setting the GW selection class is allowed only if the routing
567596 * algorithm in use implements the GW API
....@@ -577,10 +606,14 @@
577606 return bat_priv->algo_ops->gw.store_sel_class(bat_priv, buff,
578607 count);
579608
580
- return __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE,
581
- batadv_post_gw_reselect, attr,
582
- &bat_priv->gw.sel_class,
583
- bat_priv->soft_iface, NULL);
609
+ length = __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE,
610
+ batadv_post_gw_reselect, attr,
611
+ &bat_priv->gw.sel_class,
612
+ bat_priv->soft_iface, NULL);
613
+
614
+ batadv_netlink_notify_mesh(bat_priv);
615
+
616
+ return length;
584617 }
585618
586619 static ssize_t batadv_show_gw_bwidth(struct kobject *kobj,
....@@ -588,6 +621,8 @@
588621 {
589622 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
590623 u32 down, up;
624
+
625
+ batadv_sysfs_deprecated(attr);
591626
592627 down = atomic_read(&bat_priv->gw.bandwidth_down);
593628 up = atomic_read(&bat_priv->gw.bandwidth_up);
....@@ -600,12 +635,20 @@
600635 struct attribute *attr, char *buff,
601636 size_t count)
602637 {
638
+ struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
603639 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
640
+ ssize_t length;
641
+
642
+ batadv_sysfs_deprecated(attr);
604643
605644 if (buff[count - 1] == '\n')
606645 buff[count - 1] = '\0';
607646
608
- return batadv_gw_bandwidth_set(net_dev, buff, count);
647
+ length = batadv_gw_bandwidth_set(net_dev, buff, count);
648
+
649
+ batadv_netlink_notify_mesh(bat_priv);
650
+
651
+ return length;
609652 }
610653
611654 /**
....@@ -622,6 +665,7 @@
622665 {
623666 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
624667
668
+ batadv_sysfs_deprecated(attr);
625669 return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark,
626670 bat_priv->isolation_mark_mask);
627671 }
....@@ -644,6 +688,8 @@
644688 struct batadv_priv *bat_priv = netdev_priv(net_dev);
645689 u32 mark, mask;
646690 char *mask_ptr;
691
+
692
+ batadv_sysfs_deprecated(attr);
647693
648694 /* parse the mask if it has been specified, otherwise assume the mask is
649695 * the biggest possible
....@@ -672,6 +718,8 @@
672718 batadv_info(net_dev,
673719 "New skb mark for extended isolation: %#.8x/%#.8x\n",
674720 bat_priv->isolation_mark, bat_priv->isolation_mark_mask);
721
+
722
+ batadv_netlink_notify_mesh(bat_priv);
675723
676724 return count;
677725 }
....@@ -898,6 +946,8 @@
898946 ssize_t length;
899947 const char *ifname;
900948
949
+ batadv_sysfs_deprecated(attr);
950
+
901951 hard_iface = batadv_hardif_get_by_netdev(net_dev);
902952 if (!hard_iface)
903953 return 0;
....@@ -1002,6 +1052,8 @@
10021052 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
10031053 struct batadv_store_mesh_work *store_work;
10041054
1055
+ batadv_sysfs_deprecated(attr);
1056
+
10051057 if (buff[count - 1] == '\n')
10061058 buff[count - 1] = '\0';
10071059
....@@ -1018,7 +1070,7 @@
10181070 dev_hold(net_dev);
10191071 INIT_WORK(&store_work->work, batadv_store_mesh_iface_work);
10201072 store_work->net_dev = net_dev;
1021
- strlcpy(store_work->soft_iface_name, buff,
1073
+ strscpy(store_work->soft_iface_name, buff,
10221074 sizeof(store_work->soft_iface_name));
10231075
10241076 queue_work(batadv_event_workqueue, &store_work->work);
....@@ -1032,6 +1084,8 @@
10321084 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
10331085 struct batadv_hard_iface *hard_iface;
10341086 ssize_t length;
1087
+
1088
+ batadv_sysfs_deprecated(attr);
10351089
10361090 hard_iface = batadv_hardif_get_by_netdev(net_dev);
10371091 if (!hard_iface)
....@@ -1079,9 +1133,12 @@
10791133 {
10801134 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
10811135 struct batadv_hard_iface *hard_iface;
1136
+ struct batadv_priv *bat_priv;
10821137 u32 tp_override;
10831138 u32 old_tp_override;
10841139 bool ret;
1140
+
1141
+ batadv_sysfs_deprecated(attr);
10851142
10861143 hard_iface = batadv_hardif_get_by_netdev(net_dev);
10871144 if (!hard_iface)
....@@ -1107,6 +1164,11 @@
11071164
11081165 atomic_set(&hard_iface->bat_v.throughput_override, tp_override);
11091166
1167
+ if (hard_iface->soft_iface) {
1168
+ bat_priv = netdev_priv(hard_iface->soft_iface);
1169
+ batadv_netlink_notify_hardif(bat_priv, hard_iface);
1170
+ }
1171
+
11101172 out:
11111173 batadv_hardif_put(hard_iface);
11121174 return count;
....@@ -1119,6 +1181,8 @@
11191181 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
11201182 struct batadv_hard_iface *hard_iface;
11211183 u32 tp_override;
1184
+
1185
+ batadv_sysfs_deprecated(attr);
11221186
11231187 hard_iface = batadv_hardif_get_by_netdev(net_dev);
11241188 if (!hard_iface)
....@@ -1205,58 +1269,4 @@
12051269 kobject_del(*hardif_obj);
12061270 kobject_put(*hardif_obj);
12071271 *hardif_obj = NULL;
1208
-}
1209
-
1210
-/**
1211
- * batadv_throw_uevent() - Send an uevent with batman-adv specific env data
1212
- * @bat_priv: the bat priv with all the soft interface information
1213
- * @type: subsystem type of event. Stored in uevent's BATTYPE
1214
- * @action: action type of event. Stored in uevent's BATACTION
1215
- * @data: string with additional information to the event (ignored for
1216
- * BATADV_UEV_DEL). Stored in uevent's BATDATA
1217
- *
1218
- * Return: 0 on success or negative error number in case of failure
1219
- */
1220
-int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
1221
- enum batadv_uev_action action, const char *data)
1222
-{
1223
- int ret = -ENOMEM;
1224
- struct kobject *bat_kobj;
1225
- char *uevent_env[4] = { NULL, NULL, NULL, NULL };
1226
-
1227
- bat_kobj = &bat_priv->soft_iface->dev.kobj;
1228
-
1229
- uevent_env[0] = kasprintf(GFP_ATOMIC,
1230
- "%s%s", BATADV_UEV_TYPE_VAR,
1231
- batadv_uev_type_str[type]);
1232
- if (!uevent_env[0])
1233
- goto out;
1234
-
1235
- uevent_env[1] = kasprintf(GFP_ATOMIC,
1236
- "%s%s", BATADV_UEV_ACTION_VAR,
1237
- batadv_uev_action_str[action]);
1238
- if (!uevent_env[1])
1239
- goto out;
1240
-
1241
- /* If the event is DEL, ignore the data field */
1242
- if (action != BATADV_UEV_DEL) {
1243
- uevent_env[2] = kasprintf(GFP_ATOMIC,
1244
- "%s%s", BATADV_UEV_DATA_VAR, data);
1245
- if (!uevent_env[2])
1246
- goto out;
1247
- }
1248
-
1249
- ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
1250
-out:
1251
- kfree(uevent_env[0]);
1252
- kfree(uevent_env[1]);
1253
- kfree(uevent_env[2]);
1254
-
1255
- if (ret)
1256
- batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1257
- "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
1258
- batadv_uev_type_str[type],
1259
- batadv_uev_action_str[action],
1260
- (action == BATADV_UEV_DEL ? "NULL" : data), ret);
1261
- return ret;
12621272 }