cregit-Linux how code gets into the kernel

Release 4.8 net/batman-adv/bat_iv_ogm.c

Directory: net/batman-adv
/* Copyright (C) 2007-2016  B.A.T.M.A.N. contributors:
 * Marek Lindner, Simon Wunderlich
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <>.

#include "bat_iv_ogm.h"
#include "main.h"

#include <linux/atomic.h>
#include <linux/bitmap.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/byteorder/generic.h>
#include <linux/cache.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/fs.h>
#include <linux/if_ether.h>
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/lockdep.h>
#include <linux/netdevice.h>
#include <linux/pkt_sched.h>
#include <linux/printk.h>
#include <linux/random.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
#include <linux/seq_file.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/workqueue.h>

#include "bat_algo.h"
#include "bitarray.h"
#include "hard-interface.h"
#include "hash.h"
#include "log.h"
#include "network-coding.h"
#include "originator.h"
#include "packet.h"
#include "routing.h"
#include "send.h"
#include "translation-table.h"
#include "tvlv.h"

static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work);

 * enum batadv_dup_status - duplicate status
 * @BATADV_NO_DUP: the packet is no duplicate
 * @BATADV_ORIG_DUP: OGM is a duplicate in the originator (but not for the
 *  neighbor)
 * @BATADV_NEIGH_DUP: OGM is a duplicate for the neighbor
 * @BATADV_PROTECTED: originator is currently protected (after reboot)

enum batadv_dup_status {

 * batadv_ring_buffer_set - update the ring buffer with the given value
 * @lq_recv: pointer to the ring buffer
 * @lq_index: index to store the value at
 * @value: value to store in the ring buffer

static void batadv_ring_buffer_set(u8 lq_recv[], u8 *lq_index, u8 value) { lq_recv[*lq_index] = value; *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE; }


antonio quartulliantonio quartulli3491.89%150.00%
sven eckelmannsven eckelmann38.11%150.00%

/** * batadv_ring_buffer_avg - compute the average of all non-zero values stored * in the given ring buffer * @lq_recv: pointer to the ring buffer * * Return: computed average value. */
static u8 batadv_ring_buffer_avg(const u8 lq_recv[]) { const u8 *ptr; u16 count = 0; u16 i = 0; u16 sum = 0; ptr = lq_recv; while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) { if (*ptr != 0) { count++; sum += *ptr; } i++; ptr++; } if (count == 0) return 0; return (u8)(sum / count); }


antonio quartulliantonio quartulli7689.41%133.33%
sven eckelmannsven eckelmann78.24%133.33%
markus pargmannmarkus pargmann22.35%133.33%

/** * batadv_iv_ogm_orig_free - free the private resources allocated for this * orig_node * @orig_node: the orig_node for which the resources have to be free'd */
static void batadv_iv_ogm_orig_free(struct batadv_orig_node *orig_node) { kfree(orig_node->bat_iv.bcast_own); kfree(orig_node->bat_iv.bcast_own_sum); }


antonio quartulliantonio quartulli29100.00%1100.00%

/** * batadv_iv_ogm_orig_add_if - change the private structures of the orig_node to * include the new hard-interface * @orig_node: the orig_node that has to be changed * @max_if_num: the current amount of interfaces * * Return: 0 on success, a negative error code otherwise. */
static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node, int max_if_num) { void *data_ptr; size_t old_size; int ret = -ENOMEM; spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS; data_ptr = kmalloc_array(max_if_num, BATADV_NUM_WORDS * sizeof(unsigned long), GFP_ATOMIC); if (!data_ptr) goto unlock; memcpy(data_ptr, orig_node->bat_iv.bcast_own, old_size); kfree(orig_node->bat_iv.bcast_own); orig_node->bat_iv.bcast_own = data_ptr; data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC); if (!data_ptr) goto unlock; memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum, (max_if_num - 1) * sizeof(u8)); kfree(orig_node->bat_iv.bcast_own_sum); orig_node->bat_iv.bcast_own_sum = data_ptr; ret = 0; unlock: spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); return ret; }


antonio quartulliantonio quartulli18698.94%266.67%
sven eckelmannsven eckelmann21.06%133.33%

/** * batadv_iv_ogm_drop_bcast_own_entry - drop section of bcast_own * @orig_node: the orig_node that has to be changed * @max_if_num: the current amount of interfaces * @del_if_num: the index of the interface being removed */
static void batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node, int max_if_num, int del_if_num) { size_t chunk_size; size_t if_offset; void *data_ptr; lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock); chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS; data_ptr = kmalloc_array(max_if_num, chunk_size, GFP_ATOMIC); if (!data_ptr) /* use old buffer when new one could not be allocated */ data_ptr = orig_node->bat_iv.bcast_own; /* copy first part */ memmove(data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size); /* copy second part */ if_offset = (del_if_num + 1) * chunk_size; memmove((char *)data_ptr + del_if_num * chunk_size, (uint8_t *)orig_node->bat_iv.bcast_own + if_offset, (max_if_num - del_if_num) * chunk_size); /* bcast_own was shrunk down in new buffer; free old one */ if (orig_node->bat_iv.bcast_own != data_ptr) { kfree(orig_node->bat_iv.bcast_own); orig_node->bat_iv.bcast_own = data_ptr; } }


antonio quartulliantonio quartulli11570.99%250.00%
sven eckelmannsven eckelmann4729.01%250.00%

/** * batadv_iv_ogm_drop_bcast_own_sum_entry - drop section of bcast_own_sum * @orig_node: the orig_node that has to be changed * @max_if_num: the current amount of interfaces * @del_if_num: the index of the interface being removed */
static void batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node, int max_if_num, int del_if_num) { size_t if_offset; void *data_ptr; lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock); data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC); if (!data_ptr) /* use old buffer when new one could not be allocated */ data_ptr = orig_node->bat_iv.bcast_own_sum; memmove(data_ptr, orig_node->bat_iv.bcast_own_sum, del_if_num * sizeof(u8)); if_offset = (del_if_num + 1) * sizeof(u8); memmove((char *)data_ptr + del_if_num * sizeof(u8), orig_node->bat_iv.bcast_own_sum + if_offset, (max_if_num - del_if_num) * sizeof(u8)); /* bcast_own_sum was shrunk down in new buffer; free old one */ if (orig_node->bat_iv.bcast_own_sum != data_ptr) { kfree(orig_node->bat_iv.bcast_own_sum); orig_node->bat_iv.bcast_own_sum = data_ptr; } }


antonio quartulliantonio quartulli10163.92%250.00%
sven eckelmannsven eckelmann5736.08%250.00%

/** * batadv_iv_ogm_orig_del_if - change the private structures of the orig_node to * exclude the removed interface * @orig_node: the orig_node that has to be changed * @max_if_num: the current amount of interfaces * @del_if_num: the index of the interface being removed * * Return: 0 on success, a negative error code otherwise. */
static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node, int max_if_num, int del_if_num) { spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); if (max_if_num == 0) { kfree(orig_node->bat_iv.bcast_own); kfree(orig_node->bat_iv.bcast_own_sum); orig_node->bat_iv.bcast_own = NULL; orig_node->bat_iv.bcast_own_sum = NULL; } else { batadv_iv_ogm_drop_bcast_own_entry(orig_node, max_if_num, del_if_num); batadv_iv_ogm_drop_bcast_own_sum_entry(orig_node, max_if_num, del_if_num); } spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); return 0; }


sven eckelmannsven eckelmann8885.44%150.00%
antonio quartulliantonio quartulli1514.56%150.00%

/** * batadv_iv_ogm_orig_get - retrieve or create (if does not exist) an originator * @bat_priv: the bat priv with all the soft interface information * @addr: mac address of the originator * * Return: the originator object corresponding to the passed mac address or NULL * on failure. * If the object does not exists it is created an initialised. */
static struct batadv_orig_node * batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr) { struct batadv_orig_node *orig_node; int size, 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; spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock); size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS; orig_node->bat_iv.bcast_own = kzalloc(size, GFP_ATOMIC); if (!orig_node->bat_iv.bcast_own) goto free_orig_node; size = bat_priv->num_ifaces * sizeof(u8); orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC); if (!orig_node->bat_iv.bcast_own_sum) goto free_orig_node; 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) goto free_orig_node; return orig_node; free_orig_node: /* free twice, as batadv_orig_node_new sets refcount to 2 */ batadv_orig_node_put(orig_node); batadv_orig_node_put(orig_node); return NULL; }


antonio quartulliantonio quartulli18595.36%240.00%
simon wunderlichsimon wunderlich52.58%120.00%
sven eckelmannsven eckelmann42.06%240.00%

static struct batadv_neigh_node * batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, const u8 *neigh_addr, struct batadv_orig_node *orig_node, struct batadv_orig_node *orig_neigh) { struct batadv_neigh_node *neigh_node; neigh_node = batadv_neigh_node_get_or_create(orig_node, hard_iface, neigh_addr); if (!neigh_node) goto out; neigh_node->orig_node = orig_neigh; out: return neigh_node; }


marek lindnermarek lindner4977.78%337.50%
sven eckelmannsven eckelmann711.11%337.50%
simon wunderlichsimon wunderlich69.52%112.50%
al viroal viro11.59%112.50%

static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface) { struct batadv_ogm_packet *batadv_ogm_packet; unsigned char *ogm_buff; u32 random_seqno; /* randomize initial seqno to avoid collision */ get_random_bytes(&random_seqno, sizeof(random_seqno)); atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno); hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN; ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC); if (!ogm_buff) return -ENOMEM; hard_iface->bat_iv.ogm_buff = ogm_buff; batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; batadv_ogm_packet->packet_type = BATADV_IV_OGM; batadv_ogm_packet->version = BATADV_COMPAT_VERSION; batadv_ogm_packet->ttl = 2; batadv_ogm_packet->flags = BATADV_NO_FLAGS; batadv_ogm_packet->reserved = 0; batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE; return 0; }


marek lindnermarek lindner10981.34%640.00%
sven eckelmannsven eckelmann2014.93%853.33%
markus pargmannmarkus pargmann53.73%16.67%

static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface) { kfree(hard_iface->bat_iv.ogm_buff); hard_iface->bat_iv.ogm_buff = NULL; }


marek lindnermarek lindner2692.86%250.00%
sven eckelmannsven eckelmann27.14%250.00%

static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface) { struct batadv_ogm_packet *batadv_ogm_packet; unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; ether_addr_copy(batadv_ogm_packet->orig, hard_iface->net_dev->dev_addr); ether_addr_copy(batadv_ogm_packet->prev_sender, hard_iface->net_dev->dev_addr); }


marek lindnermarek lindner5283.87%450.00%
sven eckelmannsven eckelmann812.90%337.50%
antonio quartulliantonio quartulli23.23%112.50%

static void batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface) { struct batadv_ogm_packet *batadv_ogm_packet; unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; batadv_ogm_packet->ttl = BATADV_TTL; }


marek lindnermarek lindner3480.95%450.00%
sven eckelmannsven eckelmann819.05%450.00%

/* when do we schedule our own ogm to be sent */
static unsigned long batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv) { unsigned int msecs; msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER; msecs += prandom_u32() % (2 * BATADV_JITTER); return jiffies + msecs_to_jiffies(msecs); }


marek lindnermarek lindner2654.17%116.67%
sven eckelmannsven eckelmann2041.67%350.00%
akinobu mitaakinobu mita24.17%233.33%

/* when do we schedule a ogm packet to be sent */
static unsigned long batadv_iv_ogm_fwd_send_time(void) { return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2)); }


marek lindnermarek lindner2187.50%125.00%
sven eckelmannsven eckelmann28.33%250.00%
akinobu mitaakinobu mita14.17%125.00%

/* apply hop penalty for a normal link */
static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv) { int hop_penalty = atomic_read(&bat_priv->hop_penalty); int new_tq; new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty); new_tq /= BATADV_TQ_MAX_VALUE; return new_tq; }


marek lindnermarek lindner2963.04%120.00%
sven eckelmannsven eckelmann1736.96%480.00%

/** * batadv_iv_ogm_aggr_packet - checks if there is another OGM attached * @buff_pos: current position in the skb * @packet_len: total length of the skb * @tvlv_len: tvlv length of the previously considered OGM * * Return: true if there is enough space for another OGM, false otherwise. */
static bool batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len, __be16 tvlv_len) { int next_buff_pos = 0; next_buff_pos += buff_pos + BATADV_OGM_HLEN; next_buff_pos += ntohs(tvlv_len); return (next_buff_pos <= packet_len) && (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES); }


marek lindnermarek lindner3473.91%228.57%
sven eckelmannsven eckelmann1123.91%457.14%
markus pargmannmarkus pargmann12.17%114.29%

/* send a batman ogm to a given interface */
static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, struct batadv_hard_iface *hard_iface) { struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); const char *fwd_str; u8 packet_num; s16 buff_pos; struct batadv_ogm_packet *batadv_ogm_packet; struct sk_buff *skb; u8 *packet_pos; if (hard_iface->if_status != BATADV_IF_ACTIVE) return; packet_num = 0; buff_pos = 0; packet_pos = forw_packet->skb->data; batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; /* adjust all flags and log packets */ while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, batadv_ogm_packet->tvlv_len)) { /* we might have aggregated direct link packets with an * ordinary base packet */ if (forw_packet->direct_link_flags & BIT(packet_num) && forw_packet->if_incoming == hard_iface) batadv_ogm_packet->flags |= BATADV_DIRECTLINK; else batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; if (packet_num > 0 || !forw_packet->own) fwd_str = "Forwarding"; else fwd_str = "Sending own"; batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s) on interface %s [%pM]\n", fwd_str, (packet_num > 0 ? "aggregated " : ""), batadv_ogm_packet->orig, ntohl(batadv_ogm_packet->seqno), batadv_ogm_packet->tq, batadv_ogm_packet->ttl, ((batadv_ogm_packet->flags & BATADV_DIRECTLINK) ? "on" : "off"), hard_iface->net_dev->name, hard_iface->net_dev->dev_addr); buff_pos += BATADV_OGM_HLEN; buff_pos += ntohs(batadv_ogm_packet->tvlv_len); packet_num++; packet_pos = forw_packet->skb->data + buff_pos; batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; } /* create clone because function is called more than once */ skb = skb_clone(forw_packet->skb, GFP_ATOMIC); if (skb) { batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_TX); batadv_add_counter(bat_priv, BATADV_CNT_MGMT_TX_BYTES, skb->len + ETH_HLEN); batadv_send_broadcast_skb(skb, hard_iface); } }


marek lindnermarek lindner20968.98%314.29%
sven eckelmannsven eckelmann7223.76%1571.43%
martin hundebollmartin hundeboll206.60%14.76%
markus pargmannmarkus pargmann10.33%14.76%
antonio quartulliantonio quartulli10.33%14.76%

/* send a batman ogm packet */
static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet) { struct net_device *soft_iface; struct batadv_priv *bat_priv; struct batadv_hard_iface *primary_if = NULL; if (!forw_packet->if_incoming) { pr_err("Error - can't forward packet: incoming iface not specified\n"); goto out; } soft_iface = forw_packet->if_incoming->soft_iface; bat_priv = netdev_priv(soft_iface); if (WARN_ON(!forw_packet->if_outgoing)) goto out; if (WARN_ON(forw_packet->if_outgoing->soft_iface != soft_iface)) goto out; if (forw_packet->if_incoming->if_status != BATADV_IF_ACTIVE) goto out; primary_if = batadv_primary_if_get_selected(bat_priv); if (!primary_if) goto out; /* only for one specific outgoing interface */ batadv_iv_ogm_send_to_if(forw_packet, forw_packet->if_outgoing); out: if (primary_if) batadv_hardif_put(primary_if); }


marek lindnermarek lindner9971.74%228.57%
simon wunderlichsimon wunderlich3223.19%114.29%
sven eckelmannsven eckelmann75.07%457.14%

/** * batadv_iv_ogm_can_aggregate - find out if an OGM can be aggregated on an * existing forward packet * @new_bat_ogm_packet: OGM packet to be aggregated * @bat_priv: the bat priv with all the soft interface information * @packet_len: (total) length of the OGM * @send_time: timestamp (jiffies) when the packet is to be sent * @directlink: true if this is a direct link packet * @if_incoming: interface where the packet was received * @if_outgoing: interface for which the retransmission should be considered * @forw_packet: the forwarded packet which should be checked * * Return: true if new_packet can be aggregated with forw_packet */
static bool batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet, struct batadv_priv *bat_priv, int packet_len, unsigned long send_time, bool directlink, const struct batadv_hard_iface *if_incoming, const struct batadv_hard_iface *if_outgoing, const struct batadv_forw_packet *forw_packet) { struct batadv_ogm_packet *batadv_ogm_packet; int aggregated_bytes = forw_packet->packet_len + packet_len; struct batadv_hard_iface *primary_if = NULL; bool res = false; unsigned long aggregation_end_time; batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data; aggregation_end_time = send_time; aggregation_end_time += msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS); /* we can aggregate the current packet to this aggregated packet * if: * * - the send time is within our MAX_AGGREGATION_MS time * - the resulting packet wont be bigger than * MAX_AGGREGATION_BYTES * otherwise aggregation is not possible */ if (!time_before(send_time, forw_packet->send_time) || !time_after_eq(aggregation_end_time, forw_packet->send_time)) return false; if (aggregated_bytes > BATADV_MAX_AGGREGATION_BYTES) return false; /* packet is not leaving on the same interface. */ if (forw_packet->if_outgoing != if_outgoing) return false; /* check aggregation compatibility * -> direct link packets are broadcasted on * their interface only * -> aggregate packet if the current packet is * a "global" packet as well as the base * packet */ primary_if = batadv_primary_if_get_selected(bat_priv); if (!primary_if) return false; /* packets without direct link flag and high TTL * are flooded through the net */ if (!directlink && !(batadv_ogm_packet->flags & BATADV_DIRECTLINK) && batadv_ogm_packet->ttl != 1 && /* own packets originating non-primary * interfaces leave only that interface */ (!forw_packet->own || forw_packet->if_incoming == primary_if)) { res = true; goto out; } /* if the incoming packet is sent via this one * interface only - we still can aggregate */ if (directlink && new_bat_ogm_packet->ttl == 1 && forw_packet->if_incoming == if_incoming && /* packets from direct neighbors or * own secondary interface packets * (= secondary interface packets in general) */ (batadv_ogm_packet->flags & BATADV_DIRECTLINK || (forw_packet->own && forw_packet->if_incoming != primary_if))) { res = true; goto out; } out: if (primary_if) batadv_hardif_put(primary_if); return res; }


marek lindnermarek lindner19171.54%110.00%
sven eckelmannsven eckelmann3613.48%770.00%
markus pargmannmarkus pargmann3412.73%110.00%
simon wunderlichsimon wunderlich62.25%110.00%

/** * batadv_iv_ogm_aggregate_new - create a new aggregated packet and add this * packet to it. * @packet_buff: pointer to the OGM * @packet_len: (total) length of the OGM * @send_time: timestamp (jiffies) when the packet is to be sent * @direct_link: whether this OGM has direct link status * @if_incoming: interface where the packet was received * @if_outgoing: interface for which the retransmission should be considered * @own_packet: true if it is a self-generated ogm */
static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, int packet_len, unsigned long send_time, bool direct_link, struct batadv_hard_iface *if_incoming, struct batadv_hard_iface *if_outgoing, int own_packet) { struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct batadv_forw_packet *forw_packet_aggr; unsigned char *skb_buff; unsigned int skb_size; /* own packet should always be scheduled */ if (!own_packet) { if (!batadv_atomic_dec_not_zero(&bat_priv->batman_queue_left)) { batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "batman packet queue full\n"); return; } } forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC); if (!forw_packet_aggr) goto out_nomem; if (atomic_read(&bat_priv->aggregated_ogms) && packet_len < BATADV_MAX_AGGREGATION_BYTES) skb_size = BATADV_MAX_AGGREGATION_BYTES; else skb_size = packet_len; skb_size += ETH_HLEN; forw_packet_aggr->skb = netdev_alloc_skb_ip_align(NULL, skb_size); if (!forw_packet_aggr->skb) goto out_free_forw_packet; forw_packet_aggr->skb->priority = TC_PRIO_CONTROL; skb_reserve(forw_packet_aggr->skb, ETH_HLEN); skb_buff = skb_put(forw_packet_aggr->skb, packet_len); forw_packet_aggr->packet_len = packet_len; memcpy(skb_buff, packet_buff, packet_len); kref_get(&if_incoming->refcount); kref_get(&if_outgoing->refcount); forw_packet_aggr->own = own_packet; forw_packet_aggr->if_incoming = if_incoming; forw_packet_aggr->if_outgoing = if_outgoing; forw_packet_aggr->num_packets = 0; forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS; forw_packet_aggr->send_time = send_time; /* save packet direct link flag status */ if (direct_link) forw_packet_aggr->direct_link_flags |= 1; /* add new packet to packet list */ spin_lock_bh(&bat_priv->forw_bat_list_lock); hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list); spin_unlock_bh(&bat_priv->forw_bat_list_lock); /* start timer for this packet */ INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, batadv_iv_send_outstanding_bat_ogm_packet); queue_delayed_work(batadv_event_workqueue, &forw_packet_aggr->delayed_work, send_time - jiffies); return; out_free_forw_packet: kfree(forw_packet_aggr); out_nomem: if (!own_packet) atomic_inc(&bat_priv->batman_queue_left); }


marek lindnermarek lindner25573.91%16.25%
sven eckelmannsven eckelmann4212.17%956.25%
markus pargmannmarkus pargmann246.96%16.25%
simon wunderlichsimon wunderlich195.51%212.50%
antonio quartulliantonio quartulli51.45%318.75%

/* aggregate a new packet into the existing ogm packet */
static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr, const unsigned char *packet_buff, int packet_len, bool direct_link) { unsigned char *skb_buff; unsigned long new_direct_link_flag; skb_buff = skb_put(forw_packet_aggr->skb, packet_len); memcpy(skb_buff, packet_buff, packet_len); forw_packet_aggr->packet_len += packet_len; forw_packet_aggr->num_packets++; /* save packet direct link flag status */ if (direct_link) { new_direct_link_flag = BIT(forw_packet_aggr->num_packets); forw_packet_aggr