From patchwork Sun Jun 27 15:46:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 108271 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5RFqOms002717 for ; Sun, 27 Jun 2010 15:52:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755703Ab0F0PwV (ORCPT ); Sun, 27 Jun 2010 11:52:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8519 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755482Ab0F0PwT (ORCPT ); Sun, 27 Jun 2010 11:52:19 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5RFq0Y1021138 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 27 Jun 2010 11:52:00 -0400 Received: from redhat.com (vpn1-7-98.ams2.redhat.com [10.36.7.98]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o5RFpuIe022758; Sun, 27 Jun 2010 11:51:56 -0400 Date: Sun, 27 Jun 2010 18:46:57 +0300 From: "Michael S. Tsirkin" To: Sridhar Samudrala , "David S. Miller" , Arnd Bergmann , "Paul E. McKenney" , kvm@vger.kernel.org, virtualization@lists.osdl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC] vhost-net: add dhclient work-around from userspace Message-ID: <20100627154657.GA9723@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100626.200320.43025947.davem@davemloft.net> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 27 Jun 2010 15:52:25 +0000 (UTC) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 54096ee..9ed4051 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -25,6 +25,10 @@ #include #include +#include +#include +#include + #include #include "vhost.h" @@ -191,6 +195,42 @@ static void handle_tx(struct vhost_net *net) unuse_mm(net->dev.mm); } +static int peek_head(struct sock *sk) +{ + struct sk_buff *head; + int ret; + + lock_sock(sk); + head = skb_peek(&sk->sk_receive_queue); + if (likely(head)) { + ret = 1; + /* Userspace virtio server has the following hack so + * guests rely on it, and we have to replicate it, too: */ + /* On linux guests, some apps that use recvmsg with AF_PACKET + * sockets, don't know how to handle CHECKSUM_PARTIAL; + * The interface to return the relevant information was added in + * 8dc4194474159660d7f37c495e3fc3f10d0db8cc, + * and older userspace does not use it. + * One important user of recvmsg with AF_PACKET is dhclient, + * so we add a work-around just for DHCP. */ + /* We use source port to detect DHCP packets. */ + if (skb->ip_summed == CHECKSUM_PARTIAL && + skb->protocol == htons(ETH_P_IP) && + skb_network_header_len(skb) >= sizeof(struct iphdr) && + ip_hdr(skb)->protocol == IPPRODO_UDP && + skb_headlen(skb) >= skb_transport_offset(skb) + sizeof(struct udphdr) && + udp_hdr(skb)->source == htons(0x67)) { + skb_checksum_help(skb); + /* Restore ip_summed value: tun passes it to user. */ + skb->ip_summed = CHECKSUM_PARTIAL; + } + } else { + ret = 0; + } + release_sock(sk); + return len; +} + /* Expects to be always run from workqueue - which acts as * read-size critical section for our kind of RCU. */ static void handle_rx(struct vhost_net *net) @@ -228,7 +268,7 @@ static void handle_rx(struct vhost_net *net) vq_log = unlikely(vhost_has_feature(&net->dev, VHOST_F_LOG_ALL)) ? vq->log : NULL; - for (;;) { + while (peek_head(sock)) { head = vhost_get_vq_desc(&net->dev, vq, vq->iov, ARRAY_SIZE(vq->iov), &out, &in,