2017-11-19 17:05:11 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2021-01-01 02:00:01 +03:00
|
|
|
/* Copyright (C) B.A.T.M.A.N. contributors:
|
2016-01-16 11:40:12 +03:00
|
|
|
*
|
|
|
|
* Antonio Quartulli
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bat_v_ogm.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include <linux/atomic.h>
|
|
|
|
#include <linux/byteorder/generic.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/etherdevice.h>
|
2017-11-19 19:12:02 +03:00
|
|
|
#include <linux/gfp.h>
|
2016-01-16 11:40:12 +03:00
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/kernel.h>
|
2016-03-05 18:09:16 +03:00
|
|
|
#include <linux/kref.h>
|
2016-01-16 11:40:13 +03:00
|
|
|
#include <linux/list.h>
|
2019-08-04 21:54:53 +03:00
|
|
|
#include <linux/lockdep.h>
|
2020-10-26 23:01:59 +03:00
|
|
|
#include <linux/minmax.h>
|
2019-10-03 18:02:01 +03:00
|
|
|
#include <linux/mutex.h>
|
2016-01-16 11:40:12 +03:00
|
|
|
#include <linux/netdevice.h>
|
2020-08-17 09:09:48 +03:00
|
|
|
#include <linux/prandom.h>
|
2016-01-16 11:40:12 +03:00
|
|
|
#include <linux/random.h>
|
|
|
|
#include <linux/rculist.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/slab.h>
|
2019-08-04 21:54:53 +03:00
|
|
|
#include <linux/spinlock.h>
|
2016-01-16 11:40:12 +03:00
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/workqueue.h>
|
2017-12-21 12:17:41 +03:00
|
|
|
#include <uapi/linux/batadv_packet.h>
|
2016-01-16 11:40:12 +03:00
|
|
|
|
2016-05-15 12:07:44 +03:00
|
|
|
#include "bat_algo.h"
|
2016-01-16 11:40:12 +03:00
|
|
|
#include "hard-interface.h"
|
2016-01-16 11:40:13 +03:00
|
|
|
#include "hash.h"
|
2016-05-16 00:48:31 +03:00
|
|
|
#include "log.h"
|
2016-01-16 11:40:13 +03:00
|
|
|
#include "originator.h"
|
2016-01-16 11:40:12 +03:00
|
|
|
#include "routing.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "translation-table.h"
|
2016-05-15 12:07:43 +03:00
|
|
|
#include "tvlv.h"
|
2016-01-16 11:40:12 +03:00
|
|
|
|
2016-01-16 11:40:13 +03:00
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_orig_get() - retrieve and possibly create an originator node
|
2016-01-16 11:40:13 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
* @addr: the address of the originator
|
|
|
|
*
|
2020-06-01 21:13:21 +03:00
|
|
|
* Return: the orig_node corresponding to the specified address. If such an
|
|
|
|
* object does not exist, it is allocated here. In case of allocation failure
|
|
|
|
* returns NULL.
|
2016-01-16 11:40:13 +03:00
|
|
|
*/
|
|
|
|
struct batadv_orig_node *batadv_v_ogm_orig_get(struct batadv_priv *bat_priv,
|
|
|
|
const u8 *addr)
|
|
|
|
{
|
|
|
|
struct batadv_orig_node *orig_node;
|
|
|
|
int hash_added;
|
|
|
|
|
|
|
|
orig_node = batadv_orig_hash_find(bat_priv, addr);
|
|
|
|
if (orig_node)
|
|
|
|
return orig_node;
|
|
|
|
|
|
|
|
orig_node = batadv_orig_node_new(bat_priv, addr);
|
|
|
|
if (!orig_node)
|
|
|
|
return NULL;
|
|
|
|
|
2016-07-15 18:39:21 +03:00
|
|
|
kref_get(&orig_node->refcount);
|
2016-01-16 11:40:13 +03:00
|
|
|
hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
|
|
|
|
batadv_choose_orig, orig_node,
|
|
|
|
&orig_node->hash_entry);
|
|
|
|
if (hash_added != 0) {
|
2016-07-15 18:39:21 +03:00
|
|
|
/* remove refcnt for newly created orig_node and hash entry */
|
2016-01-16 11:40:13 +03:00
|
|
|
batadv_orig_node_put(orig_node);
|
|
|
|
batadv_orig_node_put(orig_node);
|
|
|
|
orig_node = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return orig_node;
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:54:53 +03:00
|
|
|
/**
|
|
|
|
* batadv_v_ogm_start_queue_timer() - restart the OGM aggregation timer
|
|
|
|
* @hard_iface: the interface to use to send the OGM
|
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_start_queue_timer(struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
|
|
|
unsigned int msecs = BATADV_MAX_AGGREGATION_MS * 1000;
|
|
|
|
|
|
|
|
/* msecs * [0.9, 1.1] */
|
2020-04-13 22:23:29 +03:00
|
|
|
msecs += prandom_u32_max(msecs / 5) - (msecs / 10);
|
2019-08-04 21:54:53 +03:00
|
|
|
queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.aggr_wq,
|
|
|
|
msecs_to_jiffies(msecs / 1000));
|
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_start_timer() - restart the OGM sending timer
|
2016-01-16 11:40:12 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_start_timer(struct batadv_priv *bat_priv)
|
|
|
|
{
|
|
|
|
unsigned long msecs;
|
|
|
|
/* this function may be invoked in different contexts (ogm rescheduling
|
|
|
|
* or hard_iface activation), but the work timer should not be reset
|
|
|
|
*/
|
|
|
|
if (delayed_work_pending(&bat_priv->bat_v.ogm_wq))
|
|
|
|
return;
|
|
|
|
|
|
|
|
msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
|
2020-04-13 22:23:29 +03:00
|
|
|
msecs += prandom_u32_max(2 * BATADV_JITTER);
|
2016-01-16 11:40:12 +03:00
|
|
|
queue_delayed_work(batadv_event_workqueue, &bat_priv->bat_v.ogm_wq,
|
|
|
|
msecs_to_jiffies(msecs));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_send_to_if() - send a batman ogm using a given interface
|
2016-01-16 11:40:12 +03:00
|
|
|
* @skb: the OGM to send
|
|
|
|
* @hard_iface: the interface to use to send the OGM
|
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_send_to_if(struct sk_buff *skb,
|
|
|
|
struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
|
|
|
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
|
|
|
|
|
2023-08-09 18:29:13 +03:00
|
|
|
if (hard_iface->if_status != BATADV_IF_ACTIVE) {
|
|
|
|
kfree_skb(skb);
|
2016-01-16 11:40:12 +03:00
|
|
|
return;
|
2023-08-09 18:29:13 +03:00
|
|
|
}
|
2016-01-16 11:40:12 +03:00
|
|
|
|
|
|
|
batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_TX);
|
|
|
|
batadv_add_counter(bat_priv, BATADV_CNT_MGMT_TX_BYTES,
|
|
|
|
skb->len + ETH_HLEN);
|
|
|
|
|
2016-01-16 11:40:15 +03:00
|
|
|
batadv_send_broadcast_skb(skb, hard_iface);
|
2016-01-16 11:40:12 +03:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:54:53 +03:00
|
|
|
/**
|
|
|
|
* batadv_v_ogm_len() - OGMv2 packet length
|
|
|
|
* @skb: the OGM to check
|
|
|
|
*
|
|
|
|
* Return: Length of the given OGMv2 packet, including tvlv length, excluding
|
|
|
|
* ethernet header length.
|
|
|
|
*/
|
|
|
|
static unsigned int batadv_v_ogm_len(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct batadv_ogm2_packet *ogm_packet;
|
|
|
|
|
|
|
|
ogm_packet = (struct batadv_ogm2_packet *)skb->data;
|
|
|
|
return BATADV_OGM2_HLEN + ntohs(ogm_packet->tvlv_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* batadv_v_ogm_queue_left() - check if given OGM still fits aggregation queue
|
|
|
|
* @skb: the OGM to check
|
|
|
|
* @hard_iface: the interface to use to send the OGM
|
|
|
|
*
|
2019-10-31 11:52:40 +03:00
|
|
|
* Caller needs to hold the hard_iface->bat_v.aggr_list.lock.
|
2019-08-04 21:54:53 +03:00
|
|
|
*
|
|
|
|
* Return: True, if the given OGMv2 packet still fits, false otherwise.
|
|
|
|
*/
|
|
|
|
static bool batadv_v_ogm_queue_left(struct sk_buff *skb,
|
|
|
|
struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
|
|
|
unsigned int max = min_t(unsigned int, hard_iface->net_dev->mtu,
|
|
|
|
BATADV_MAX_AGGREGATION_BYTES);
|
|
|
|
unsigned int ogm_len = batadv_v_ogm_len(skb);
|
|
|
|
|
2019-10-31 11:52:40 +03:00
|
|
|
lockdep_assert_held(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
|
|
|
|
return hard_iface->bat_v.aggr_len + ogm_len <= max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* batadv_v_ogm_aggr_list_free - free all elements in an aggregation queue
|
|
|
|
* @hard_iface: the interface holding the aggregation queue
|
|
|
|
*
|
2020-06-01 21:13:21 +03:00
|
|
|
* Empties the OGMv2 aggregation queue and frees all the skbs it contains.
|
2019-08-04 21:54:53 +03:00
|
|
|
*
|
2019-10-31 11:52:40 +03:00
|
|
|
* Caller needs to hold the hard_iface->bat_v.aggr_list.lock.
|
2019-08-04 21:54:53 +03:00
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_aggr_list_free(struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
2019-10-31 11:52:40 +03:00
|
|
|
lockdep_assert_held(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
|
2019-10-31 11:52:40 +03:00
|
|
|
__skb_queue_purge(&hard_iface->bat_v.aggr_list);
|
2019-08-04 21:54:53 +03:00
|
|
|
hard_iface->bat_v.aggr_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* batadv_v_ogm_aggr_send() - flush & send aggregation queue
|
|
|
|
* @hard_iface: the interface with the aggregation queue to flush
|
|
|
|
*
|
2019-08-04 21:54:54 +03:00
|
|
|
* Aggregates all OGMv2 packets currently in the aggregation queue into a
|
|
|
|
* single OGMv2 packet and transmits this aggregate.
|
|
|
|
*
|
|
|
|
* The aggregation queue is empty after this call.
|
|
|
|
*
|
2019-10-31 11:52:40 +03:00
|
|
|
* Caller needs to hold the hard_iface->bat_v.aggr_list.lock.
|
2019-08-04 21:54:53 +03:00
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_aggr_send(struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
2019-08-04 21:54:54 +03:00
|
|
|
unsigned int aggr_len = hard_iface->bat_v.aggr_len;
|
|
|
|
struct sk_buff *skb_aggr;
|
|
|
|
unsigned int ogm_len;
|
2019-08-04 21:54:53 +03:00
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2019-10-31 11:52:40 +03:00
|
|
|
lockdep_assert_held(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
|
2019-08-04 21:54:54 +03:00
|
|
|
if (!aggr_len)
|
|
|
|
return;
|
|
|
|
|
|
|
|
skb_aggr = dev_alloc_skb(aggr_len + ETH_HLEN + NET_IP_ALIGN);
|
|
|
|
if (!skb_aggr) {
|
|
|
|
batadv_v_ogm_aggr_list_free(hard_iface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_reserve(skb_aggr, ETH_HLEN + NET_IP_ALIGN);
|
|
|
|
skb_reset_network_header(skb_aggr);
|
|
|
|
|
2019-10-31 11:52:40 +03:00
|
|
|
while ((skb = __skb_dequeue(&hard_iface->bat_v.aggr_list))) {
|
2019-08-04 21:54:53 +03:00
|
|
|
hard_iface->bat_v.aggr_len -= batadv_v_ogm_len(skb);
|
2019-08-04 21:54:54 +03:00
|
|
|
|
|
|
|
ogm_len = batadv_v_ogm_len(skb);
|
|
|
|
skb_put_data(skb_aggr, skb->data, ogm_len);
|
|
|
|
|
|
|
|
consume_skb(skb);
|
2019-08-04 21:54:53 +03:00
|
|
|
}
|
2019-08-04 21:54:54 +03:00
|
|
|
|
|
|
|
batadv_v_ogm_send_to_if(skb_aggr, hard_iface);
|
2019-08-04 21:54:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* batadv_v_ogm_queue_on_if() - queue a batman ogm on a given interface
|
|
|
|
* @skb: the OGM to queue
|
|
|
|
* @hard_iface: the interface to queue the OGM on
|
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_queue_on_if(struct sk_buff *skb,
|
|
|
|
struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
|
|
|
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
|
|
|
|
|
|
|
|
if (!atomic_read(&bat_priv->aggregated_ogms)) {
|
|
|
|
batadv_v_ogm_send_to_if(skb, hard_iface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-31 11:52:40 +03:00
|
|
|
spin_lock_bh(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
if (!batadv_v_ogm_queue_left(skb, hard_iface))
|
|
|
|
batadv_v_ogm_aggr_send(hard_iface);
|
|
|
|
|
|
|
|
hard_iface->bat_v.aggr_len += batadv_v_ogm_len(skb);
|
2019-10-31 11:52:40 +03:00
|
|
|
__skb_queue_tail(&hard_iface->bat_v.aggr_list, skb);
|
|
|
|
spin_unlock_bh(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
/**
|
2019-10-03 18:02:01 +03:00
|
|
|
* batadv_v_ogm_send_softif() - periodic worker broadcasting the own OGM
|
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
2016-01-16 11:40:12 +03:00
|
|
|
*/
|
2019-10-03 18:02:01 +03:00
|
|
|
static void batadv_v_ogm_send_softif(struct batadv_priv *bat_priv)
|
2016-01-16 11:40:12 +03:00
|
|
|
{
|
|
|
|
struct batadv_hard_iface *hard_iface;
|
|
|
|
struct batadv_ogm2_packet *ogm_packet;
|
|
|
|
struct sk_buff *skb, *skb_tmp;
|
2017-06-18 10:59:28 +03:00
|
|
|
unsigned char *ogm_buff;
|
2016-01-16 11:40:12 +03:00
|
|
|
int ogm_buff_len;
|
|
|
|
u16 tvlv_len = 0;
|
batman-adv: Simple (re)broadcast avoidance
With this patch, (re)broadcasting on a specific interfaces is avoided:
* No neighbor: There is no need to broadcast on an interface if there
is no node behind it.
* Single neighbor is source: If there is just one neighbor on an
interface and if this neighbor is the one we actually got this
broadcast packet from, then we do not need to echo it back.
* Single neighbor is originator: If there is just one neighbor on
an interface and if this neighbor is the originator of this
broadcast packet, then we do not need to echo it back.
Goodies for BATMAN V:
("Upgrade your BATMAN IV network to V now to get these for free!")
Thanks to the split of OGMv1 into two packet types, OGMv2 and ELP
that is, we can now apply the same optimizations stated above to OGMv2
packets, too.
Furthermore, with BATMAN V, rebroadcasts can be reduced in certain
multi interface cases, too, where BATMAN IV cannot. This is thanks to
the removal of the "secondary interface originator" concept in BATMAN V.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
2016-08-07 13:34:19 +03:00
|
|
|
int ret;
|
2016-01-16 11:40:12 +03:00
|
|
|
|
2019-10-03 18:02:01 +03:00
|
|
|
lockdep_assert_held(&bat_priv->bat_v.ogm_buff_mutex);
|
2016-01-16 11:40:12 +03:00
|
|
|
|
|
|
|
if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ogm_buff = bat_priv->bat_v.ogm_buff;
|
|
|
|
ogm_buff_len = bat_priv->bat_v.ogm_buff_len;
|
|
|
|
/* tt changes have to be committed before the tvlv data is
|
|
|
|
* appended as it may alter the tt tvlv container
|
|
|
|
*/
|
|
|
|
batadv_tt_local_commit_changes(bat_priv);
|
|
|
|
tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, &ogm_buff,
|
|
|
|
&ogm_buff_len,
|
|
|
|
BATADV_OGM2_HLEN);
|
|
|
|
|
|
|
|
bat_priv->bat_v.ogm_buff = ogm_buff;
|
|
|
|
bat_priv->bat_v.ogm_buff_len = ogm_buff_len;
|
|
|
|
|
|
|
|
skb = netdev_alloc_skb_ip_align(NULL, ETH_HLEN + ogm_buff_len);
|
|
|
|
if (!skb)
|
|
|
|
goto reschedule;
|
|
|
|
|
|
|
|
skb_reserve(skb, ETH_HLEN);
|
2017-06-18 10:59:28 +03:00
|
|
|
skb_put_data(skb, ogm_buff, ogm_buff_len);
|
2016-01-16 11:40:12 +03:00
|
|
|
|
|
|
|
ogm_packet = (struct batadv_ogm2_packet *)skb->data;
|
|
|
|
ogm_packet->seqno = htonl(atomic_read(&bat_priv->bat_v.ogm_seqno));
|
|
|
|
atomic_inc(&bat_priv->bat_v.ogm_seqno);
|
|
|
|
ogm_packet->tvlv_len = htons(tvlv_len);
|
|
|
|
|
|
|
|
/* broadcast on every interface */
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
|
|
|
|
if (hard_iface->soft_iface != bat_priv->soft_iface)
|
|
|
|
continue;
|
|
|
|
|
2016-03-05 18:09:16 +03:00
|
|
|
if (!kref_get_unless_zero(&hard_iface->refcount))
|
|
|
|
continue;
|
|
|
|
|
batman-adv: Simple (re)broadcast avoidance
With this patch, (re)broadcasting on a specific interfaces is avoided:
* No neighbor: There is no need to broadcast on an interface if there
is no node behind it.
* Single neighbor is source: If there is just one neighbor on an
interface and if this neighbor is the one we actually got this
broadcast packet from, then we do not need to echo it back.
* Single neighbor is originator: If there is just one neighbor on
an interface and if this neighbor is the originator of this
broadcast packet, then we do not need to echo it back.
Goodies for BATMAN V:
("Upgrade your BATMAN IV network to V now to get these for free!")
Thanks to the split of OGMv1 into two packet types, OGMv2 and ELP
that is, we can now apply the same optimizations stated above to OGMv2
packets, too.
Furthermore, with BATMAN V, rebroadcasts can be reduced in certain
multi interface cases, too, where BATMAN IV cannot. This is thanks to
the removal of the "secondary interface originator" concept in BATMAN V.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
2016-08-07 13:34:19 +03:00
|
|
|
ret = batadv_hardif_no_broadcast(hard_iface, NULL, NULL);
|
|
|
|
if (ret) {
|
|
|
|
char *type;
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case BATADV_HARDIF_BCAST_NORECIPIENT:
|
|
|
|
type = "no neighbor";
|
|
|
|
break;
|
|
|
|
case BATADV_HARDIF_BCAST_DUPFWD:
|
|
|
|
type = "single neighbor is source";
|
|
|
|
break;
|
|
|
|
case BATADV_HARDIF_BCAST_DUPORIG:
|
|
|
|
type = "single neighbor is originator";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "unknown";
|
|
|
|
}
|
|
|
|
|
2017-06-26 13:26:44 +03:00
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "OGM2 from ourselves on %s suppressed: %s\n",
|
batman-adv: Simple (re)broadcast avoidance
With this patch, (re)broadcasting on a specific interfaces is avoided:
* No neighbor: There is no need to broadcast on an interface if there
is no node behind it.
* Single neighbor is source: If there is just one neighbor on an
interface and if this neighbor is the one we actually got this
broadcast packet from, then we do not need to echo it back.
* Single neighbor is originator: If there is just one neighbor on
an interface and if this neighbor is the originator of this
broadcast packet, then we do not need to echo it back.
Goodies for BATMAN V:
("Upgrade your BATMAN IV network to V now to get these for free!")
Thanks to the split of OGMv1 into two packet types, OGMv2 and ELP
that is, we can now apply the same optimizations stated above to OGMv2
packets, too.
Furthermore, with BATMAN V, rebroadcasts can be reduced in certain
multi interface cases, too, where BATMAN IV cannot. This is thanks to
the removal of the "secondary interface originator" concept in BATMAN V.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
2016-08-07 13:34:19 +03:00
|
|
|
hard_iface->net_dev->name, type);
|
|
|
|
|
|
|
|
batadv_hardif_put(hard_iface);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Sending own OGM2 packet (originator %pM, seqno %u, throughput %u, TTL %d) on interface %s [%pM]\n",
|
|
|
|
ogm_packet->orig, ntohl(ogm_packet->seqno),
|
|
|
|
ntohl(ogm_packet->throughput), ogm_packet->ttl,
|
|
|
|
hard_iface->net_dev->name,
|
|
|
|
hard_iface->net_dev->dev_addr);
|
|
|
|
|
|
|
|
/* this skb gets consumed by batadv_v_ogm_send_to_if() */
|
|
|
|
skb_tmp = skb_clone(skb, GFP_ATOMIC);
|
2016-03-05 18:09:16 +03:00
|
|
|
if (!skb_tmp) {
|
|
|
|
batadv_hardif_put(hard_iface);
|
2016-01-16 11:40:12 +03:00
|
|
|
break;
|
2016-03-05 18:09:16 +03:00
|
|
|
}
|
2016-01-16 11:40:12 +03:00
|
|
|
|
2019-08-04 21:54:53 +03:00
|
|
|
batadv_v_ogm_queue_on_if(skb_tmp, hard_iface);
|
2016-03-05 18:09:16 +03:00
|
|
|
batadv_hardif_put(hard_iface);
|
2016-01-16 11:40:12 +03:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
consume_skb(skb);
|
|
|
|
|
|
|
|
reschedule:
|
|
|
|
batadv_v_ogm_start_timer(bat_priv);
|
|
|
|
out:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-03 18:02:01 +03:00
|
|
|
/**
|
|
|
|
* batadv_v_ogm_send() - periodic worker broadcasting the own OGM
|
|
|
|
* @work: work queue item
|
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_send(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct batadv_priv_bat_v *bat_v;
|
|
|
|
struct batadv_priv *bat_priv;
|
|
|
|
|
|
|
|
bat_v = container_of(work, struct batadv_priv_bat_v, ogm_wq.work);
|
|
|
|
bat_priv = container_of(bat_v, struct batadv_priv, bat_v);
|
|
|
|
|
|
|
|
mutex_lock(&bat_priv->bat_v.ogm_buff_mutex);
|
|
|
|
batadv_v_ogm_send_softif(bat_priv);
|
|
|
|
mutex_unlock(&bat_priv->bat_v.ogm_buff_mutex);
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:54:53 +03:00
|
|
|
/**
|
|
|
|
* batadv_v_ogm_aggr_work() - OGM queue periodic task per interface
|
|
|
|
* @work: work queue item
|
|
|
|
*
|
2020-06-01 21:13:21 +03:00
|
|
|
* Emits aggregated OGM messages in regular intervals.
|
2019-08-04 21:54:53 +03:00
|
|
|
*/
|
|
|
|
void batadv_v_ogm_aggr_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct batadv_hard_iface_bat_v *batv;
|
|
|
|
struct batadv_hard_iface *hard_iface;
|
|
|
|
|
|
|
|
batv = container_of(work, struct batadv_hard_iface_bat_v, aggr_wq.work);
|
|
|
|
hard_iface = container_of(batv, struct batadv_hard_iface, bat_v);
|
|
|
|
|
2019-10-31 11:52:40 +03:00
|
|
|
spin_lock_bh(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
batadv_v_ogm_aggr_send(hard_iface);
|
2019-10-31 11:52:40 +03:00
|
|
|
spin_unlock_bh(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
|
|
|
|
batadv_v_ogm_start_queue_timer(hard_iface);
|
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_iface_enable() - prepare an interface for B.A.T.M.A.N. V
|
2016-01-16 11:40:12 +03:00
|
|
|
* @hard_iface: the interface to prepare
|
|
|
|
*
|
2020-06-01 21:13:21 +03:00
|
|
|
* Takes care of scheduling its own OGM sending routine for this interface.
|
2016-01-16 11:40:12 +03:00
|
|
|
*
|
|
|
|
* Return: 0 on success or a negative error code otherwise
|
|
|
|
*/
|
|
|
|
int batadv_v_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
|
|
|
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
|
|
|
|
|
2019-08-04 21:54:53 +03:00
|
|
|
batadv_v_ogm_start_queue_timer(hard_iface);
|
2016-01-16 11:40:12 +03:00
|
|
|
batadv_v_ogm_start_timer(bat_priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:54:53 +03:00
|
|
|
/**
|
|
|
|
* batadv_v_ogm_iface_disable() - release OGM interface private resources
|
|
|
|
* @hard_iface: interface for which the resources have to be released
|
|
|
|
*/
|
|
|
|
void batadv_v_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
|
|
|
|
{
|
|
|
|
cancel_delayed_work_sync(&hard_iface->bat_v.aggr_wq);
|
|
|
|
|
2019-10-31 11:52:40 +03:00
|
|
|
spin_lock_bh(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
batadv_v_ogm_aggr_list_free(hard_iface);
|
2019-10-31 11:52:40 +03:00
|
|
|
spin_unlock_bh(&hard_iface->bat_v.aggr_list.lock);
|
2019-08-04 21:54:53 +03:00
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_primary_iface_set() - set a new primary interface
|
2016-01-16 11:40:12 +03:00
|
|
|
* @primary_iface: the new primary interface
|
|
|
|
*/
|
|
|
|
void batadv_v_ogm_primary_iface_set(struct batadv_hard_iface *primary_iface)
|
|
|
|
{
|
|
|
|
struct batadv_priv *bat_priv = netdev_priv(primary_iface->soft_iface);
|
|
|
|
struct batadv_ogm2_packet *ogm_packet;
|
|
|
|
|
2019-10-03 18:02:01 +03:00
|
|
|
mutex_lock(&bat_priv->bat_v.ogm_buff_mutex);
|
2016-01-16 11:40:12 +03:00
|
|
|
if (!bat_priv->bat_v.ogm_buff)
|
2019-10-03 18:02:01 +03:00
|
|
|
goto unlock;
|
2016-01-16 11:40:12 +03:00
|
|
|
|
|
|
|
ogm_packet = (struct batadv_ogm2_packet *)bat_priv->bat_v.ogm_buff;
|
|
|
|
ether_addr_copy(ogm_packet->orig, primary_iface->net_dev->dev_addr);
|
2019-10-03 18:02:01 +03:00
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&bat_priv->bat_v.ogm_buff_mutex);
|
2016-01-16 11:40:12 +03:00
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:13 +03:00
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_forward_penalty() - apply a penalty to the throughput metric
|
|
|
|
* forwarded with B.A.T.M.A.N. V OGMs
|
2016-01-16 11:40:13 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
* @if_incoming: the interface where the OGM has been received
|
|
|
|
* @if_outgoing: the interface where the OGM has to be forwarded to
|
|
|
|
* @throughput: the current throughput
|
|
|
|
*
|
|
|
|
* Apply a penalty on the current throughput metric value based on the
|
2020-06-01 23:35:22 +03:00
|
|
|
* characteristic of the interface where the OGM has been received.
|
|
|
|
*
|
|
|
|
* Initially the per hardif hop penalty is applied to the throughput. After
|
|
|
|
* that the return value is then computed as follows:
|
2016-01-16 11:40:13 +03:00
|
|
|
* - throughput * 50% if the incoming and outgoing interface are the
|
|
|
|
* same WiFi interface and the throughput is above
|
|
|
|
* 1MBit/s
|
|
|
|
* - throughput if the outgoing interface is the default
|
|
|
|
* interface (i.e. this OGM is processed for the
|
|
|
|
* internal table and not forwarded)
|
2020-06-01 23:35:22 +03:00
|
|
|
* - throughput * node hop penalty otherwise
|
2016-01-16 11:40:13 +03:00
|
|
|
*
|
|
|
|
* Return: the penalised throughput metric.
|
|
|
|
*/
|
|
|
|
static u32 batadv_v_forward_penalty(struct batadv_priv *bat_priv,
|
|
|
|
struct batadv_hard_iface *if_incoming,
|
|
|
|
struct batadv_hard_iface *if_outgoing,
|
|
|
|
u32 throughput)
|
|
|
|
{
|
2020-06-01 23:35:22 +03:00
|
|
|
int if_hop_penalty = atomic_read(&if_incoming->hop_penalty);
|
2016-01-16 11:40:13 +03:00
|
|
|
int hop_penalty = atomic_read(&bat_priv->hop_penalty);
|
|
|
|
int hop_penalty_max = BATADV_TQ_MAX_VALUE;
|
|
|
|
|
2020-06-01 23:35:22 +03:00
|
|
|
/* Apply per hardif hop penalty */
|
|
|
|
throughput = throughput * (hop_penalty_max - if_hop_penalty) /
|
|
|
|
hop_penalty_max;
|
|
|
|
|
2016-01-16 11:40:13 +03:00
|
|
|
/* Don't apply hop penalty in default originator table. */
|
|
|
|
if (if_outgoing == BATADV_IF_DEFAULT)
|
|
|
|
return throughput;
|
|
|
|
|
|
|
|
/* Forwarding on the same WiFi interface cuts the throughput in half
|
|
|
|
* due to the store & forward characteristics of WIFI.
|
|
|
|
* Very low throughput values are the exception.
|
|
|
|
*/
|
2017-08-23 22:52:13 +03:00
|
|
|
if (throughput > 10 &&
|
|
|
|
if_incoming == if_outgoing &&
|
2015-11-10 20:50:51 +03:00
|
|
|
!(if_incoming->bat_v.flags & BATADV_FULL_DUPLEX))
|
2016-01-16 11:40:13 +03:00
|
|
|
return throughput / 2;
|
|
|
|
|
|
|
|
/* hop penalty of 255 equals 100% */
|
|
|
|
return throughput * (hop_penalty_max - hop_penalty) / hop_penalty_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_forward() - check conditions and forward an OGM to the given
|
2016-02-01 17:21:37 +03:00
|
|
|
* outgoing interface
|
2016-01-16 11:40:13 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
* @ogm_received: previously received OGM to be forwarded
|
2016-02-01 17:21:37 +03:00
|
|
|
* @orig_node: the originator which has been updated
|
|
|
|
* @neigh_node: the neigh_node through with the OGM has been received
|
2016-01-16 11:40:13 +03:00
|
|
|
* @if_incoming: the interface on which this OGM was received on
|
|
|
|
* @if_outgoing: the interface to which the OGM has to be forwarded to
|
|
|
|
*
|
|
|
|
* Forward an OGM to an interface after having altered the throughput metric and
|
|
|
|
* the TTL value contained in it. The original OGM isn't modified.
|
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_forward(struct batadv_priv *bat_priv,
|
|
|
|
const struct batadv_ogm2_packet *ogm_received,
|
2016-02-01 17:21:37 +03:00
|
|
|
struct batadv_orig_node *orig_node,
|
|
|
|
struct batadv_neigh_node *neigh_node,
|
2016-01-16 11:40:13 +03:00
|
|
|
struct batadv_hard_iface *if_incoming,
|
|
|
|
struct batadv_hard_iface *if_outgoing)
|
|
|
|
{
|
2016-02-01 17:21:37 +03:00
|
|
|
struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
|
|
|
|
struct batadv_orig_ifinfo *orig_ifinfo = NULL;
|
|
|
|
struct batadv_neigh_node *router = NULL;
|
2016-01-16 11:40:13 +03:00
|
|
|
struct batadv_ogm2_packet *ogm_forward;
|
|
|
|
unsigned char *skb_buff;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
size_t packet_len;
|
|
|
|
u16 tvlv_len;
|
|
|
|
|
2016-02-01 17:21:37 +03:00
|
|
|
/* only forward for specific interfaces, not for the default one. */
|
|
|
|
if (if_outgoing == BATADV_IF_DEFAULT)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
|
|
|
|
if (!orig_ifinfo)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* acquire possibly updated router */
|
|
|
|
router = batadv_orig_router_get(orig_node, if_outgoing);
|
|
|
|
|
|
|
|
/* strict rule: forward packets coming from the best next hop only */
|
|
|
|
if (neigh_node != router)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* don't forward the same seqno twice on one interface */
|
|
|
|
if (orig_ifinfo->last_seqno_forwarded == ntohl(ogm_received->seqno))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
orig_ifinfo->last_seqno_forwarded = ntohl(ogm_received->seqno);
|
|
|
|
|
2016-01-16 11:40:13 +03:00
|
|
|
if (ogm_received->ttl <= 1) {
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n");
|
2016-02-01 17:21:37 +03:00
|
|
|
goto out;
|
2016-01-16 11:40:13 +03:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:21:37 +03:00
|
|
|
neigh_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
|
|
|
|
if (!neigh_ifinfo)
|
|
|
|
goto out;
|
|
|
|
|
2016-01-16 11:40:13 +03:00
|
|
|
tvlv_len = ntohs(ogm_received->tvlv_len);
|
|
|
|
|
|
|
|
packet_len = BATADV_OGM2_HLEN + tvlv_len;
|
|
|
|
skb = netdev_alloc_skb_ip_align(if_outgoing->net_dev,
|
|
|
|
ETH_HLEN + packet_len);
|
|
|
|
if (!skb)
|
2016-02-01 17:21:37 +03:00
|
|
|
goto out;
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
skb_reserve(skb, ETH_HLEN);
|
networking: introduce and use skb_put_data()
A common pattern with skb_put() is to just want to memcpy()
some data into the new space, introduce skb_put_data() for
this.
An spatch similar to the one for skb_put_zero() converts many
of the places using it:
@@
identifier p, p2;
expression len, skb, data;
type t, t2;
@@
(
-p = skb_put(skb, len);
+p = skb_put_data(skb, data, len);
|
-p = (t)skb_put(skb, len);
+p = skb_put_data(skb, data, len);
)
(
p2 = (t2)p;
-memcpy(p2, data, len);
|
-memcpy(p, data, len);
)
@@
type t, t2;
identifier p, p2;
expression skb, data;
@@
t *p;
...
(
-p = skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
|
-p = (t *)skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
)
(
p2 = (t2)p;
-memcpy(p2, data, sizeof(*p));
|
-memcpy(p, data, sizeof(*p));
)
@@
expression skb, len, data;
@@
-memcpy(skb_put(skb, len), data, len);
+skb_put_data(skb, data, len);
(again, manually post-processed to retain some comments)
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 15:29:20 +03:00
|
|
|
skb_buff = skb_put_data(skb, ogm_received, packet_len);
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
/* apply forward penalty */
|
|
|
|
ogm_forward = (struct batadv_ogm2_packet *)skb_buff;
|
2016-02-01 17:21:37 +03:00
|
|
|
ogm_forward->throughput = htonl(neigh_ifinfo->bat_v.throughput);
|
2016-01-16 11:40:13 +03:00
|
|
|
ogm_forward->ttl--;
|
|
|
|
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Forwarding OGM2 packet on %s: throughput %u, ttl %u, received via %s\n",
|
2016-02-01 17:21:37 +03:00
|
|
|
if_outgoing->net_dev->name, ntohl(ogm_forward->throughput),
|
|
|
|
ogm_forward->ttl, if_incoming->net_dev->name);
|
2016-01-16 11:40:13 +03:00
|
|
|
|
2019-08-04 21:54:53 +03:00
|
|
|
batadv_v_ogm_queue_on_if(skb, if_outgoing);
|
2016-02-01 17:21:37 +03:00
|
|
|
|
|
|
|
out:
|
2021-08-08 20:11:08 +03:00
|
|
|
batadv_orig_ifinfo_put(orig_ifinfo);
|
|
|
|
batadv_neigh_node_put(router);
|
|
|
|
batadv_neigh_ifinfo_put(neigh_ifinfo);
|
2016-01-16 11:40:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_metric_update() - update route metric based on OGM
|
2016-01-16 11:40:13 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
* @ogm2: OGM2 structure
|
|
|
|
* @orig_node: Originator structure for which the OGM has been received
|
|
|
|
* @neigh_node: the neigh_node through with the OGM has been received
|
|
|
|
* @if_incoming: the interface where this packet was received
|
|
|
|
* @if_outgoing: the interface for which the packet should be considered
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* 1 if the OGM is new,
|
|
|
|
* 0 if it is not new but valid,
|
|
|
|
* <0 on error (e.g. old OGM)
|
|
|
|
*/
|
|
|
|
static int batadv_v_ogm_metric_update(struct batadv_priv *bat_priv,
|
|
|
|
const struct batadv_ogm2_packet *ogm2,
|
|
|
|
struct batadv_orig_node *orig_node,
|
|
|
|
struct batadv_neigh_node *neigh_node,
|
|
|
|
struct batadv_hard_iface *if_incoming,
|
|
|
|
struct batadv_hard_iface *if_outgoing)
|
|
|
|
{
|
2016-07-25 01:42:44 +03:00
|
|
|
struct batadv_orig_ifinfo *orig_ifinfo;
|
2016-01-16 11:40:13 +03:00
|
|
|
struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
|
|
|
|
bool protection_started = false;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
u32 path_throughput;
|
|
|
|
s32 seq_diff;
|
|
|
|
|
|
|
|
orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
|
|
|
|
if (!orig_ifinfo)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
seq_diff = ntohl(ogm2->seqno) - orig_ifinfo->last_real_seqno;
|
|
|
|
|
|
|
|
if (!hlist_empty(&orig_node->neigh_list) &&
|
|
|
|
batadv_window_protected(bat_priv, seq_diff,
|
|
|
|
BATADV_OGM_MAX_AGE,
|
|
|
|
&orig_ifinfo->batman_seqno_reset,
|
|
|
|
&protection_started)) {
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Drop packet: packet within window protection time from %pM\n",
|
|
|
|
ogm2->orig);
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Last reset: %ld, %ld\n",
|
|
|
|
orig_ifinfo->batman_seqno_reset, jiffies);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* drop packets with old seqnos, however accept the first packet after
|
|
|
|
* a host has been rebooted.
|
|
|
|
*/
|
2017-08-23 22:52:13 +03:00
|
|
|
if (seq_diff < 0 && !protection_started)
|
2016-01-16 11:40:13 +03:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
neigh_node->last_seen = jiffies;
|
|
|
|
|
|
|
|
orig_node->last_seen = jiffies;
|
|
|
|
|
|
|
|
orig_ifinfo->last_real_seqno = ntohl(ogm2->seqno);
|
|
|
|
orig_ifinfo->last_ttl = ogm2->ttl;
|
|
|
|
|
|
|
|
neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing);
|
|
|
|
if (!neigh_ifinfo)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
path_throughput = batadv_v_forward_penalty(bat_priv, if_incoming,
|
|
|
|
if_outgoing,
|
|
|
|
ntohl(ogm2->throughput));
|
|
|
|
neigh_ifinfo->bat_v.throughput = path_throughput;
|
|
|
|
neigh_ifinfo->bat_v.last_seqno = ntohl(ogm2->seqno);
|
|
|
|
neigh_ifinfo->last_ttl = ogm2->ttl;
|
|
|
|
|
|
|
|
if (seq_diff > 0 || protection_started)
|
|
|
|
ret = 1;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out:
|
2021-08-08 20:11:08 +03:00
|
|
|
batadv_orig_ifinfo_put(orig_ifinfo);
|
|
|
|
batadv_neigh_ifinfo_put(neigh_ifinfo);
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_route_update() - update routes based on OGM
|
2016-01-16 11:40:13 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
* @ethhdr: the Ethernet header of the OGM2
|
|
|
|
* @ogm2: OGM2 structure
|
|
|
|
* @orig_node: Originator structure for which the OGM has been received
|
|
|
|
* @neigh_node: the neigh_node through with the OGM has been received
|
|
|
|
* @if_incoming: the interface where this packet was received
|
|
|
|
* @if_outgoing: the interface for which the packet should be considered
|
2016-02-01 17:21:37 +03:00
|
|
|
*
|
|
|
|
* Return: true if the packet should be forwarded, false otherwise
|
2016-01-16 11:40:13 +03:00
|
|
|
*/
|
2016-02-01 17:21:37 +03:00
|
|
|
static bool batadv_v_ogm_route_update(struct batadv_priv *bat_priv,
|
2016-01-16 11:40:13 +03:00
|
|
|
const struct ethhdr *ethhdr,
|
|
|
|
const struct batadv_ogm2_packet *ogm2,
|
|
|
|
struct batadv_orig_node *orig_node,
|
|
|
|
struct batadv_neigh_node *neigh_node,
|
|
|
|
struct batadv_hard_iface *if_incoming,
|
|
|
|
struct batadv_hard_iface *if_outgoing)
|
|
|
|
{
|
|
|
|
struct batadv_neigh_node *router = NULL;
|
2016-07-25 01:42:44 +03:00
|
|
|
struct batadv_orig_node *orig_neigh_node;
|
2016-01-16 11:40:13 +03:00
|
|
|
struct batadv_neigh_node *orig_neigh_router = NULL;
|
2016-02-01 17:21:38 +03:00
|
|
|
struct batadv_neigh_ifinfo *router_ifinfo = NULL, *neigh_ifinfo = NULL;
|
|
|
|
u32 router_throughput, neigh_throughput;
|
|
|
|
u32 router_last_seqno;
|
|
|
|
u32 neigh_last_seqno;
|
|
|
|
s32 neigh_seq_diff;
|
2016-02-01 17:21:37 +03:00
|
|
|
bool forward = false;
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
orig_neigh_node = batadv_v_ogm_orig_get(bat_priv, ethhdr->h_source);
|
|
|
|
if (!orig_neigh_node)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
orig_neigh_router = batadv_orig_router_get(orig_neigh_node,
|
|
|
|
if_outgoing);
|
|
|
|
|
|
|
|
/* drop packet if sender is not a direct neighbor and if we
|
|
|
|
* don't route towards it
|
|
|
|
*/
|
|
|
|
router = batadv_orig_router_get(orig_node, if_outgoing);
|
|
|
|
if (router && router->orig_node != orig_node && !orig_neigh_router) {
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Drop packet: OGM via unknown neighbor!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:21:38 +03:00
|
|
|
/* Mark the OGM to be considered for forwarding, and update routes
|
|
|
|
* if needed.
|
|
|
|
*/
|
2016-02-01 17:21:37 +03:00
|
|
|
forward = true;
|
2016-02-01 17:21:38 +03:00
|
|
|
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Searching and updating originator entry of received packet\n");
|
|
|
|
|
|
|
|
/* if this neighbor already is our next hop there is nothing
|
|
|
|
* to change
|
|
|
|
*/
|
|
|
|
if (router == neigh_node)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* don't consider neighbours with worse throughput.
|
|
|
|
* also switch route if this seqno is BATADV_V_MAX_ORIGDIFF newer than
|
|
|
|
* the last received seqno from our best next hop.
|
|
|
|
*/
|
|
|
|
if (router) {
|
|
|
|
router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing);
|
|
|
|
neigh_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing);
|
|
|
|
|
|
|
|
/* if these are not allocated, something is wrong. */
|
|
|
|
if (!router_ifinfo || !neigh_ifinfo)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
neigh_last_seqno = neigh_ifinfo->bat_v.last_seqno;
|
|
|
|
router_last_seqno = router_ifinfo->bat_v.last_seqno;
|
|
|
|
neigh_seq_diff = neigh_last_seqno - router_last_seqno;
|
|
|
|
router_throughput = router_ifinfo->bat_v.throughput;
|
|
|
|
neigh_throughput = neigh_ifinfo->bat_v.throughput;
|
|
|
|
|
2017-08-23 22:52:13 +03:00
|
|
|
if (neigh_seq_diff < BATADV_OGM_MAX_ORIGDIFF &&
|
|
|
|
router_throughput >= neigh_throughput)
|
2016-02-01 17:21:38 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node);
|
2016-01-16 11:40:13 +03:00
|
|
|
out:
|
2021-08-08 20:11:08 +03:00
|
|
|
batadv_neigh_node_put(router);
|
|
|
|
batadv_neigh_node_put(orig_neigh_router);
|
|
|
|
batadv_orig_node_put(orig_neigh_node);
|
|
|
|
batadv_neigh_ifinfo_put(router_ifinfo);
|
|
|
|
batadv_neigh_ifinfo_put(neigh_ifinfo);
|
2016-02-01 17:21:37 +03:00
|
|
|
|
|
|
|
return forward;
|
2016-01-16 11:40:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_process_per_outif() - process a batman v OGM for an outgoing if
|
2016-01-16 11:40:13 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
* @ethhdr: the Ethernet header of the OGM2
|
|
|
|
* @ogm2: OGM2 structure
|
|
|
|
* @orig_node: Originator structure for which the OGM has been received
|
|
|
|
* @neigh_node: the neigh_node through with the OGM has been received
|
|
|
|
* @if_incoming: the interface where this packet was received
|
|
|
|
* @if_outgoing: the interface for which the packet should be considered
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
batadv_v_ogm_process_per_outif(struct batadv_priv *bat_priv,
|
|
|
|
const struct ethhdr *ethhdr,
|
|
|
|
const struct batadv_ogm2_packet *ogm2,
|
|
|
|
struct batadv_orig_node *orig_node,
|
|
|
|
struct batadv_neigh_node *neigh_node,
|
|
|
|
struct batadv_hard_iface *if_incoming,
|
|
|
|
struct batadv_hard_iface *if_outgoing)
|
|
|
|
{
|
|
|
|
int seqno_age;
|
2016-02-01 17:21:37 +03:00
|
|
|
bool forward;
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
/* first, update the metric with according sanity checks */
|
|
|
|
seqno_age = batadv_v_ogm_metric_update(bat_priv, ogm2, orig_node,
|
|
|
|
neigh_node, if_incoming,
|
|
|
|
if_outgoing);
|
|
|
|
|
|
|
|
/* outdated sequence numbers are to be discarded */
|
|
|
|
if (seqno_age < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* only unknown & newer OGMs contain TVLVs we are interested in */
|
2017-08-23 22:52:13 +03:00
|
|
|
if (seqno_age > 0 && if_outgoing == BATADV_IF_DEFAULT)
|
2016-01-16 11:40:13 +03:00
|
|
|
batadv_tvlv_containers_process(bat_priv, true, orig_node,
|
|
|
|
NULL, NULL,
|
|
|
|
(unsigned char *)(ogm2 + 1),
|
|
|
|
ntohs(ogm2->tvlv_len));
|
|
|
|
|
|
|
|
/* if the metric update went through, update routes if needed */
|
2016-02-01 17:21:37 +03:00
|
|
|
forward = batadv_v_ogm_route_update(bat_priv, ethhdr, ogm2, orig_node,
|
|
|
|
neigh_node, if_incoming,
|
|
|
|
if_outgoing);
|
|
|
|
|
|
|
|
/* if the routes have been processed correctly, check and forward */
|
|
|
|
if (forward)
|
|
|
|
batadv_v_ogm_forward(bat_priv, ogm2, orig_node, neigh_node,
|
|
|
|
if_incoming, if_outgoing);
|
2016-01-16 11:40:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_aggr_packet() - checks if there is another OGM aggregated
|
2016-01-16 11:40:13 +03:00
|
|
|
* @buff_pos: current position in the skb
|
|
|
|
* @packet_len: total length of the skb
|
2019-08-22 09:55:36 +03:00
|
|
|
* @ogm2_packet: potential OGM2 in buffer
|
2016-01-16 11:40:13 +03:00
|
|
|
*
|
|
|
|
* Return: true if there is enough space for another OGM, false otherwise.
|
|
|
|
*/
|
2019-08-22 09:55:36 +03:00
|
|
|
static bool
|
|
|
|
batadv_v_ogm_aggr_packet(int buff_pos, int packet_len,
|
|
|
|
const struct batadv_ogm2_packet *ogm2_packet)
|
2016-01-16 11:40:13 +03:00
|
|
|
{
|
|
|
|
int next_buff_pos = 0;
|
|
|
|
|
2019-08-22 09:55:36 +03:00
|
|
|
/* check if there is enough space for the header */
|
|
|
|
next_buff_pos += buff_pos + sizeof(*ogm2_packet);
|
|
|
|
if (next_buff_pos > packet_len)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* check if there is enough space for the optional TVLV */
|
|
|
|
next_buff_pos += ntohs(ogm2_packet->tvlv_len);
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
return (next_buff_pos <= packet_len) &&
|
|
|
|
(next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_process() - process an incoming batman v OGM
|
2016-01-16 11:40:13 +03:00
|
|
|
* @skb: the skb containing the OGM
|
|
|
|
* @ogm_offset: offset to the OGM which should be processed (for aggregates)
|
2020-06-01 21:13:21 +03:00
|
|
|
* @if_incoming: the interface where this packet was received
|
2016-01-16 11:40:13 +03:00
|
|
|
*/
|
|
|
|
static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
|
|
|
|
struct batadv_hard_iface *if_incoming)
|
|
|
|
{
|
|
|
|
struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
|
|
|
|
struct ethhdr *ethhdr;
|
|
|
|
struct batadv_orig_node *orig_node = NULL;
|
|
|
|
struct batadv_hardif_neigh_node *hardif_neigh = NULL;
|
|
|
|
struct batadv_neigh_node *neigh_node = NULL;
|
|
|
|
struct batadv_hard_iface *hard_iface;
|
|
|
|
struct batadv_ogm2_packet *ogm_packet;
|
|
|
|
u32 ogm_throughput, link_throughput, path_throughput;
|
batman-adv: Simple (re)broadcast avoidance
With this patch, (re)broadcasting on a specific interfaces is avoided:
* No neighbor: There is no need to broadcast on an interface if there
is no node behind it.
* Single neighbor is source: If there is just one neighbor on an
interface and if this neighbor is the one we actually got this
broadcast packet from, then we do not need to echo it back.
* Single neighbor is originator: If there is just one neighbor on
an interface and if this neighbor is the originator of this
broadcast packet, then we do not need to echo it back.
Goodies for BATMAN V:
("Upgrade your BATMAN IV network to V now to get these for free!")
Thanks to the split of OGMv1 into two packet types, OGMv2 and ELP
that is, we can now apply the same optimizations stated above to OGMv2
packets, too.
Furthermore, with BATMAN V, rebroadcasts can be reduced in certain
multi interface cases, too, where BATMAN IV cannot. This is thanks to
the removal of the "secondary interface originator" concept in BATMAN V.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
2016-08-07 13:34:19 +03:00
|
|
|
int ret;
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
ethhdr = eth_hdr(skb);
|
|
|
|
ogm_packet = (struct batadv_ogm2_packet *)(skb->data + ogm_offset);
|
|
|
|
|
|
|
|
ogm_throughput = ntohl(ogm_packet->throughput);
|
|
|
|
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
2017-06-26 13:26:44 +03:00
|
|
|
"Received OGM2 packet via NB: %pM, IF: %s [%pM] (from OG: %pM, seqno %u, throughput %u, TTL %u, V %u, tvlv_len %u)\n",
|
2016-01-16 11:40:13 +03:00
|
|
|
ethhdr->h_source, if_incoming->net_dev->name,
|
|
|
|
if_incoming->net_dev->dev_addr, ogm_packet->orig,
|
|
|
|
ntohl(ogm_packet->seqno), ogm_throughput, ogm_packet->ttl,
|
|
|
|
ogm_packet->version, ntohs(ogm_packet->tvlv_len));
|
|
|
|
|
2020-07-23 15:28:08 +03:00
|
|
|
if (batadv_is_my_mac(bat_priv, ogm_packet->orig)) {
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Drop packet: originator packet from ourself\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-26 13:26:44 +03:00
|
|
|
/* If the throughput metric is 0, immediately drop the packet. No need
|
|
|
|
* to create orig_node / neigh_node for an unusable route.
|
2016-01-16 11:40:13 +03:00
|
|
|
*/
|
|
|
|
if (ogm_throughput == 0) {
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
2017-06-26 13:26:44 +03:00
|
|
|
"Drop packet: originator packet with throughput metric of 0\n");
|
2016-01-16 11:40:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* require ELP packets be to received from this neighbor first */
|
|
|
|
hardif_neigh = batadv_hardif_neigh_get(if_incoming, ethhdr->h_source);
|
|
|
|
if (!hardif_neigh) {
|
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
|
|
|
|
"Drop packet: OGM via unknown neighbor!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
orig_node = batadv_v_ogm_orig_get(bat_priv, ogm_packet->orig);
|
|
|
|
if (!orig_node)
|
2020-04-20 08:37:20 +03:00
|
|
|
goto out;
|
2016-01-16 11:40:13 +03:00
|
|
|
|
2016-05-02 20:52:08 +03:00
|
|
|
neigh_node = batadv_neigh_node_get_or_create(orig_node, if_incoming,
|
|
|
|
ethhdr->h_source);
|
2016-01-16 11:40:13 +03:00
|
|
|
if (!neigh_node)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Update the received throughput metric to match the link
|
|
|
|
* characteristic:
|
|
|
|
* - If this OGM traveled one hop so far (emitted by single hop
|
|
|
|
* neighbor) the path throughput metric equals the link throughput.
|
|
|
|
* - For OGMs traversing more than hop the path throughput metric is
|
|
|
|
* the smaller of the path throughput and the link throughput.
|
|
|
|
*/
|
|
|
|
link_throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput);
|
|
|
|
path_throughput = min_t(u32, link_throughput, ogm_throughput);
|
|
|
|
ogm_packet->throughput = htonl(path_throughput);
|
|
|
|
|
|
|
|
batadv_v_ogm_process_per_outif(bat_priv, ethhdr, ogm_packet, orig_node,
|
|
|
|
neigh_node, if_incoming,
|
|
|
|
BATADV_IF_DEFAULT);
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
|
|
|
|
if (hard_iface->if_status != BATADV_IF_ACTIVE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (hard_iface->soft_iface != bat_priv->soft_iface)
|
|
|
|
continue;
|
|
|
|
|
2016-03-05 18:09:16 +03:00
|
|
|
if (!kref_get_unless_zero(&hard_iface->refcount))
|
|
|
|
continue;
|
|
|
|
|
batman-adv: Simple (re)broadcast avoidance
With this patch, (re)broadcasting on a specific interfaces is avoided:
* No neighbor: There is no need to broadcast on an interface if there
is no node behind it.
* Single neighbor is source: If there is just one neighbor on an
interface and if this neighbor is the one we actually got this
broadcast packet from, then we do not need to echo it back.
* Single neighbor is originator: If there is just one neighbor on
an interface and if this neighbor is the originator of this
broadcast packet, then we do not need to echo it back.
Goodies for BATMAN V:
("Upgrade your BATMAN IV network to V now to get these for free!")
Thanks to the split of OGMv1 into two packet types, OGMv2 and ELP
that is, we can now apply the same optimizations stated above to OGMv2
packets, too.
Furthermore, with BATMAN V, rebroadcasts can be reduced in certain
multi interface cases, too, where BATMAN IV cannot. This is thanks to
the removal of the "secondary interface originator" concept in BATMAN V.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
2016-08-07 13:34:19 +03:00
|
|
|
ret = batadv_hardif_no_broadcast(hard_iface,
|
|
|
|
ogm_packet->orig,
|
|
|
|
hardif_neigh->orig);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
char *type;
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case BATADV_HARDIF_BCAST_NORECIPIENT:
|
|
|
|
type = "no neighbor";
|
|
|
|
break;
|
|
|
|
case BATADV_HARDIF_BCAST_DUPFWD:
|
|
|
|
type = "single neighbor is source";
|
|
|
|
break;
|
|
|
|
case BATADV_HARDIF_BCAST_DUPORIG:
|
|
|
|
type = "single neighbor is originator";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "unknown";
|
|
|
|
}
|
|
|
|
|
2017-06-26 13:26:44 +03:00
|
|
|
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "OGM2 packet from %pM on %s suppressed: %s\n",
|
batman-adv: Simple (re)broadcast avoidance
With this patch, (re)broadcasting on a specific interfaces is avoided:
* No neighbor: There is no need to broadcast on an interface if there
is no node behind it.
* Single neighbor is source: If there is just one neighbor on an
interface and if this neighbor is the one we actually got this
broadcast packet from, then we do not need to echo it back.
* Single neighbor is originator: If there is just one neighbor on
an interface and if this neighbor is the originator of this
broadcast packet, then we do not need to echo it back.
Goodies for BATMAN V:
("Upgrade your BATMAN IV network to V now to get these for free!")
Thanks to the split of OGMv1 into two packet types, OGMv2 and ELP
that is, we can now apply the same optimizations stated above to OGMv2
packets, too.
Furthermore, with BATMAN V, rebroadcasts can be reduced in certain
multi interface cases, too, where BATMAN IV cannot. This is thanks to
the removal of the "secondary interface originator" concept in BATMAN V.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
2016-08-07 13:34:19 +03:00
|
|
|
ogm_packet->orig, hard_iface->net_dev->name,
|
|
|
|
type);
|
|
|
|
|
|
|
|
batadv_hardif_put(hard_iface);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:13 +03:00
|
|
|
batadv_v_ogm_process_per_outif(bat_priv, ethhdr, ogm_packet,
|
|
|
|
orig_node, neigh_node,
|
|
|
|
if_incoming, hard_iface);
|
2016-03-05 18:09:16 +03:00
|
|
|
|
|
|
|
batadv_hardif_put(hard_iface);
|
2016-01-16 11:40:13 +03:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
out:
|
2021-08-08 20:11:08 +03:00
|
|
|
batadv_orig_node_put(orig_node);
|
|
|
|
batadv_neigh_node_put(neigh_node);
|
|
|
|
batadv_hardif_neigh_put(hardif_neigh);
|
2016-01-16 11:40:13 +03:00
|
|
|
}
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_packet_recv() - OGM2 receiving handler
|
2016-01-16 11:40:12 +03:00
|
|
|
* @skb: the received OGM
|
|
|
|
* @if_incoming: the interface where this OGM has been received
|
|
|
|
*
|
|
|
|
* Return: NET_RX_SUCCESS and consume the skb on success or returns NET_RX_DROP
|
|
|
|
* (without freeing the skb) on failure
|
|
|
|
*/
|
|
|
|
int batadv_v_ogm_packet_recv(struct sk_buff *skb,
|
|
|
|
struct batadv_hard_iface *if_incoming)
|
|
|
|
{
|
|
|
|
struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
|
|
|
|
struct batadv_ogm2_packet *ogm_packet;
|
batman-adv: Do not get eth header before batadv_check_management_packet
commit eac27a41ab641de074655d2932fc7f8cdb446881 upstream.
If received skb in batadv_v_elp_packet_recv or batadv_v_ogm_packet_recv
is either cloned or non linearized then its data buffer will be
reallocated by batadv_check_management_packet when skb_cow or
skb_linearize get called. Thus geting ethernet header address inside
skb data buffer before batadv_check_management_packet had any chance to
reallocate it could lead to the following kernel panic:
Unable to handle kernel paging request at virtual address ffffff8020ab069a
Mem abort info:
ESR = 0x96000007
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x07: level 3 translation fault
Data abort info:
ISV = 0, ISS = 0x00000007
CM = 0, WnR = 0
swapper pgtable: 4k pages, 39-bit VAs, pgdp=0000000040f45000
[ffffff8020ab069a] pgd=180000007fffa003, p4d=180000007fffa003, pud=180000007fffa003, pmd=180000007fefe003, pte=0068000020ab0706
Internal error: Oops: 96000007 [#1] SMP
Modules linked in: ahci_mvebu libahci_platform libahci dvb_usb_af9035 dvb_usb_dib0700 dib0070 dib7000m dibx000_common ath11k_pci ath10k_pci ath10k_core mwl8k_new nf_nat_sip nf_conntrack_sip xhci_plat_hcd xhci_hcd nf_nat_pptp nf_conntrack_pptp at24 sbsa_gwdt
CPU: 1 PID: 16 Comm: ksoftirqd/1 Not tainted 5.15.42-00066-g3242268d425c-dirty #550
Hardware name: A8k (DT)
pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : batadv_is_my_mac+0x60/0xc0
lr : batadv_v_ogm_packet_recv+0x98/0x5d0
sp : ffffff8000183820
x29: ffffff8000183820 x28: 0000000000000001 x27: ffffff8014f9af00
x26: 0000000000000000 x25: 0000000000000543 x24: 0000000000000003
x23: ffffff8020ab0580 x22: 0000000000000110 x21: ffffff80168ae880
x20: 0000000000000000 x19: ffffff800b561000 x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000 x15: 00dc098924ae0032
x14: 0f0405433e0054b0 x13: ffffffff00000080 x12: 0000004000000001
x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000
x8 : 0000000000000000 x7 : ffffffc076dae000 x6 : ffffff8000183700
x5 : ffffffc00955e698 x4 : ffffff80168ae000 x3 : ffffff80059cf000
x2 : ffffff800b561000 x1 : ffffff8020ab0696 x0 : ffffff80168ae880
Call trace:
batadv_is_my_mac+0x60/0xc0
batadv_v_ogm_packet_recv+0x98/0x5d0
batadv_batman_skb_recv+0x1b8/0x244
__netif_receive_skb_core.isra.0+0x440/0xc74
__netif_receive_skb_one_core+0x14/0x20
netif_receive_skb+0x68/0x140
br_pass_frame_up+0x70/0x80
br_handle_frame_finish+0x108/0x284
br_handle_frame+0x190/0x250
__netif_receive_skb_core.isra.0+0x240/0xc74
__netif_receive_skb_list_core+0x6c/0x90
netif_receive_skb_list_internal+0x1f4/0x310
napi_complete_done+0x64/0x1d0
gro_cell_poll+0x7c/0xa0
__napi_poll+0x34/0x174
net_rx_action+0xf8/0x2a0
_stext+0x12c/0x2ac
run_ksoftirqd+0x4c/0x7c
smpboot_thread_fn+0x120/0x210
kthread+0x140/0x150
ret_from_fork+0x10/0x20
Code: f9403844 eb03009f 54fffee1 f94
Thus ethernet header address should only be fetched after
batadv_check_management_packet has been called.
Fixes: 0da0035942d4 ("batman-adv: OGMv2 - add basic infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: Remi Pommarel <repk@triplefau.lt>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-07-28 16:38:50 +03:00
|
|
|
struct ethhdr *ethhdr;
|
2016-01-16 11:40:13 +03:00
|
|
|
int ogm_offset;
|
|
|
|
u8 *packet_pos;
|
|
|
|
int ret = NET_RX_DROP;
|
2016-01-16 11:40:12 +03:00
|
|
|
|
|
|
|
/* did we receive a OGM2 packet on an interface that does not have
|
|
|
|
* B.A.T.M.A.N. V enabled ?
|
|
|
|
*/
|
2016-05-25 18:27:31 +03:00
|
|
|
if (strcmp(bat_priv->algo_ops->name, "BATMAN_V") != 0)
|
2016-07-17 22:04:04 +03:00
|
|
|
goto free_skb;
|
2016-01-16 11:40:12 +03:00
|
|
|
|
|
|
|
if (!batadv_check_management_packet(skb, if_incoming, BATADV_OGM2_HLEN))
|
2016-07-17 22:04:04 +03:00
|
|
|
goto free_skb;
|
2016-01-16 11:40:12 +03:00
|
|
|
|
batman-adv: Do not get eth header before batadv_check_management_packet
commit eac27a41ab641de074655d2932fc7f8cdb446881 upstream.
If received skb in batadv_v_elp_packet_recv or batadv_v_ogm_packet_recv
is either cloned or non linearized then its data buffer will be
reallocated by batadv_check_management_packet when skb_cow or
skb_linearize get called. Thus geting ethernet header address inside
skb data buffer before batadv_check_management_packet had any chance to
reallocate it could lead to the following kernel panic:
Unable to handle kernel paging request at virtual address ffffff8020ab069a
Mem abort info:
ESR = 0x96000007
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x07: level 3 translation fault
Data abort info:
ISV = 0, ISS = 0x00000007
CM = 0, WnR = 0
swapper pgtable: 4k pages, 39-bit VAs, pgdp=0000000040f45000
[ffffff8020ab069a] pgd=180000007fffa003, p4d=180000007fffa003, pud=180000007fffa003, pmd=180000007fefe003, pte=0068000020ab0706
Internal error: Oops: 96000007 [#1] SMP
Modules linked in: ahci_mvebu libahci_platform libahci dvb_usb_af9035 dvb_usb_dib0700 dib0070 dib7000m dibx000_common ath11k_pci ath10k_pci ath10k_core mwl8k_new nf_nat_sip nf_conntrack_sip xhci_plat_hcd xhci_hcd nf_nat_pptp nf_conntrack_pptp at24 sbsa_gwdt
CPU: 1 PID: 16 Comm: ksoftirqd/1 Not tainted 5.15.42-00066-g3242268d425c-dirty #550
Hardware name: A8k (DT)
pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : batadv_is_my_mac+0x60/0xc0
lr : batadv_v_ogm_packet_recv+0x98/0x5d0
sp : ffffff8000183820
x29: ffffff8000183820 x28: 0000000000000001 x27: ffffff8014f9af00
x26: 0000000000000000 x25: 0000000000000543 x24: 0000000000000003
x23: ffffff8020ab0580 x22: 0000000000000110 x21: ffffff80168ae880
x20: 0000000000000000 x19: ffffff800b561000 x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000 x15: 00dc098924ae0032
x14: 0f0405433e0054b0 x13: ffffffff00000080 x12: 0000004000000001
x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000
x8 : 0000000000000000 x7 : ffffffc076dae000 x6 : ffffff8000183700
x5 : ffffffc00955e698 x4 : ffffff80168ae000 x3 : ffffff80059cf000
x2 : ffffff800b561000 x1 : ffffff8020ab0696 x0 : ffffff80168ae880
Call trace:
batadv_is_my_mac+0x60/0xc0
batadv_v_ogm_packet_recv+0x98/0x5d0
batadv_batman_skb_recv+0x1b8/0x244
__netif_receive_skb_core.isra.0+0x440/0xc74
__netif_receive_skb_one_core+0x14/0x20
netif_receive_skb+0x68/0x140
br_pass_frame_up+0x70/0x80
br_handle_frame_finish+0x108/0x284
br_handle_frame+0x190/0x250
__netif_receive_skb_core.isra.0+0x240/0xc74
__netif_receive_skb_list_core+0x6c/0x90
netif_receive_skb_list_internal+0x1f4/0x310
napi_complete_done+0x64/0x1d0
gro_cell_poll+0x7c/0xa0
__napi_poll+0x34/0x174
net_rx_action+0xf8/0x2a0
_stext+0x12c/0x2ac
run_ksoftirqd+0x4c/0x7c
smpboot_thread_fn+0x120/0x210
kthread+0x140/0x150
ret_from_fork+0x10/0x20
Code: f9403844 eb03009f 54fffee1 f94
Thus ethernet header address should only be fetched after
batadv_check_management_packet has been called.
Fixes: 0da0035942d4 ("batman-adv: OGMv2 - add basic infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: Remi Pommarel <repk@triplefau.lt>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-07-28 16:38:50 +03:00
|
|
|
ethhdr = eth_hdr(skb);
|
2016-01-16 11:40:12 +03:00
|
|
|
if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
|
2016-07-17 22:04:04 +03:00
|
|
|
goto free_skb;
|
2016-01-16 11:40:12 +03:00
|
|
|
|
|
|
|
batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
|
|
|
|
batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES,
|
|
|
|
skb->len + ETH_HLEN);
|
|
|
|
|
2016-01-16 11:40:13 +03:00
|
|
|
ogm_offset = 0;
|
|
|
|
ogm_packet = (struct batadv_ogm2_packet *)skb->data;
|
|
|
|
|
|
|
|
while (batadv_v_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
|
2019-08-22 09:55:36 +03:00
|
|
|
ogm_packet)) {
|
2016-01-16 11:40:13 +03:00
|
|
|
batadv_v_ogm_process(skb, ogm_offset, if_incoming);
|
|
|
|
|
|
|
|
ogm_offset += BATADV_OGM2_HLEN;
|
|
|
|
ogm_offset += ntohs(ogm_packet->tvlv_len);
|
|
|
|
|
|
|
|
packet_pos = skb->data + ogm_offset;
|
|
|
|
ogm_packet = (struct batadv_ogm2_packet *)packet_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = NET_RX_SUCCESS;
|
2016-07-17 22:04:04 +03:00
|
|
|
|
|
|
|
free_skb:
|
|
|
|
if (ret == NET_RX_SUCCESS)
|
|
|
|
consume_skb(skb);
|
|
|
|
else
|
|
|
|
kfree_skb(skb);
|
2016-01-16 11:40:13 +03:00
|
|
|
|
|
|
|
return ret;
|
2016-01-16 11:40:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_init() - initialise the OGM2 engine
|
2016-01-16 11:40:12 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
*
|
|
|
|
* Return: 0 on success or a negative error code in case of failure
|
|
|
|
*/
|
|
|
|
int batadv_v_ogm_init(struct batadv_priv *bat_priv)
|
|
|
|
{
|
|
|
|
struct batadv_ogm2_packet *ogm_packet;
|
|
|
|
unsigned char *ogm_buff;
|
|
|
|
u32 random_seqno;
|
|
|
|
|
|
|
|
bat_priv->bat_v.ogm_buff_len = BATADV_OGM2_HLEN;
|
|
|
|
ogm_buff = kzalloc(bat_priv->bat_v.ogm_buff_len, GFP_ATOMIC);
|
|
|
|
if (!ogm_buff)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
bat_priv->bat_v.ogm_buff = ogm_buff;
|
|
|
|
ogm_packet = (struct batadv_ogm2_packet *)ogm_buff;
|
|
|
|
ogm_packet->packet_type = BATADV_OGM2;
|
|
|
|
ogm_packet->version = BATADV_COMPAT_VERSION;
|
|
|
|
ogm_packet->ttl = BATADV_TTL;
|
|
|
|
ogm_packet->flags = BATADV_NO_FLAGS;
|
|
|
|
ogm_packet->throughput = htonl(BATADV_THROUGHPUT_MAX_VALUE);
|
|
|
|
|
|
|
|
/* randomize initial seqno to avoid collision */
|
|
|
|
get_random_bytes(&random_seqno, sizeof(random_seqno));
|
|
|
|
atomic_set(&bat_priv->bat_v.ogm_seqno, random_seqno);
|
|
|
|
INIT_DELAYED_WORK(&bat_priv->bat_v.ogm_wq, batadv_v_ogm_send);
|
|
|
|
|
2019-10-03 18:02:01 +03:00
|
|
|
mutex_init(&bat_priv->bat_v.ogm_buff_mutex);
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-02 21:51:47 +03:00
|
|
|
* batadv_v_ogm_free() - free OGM private resources
|
2016-01-16 11:40:12 +03:00
|
|
|
* @bat_priv: the bat priv with all the soft interface information
|
|
|
|
*/
|
|
|
|
void batadv_v_ogm_free(struct batadv_priv *bat_priv)
|
|
|
|
{
|
|
|
|
cancel_delayed_work_sync(&bat_priv->bat_v.ogm_wq);
|
|
|
|
|
2019-10-03 18:02:01 +03:00
|
|
|
mutex_lock(&bat_priv->bat_v.ogm_buff_mutex);
|
|
|
|
|
2016-01-16 11:40:12 +03:00
|
|
|
kfree(bat_priv->bat_v.ogm_buff);
|
|
|
|
bat_priv->bat_v.ogm_buff = NULL;
|
|
|
|
bat_priv->bat_v.ogm_buff_len = 0;
|
2019-10-03 18:02:01 +03:00
|
|
|
|
|
|
|
mutex_unlock(&bat_priv->bat_v.ogm_buff_mutex);
|
2016-01-16 11:40:12 +03:00
|
|
|
}
|