Skip to content

Commit a006aa5

Browse files
T-Xecsv
authored andcommitted
batman-adv: bcast: remove remaining skb-copy calls
We currently have two code paths for broadcast packets: A) self-generated, via batadv_interface_tx()-> batadv_send_bcast_packet(). B) received/forwarded, via batadv_recv_bcast_packet()-> batadv_forw_bcast_packet(). For A), self-generated broadcast packets: The only modifications to the skb data is the ethernet header which is added/pushed to the skb in batadv_send_broadcast_skb()->batadv_send_skb_packet(). However before doing so, batadv_skb_head_push() is called which calls skb_cow_head() to unshare the space for the to be pushed ethernet header. So for this case, it is safe to use skb clones. For B), received/forwarded packets: The same applies as in A) for the to be forwarded packets. Only the ethernet header is added. However after (queueing for) forwarding the packet in batadv_recv_bcast_packet()->batadv_forw_bcast_packet(), a packet is additionally decapsulated and is sent up the stack through batadv_recv_bcast_packet()->batadv_interface_rx(). Protocols higher up the stack are already required to check if the packet is shared and create a copy for further modifications. When the next (protocol) layer works correctly, it cannot happen that it tries to operate on the data behind the skb clone which is still queued up for forwarding. Co-authored-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
1 parent a2b7b14 commit a006aa5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

net/batman-adv/send.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,10 @@ void batadv_forw_packet_ogmv1_queue(struct batadv_priv *bat_priv,
742742
* Adds a broadcast packet to the queue and sets up timers. Broadcast packets
743743
* are sent multiple times to increase probability for being received.
744744
*
745+
* This call clones the given skb, hence the caller needs to take into
746+
* account that the data segment of the original skb might not be
747+
* modifiable anymore.
748+
*
745749
* Return: NETDEV_TX_OK on success and NETDEV_TX_BUSY on errors.
746750
*/
747751
static int batadv_forw_bcast_packet_to_list(struct batadv_priv *bat_priv,
@@ -755,7 +759,7 @@ static int batadv_forw_bcast_packet_to_list(struct batadv_priv *bat_priv,
755759
unsigned long send_time = jiffies;
756760
struct sk_buff *newskb;
757761

758-
newskb = skb_copy(skb, GFP_ATOMIC);
762+
newskb = skb_clone(skb, GFP_ATOMIC);
759763
if (!newskb)
760764
goto err;
761765

@@ -794,6 +798,10 @@ static int batadv_forw_bcast_packet_to_list(struct batadv_priv *bat_priv,
794798
* or if a delay is given after that. Furthermore, queues additional
795799
* retransmissions if this interface is a wireless one.
796800
*
801+
* This call clones the given skb, hence the caller needs to take into
802+
* account that the data segment of the original skb might not be
803+
* modifiable anymore.
804+
*
797805
* Return: NETDEV_TX_OK on success and NETDEV_TX_BUSY on errors.
798806
*/
799807
static int batadv_forw_bcast_packet_if(struct batadv_priv *bat_priv,
@@ -808,7 +816,7 @@ static int batadv_forw_bcast_packet_if(struct batadv_priv *bat_priv,
808816
int ret = NETDEV_TX_OK;
809817

810818
if (!delay) {
811-
newskb = skb_copy(skb, GFP_ATOMIC);
819+
newskb = skb_clone(skb, GFP_ATOMIC);
812820
if (!newskb)
813821
return NETDEV_TX_BUSY;
814822

0 commit comments

Comments
 (0)