forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/net/batman-adv/translation-table.c
....@@ -1,19 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/* Copyright (C) 2007-2018 B.A.T.M.A.N. contributors:
2
+/* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors:
33 *
44 * Marek Lindner, Simon Wunderlich, Antonio Quartulli
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 "translation-table.h"
....@@ -205,7 +193,7 @@
205193 * Return: a pointer to the corresponding tt_global_entry struct if the client
206194 * is found, NULL otherwise.
207195 */
208
-static struct batadv_tt_global_entry *
196
+struct batadv_tt_global_entry *
209197 batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
210198 unsigned short vid)
211199 {
....@@ -260,6 +248,9 @@
260248 static void
261249 batadv_tt_local_entry_put(struct batadv_tt_local_entry *tt_local_entry)
262250 {
251
+ if (!tt_local_entry)
252
+ return;
253
+
263254 kref_put(&tt_local_entry->common.refcount,
264255 batadv_tt_local_entry_release);
265256 }
....@@ -283,7 +274,7 @@
283274 * queue for free after rcu grace period
284275 * @ref: kref pointer of the nc_node
285276 */
286
-static void batadv_tt_global_entry_release(struct kref *ref)
277
+void batadv_tt_global_entry_release(struct kref *ref)
287278 {
288279 struct batadv_tt_global_entry *tt_global_entry;
289280
....@@ -296,25 +287,13 @@
296287 }
297288
298289 /**
299
- * batadv_tt_global_entry_put() - decrement the tt_global_entry refcounter and
300
- * possibly release it
301
- * @tt_global_entry: tt_global_entry to be free'd
302
- */
303
-static void
304
-batadv_tt_global_entry_put(struct batadv_tt_global_entry *tt_global_entry)
305
-{
306
- kref_put(&tt_global_entry->common.refcount,
307
- batadv_tt_global_entry_release);
308
-}
309
-
310
-/**
311290 * batadv_tt_global_hash_count() - count the number of orig entries
312291 * @bat_priv: the bat priv with all the soft interface information
313292 * @addr: the mac address of the client to count entries for
314293 * @vid: VLAN identifier
315294 *
316295 * Return: the number of originators advertising the given address/data
317
- * (excluding ourself).
296
+ * (excluding our self).
318297 */
319298 int batadv_tt_global_hash_count(struct batadv_priv *bat_priv,
320299 const u8 *addr, unsigned short vid)
....@@ -466,6 +445,9 @@
466445 static void
467446 batadv_tt_orig_list_entry_put(struct batadv_tt_orig_list_entry *orig_entry)
468447 {
448
+ if (!orig_entry)
449
+ return;
450
+
469451 kref_put(&orig_entry->refcount, batadv_tt_orig_list_entry_release);
470452 }
471453
....@@ -855,7 +837,7 @@
855837 * table. In case of success the value is updated with the real amount of
856838 * reserved bytes
857839 * Allocate the needed amount of memory for the entire TT TVLV and write its
858
- * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data
840
+ * header made up of one tvlv_tt_data object and a series of tvlv_tt_vlan_data
859841 * objects, one per active VLAN served by the originator node.
860842 *
861843 * Return: the size of the allocated buffer or 0 in case of failure.
....@@ -875,7 +857,7 @@
875857 u8 *tt_change_ptr;
876858
877859 spin_lock_bh(&orig_node->vlan_list_lock);
878
- hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
860
+ hlist_for_each_entry(vlan, &orig_node->vlan_list, list) {
879861 num_vlan++;
880862 num_entries += atomic_read(&vlan->tt.num_entries);
881863 }
....@@ -901,7 +883,7 @@
901883 (*tt_data)->num_vlan = htons(num_vlan);
902884
903885 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
904
- hlist_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) {
886
+ hlist_for_each_entry(vlan, &orig_node->vlan_list, list) {
905887 tt_vlan->vid = htons(vlan->vid);
906888 tt_vlan->crc = htonl(vlan->tt.crc);
907889 tt_vlan->reserved = 0;
....@@ -951,7 +933,7 @@
951933 int change_offset;
952934
953935 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
954
- hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
936
+ hlist_for_each_entry(vlan, &bat_priv->softif_vlan_list, list) {
955937 vlan_entries = atomic_read(&vlan->tt.num_entries);
956938 if (vlan_entries < 1)
957939 continue;
....@@ -981,7 +963,7 @@
981963 (*tt_data)->num_vlan = htons(num_vlan);
982964
983965 tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1);
984
- hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
966
+ hlist_for_each_entry(vlan, &bat_priv->softif_vlan_list, list) {
985967 vlan_entries = atomic_read(&vlan->tt.num_entries);
986968 if (vlan_entries < 1)
987969 continue;
....@@ -1159,14 +1141,15 @@
11591141 * batadv_tt_local_dump_entry() - Dump one TT local entry into a message
11601142 * @msg :Netlink message to dump into
11611143 * @portid: Port making netlink request
1162
- * @seq: Sequence number of netlink message
1144
+ * @cb: Control block containing additional options
11631145 * @bat_priv: The bat priv with all the soft interface information
11641146 * @common: tt local & tt global common data
11651147 *
11661148 * Return: Error code, or 0 on success
11671149 */
11681150 static int
1169
-batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
1151
+batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid,
1152
+ struct netlink_callback *cb,
11701153 struct batadv_priv *bat_priv,
11711154 struct batadv_tt_common_entry *common)
11721155 {
....@@ -1187,11 +1170,13 @@
11871170
11881171 batadv_softif_vlan_put(vlan);
11891172
1190
- hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
1191
- NLM_F_MULTI,
1173
+ hdr = genlmsg_put(msg, portid, cb->nlh->nlmsg_seq,
1174
+ &batadv_netlink_family, NLM_F_MULTI,
11921175 BATADV_CMD_GET_TRANSTABLE_LOCAL);
11931176 if (!hdr)
11941177 return -ENOBUFS;
1178
+
1179
+ genl_dump_check_consistent(cb, hdr);
11951180
11961181 if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) ||
11971182 nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) ||
....@@ -1215,34 +1200,39 @@
12151200 * batadv_tt_local_dump_bucket() - Dump one TT local bucket into a message
12161201 * @msg: Netlink message to dump into
12171202 * @portid: Port making netlink request
1218
- * @seq: Sequence number of netlink message
1203
+ * @cb: Control block containing additional options
12191204 * @bat_priv: The bat priv with all the soft interface information
1220
- * @head: Pointer to the list containing the local tt entries
1205
+ * @hash: hash to dump
1206
+ * @bucket: bucket index to dump
12211207 * @idx_s: Number of entries to skip
12221208 *
12231209 * Return: Error code, or 0 on success
12241210 */
12251211 static int
1226
-batadv_tt_local_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
1212
+batadv_tt_local_dump_bucket(struct sk_buff *msg, u32 portid,
1213
+ struct netlink_callback *cb,
12271214 struct batadv_priv *bat_priv,
1228
- struct hlist_head *head, int *idx_s)
1215
+ struct batadv_hashtable *hash, unsigned int bucket,
1216
+ int *idx_s)
12291217 {
12301218 struct batadv_tt_common_entry *common;
12311219 int idx = 0;
12321220
1233
- rcu_read_lock();
1234
- hlist_for_each_entry_rcu(common, head, hash_entry) {
1221
+ spin_lock_bh(&hash->list_locks[bucket]);
1222
+ cb->seq = atomic_read(&hash->generation) << 1 | 1;
1223
+
1224
+ hlist_for_each_entry(common, &hash->table[bucket], hash_entry) {
12351225 if (idx++ < *idx_s)
12361226 continue;
12371227
1238
- if (batadv_tt_local_dump_entry(msg, portid, seq, bat_priv,
1228
+ if (batadv_tt_local_dump_entry(msg, portid, cb, bat_priv,
12391229 common)) {
1240
- rcu_read_unlock();
1230
+ spin_unlock_bh(&hash->list_locks[bucket]);
12411231 *idx_s = idx - 1;
12421232 return -EMSGSIZE;
12431233 }
12441234 }
1245
- rcu_read_unlock();
1235
+ spin_unlock_bh(&hash->list_locks[bucket]);
12461236
12471237 *idx_s = 0;
12481238 return 0;
....@@ -1262,7 +1252,6 @@
12621252 struct batadv_priv *bat_priv;
12631253 struct batadv_hard_iface *primary_if = NULL;
12641254 struct batadv_hashtable *hash;
1265
- struct hlist_head *head;
12661255 int ret;
12671256 int ifindex;
12681257 int bucket = cb->args[0];
....@@ -1290,10 +1279,8 @@
12901279 hash = bat_priv->tt.local_hash;
12911280
12921281 while (bucket < hash->size) {
1293
- head = &hash->table[bucket];
1294
-
1295
- if (batadv_tt_local_dump_bucket(msg, portid, cb->nlh->nlmsg_seq,
1296
- bat_priv, head, &idx))
1282
+ if (batadv_tt_local_dump_bucket(msg, portid, cb, bat_priv,
1283
+ hash, bucket, &idx))
12971284 break;
12981285
12991286 bucket++;
....@@ -1684,7 +1671,7 @@
16841671 * the function argument.
16851672 * If a TT local entry exists for this non-mesh client remove it.
16861673 *
1687
- * The caller must hold orig_node refcount.
1674
+ * The caller must hold the orig_node refcount.
16881675 *
16891676 * Return: true if the new entry has been added, false otherwise
16901677 */
....@@ -1849,7 +1836,7 @@
18491836 * @bat_priv: the bat priv with all the soft interface information
18501837 * @tt_global_entry: global translation table entry to be analyzed
18511838 *
1852
- * This functon assumes the caller holds rcu_read_lock().
1839
+ * This function assumes the caller holds rcu_read_lock().
18531840 * Return: best originator list entry or NULL on errors.
18541841 */
18551842 static struct batadv_tt_orig_list_entry *
....@@ -1897,7 +1884,7 @@
18971884 * @tt_global_entry: global translation table entry to be printed
18981885 * @seq: debugfs table seq_file struct
18991886 *
1900
- * This functon assumes the caller holds rcu_read_lock().
1887
+ * This function assumes the caller holds rcu_read_lock().
19011888 */
19021889 static void
19031890 batadv_tt_global_print_entry(struct batadv_priv *bat_priv,
....@@ -2826,6 +2813,9 @@
28262813 */
28272814 static void batadv_tt_req_node_put(struct batadv_tt_req_node *tt_req_node)
28282815 {
2816
+ if (!tt_req_node)
2817
+ return;
2818
+
28292819 kref_put(&tt_req_node->refcount, batadv_tt_req_node_release);
28302820 }
28312821