]> git.hungrycats.org Git - linux/commitdiff
[NETLINK]: Trim SKBs at netlink_{unicast,broadcast}() time.
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 28 Sep 2004 07:44:58 +0000 (00:44 -0700)
committerDavid S. Miller <davem@nuts.davemloft.net>
Tue, 28 Sep 2004 07:44:58 +0000 (00:44 -0700)
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netlink/af_netlink.c

index 671071666d0944a1ffc8f31ed5810d0b310b24e0..8bcf3f30f306889923e6f11ecacb70b66d9ad334 100644 (file)
@@ -536,12 +536,25 @@ void netlink_detachskb(struct sock *sk, struct sk_buff *skb)
        sock_put(sk);
 }
 
+static inline void netlink_trim(struct sk_buff *skb, int allocation)
+{
+       int delta = skb->end - skb->tail;
+
+       if (delta * 2 < skb->truesize)
+               return;
+       if (pskb_expand_head(skb, 0, -delta, allocation))
+               return;
+       skb->truesize -= delta;
+}
+
 int netlink_unicast(struct sock *ssk, struct sk_buff *skb, u32 pid, int nonblock)
 {
        struct sock *sk;
        int err;
        long timeo;
 
+       netlink_trim(skb, gfp_any());
+
        timeo = sock_sndtimeo(ssk, nonblock);
 retry:
        sk = netlink_getsockbypid(ssk, pid);
@@ -588,6 +601,8 @@ int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 pid,
        int protocol = ssk->sk_protocol;
        int failure = 0, delivered = 0;
 
+       netlink_trim(skb, allocation);
+
        /* While we sleep in clone, do not allow to change socket list */
 
        netlink_lock_table();