codingfreak
codingfreak

Reputation: 4595

Increasing the reference count of a SKB

Is there any simple way I can increase the reference count of SKB buffer in linux kernel so that the hardware wont free it.

I know that using skb_clone the reference count is automatically increased but I would like to know without creating a clone how can I increase the SKB reference count.

My purpose is to send the same packet multiple times and I dont want to do a skb_clone every time for this operation as I want to reuse the same memory.

Sample code I am using to the same SKB is as shown below

  for (i=0;i<=100;i++)
  {
    tmp_skb = skb_get(skb);
    if (tmp_skb == NULL)
    {
      printk ("Clone Failed");
      continue;
    }

    if ( (err = dev_queue_xmit(tmp_skb)) != NETDEV_TX_OK) {
      if(unlikely(enable_error))
        printk("ERROR - DEV QUEUE FAILED %d\n", err);

      err = -ENETDOWN; /* Probably we need a better error here */
      continue;
    }

    if (i==100)
    {
     printk("Loop is done\n");
     kfree_skb(skb);
     return(len);
    }
  }

Upvotes: 3

Views: 2218

Answers (1)

Ilya Matveychikov
Ilya Matveychikov

Reputation: 4024

Try to get an skb via the skb_get method:

758 /**
759  *      skb_get - reference buffer
760  *      @skb: buffer to reference
761  *
762  *      Makes another reference to a socket buffer and returns a pointer
763  *      to the buffer.
764  */
765 static inline struct sk_buff *skb_get(struct sk_buff *skb)
766 {
767         atomic_inc(&skb->users);
768         return skb;
769 }

Upvotes: 2

Related Questions