hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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"
....@@ -167,11 +156,14 @@
167156
168157 static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
169158 {
159
+ struct batadv_priv *bat_priv = netdev_priv(dev);
160
+
170161 /* check ranges */
171162 if (new_mtu < 68 || new_mtu > batadv_hardif_min_mtu(dev))
172163 return -EINVAL;
173164
174165 dev->mtu = new_mtu;
166
+ bat_priv->mtu_set_by_user = new_mtu;
175167
176168 return 0;
177169 }
....@@ -209,9 +201,11 @@
209201 unsigned short vid;
210202 u32 seqno;
211203 int gw_mode;
212
- enum batadv_forw_mode forw_mode;
204
+ enum batadv_forw_mode forw_mode = BATADV_FORW_SINGLE;
213205 struct batadv_orig_node *mcast_single_orig = NULL;
206
+ int mcast_is_routable = 0;
214207 int network_offset = ETH_HLEN;
208
+ __be16 proto;
215209
216210 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
217211 goto dropped;
....@@ -225,19 +219,22 @@
225219 skb_reset_mac_header(skb);
226220 ethhdr = eth_hdr(skb);
227221
228
- switch (ntohs(ethhdr->h_proto)) {
222
+ proto = ethhdr->h_proto;
223
+
224
+ switch (ntohs(proto)) {
229225 case ETH_P_8021Q:
230226 if (!pskb_may_pull(skb, sizeof(*vhdr)))
231227 goto dropped;
232228 vhdr = vlan_eth_hdr(skb);
229
+ proto = vhdr->h_vlan_encapsulated_proto;
233230
234231 /* drop batman-in-batman packets to prevent loops */
235
- if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN)) {
232
+ if (proto != htons(ETH_P_BATMAN)) {
236233 network_offset += VLAN_HLEN;
237234 break;
238235 }
239236
240
- /* fall through */
237
+ fallthrough;
241238 case ETH_P_BATMAN:
242239 goto dropped;
243240 }
....@@ -259,6 +256,9 @@
259256 if (!client_added)
260257 goto dropped;
261258 }
259
+
260
+ /* Snoop address candidates from DHCPACKs for early DAT filling */
261
+ batadv_dat_snoop_outgoing_dhcp_ack(bat_priv, skb, proto, vid);
262262
263263 /* don't accept stp packets. STP does not help in meshes.
264264 * better use the bridge loop avoidance ...
....@@ -306,11 +306,13 @@
306306 send:
307307 if (do_bcast && !is_broadcast_ether_addr(ethhdr->h_dest)) {
308308 forw_mode = batadv_mcast_forw_mode(bat_priv, skb,
309
- &mcast_single_orig);
309
+ &mcast_single_orig,
310
+ &mcast_is_routable);
310311 if (forw_mode == BATADV_FORW_NONE)
311312 goto dropped;
312313
313
- if (forw_mode == BATADV_FORW_SINGLE)
314
+ if (forw_mode == BATADV_FORW_SINGLE ||
315
+ forw_mode == BATADV_FORW_SOME)
314316 do_bcast = false;
315317 }
316318 }
....@@ -369,6 +371,9 @@
369371 } else if (mcast_single_orig) {
370372 ret = batadv_mcast_forw_send_orig(bat_priv, skb, vid,
371373 mcast_single_orig);
374
+ } else if (forw_mode == BATADV_FORW_SOME) {
375
+ ret = batadv_mcast_forw_send(bat_priv, skb, vid,
376
+ mcast_is_routable);
372377 } else {
373378 if (batadv_dat_snoop_outgoing_arp_request(bat_priv,
374379 skb))
....@@ -406,7 +411,7 @@
406411 * @hdr_size: size of already parsed batman-adv header
407412 * @orig_node: originator from which the batman-adv packet was sent
408413 *
409
- * Sends a ethernet frame to the receive path of the local @soft_iface.
414
+ * Sends an ethernet frame to the receive path of the local @soft_iface.
410415 * skb->data has still point to the batman-adv header with the size @hdr_size.
411416 * The caller has to have parsed this header already and made sure that at least
412417 * @hdr_size bytes are still available for pull in @skb.
....@@ -436,7 +441,7 @@
436441 /* clean the netfilter state now that the batman-adv header has been
437442 * removed
438443 */
439
- nf_reset(skb);
444
+ nf_reset_ct(skb);
440445
441446 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
442447 goto dropped;
....@@ -455,7 +460,7 @@
455460 if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))
456461 break;
457462
458
- /* fall through */
463
+ fallthrough;
459464 case ETH_P_BATMAN:
460465 goto dropped;
461466 }
....@@ -510,7 +515,7 @@
510515 * after rcu grace period
511516 * @ref: kref pointer of the vlan object
512517 */
513
-static void batadv_softif_vlan_release(struct kref *ref)
518
+void batadv_softif_vlan_release(struct kref *ref)
514519 {
515520 struct batadv_softif_vlan *vlan;
516521
....@@ -521,19 +526,6 @@
521526 spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
522527
523528 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);
537529 }
538530
539531 /**
....@@ -649,7 +641,7 @@
649641 /**
650642 * batadv_interface_add_vid() - ndo_add_vid API implementation
651643 * @dev: the netdev of the mesh interface
652
- * @proto: protocol of the the vlan id
644
+ * @proto: protocol of the vlan id
653645 * @vid: identifier of the new vlan
654646 *
655647 * Set up all the internal structures for handling the new vlan on top of the
....@@ -707,7 +699,7 @@
707699 /**
708700 * batadv_interface_kill_vid() - ndo_kill_vid API implementation
709701 * @dev: the netdev of the mesh interface
710
- * @proto: protocol of the the vlan id
702
+ * @proto: protocol of the vlan id
711703 * @vid: identifier of the deleted vlan
712704 *
713705 * Destroy all the internal structures used to handle the vlan identified by vid
....@@ -804,12 +796,8 @@
804796 atomic_set(&bat_priv->distributed_arp_table, 1);
805797 #endif
806798 #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;
812799 atomic_set(&bat_priv->multicast_mode, 1);
800
+ atomic_set(&bat_priv->multicast_fanout, 16);
813801 atomic_set(&bat_priv->mcast.num_want_all_unsnoopables, 0);
814802 atomic_set(&bat_priv->mcast.num_want_all_ipv4, 0);
815803 atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0);
....@@ -847,7 +835,6 @@
847835 atomic_set(&bat_priv->frag_seqno, random_seqno);
848836
849837 bat_priv->primary_if = NULL;
850
- bat_priv->num_ifaces = 0;
851838
852839 batadv_nc_init_bat_priv(bat_priv);
853840
....@@ -948,10 +935,10 @@
948935 static void batadv_get_drvinfo(struct net_device *dev,
949936 struct ethtool_drvinfo *info)
950937 {
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));
938
+ strscpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
939
+ strscpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
940
+ strscpy(info->fw_version, "N/A", sizeof(info->fw_version));
941
+ strscpy(info->bus_info, "batman", sizeof(info->bus_info));
955942 }
956943
957944 /* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
....@@ -1065,6 +1052,7 @@
10651052 dev->needs_free_netdev = true;
10661053 dev->priv_destructor = batadv_softif_free;
10671054 dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_NETNS_LOCAL;
1055
+ dev->features |= NETIF_F_LLTX;
10681056 dev->priv_flags |= IFF_NO_QUEUE;
10691057
10701058 /* can't call min_mtu, because the needed variables