提交 99ba18ef 编写于 作者: L Linus Lüssing 提交者: Simon Wunderlich

batman-adv: privatize forw_packet skb assignment

An skb is assigned to a forw_packet only once, shortly after the
forw_packet allocation.

With this patch the assignment is moved into the this allocation
function.
Signed-off-by: NLinus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: NSven Eckelmann <sven@narfation.org>
Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
上级 a3a5129e
...@@ -679,15 +679,11 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, ...@@ -679,15 +679,11 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
{ {
struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
struct batadv_forw_packet *forw_packet_aggr; struct batadv_forw_packet *forw_packet_aggr;
struct sk_buff *skb;
unsigned char *skb_buff; unsigned char *skb_buff;
unsigned int skb_size; unsigned int skb_size;
atomic_t *queue_left = own_packet ? NULL : &bat_priv->batman_queue_left; atomic_t *queue_left = own_packet ? NULL : &bat_priv->batman_queue_left;
forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,
queue_left, bat_priv);
if (!forw_packet_aggr)
return;
if (atomic_read(&bat_priv->aggregated_ogms) && if (atomic_read(&bat_priv->aggregated_ogms) &&
packet_len < BATADV_MAX_AGGREGATION_BYTES) packet_len < BATADV_MAX_AGGREGATION_BYTES)
skb_size = BATADV_MAX_AGGREGATION_BYTES; skb_size = BATADV_MAX_AGGREGATION_BYTES;
...@@ -696,9 +692,14 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, ...@@ -696,9 +692,14 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
skb_size += ETH_HLEN; skb_size += ETH_HLEN;
forw_packet_aggr->skb = netdev_alloc_skb_ip_align(NULL, skb_size); skb = netdev_alloc_skb_ip_align(NULL, skb_size);
if (!forw_packet_aggr->skb) { if (!skb)
batadv_forw_packet_free(forw_packet_aggr, true); return;
forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,
queue_left, bat_priv, skb);
if (!forw_packet_aggr) {
kfree_skb(skb);
return; return;
} }
......
...@@ -482,6 +482,7 @@ void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet, ...@@ -482,6 +482,7 @@ void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
* @if_outgoing: The (optional) if_outgoing to be grabbed * @if_outgoing: The (optional) if_outgoing to be grabbed
* @queue_left: The (optional) queue counter to decrease * @queue_left: The (optional) queue counter to decrease
* @bat_priv: The bat_priv for the mesh of this forw_packet * @bat_priv: The bat_priv for the mesh of this forw_packet
* @skb: The raw packet this forwarding packet shall contain
* *
* Allocates a forwarding packet and tries to get a reference to the * Allocates a forwarding packet and tries to get a reference to the
* (optional) if_incoming, if_outgoing and queue_left. If queue_left * (optional) if_incoming, if_outgoing and queue_left. If queue_left
...@@ -493,7 +494,8 @@ struct batadv_forw_packet * ...@@ -493,7 +494,8 @@ struct batadv_forw_packet *
batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming, batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
struct batadv_hard_iface *if_outgoing, struct batadv_hard_iface *if_outgoing,
atomic_t *queue_left, atomic_t *queue_left,
struct batadv_priv *bat_priv) struct batadv_priv *bat_priv,
struct sk_buff *skb)
{ {
struct batadv_forw_packet *forw_packet; struct batadv_forw_packet *forw_packet;
const char *qname; const char *qname;
...@@ -525,7 +527,7 @@ batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming, ...@@ -525,7 +527,7 @@ batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
INIT_HLIST_NODE(&forw_packet->list); INIT_HLIST_NODE(&forw_packet->list);
INIT_HLIST_NODE(&forw_packet->cleanup_list); INIT_HLIST_NODE(&forw_packet->cleanup_list);
forw_packet->skb = NULL; forw_packet->skb = skb;
forw_packet->queue_left = queue_left; forw_packet->queue_left = queue_left;
forw_packet->if_incoming = if_incoming; forw_packet->if_incoming = if_incoming;
forw_packet->if_outgoing = if_outgoing; forw_packet->if_outgoing = if_outgoing;
...@@ -756,22 +758,23 @@ int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv, ...@@ -756,22 +758,23 @@ int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
if (!primary_if) if (!primary_if)
goto err; goto err;
newskb = skb_copy(skb, GFP_ATOMIC);
if (!newskb) {
batadv_hardif_put(primary_if);
goto err;
}
forw_packet = batadv_forw_packet_alloc(primary_if, NULL, forw_packet = batadv_forw_packet_alloc(primary_if, NULL,
&bat_priv->bcast_queue_left, &bat_priv->bcast_queue_left,
bat_priv); bat_priv, newskb);
batadv_hardif_put(primary_if); batadv_hardif_put(primary_if);
if (!forw_packet) if (!forw_packet)
goto err;
newskb = skb_copy(skb, GFP_ATOMIC);
if (!newskb)
goto err_packet_free; goto err_packet_free;
/* as we have a copy now, it is safe to decrease the TTL */ /* as we have a copy now, it is safe to decrease the TTL */
bcast_packet = (struct batadv_bcast_packet *)newskb->data; bcast_packet = (struct batadv_bcast_packet *)newskb->data;
bcast_packet->ttl--; bcast_packet->ttl--;
forw_packet->skb = newskb;
forw_packet->own = own_packet; forw_packet->own = own_packet;
INIT_DELAYED_WORK(&forw_packet->delayed_work, INIT_DELAYED_WORK(&forw_packet->delayed_work,
...@@ -781,7 +784,7 @@ int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv, ...@@ -781,7 +784,7 @@ int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
return NETDEV_TX_OK; return NETDEV_TX_OK;
err_packet_free: err_packet_free:
batadv_forw_packet_free(forw_packet, true); kfree_skb(newskb);
err: err:
return NETDEV_TX_BUSY; return NETDEV_TX_BUSY;
} }
......
...@@ -34,7 +34,8 @@ struct batadv_forw_packet * ...@@ -34,7 +34,8 @@ struct batadv_forw_packet *
batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming, batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
struct batadv_hard_iface *if_outgoing, struct batadv_hard_iface *if_outgoing,
atomic_t *queue_left, atomic_t *queue_left,
struct batadv_priv *bat_priv); struct batadv_priv *bat_priv,
struct sk_buff *skb);
bool batadv_forw_packet_steal(struct batadv_forw_packet *packet, spinlock_t *l); bool batadv_forw_packet_steal(struct batadv_forw_packet *packet, spinlock_t *l);
void batadv_forw_packet_ogmv1_queue(struct batadv_priv *bat_priv, void batadv_forw_packet_ogmv1_queue(struct batadv_priv *bat_priv,
struct batadv_forw_packet *forw_packet, struct batadv_forw_packet *forw_packet,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册