forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/net/batman-adv/soft-interface.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
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 "soft-interface.h"
....@@ -36,6 +24,7 @@
3624 #include <linux/list.h>
3725 #include <linux/lockdep.h>
3826 #include <linux/netdevice.h>
27
+#include <linux/netlink.h>
3928 #include <linux/percpu.h>
4029 #include <linux/printk.h>
4130 #include <linux/random.h>
....@@ -50,13 +39,13 @@
5039 #include <linux/string.h>
5140 #include <linux/types.h>
5241 #include <uapi/linux/batadv_packet.h>
42
+#include <uapi/linux/batman_adv.h>
5343
5444 #include "bat_algo.h"
5545 #include "bridge_loop_avoidance.h"
5646 #include "debugfs.h"
5747 #include "distributed-arp-table.h"
5848 #include "gateway_client.h"
59
-#include "gateway_common.h"
6049 #include "hard-interface.h"
6150 #include "multicast.h"
6251 #include "network-coding.h"
....@@ -209,9 +198,11 @@
209198 unsigned short vid;
210199 u32 seqno;
211200 int gw_mode;
212
- enum batadv_forw_mode forw_mode;
201
+ enum batadv_forw_mode forw_mode = BATADV_FORW_SINGLE;
213202 struct batadv_orig_node *mcast_single_orig = NULL;
203
+ int mcast_is_routable = 0;
214204 int network_offset = ETH_HLEN;
205
+ __be16 proto;
215206
216207 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
217208 goto dropped;
....@@ -225,19 +216,22 @@
225216 skb_reset_mac_header(skb);
226217 ethhdr = eth_hdr(skb);
227218
228
- switch (ntohs(ethhdr->h_proto)) {
219
+ proto = ethhdr->h_proto;
220
+
221
+ switch (ntohs(proto)) {
229222 case ETH_P_8021Q:
230223 if (!pskb_may_pull(skb, sizeof(*vhdr)))
231224 goto dropped;
232225 vhdr = vlan_eth_hdr(skb);
226
+ proto = vhdr->h_vlan_encapsulated_proto;
233227
234228 /* drop batman-in-batman packets to prevent loops */
235
- if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN)) {
229
+ if (proto != htons(ETH_P_BATMAN)) {
236230 network_offset += VLAN_HLEN;
237231 break;
238232 }
239233
240
- /* fall through */
234
+ fallthrough;
241235 case ETH_P_BATMAN:
242236 goto dropped;
243237 }
....@@ -259,6 +253,9 @@
259253 if (!client_added)
260254 goto dropped;
261255 }
256
+
257
+ /* Snoop address candidates from DHCPACKs for early DAT filling */
258
+ batadv_dat_snoop_outgoing_dhcp_ack(bat_priv, skb, proto, vid);
262259
263260 /* don't accept stp packets. STP does not help in meshes.
264261 * better use the bridge loop avoidance ...
....@@ -306,11 +303,13 @@
306303 send:
307304 if (do_bcast && !is_broadcast_ether_addr(ethhdr->h_dest)) {
308305 forw_mode = batadv_mcast_forw_mode(bat_priv, skb,
309
- &mcast_single_orig);
306
+ &mcast_single_orig,
307
+ &mcast_is_routable);
310308 if (forw_mode == BATADV_FORW_NONE)
311309 goto dropped;
312310
313
- if (forw_mode == BATADV_FORW_SINGLE)
311
+ if (forw_mode == BATADV_FORW_SINGLE ||
312
+ forw_mode == BATADV_FORW_SOME)
314313 do_bcast = false;
315314 }
316315 }
....@@ -369,6 +368,9 @@
369368 } else if (mcast_single_orig) {
370369 ret = batadv_mcast_forw_send_orig(bat_priv, skb, vid,
371370 mcast_single_orig);
371
+ } else if (forw_mode == BATADV_FORW_SOME) {
372
+ ret = batadv_mcast_forw_send(bat_priv, skb, vid,
373
+ mcast_is_routable);
372374 } else {
373375 if (batadv_dat_snoop_outgoing_arp_request(bat_priv,
374376 skb))
....@@ -406,7 +408,7 @@
406408 * @hdr_size: size of already parsed batman-adv header
407409 * @orig_node: originator from which the batman-adv packet was sent
408410 *
409
- * Sends a ethernet frame to the receive path of the local @soft_iface.
411
+ * Sends an ethernet frame to the receive path of the local @soft_iface.
410412 * skb->data has still point to the batman-adv header with the size @hdr_size.
411413 * The caller has to have parsed this header already and made sure that at least
412414 * @hdr_size bytes are still available for pull in @skb.
....@@ -436,7 +438,7 @@
436438 /* clean the netfilter state now that the batman-adv header has been
437439 * removed
438440 */
439
- nf_reset(skb);
441
+ nf_reset_ct(skb);
440442
441443 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
442444 goto dropped;
....@@ -455,7 +457,7 @@
455457 if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))
456458 break;
457459
458
- /* fall through */
460
+ fallthrough;
459461 case ETH_P_BATMAN:
460462 goto dropped;
461463 }
....@@ -510,7 +512,7 @@
510512 * after rcu grace period
511513 * @ref: kref pointer of the vlan object
512514 */
513
-static void batadv_softif_vlan_release(struct kref *ref)
515
+void batadv_softif_vlan_release(struct kref *ref)
514516 {
515517 struct batadv_softif_vlan *vlan;
516518
....@@ -521,19 +523,6 @@
521523 spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
522524
523525 kfree_rcu(vlan, rcu);
524
-}
525
-
526
-/**
527
- * batadv_softif_vlan_put() - decrease the vlan object refcounter and
528
- * possibly release it
529
- * @vlan: the vlan object to release
530
- */
531
-void batadv_softif_vlan_put(struct batadv_softif_vlan *vlan)
532
-{
533
- if (!vlan)
534
- return;
535
-
536
- kref_put(&vlan->refcount, batadv_softif_vlan_release);
537526 }
538527
539528 /**
....@@ -649,7 +638,7 @@
649638 /**
650639 * batadv_interface_add_vid() - ndo_add_vid API implementation
651640 * @dev: the netdev of the mesh interface
652
- * @proto: protocol of the the vlan id
641
+ * @proto: protocol of the vlan id
653642 * @vid: identifier of the new vlan
654643 *
655644 * Set up all the internal structures for handling the new vlan on top of the
....@@ -707,7 +696,7 @@
707696 /**
708697 * batadv_interface_kill_vid() - ndo_kill_vid API implementation
709698 * @dev: the netdev of the mesh interface
710
- * @proto: protocol of the the vlan id
699
+ * @proto: protocol of the vlan id
711700 * @vid: identifier of the deleted vlan
712701 *
713702 * Destroy all the internal structures used to handle the vlan identified by vid
....@@ -804,12 +793,8 @@
804793 atomic_set(&bat_priv->distributed_arp_table, 1);
805794 #endif
806795 #ifdef CONFIG_BATMAN_ADV_MCAST
807
- bat_priv->mcast.querier_ipv4.exists = false;
808
- bat_priv->mcast.querier_ipv4.shadowing = false;
809
- bat_priv->mcast.querier_ipv6.exists = false;
810
- bat_priv->mcast.querier_ipv6.shadowing = false;
811
- bat_priv->mcast.flags = BATADV_NO_FLAGS;
812796 atomic_set(&bat_priv->multicast_mode, 1);
797
+ atomic_set(&bat_priv->multicast_fanout, 16);
813798 atomic_set(&bat_priv->mcast.num_want_all_unsnoopables, 0);
814799 atomic_set(&bat_priv->mcast.num_want_all_ipv4, 0);
815800 atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0);
....@@ -847,7 +832,6 @@
847832 atomic_set(&bat_priv->frag_seqno, random_seqno);
848833
849834 bat_priv->primary_if = NULL;
850
- bat_priv->num_ifaces = 0;
851835
852836 batadv_nc_init_bat_priv(bat_priv);
853837
....@@ -948,10 +932,10 @@
948932 static void batadv_get_drvinfo(struct net_device *dev,
949933 struct ethtool_drvinfo *info)
950934 {
951
- strlcpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
952
- strlcpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
953
- strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
954
- strlcpy(info->bus_info, "batman", sizeof(info->bus_info));
935
+ strscpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
936
+ strscpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
937
+ strscpy(info->fw_version, "N/A", sizeof(info->fw_version));
938
+ strscpy(info->bus_info, "batman", sizeof(info->bus_info));
955939 }
956940
957941 /* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
....@@ -1065,6 +1049,7 @@
10651049 dev->needs_free_netdev = true;
10661050 dev->priv_destructor = batadv_softif_free;
10671051 dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_NETNS_LOCAL;
1052
+ dev->features |= NETIF_F_LLTX;
10681053 dev->priv_flags |= IFF_NO_QUEUE;
10691054
10701055 /* can't call min_mtu, because the needed variables