From patchwork Mon Jun 28 10:08:07 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: 108328 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 o5SATJtA026092 for ; Mon, 28 Jun 2010 10:30:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751438Ab0F1KNT (ORCPT ); Mon, 28 Jun 2010 06:13:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12001 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751398Ab0F1KNS (ORCPT ); Mon, 28 Jun 2010 06:13:18 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5SAD9cX023733 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 Jun 2010 06:13:09 -0400 Received: from redhat.com (vpn2-11-23.ams2.redhat.com [10.36.11.23]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o5SAD5KH011548; Mon, 28 Jun 2010 06:13:05 -0400 Date: Mon, 28 Jun 2010 13:08:07 +0300 From: "Michael S. Tsirkin" To: "Michael S. Tsirkin" , Aristeu Rozanski , Herbert Xu , Juan Quintela , "David S. Miller" , kvm@vger.kernel.org, virtualization@lists.osdl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, ykaul@redhat.com, markmc@redhat.com Subject: [PATCHv2] vhost-net: add dhclient work-around from userspace Message-ID: <20100628100807.GA30685@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 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]); Mon, 28 Jun 2010 10:30:18 +0000 (UTC) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index cc19595..03bba6a 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -24,6 +24,10 @@ #include #include +#include +#include +#include + #include #include "vhost.h" @@ -186,6 +190,44 @@ static void handle_tx(struct vhost_net *net) unuse_mm(net->dev.mm); } +static int peek_head(struct sock *sk) +{ + struct sk_buff *skb; + + lock_sock(sk); + skb = skb_peek(&sk->sk_receive_queue); + if (unlikely(!skb)) { + release_sock(sk); + return 0; + } + /* Userspace virtio server has the following hack so + * guests rely on it, and we have to replicate it, too: */ + /* Use port number to detect incoming IPv4 DHCP response packets, + * and fill in the checksum. */ + + /* The issue we are solving is that 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. */ + if (skb->ip_summed == CHECKSUM_PARTIAL && + skb_headlen(skb) >= skb_transport_offset(skb) + + sizeof(struct udphdr) && + udp_hdr(skb)->dest == htons(68) && + skb_network_header_len(skb) >= sizeof(struct iphdr) && + ip_hdr(skb)->protocol == IPPROTO_UDP && + skb->protocol == htons(ETH_P_IP)) { + skb_checksum_help(skb); + /* Restore ip_summed value: tun passes it to user. */ + skb->ip_summed = CHECKSUM_PARTIAL; + } + release_sock(sk); + return 1; +} + /* 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) @@ -222,7 +264,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->sk)) { head = vhost_get_vq_desc(&net->dev, vq, vq->iov, ARRAY_SIZE(vq->iov), &out, &in,