From: Ben Pfaff Date: Thu, 13 Nov 2008 20:48:02 +0000 (-0800) Subject: Copy skbs when we save them. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=304ff22391e84f100b5d9190cfe9b9a987f1b29c;p=openvswitch Copy skbs when we save them. --- diff --git a/datapath/forward.c b/datapath/forward.c index ed092fea..33b3a5e2 100644 --- a/datapath/forward.c +++ b/datapath/forward.c @@ -465,6 +465,11 @@ uint32_t fwd_save_skb(struct sk_buff *skb) unsigned long int flags; uint32_t id; + /* FIXME: Probably just need a skb_clone() here. */ + skb = skb_copy(skb, GFP_ATOMIC); + if (!skb) + return -1; + spin_lock_irqsave(&buffer_lock, flags); buffer_idx = (buffer_idx + 1) & PKT_BUFFER_MASK; p = &buffers[buffer_idx]; @@ -473,9 +478,13 @@ uint32_t fwd_save_skb(struct sk_buff *skb) * OVERWRITE_SECS old. */ if (time_before(jiffies, p->exp_jiffies)) { spin_unlock_irqrestore(&buffer_lock, flags); + kfree_skb(skb); return -1; } else { - /* Defer kfree_skb() until interrupts re-enabled. */ + /* Defer kfree_skb() until interrupts re-enabled. + * FIXME: we only need to do that if it has a + * destructor, but it never should since we orphan + * sk_buffs on entry. */ old_skb = p->skb; } } @@ -483,7 +492,6 @@ uint32_t fwd_save_skb(struct sk_buff *skb) * special. */ if (++p->cookie >= (1u << PKT_COOKIE_BITS) - 1) p->cookie = 0; - skb_get(skb); p->skb = skb; p->exp_jiffies = jiffies + OVERWRITE_JIFFIES; id = buffer_idx | (p->cookie << PKT_BUFFER_BITS);