]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
net: ip_queue_rcv_skb() helper
authorEric Dumazet <eric.dumazet@gmail.com>
Wed, 28 Apr 2010 22:31:51 +0000 (15:31 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 28 Apr 2010 22:31:51 +0000 (15:31 -0700)
When queueing a skb to socket, we can immediately release its dst if
target socket do not use IP_CMSG_PKTINFO.

tcp_data_queue() can drop dst too.

This to benefit from a hot cache line and avoid the receiver, possibly
on another cpu, to dirty this cache line himself.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
net/ipv4/ip_sockglue.c
net/ipv4/raw.c
net/ipv4/tcp_input.c
net/ipv4/udp.c
net/ipv6/raw.c
net/ipv6/udp.c

index a84ceb692687c57e50b7bd5d2a989d3b17e481a0..8149b77cea9b30e9199bb8609e8deb11147b7220 100644 (file)
@@ -393,6 +393,7 @@ extern int ip_options_rcv_srr(struct sk_buff *skb);
  *     Functions provided by ip_sockglue.c
  */
 
+extern int     ip_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
 extern void    ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb);
 extern int     ip_cmsg_send(struct net *net,
                             struct msghdr *msg, struct ipcm_cookie *ipc);
index b0aa0546a3b317ef9210645437792e5a4ae09dcc..ce231780a2b14ef4e15a33baad4b0c887e96df16 100644 (file)
@@ -954,6 +954,22 @@ e_inval:
        return -EINVAL;
 }
 
+/**
+ * ip_queue_rcv_skb - Queue an skb into sock receive queue
+ * @sk: socket
+ * @skb: buffer
+ *
+ * Queues an skb into socket receive queue. If IP_CMSG_PKTINFO option
+ * is not set, we drop skb dst entry now, while dst cache line is hot.
+ */
+int ip_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
+{
+       if (!(inet_sk(sk)->cmsg_flags & IP_CMSG_PKTINFO))
+               skb_dst_drop(skb);
+       return sock_queue_rcv_skb(sk, skb);
+}
+EXPORT_SYMBOL(ip_queue_rcv_skb);
+
 int ip_setsockopt(struct sock *sk, int level,
                int optname, char __user *optval, unsigned int optlen)
 {
index cc6f097fbd5fb9a24ce0b80737f6973ee48e3b7a..52ef5af78a45e0ea012fb91636ea00abbf9ec3ac 100644 (file)
@@ -290,7 +290,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
 {
        /* Charge it to the socket. */
 
-       if (sock_queue_rcv_skb(sk, skb) < 0) {
+       if (ip_queue_rcv_skb(sk, skb) < 0) {
                kfree_skb(skb);
                return NET_RX_DROP;
        }
index ae3ec15fb630575a6e04d35e9630f7d0e08bf696..e82162c211bf8ba2c26841da4a505fe54b42a7d5 100644 (file)
@@ -4367,6 +4367,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
        if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq)
                goto drop;
 
+       skb_dst_drop(skb);
        __skb_pull(skb, th->doff * 4);
 
        TCP_ECN_accept_cwr(tp, skb);
index 1f86965ba7d72e146bed86cae4d84240ea7e3f34..4560b291180ba433e6df630b0b8a6599dbbb165f 100644 (file)
@@ -1264,7 +1264,7 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
        if (inet_sk(sk)->inet_daddr)
                sock_rps_save_rxhash(sk, skb->rxhash);
 
-       rc = sock_queue_rcv_skb(sk, skb);
+       rc = ip_queue_rcv_skb(sk, skb);
        if (rc < 0) {
                int is_udplite = IS_UDPLITE(sk);
 
index 85627386cb02abcf557556fe4e329eb7f7022e4b..0e3d2dd920783244c55194746c78db243d5efa39 100644 (file)
@@ -381,7 +381,7 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
        }
 
        /* Charge it to the socket. */
-       if (sock_queue_rcv_skb(sk, skb) < 0) {
+       if (ip_queue_rcv_skb(sk, skb) < 0) {
                kfree_skb(skb);
                return NET_RX_DROP;
        }
index 91c60f0090a4734dd1dfa1b2995d229d44d2a4b4..79359c8380bc84a4726744059acecb73d079b6a4 100644 (file)
@@ -514,7 +514,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
                        goto drop;
        }
 
-       if ((rc = sock_queue_rcv_skb(sk, skb)) < 0) {
+       if ((rc = ip_queue_rcv_skb(sk, skb)) < 0) {
                /* Note that an ENOMEM error is charged twice */
                if (rc == -ENOMEM)
                        UDP6_INC_STATS_BH(sock_net(sk),